UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-20)
usNeedleInsertionModelRayleighRitzSpline.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 __usNeedleInsertionModelRayleighRitzSpline_h
34 #define __usNeedleInsertionModelRayleighRitzSpline_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 
43 #include <visp3/ustk_needle_modeling/usNeedleTip.h>
44 #include <visp3/ustk_needle_modeling/usNeedleTipActuated.h>
45 #include <visp3/ustk_needle_modeling/usNeedleTipBeveled.h>
46 #include <visp3/ustk_needle_modeling/usNeedleTipPrebent.h>
47 #include <visp3/ustk_needle_modeling/usNeedleTipSymmetric.h>
48 
49 #include <visp3/ustk_needle_modeling/usNeedleInsertionModelInterface.h>
50 #include <visp3/ustk_needle_modeling/usNeedleModelSpline.h>
51 #include <visp3/ustk_needle_modeling/usTissueModelSpline.h>
52 
54 {
55 public:
56  enum class ModelPreset : int {
57  BiopsyNeedle,
58  BiopsyCannula,
59  Symmetric,
60  AbayazidRRM13,
61  MisraRSRO10_PlastisolA,
62  RoesthuisAM12,
63  SteelSoftTissue,
64  SRL_ActuatedFBG,
65  SRL_BiopsySimple,
66  SRL_BiopsyNID,
67  NDI_Pink_Stylet
68  };
69  enum class PathUpdateType : int { NoUpdate, WithTipPosition, WithTipDirection, WithTipMix };
70  enum class NeedleTipType : int { SymmetricTip, BeveledTip, PrebentTip, ActuatedTip };
71  enum class SolvingMethod : int { Classic, FixedBeamLength, NoBevel };
72 
73 public: // protected:
75 
77 
79 
82 
84 
86  std::vector<double> m_stiffnessPerUnitLength;
87  std::vector<double> m_layerLength;
88 
90 
92  double m_pathUpdateLengthThreshold; // insertion step before adding a new segment to the rest path (min length of the
93  // rest path segment)
94  double m_pathUpdateMixCoefficient; // coefficient to weight the effect of tip position update(1) and tip direction
95  // update(0) for Mix PathUpdateType
96 
98 
100 
102  std::vector<double> m_restDilatationFactor;
103 
104 public:
106 
111  virtual usNeedleInsertionModelRayleighRitzSpline *clone() const; // Polymorph copy method
112 
114 
115  void loadPreset(const ModelPreset preset);
116 
118 
120 
121  const usNeedleModelSpline &accessNeedle() const;
122  usNeedleModelSpline &accessNeedle();
123 
124  usNeedleTip const &accessNeedleTip() const;
125  usNeedleTip &accessNeedleTip();
126 
127  void setNeedleTipType(NeedleTipType type);
128  NeedleTipType getNeedleTipType() const;
129 
131 
132  const usTissueModelSpline &accessTissue() const;
133  usTissueModelSpline &accessTissue();
134 
135  bool addTissueLayer(double K, double l);
136 
137  bool setStiffnessPerUnitLength(int i, double K);
138  bool setStiffnessPerUnitLength(double K);
139  double getStiffnessPerUnitLength(int i = 0) const;
140 
141  bool setLayerLength(int i, double l);
142  double getLayerLength(int i) const;
143 
144  int getNbLayers() const;
145  int getNbCurrentLayers() const;
146 
148 
149  void setPathUpdateType(PathUpdateType type);
150  void setPathUpdateLengthThreshold(double length);
151  void setPathUpdateMixCoefficient(double coef);
152  void setSolvingMethod(SolvingMethod method);
153 
155 
157 
158  bool IsNeedleInserted() const;
159  double getNeedleFreeLength(int *seg = nullptr, double *param = nullptr) const;
160  double getInsertionDepth() const;
161  vpColVector getNeedleInsertionPoint() const;
162  vpColVector getTissueInsertionPoint() const;
163 
164  bool getCorrespondingPathPoint(double l, int &correspondingRestIndex, double &correspondingRestParam) const;
165 
167 
169 
170  double getTissueDeformationEnergy() const;
171  double getSurfaceTissueStretch() const;
172  double getMaxTissueStretch(double *lmax = nullptr) const;
173  double getMeanTissueStretch() const;
174 
176 
178 
180 
182  bool setBasePose(const vpPoseVector &p);
183  vpPoseVector getBasePose() const;
184 
186 
187  void setSurfaceAtTip();
188  bool cutPathToPoint(const vpColVector &P);
189 
191 
192  void solveSegmentsParametersSparseEigen(); // solve without bevel (less accurate at tip, but less expensive since
193  // equation independant on dimension)
194  void solveSegmentsParametersFullSparseEigen(); // solve with bevel (more accurate modeling of bevel effect, but
195  // slighly more expensive)
196  void solveSegmentsParametersFullSparseEigenFixedLength(); // solve with bevel + fixed size for sub splines
197  void solveSegmentsParametersDense(); // solve with dense method with bevel + fixed size for sub splines (very slow,
198  // only here for compatibility but should be avoided)
199  void fitLength();
200  void updateTipPose();
201 
202  void solveSegmentsParameters();
203  virtual bool updateState();
204 
205  bool updatePath();
206 
208 
210  friend VISP_EXPORT std::ostream &operator<<(std::ostream &s, const usNeedleInsertionModelRayleighRitzSpline &model);
211  friend VISP_EXPORT std::istream &operator>>(std::istream &s, usNeedleInsertionModelRayleighRitzSpline &model);
213  friend VISP_EXPORT std::ostream &operator<<=(std::ostream &s, const usNeedleInsertionModelRayleighRitzSpline &model);
214  friend VISP_EXPORT std::istream &operator>>=(std::istream &s, usNeedleInsertionModelRayleighRitzSpline &model);
215 };
216 
217 VISP_EXPORT std::ostream &operator<<(std::ostream &s, const usNeedleInsertionModelRayleighRitzSpline &model);
218 VISP_EXPORT std::istream &operator>>(std::istream &s, usNeedleInsertionModelRayleighRitzSpline &model);
219 
220 VISP_EXPORT std::ostream &operator<<=(std::ostream &s, const usNeedleInsertionModelRayleighRitzSpline &model);
221 VISP_EXPORT std::istream &operator>>=(std::istream &s, usNeedleInsertionModelRayleighRitzSpline &model);
222 
223 #endif // __usNeedleInsertionModelRayleighRitzSpline_h
virtual bool setBasePose(const vpPoseVector &pose)=0
The following methods should be redefined in the derived classes.
virtual vpPoseVector getBasePose() const =0
double getCurvatureFromKinematics() const
Curvature.