UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-01-22)
testUsNeedleJacobians.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ustk software.
4  * Copyright (C) 2016 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ustk with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * This software was developed at:
17  * Inria Rennes - Bretagne Atlantique
18  * Campus Universitaire de Beaulieu
19  * 35042 Rennes Cedex
20  * France
21  *
22  * If you have questions regarding the use of this file, please contact
23  * Inria at ustk@inria.fr
24  *
25  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  *
28  * Author:
29  * Jason Chevrie
30  *
31  *****************************************************************************/
32 
41 #include <visp3/core/vpConfig.h>
42 
43 #include <iostream>
44 #include <stdlib.h>
45 #include <string>
46 #include <vector>
47 
48 #include <visp3/core/vpColVector.h>
49 #include <visp3/core/vpHomogeneousMatrix.h>
50 #include <visp3/core/vpImage.h>
51 #include <visp3/core/vpMatrix.h>
52 #include <visp3/core/vpRGBa.h>
53 
54 #include <visp3/ustk_needle_modeling/usNeedleInsertionModelRayleighRitzSpline.h>
55 #include <visp3/ustk_needle_modeling/usNeedleInsertionModelVirtualSprings.h>
56 
57 #include <visp3/ustk_needle_modeling/usNeedleJacobians.h>
58 
59 int main()
60 {
61  std::cout << "Start test testUsNeedleJacobians" << std::endl;
62 
64 
68  needleRR.setBasePose(vpPoseVector(0,0,0,0,0,0));
69  needleRR.setSurfaceAtTip();
72  needleVS.setBasePose(vpPoseVector(0,0,0,0,0,0));
73  needleVS.setSurfaceAtTip();
74 
75  for(int i=0 ; i<20 ; i++)
76  {
77  needleRR.moveBase(0.0005,0,0.001,0.0001,0,0);
78  needleVS.moveBase(0.0005,0,0.001,0.0001,0,0);
79  }
80 
81  vpMatrix JRR;
82  vpMatrix JVS;
83 
85 
87  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToWorldTipVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
89  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToWorldTipVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
91  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToTipVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
93  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTipVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
94 
96  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToWorldTipVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
98  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToWorldTipVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
100  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToTipVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
101  if(!usNeedleJacobians::getJacobianBaseVelocityToTipVelocity(needleVS, JVS)) return 1;
102  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTipVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
103 
105 
107  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToBendingEnergy<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
109  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToBendingEnergy<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
110 
112  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToBendingEnergy<usNeedleInsertionModelVirtualSprings>" << std::endl;
114  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToBendingEnergy<usNeedleInsertionModelVirtualSprings>" << std::endl;
115 
117 
119  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTissueEnergy<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
121  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToTissueEnergy<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
123  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToNeedleInsertionPointVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
125  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToSurfaceTissueStretch<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
127  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToMaxTissueStretch<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
129  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToMeanTissueStretch<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
130 
132  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTissueEnergy<usNeedleInsertionModelVirtualSprings>" << std::endl;
134  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToTissueEnergy<usNeedleInsertionModelVirtualSprings>" << std::endl;
136  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToNeedleInsertionPointVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
138  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToSurfaceTissueStretch<usNeedleInsertionModelVirtualSprings>" << std::endl;
140  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToMaxTissueStretch<usNeedleInsertionModelVirtualSprings>" << std::endl;
142  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToMeanTissueStretch<usNeedleInsertionModelVirtualSprings>" << std::endl;
143 
145 
146  if(!usNeedleJacobians::getJacobianBaseVelocityToPointVelocity(needleRR, JRR, 0.5*needleRR.accessNeedle().getFullLength())) return 1;
147  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToPointVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
149  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToPointVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
150 
151  if(!usNeedleJacobians::getJacobianBaseVelocityToPointVelocity(needleVS, JVS, 0.5*needleRR.accessNeedle().getFullLength())) return 1;
152  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToPointVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
154  std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToPointVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
155 
157 
158  vpColVector target(needleRR.accessNeedle().getTipPosition());
159  target[0] += 0.01;
160  target[2] += 0.02;
162  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTransversalTargetDistance<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
163  if(!usNeedleJacobians::getJacobianBaseVelocityToTargetAngle(needleRR, JRR, target)) return 1;
164  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTargetAngle<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
165 
167  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTransversalTargetDistance<usNeedleInsertionModelVirtualSprings>" << std::endl;
168  if(!usNeedleJacobians::getJacobianBaseVelocityToTargetAngle(needleVS, JVS, target)) return 1;
169  std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTargetAngle<usNeedleInsertionModelVirtualSprings>" << std::endl;
170 
172 
173  if(!usNeedleJacobians::getJacobianSpringVelocityToPointVelocity(needleVS, JVS, needleVS.getNbSprings()/2, 0.5 * needleVS.accessNeedle().getFullLength())) return 1;
174  std::cout << "done: usNeedleJacobians::getJacobianSpringVelocityToPointVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
175 
177 
178  vpColVector point(needleVS.accessNeedle().getPoint(0.5*needleVS.accessNeedle().getFullLength()));
179  point[0] += 0.005;
180  std::vector<vpColVector> points;
181  for(int i=0 ; i<10 ; i++)
182  {
183  point[2] += 0.002;
184  points.push_back(point);
185  }
186  if(!usNeedleJacobians::getJacobianSpringVelocityToPointsDistance(needleVS, JVS, needleVS.getNbSprings()/2, points)) return 1;
187  std::cout << "done: usNeedleJacobians::getJacobianSpringVelocityToPointsDistance<usNeedleInsertionModelVirtualSprings>" << std::endl;
188 
190 
191  std::vector<double> l;
192  for(int i=0 ; i<10 ; i++) l.push_back(i * needleRR.accessNeedle().getFullLength() / 10.);
194  std::cout << "done: usNeedleJacobians::getJacobianRestPathPointVelocityToPointsVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
195 
197 
198  if(!usNeedleJacobians::getJacobianRestPathPointVelocityToPointsDistance(needleRR, JRR, needleRR.accessTissue().accessPath().getNbSegments() / 2, points)) return 1;
199  std::cout << "done: usNeedleJacobians::getJacobianRestPathPointVelocityToPointsDistance<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
200 
202 
204  std::cout << "done: usNeedleJacobians::getJacobianStiffnessPerUnitLengthToPointsDistance<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
206  std::cout << "done: usNeedleJacobians::getJacobianStiffnessPerUnitLengthToPointsDistance<usNeedleInsertionModelVirtualSprings>" << std::endl;
207 
209 
211  std::cout << "done: usNeedleJacobians::getJacobianStiffnessPerUnitLengthToPointsVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
213  std::cout << "done: usNeedleJacobians::getJacobianStiffnessPerUnitLengthToPointsVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
214 
215  return 0;
216 }
int getNbSegments() const
Parameters setters and getters.
Definition: usBSpline3D.cpp:59
vpColVector getPoint(double param) const
Measure curve information.
bool moveBase(const vpColVector &v, double time)
void loadPreset(const ModelPreset preset)
Parameters saving and loading.
bool setBasePose(const vpPoseVector &p)
The following methods should be redefined in the derived classes.
const usTissueModelSpline & accessTissue() const
Tissue parameters.
const usNeedleModelSpline & accessNeedle() const
Parameters setters and getters.
bool setBasePose(const vpPoseVector &p)
The following methods should be redefined in the derived classes.
void loadPreset(const ModelPreset preset)
Parameters saving and loading.
const usNeedleModelSpline & accessNeedle() const
Model parameters.
vpColVector getTipPosition() const
const usBSpline3D & accessPath() const
bool getJacobianSpringVelocityToPointsDistance(const NeedleInsertionModel &model, vpMatrix &J, int spring, const std::vector< vpColVector > &points)
Springs to distance from points (nbPointsx6)
bool getJacobianBaseVelocityToTissueEnergy(const NeedleInsertionModel &model, vpMatrix &J)
Base to tissue deformation energy (1x6)
bool getJacobianBaseVelocityToTransversalTargetDistance(const NeedleInsertionModel &model, vpMatrix &J, const vpColVector &target)
Base to features (1x6)
bool getJacobianBaseVelocityToTipVelocity(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianWorldBaseVelocityToTissueEnergy(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianBaseVelocityToPointVelocity(const NeedleInsertionModel &model, vpMatrix &J, double l)
Base to needle point (3x6)
bool getJacobianBaseVelocityToSurfaceTissueStretch(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianRestPathPointVelocityToPointsVelocity(const NeedleInsertionModel &model, vpMatrix &J, int restPoint, const std::vector< double > &l)
Rest path points to model point (3x3)
bool getJacobianWorldBaseVelocityToTipVelocity(const NeedleInsertionModel &model, vpMatrix &J)
Base to tip.
bool getJacobianRestPathPointVelocityToPointsDistance(const NeedleInsertionModel &model, vpMatrix &J, int restPoint, const std::vector< vpColVector > &points)
Rest path points distance from points (nbPointsx3)
bool getJacobianBaseVelocityToNeedleInsertionPointVelocity(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianBaseVelocityToBendingEnergy(const NeedleInsertionModel &model, vpMatrix &J)
Base to bending energy (1x6)
bool getJacobianSpringVelocityToPointVelocity(const NeedleInsertionModel &model, vpMatrix &J, int spring, double l)
Springs to needle point (3x6)
bool getJacobianWorldBaseVelocityToBendingEnergy(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianBaseVelocityToTargetAngle(const NeedleInsertionModel &model, vpMatrix &J, const vpColVector &target)
bool getJacobianWorldBaseVelocityToPointVelocity(const NeedleInsertionModel &model, vpMatrix &J, double l)
bool getJacobianBaseVelocityToMaxTissueStretch(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianWorldBaseVelocityToWorldTipVelocity(const NeedleInsertionModel &model, vpMatrix &J)
Base to tip (manipulation Jacobian) (6x6)
bool getJacobianStiffnessPerUnitLengthToPointsVelocity(const NeedleInsertionModel &model, vpMatrix &J, const std::vector< double > &l)
Stiffness per unit length to needle point ( (3*nbPoints)x1 matrix)
bool getJacobianStiffnessPerUnitLengthToPointsDistance(const NeedleInsertionModel &model, vpMatrix &J, const std::vector< vpColVector > &points)
Stiffness per unit length to distance from points (nbPointsx1)
bool getJacobianBaseVelocityToWorldTipVelocity(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianBaseVelocityToMeanTissueStretch(const NeedleInsertionModel &model, vpMatrix &J)