UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-12-03)
testUsBSpline3D.cpp

USTK usBSpline3D test

This example tests all functions declared in the usBSpline3D class.

/****************************************************************************
*
* This file is part of the UsNeedleDetection software.
* Copyright (C) 2013 - 2016 by Inria. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License ("GPL") as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* See the file COPYING at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* This software was developed at:
* INRIA Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
* http://www.irisa.fr/lagadic
*
* If you have questions regarding the use of this file, please contact the
* authors at Alexandre.Krupa@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author:
* Jason Chevrie
*
*****************************************************************************/
#include <visp3/ustk_core/usBSpline3D.h>
#include <vector>
#include <visp3/core/vpColVector.h>
#include <visp3/core/vpHomogeneousMatrix.h>
int main()
{
std::cout << "Start testUsBSpline3D" << std::endl;
usBSpline3D spline;
std::cout << "done: usBSpline3D default contructor" << std::endl;
usBSpline3D spline2(spline);
std::cout << "done: usBSpline3D copy contructor" << std::endl;
spline = spline2;
std::cout << "done: usBSpline3D assignment operator" << std::endl;
usBSpline3D *spline3 = spline.clone();
std::cout << "done: usBSpline3D polymorphic copy" << std::endl;
std::vector<vpColVector> points(4, vpColVector(3, 0));
points.at(1)[0] = 1;
points.at(2)[1] = 2;
points.at(3)[2] = 1;
std::vector<double> params(4, 0);
for (int i = 0; i < 4; i++)
params[i] = i;
curve1.defineFromPoints(points, params, 3);
usPolynomialCurve3D curve2(curve1);
curve2.move(1, 0.5, 0, 1, 0, 0);
usPolynomialCurve3D curve3(curve2);
curve3.move(-0.5, 0, -0.5, 0, 1, 0.5);
spline.addSegment(curve1);
std::cout << "done: usBSpline3D::addSegment" << std::endl;
spline.addSegment(curve3);
spline.insertSegment(1, curve1);
std::cout << "done: usBSpline3D::insertSegment" << std::endl;
spline.setSegment(1, curve2);
std::cout << "done: usBSpline3D::setSegment" << std::endl;
spline.removeSegment(1);
std::cout << "done: usBSpline3D::removeSegment" << std::endl;
std::cout << "done: usBSpline3D::removeLastSegment" << std::endl;
spline.addSegment(curve2);
spline.addSegment(curve3);
spline.removeSegments(1, 2);
std::cout << "done: usBSpline3D::removeSegments" << std::endl;
spline.getNbSegments();
std::cout << "done: usBSpline3D::getNbSegments" << std::endl;
std::cout << "done: usBSpline3D::getParametricLength" << std::endl;
spline.getLength(100);
std::cout << "done: usBSpline3D::getLength" << std::endl;
spline.clear();
std::cout << "done: usBSpline3D::clear" << std::endl;
std::vector<double> lengths(3, 1);
spline.defineFromPoints(points, lengths, 3);
std::cout << "done: usBSpline3D::defineFromPoints" << std::endl;
curve2 = spline.accessSegment(1);
std::cout << "done: usBSpline3D::accessSegment const" << std::endl;
curve3 = spline.accessLastSegment();
std::cout << "done: usBSpline3D::accessLastSegment const" << std::endl;
spline.accessSegment(1) = curve2;
std::cout << "done: usBSpline3D::addSegment" << std::endl;
spline.accessLastSegment() = curve3;
std::cout << "done: usBSpline3D::addSegment" << std::endl;
*spline3 = spline.getSubSpline(0.5, 1.5);
std::cout << "done: usBSpline3D::getSubSpline" << std::endl;
spline.move(vpHomogeneousMatrix(0.5, -0.25, 0.1, 1, -1, 0.2));
std::cout << "done: usBSpline3D::move(const vpHomogeneousMatrix&)" << std::endl;
spline.move(0.5, -0.25, 0.1, 1, -1, 0.2);
std::cout << "done: usBSpline3D::move(double,double,double,double,double,double)" << std::endl;
spline.getPoint(1.2);
std::cout << "done: usBSpline3D::getPoint" << std::endl;
spline.getTangent(1.2);
std::cout << "done: usBSpline3D::getTangent" << std::endl;
spline.getDistanceFromPoint(points.at(1), 0, -1, 1e-6);
std::cout << "done: usBSpline3D::getDistanceFromPoint" << std::endl;
int index;
double param;
spline.getParametersFromLength(1.5, index, param);
std::cout << "done: usBSpline3D::getParametersFromLength" << std::endl;
vpColVector center3D;
vpColVector direction3D;
spline.getCurvatureFromShape(0, 1, center3D, direction3D);
std::cout << "done: usBSpline3D::getCurvatureFromShape" << std::endl;
delete spline3;
std::cout << "done: usBSpline3D::~usBSpline3D" << std::endl;
return 0;
}
void setSegment(int i, const usPolynomialCurve3D &poly)
Definition: usBSpline3D.cpp:90
double getLength(int nbSubSeg=50) const
Definition: usBSpline3D.cpp:70
void removeLastSegment()
Definition: usBSpline3D.cpp:92
bool getParametersFromLength(double l, int &index, double &param) const
void insertSegment(int i, const usPolynomialCurve3D &seg)
Definition: usBSpline3D.cpp:85
void clear()
Definition: usBSpline3D.cpp:98
void removeSegments(int i, int j)
Definition: usBSpline3D.cpp:96
double getDistanceFromPoint(const vpColVector &point, double start=0, double stop=-1, double threshold=1e-5) const
const usPolynomialCurve3D & accessSegment(int i) const
vpColVector getTangent(double param) const
void addSegment(const usPolynomialCurve3D &seg)
Spline definition.
Definition: usBSpline3D.cpp:79
int getNbSegments() const
Parameters setters and getters.
Definition: usBSpline3D.cpp:59
const usPolynomialCurve3D & accessLastSegment() const
bool move(const vpHomogeneousMatrix &H)
Move.
vpColVector getPoint(double param) const
Measure curve information.
virtual usBSpline3D * clone() const
Definition: usBSpline3D.cpp:57
usBSpline3D getSubSpline(double a, double b) const
double getCurvatureFromShape(double start, double end, vpColVector &center3D, vpColVector &direction3D) const
Curvature.
void defineFromPoints(const std::vector< vpColVector > &points, const std::vector< double > &lengths, int order=3)
void removeSegment(int i)
Definition: usBSpline3D.cpp:94
double getParametricLength() const
Definition: usBSpline3D.cpp:61
void defineFromPoints(const std::vector< vpColVector > &points, const std::vector< double > &param, unsigned int order=0)
void move(const vpHomogeneousMatrix &H)