33 #include <visp3/ustk_needle_modeling/usNeedleModelPolynomial.h>
37 #include <visp3/core/vpException.h>
38 #include <visp3/core/vpMatrix.h>
39 #include <visp3/core/vpRowVector.h>
40 #include <visp3/core/vpTime.h>
45 m_outerDiameter(0.001), m_insideDiameter(0), m_needleYoungModulus(200000000000)
53 m_outerDiameter(needle.m_outerDiameter), m_insideDiameter(needle.m_insideDiameter),
54 m_needleYoungModulus(needle.m_needleYoungModulus)
159 throw vpException(vpException::badValue,
"usNeedleModelPolynomial::getNeedlePoint: length out of needle");
167 throw vpException(vpException::badValue,
"usNeedleModelPolynomial::getNeedleDirection: length out of needle");
173 double threshold)
const
176 throw vpException(vpException::dimensionError,
177 "usNeedleModelPolynomial::getDistanceFromPoint: invalid point dimension");
186 throw vpException(vpException::badValue,
187 "usNeedleModelPolynomial::getDistanceFromPoint: invalid start-stop parameters");
189 double middle = (start + stop) / 2;
190 while ((stop - start) > threshold) {
195 if (d0 <= d1 && d0 < d2)
197 else if (d2 < d0 && d2 <= d1)
200 start = (start + middle) / 2;
201 stop = (middle + stop) / 2;
203 middle = (start + stop) / 2;
213 vpColVector Ls_pow(2 *
m_order - 2);
215 vpColVector Le_pow(2 *
m_order - 2);
218 for (
unsigned int i = 1; i < 2 *
m_order - 2; i++) {
227 for (
unsigned int i = 2; i <=
m_order; i++) {
228 for (
unsigned int j = 2; j <=
m_order; j++) {
229 E += i * (i - 1) * j * (j - 1) / (i + j - 3) * dotProd[i][j] * (Le_pow[i + j - 3] - Ls_pow[i + j - 3]);
233 E *= 0.5 * this->
getEI();
242 double EI = this->
getEI();
244 vpColVector Moment = EI * vpColVector::crossProd(this->
getDerivative(0, 1), d2X_dl2);
250 vpColVector Torsor(6);
251 Torsor[0] = Force[0];
252 Torsor[1] = Force[1];
253 Torsor[2] = Force[2];
254 Torsor[3] = Moment[0];
255 Torsor[4] = Moment[1];
256 Torsor[5] = Moment[2];
262 vpColVector &direction3D)
const
278 int subSegmentsNumber = 100;
279 int nbPoints = subSegmentsNumber + 1;
286 vpMatrix M(nbPoints, 3);
287 vpRowVector mean(3, 0);
290 for (
int i = 0; i < nbPoints; i++)
293 for (
int i = 0; i < nbPoints; i++)
297 for (
int i = 0; i < nbPoints; i++) {
312 U.resize(nbPoints, 2,
false);
314 S.resize(2, 2,
false);
319 vpColVector d(nbPoints);
320 for (
int i = 0; i < nbPoints; i++) {
321 d[i] = pow(P.t().getCol(i).frobeniusNorm(), 2);
324 vpColVector x(nbPoints, 1);
325 vpMatrix B(nbPoints, 3);
329 vpColVector y = B.pseudoInverse(0) * d;
331 vpColVector center(2);
332 center[0] = y[0] / 2;
333 center[1] = y[1] / 2;
335 double r = sqrt(y[2] + pow(center.frobeniusNorm(), 2));
339 vpColVector cp = P.getRow(0).t() - center;
340 for (
int i = 1; i < nbPoints; i++) {
341 double dot = vpColVector::dotProd(cp, P.getRow(i).t() - center);
346 if (direction3D.size() == 3) {
347 direction3D = V.getCol(2);
348 }
else if (direction3D.size() == 4) {
349 direction3D.insert(0, V.getCol(2));
353 if (center3D.size() == 3) {
354 V.resize(3, 2,
false);
355 center3D = V * center;
356 }
else if (center3D.size() == 4) {
357 V.resize(3, 2,
false);
358 center3D.insert(0, V * center + mean.t());
367 s <<
"usNeedleModelPolynomial\n";
382 if (c !=
"usNeedleModelPolynomial") {
383 vpException e(vpException::ioError,
"Stream does not contain usNeedleModelPolynomial data");
397 s.write(
"usNeedleModelPolynomial", 24);
412 if (strcmp(c,
"usNeedleModelPolynomial")) {
413 vpException e(vpException::ioError,
"Stream does not contain usNeedleModelPolynomial data");
virtual usNeedleModelBaseTip & operator=(const usNeedleModelBaseTip &needle)
vpColVector getBaseStaticTorsor() const
Force at base.
double getBendingEnergy() const
Needle bending.
const usNeedleModelPolynomial & operator=(const usNeedleModelPolynomial &needle)
double m_outerDiameter
Needle parameters.
usNeedleModelPolynomial()
Constructors, destructor.
void setOuterDiameter(double diameter)
Parameters setters and getters.
vpColVector getNeedlePoint(double l) const
Measure model information.
double getOuterDiameter() const
double getDistanceFromPoint(const vpColVector &P, double start=0, double stop=-1, double threshold=1e-5) const
void init()
Spline definition.
void setInsideDiameter(double diameter)
void loadPreset(const NeedlePreset preset)
Parameters saving and loading.
double getInsideDiameter() const
double getCurvatureFromNeedleShape(double start, double end, vpColVector ¢er3D, vpColVector &direction3D) const
Curvature.
double m_needleYoungModulus
vpColVector getNeedleDirection(double l) const
void setNeedleYoungModulus(double E)
virtual ~usNeedleModelPolynomial()
double getNeedleYoungModulus() const
vpColVector getDerivative(double parameter, unsigned int order) const
vpColVector getStartTangent() const
vpMatrix m_polynomialCoefficients
vpColVector getTangent(double parameter) const
vpColVector getPoint(double parameter) const
void setParametricLength(double length)
void setPolynomialCoefficients(const vpMatrix &polynomialCoefficients)
double getParametricLength() const
void setBoundaries(double startParameter, double endParamter)