UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-20)
usNeedleInsertionModelVirtualSprings.h
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 
33 #ifndef __usNeedleInsertionModelVirtualSprings_h
34 #define __usNeedleInsertionModelVirtualSprings_h
35 
36 #include <iostream>
37 #include <vector>
38 
39 #include <visp3/core/vpColVector.h>
40 #include <visp3/core/vpHomogeneousMatrix.h>
41 #include <visp3/core/vpImage.h>
42 #include <visp3/core/vpMatrix.h>
43 #include <visp3/core/vpRGBa.h>
44 
45 #include <visp3/ustk_core/usOrientedPlane3D.h>
46 #include <visp3/ustk_needle_modeling/usNeedleInsertionModelInterface.h>
47 #include <visp3/ustk_needle_modeling/usNeedleModelSpline.h>
48 #include <visp3/ustk_needle_modeling/usVirtualSpring.h>
49 
51 {
52 public:
53  enum class InsertionType : int { ForceInsert, ForceRemove, NaturalBehavior };
54  enum class ModelPreset : int {
55  BiopsyNeedle,
56  BiopsyCannula,
57  AbayazidRRM13,
58  MisraRSRO10_PlastisolA,
59  RoesthuisAM12,
60  SteelSoftTissue,
61  SRL_BiopsyNID,
62  NDI_Pink_Stylet
63  };
64 
65 protected:
67 
69 
70  double m_tipForce;
71  double m_tipMoment;
72  double m_cutAngle; // degree
73  double m_bevelLength;
74 
76 
79 
81 
83 
84  std::vector<usVirtualSpring> m_springs; // active springs used for calculation
85  std::vector<usVirtualSpring> m_inactiveAutoAddedSprings; // springs that have been automatically added by the model
86  // and that are currently disactivated
87  std::vector<usVirtualSpring> m_inactiveMeasureSprings; // springs that have been added by the user and that are
88  // currently disactivated (not reached)
90  double m_interSpringDistance; // distance between successive springs
91  double m_interTipSpringDistance; // distance between successive springs at the tip
92 
94 
96 
98 
100 
102 
104 
110 
112 
116 
117 public:
119 
124  virtual usNeedleInsertionModelVirtualSprings *clone() const; // Polymorph copy method
125 
127 
128  void loadPreset(const ModelPreset preset);
129 
131 
133 
134  void setTipForce(double tipForce);
135  double getTipForce();
136 
137  void setBevelAngle(double angle);
138  double getBevelAngle() const;
139 
141 
142  void setDefaultSpringStiffness(double K);
143  double getDefaultSpringStiffness() const;
144 
145  void setStiffnessPerUnitLength(double K);
146  double getStiffnessPerUnitLength() const;
147 
148  int getNbSprings() const;
149  int getNbMeasureSprings() const;
150 
152 
154 
155  const usNeedleModelSpline &accessNeedle() const;
156  usNeedleModelSpline &accessNeedle();
157  bool IsNeedleInserted() const;
158  vpColVector getNeedleInsertionPoint() const;
159  vpColVector getTissueInsertionPoint() const;
160  double getNeedleFreeLength() const;
161  double getInsertionDepth() const;
162 
164 
165  const usOrientedPlane3D &accessSurface() const;
166  usOrientedPlane3D &accessSurface();
167  const usVirtualSpring &accessSpring(int i) const;
168  void setInterSpringDistance(double interSpringDistance);
169  double getInterSpringDistance() const;
170  void setInterTipSpringDistance(double interTipSpringDistance);
171  double getInterTipSpringDistance() const;
172 
173  void setNbMinTipSprings(int nb);
174  int getNbMinTipSprings() const;
175 
176  void setNbMaxTipSprings(int nb);
177  int getNbMaxTipSprings() const;
178 
180 
181  void AllowSpringAddition(bool flag);
182  void AllowSpringRemoval(bool flag);
183 
184  void setInsertionBehavior(InsertionType type);
185  InsertionType getInsertionBehavior() const;
186 
187  void setAutomaticSpringAddition(bool flag);
188  bool getAutomaticSpringAddition() const;
189 
191 
193 
194  double getPathDistanceFromPoint(const vpColVector &P) const;
195 
197 
198  double getTissueDeformationEnergy() const;
199  double getSurfaceTissueStretch() const;
200  double getMaxTissueStretch(double *lmax = nullptr) const;
201  double getMeanTissueStretch() const;
202 
204 
206 
208  bool setBasePose(const vpPoseVector &p);
209  vpPoseVector getBasePose() const;
210 
212 
213  void addMeasureSpring(
214  const vpColVector &p,
215  const vpColVector &d); // Add a spring in space and recompute stiffnesses in vicinity to keep the tissue property
216 
217  bool setSpringPosition(int index, const vpColVector &P, bool update = false);
218  bool setSpringDirection(int index, const vpColVector &D, bool update = false);
219  void setSpringStiffness(int index, double K, bool update = false);
220  bool moveSpringPosition(int index, const vpColVector &dP, bool update = false);
221  bool moveSpringDirection(int index, const vpThetaUVector &thetaU, bool update = false);
222  void addSpringStiffness(int index, double dK, bool update = false);
223 
224  void setSurfaceAtTip();
225 
227 
228  int addInsertionPoint(usVirtualSpring spg);
229  int addInsertionPoint(
230  const vpColVector &p,
231  const vpColVector &d); // Add a spring in space and recompute stiffnesses in vicinity to keep the tissue property
232 
233  void addInsertionPointOnSegmentHard(int segment,
234  double s); // Add a spring on the needle with default spring stiffness
235  void addInsertionPointAtTipHard();
236  void addInsertionPointOnSegment(
237  int segment,
238  double s); // Add a spring on the needle and recompute stiffnesses in vicinity to keep the tissue property
239  void addInsertionPointAtTip();
240 
241  void removeInsertionPointsHard(int first, int last = -1);
242  void removeLastInsertionPointHard();
243  void removeInsertionPoints(int first, int last = -1);
244  void removeLastInsertionPoint();
245  void removeAutoAddedSprings();
246 
247  void fusionSprings(int firstSpring, int lastSpring);
248 
249  void updateSpringsStiffness();
250  void updateCutAngle();
251  void updateTipForce();
252  void updateInsertionDirections();
253 
254  bool checkInactiveMeasureSprings();
255 
256  void solveSegmentsParametersSparseEigen();
257  void solveSegmentsParametersOpenCV();
258  void solveSegmentsParametersViSP();
259  void solveSegmentsParameters();
260  void computeSegmentsLengths();
261  bool addRemoveSprings();
262  bool updateState();
263 
265 
266  void showInsertionPoints() const;
267  void showInsertionDirections() const;
268  void showStiffnesses() const;
269 
271 
273  friend VISP_EXPORT std::ostream &operator<<(std::ostream &s, const usNeedleInsertionModelVirtualSprings &needle);
274  friend VISP_EXPORT std::istream &operator>>(std::istream &s, usNeedleInsertionModelVirtualSprings &needle);
276  friend VISP_EXPORT std::ostream &operator<<=(std::ostream &s, const usNeedleInsertionModelVirtualSprings &needle);
277  friend VISP_EXPORT std::istream &operator>>=(std::istream &s, usNeedleInsertionModelVirtualSprings &needle);
278 };
279 
280 VISP_EXPORT std::ostream &operator<<(std::ostream &s, const usNeedleInsertionModelVirtualSprings &needle);
281 VISP_EXPORT std::istream &operator>>(std::istream &s, usNeedleInsertionModelVirtualSprings &needle);
282 
283 VISP_EXPORT std::ostream &operator<<=(std::ostream &s, const usNeedleInsertionModelVirtualSprings &needle);
284 VISP_EXPORT std::istream &operator>>=(std::istream &s, usNeedleInsertionModelVirtualSprings &needle);
285 
286 #endif // __usNeedleInsertionModelVirtualSprings_h
virtual bool setBasePose(const vpPoseVector &pose)=0
The following methods should be redefined in the derived classes.
virtual vpPoseVector getBasePose() const =0
bool m_LastSegmentLengthComputed
Segments lengths measurement.
std::vector< usVirtualSpring > m_springs
Model Parameters.
usNeedleModelSpline m_needle
Needle parameters.