PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusProbeCalibrationAlgo.h
Go to the documentation of this file.
1 
7 #ifndef __vtkPlusProbeCalibrationAlgo_h
8 #define __vtkPlusProbeCalibrationAlgo_h
9 
10 #include "vtkPlusCalibrationExport.h"
11 
12 #include <string>
13 #include <vector>
14 #include <set>
15 
16 #include <vnl/vnl_double_3.h>
17 
18 #include "vtkObject.h"
20 
21 //class igsioTrackedFrame;
22 //class vtkIGSIOTrackedFrameList;
23 //class vtkIGSIOTransformRepository;
24 class vtkXMLDataElement;
25 class PlusNWire;
26 
32 class vtkPlusCalibrationExport vtkPlusProbeCalibrationAlgo : public vtkObject
33 {
34 public:
35  static vtkPlusProbeCalibrationAlgo* New();
36  vtkTypeMacro( vtkPlusProbeCalibrationAlgo, vtkObject );
37  virtual void PrintSelf( ostream& os, vtkIndent indent );
38 
43  PlusStatus ReadConfiguration( vtkXMLDataElement* aConfig );
44 
46  vtkGetStringMacro( ImageCoordinateFrame );
48  vtkGetStringMacro( ProbeCoordinateFrame );
50  vtkGetStringMacro( PhantomCoordinateFrame );
52  vtkGetStringMacro( ReferenceCoordinateFrame );
53 
54 
66  PlusStatus Calibrate( vtkIGSIOTrackedFrameList* validationTrackedFrameList, int validationStartFrame, int validationEndFrame, vtkIGSIOTrackedFrameList* calibrationTrackedFrameList, int calibrationStartFrame, int calibrationEndFrame, vtkIGSIOTransformRepository* transformRepository, const std::vector<PlusNWire>& nWires );
67 
75  PlusStatus Calibrate( vtkIGSIOTrackedFrameList* validationTrackedFrameList, vtkIGSIOTrackedFrameList* calibrationTrackedFrameList, vtkIGSIOTransformRepository* transformRepository, const std::vector<PlusNWire>& nWires );
76 
78  void GetImageToProbeTransformMatrix( vtkMatrix4x4* imageToProbeMatrix );
79 
81  vtkSetStringMacro( CalibrationDate );
83  vtkGetStringMacro( CalibrationDate );
84 
86  double GetCalibrationReprojectionError3DMean();
88  double GetCalibrationReprojectionError3DStdDev();
89 
91  double GetValidationReprojectionError3DMean();
93  double GetValidationReprojectionError3DStdDev();
94 
95  PlusStatus GetCalibrationReport( std::vector<double>* calibError, std::vector<double>* validError, vnl_matrix_fixed<double, 4, 4>* imageToProbeTransformMatrix );
96 
102  std::string GetResultString( int precision = 3 );
103 
114  PlusStatus GetXMLCalibrationResultAndErrorReport( vtkIGSIOTrackedFrameList* validationTrackedFrameList, int validationStartFrame,
115  int validationEndFrame, vtkIGSIOTrackedFrameList* calibrationTrackedFrameList, int calibrationStartFrame, int calibrationEndFrame, vtkXMLDataElement* probeCalibrationResult );
116 
118  {
119  return this->Optimizer;
120  };
121 
122  void ComputeError2d( const vnl_matrix_fixed<double, 4, 4>& imageToProbeMatrix, double& errorMean, double& errorStDev, double& errorRms );
123  void ComputeError3d( const vnl_matrix_fixed<double, 4, 4>& imageToProbeMatrix, double& errorMean, double& errorStDev, double& errorRms );
124 
125 protected:
126 
128  {
129  CALIBRATION_ALL = 0,
132  LAST_PREPROCESSED_WIRE_POS_ID // this must be the last type
133  };
134 
135  void ComputeError3d( std::vector<double>& reprojectionErrors, PreProcessedWirePositionIdType datasetType, const vnl_matrix_fixed<double, 4, 4>& imageToProbeMatrix );
136 
137  void ComputeError2d( PreProcessedWirePositionIdType datasetType, const vnl_matrix_fixed<double, 4, 4>& imageToProbeMatrix,
138  double& errorMean, double& errorStDev, double& errorRms,
139  std::vector< std::vector< vnl_vector_fixed<double, 2> > >* ReprojectionError2Ds = NULL );
140 
147  PlusStatus AddPositionsPerImage( igsioTrackedFrame* trackedFrame, vtkIGSIOTransformRepository* transformRepository, PreProcessedWirePositionIdType datasetType );
148 
157  PlusStatus ComputeReprojectionErrors3D( PreProcessedWirePositionIdType datasetType, const vnl_matrix_fixed<double, 4, 4>& imageToProbeTransformMatrix );
158 
167  PlusStatus ComputeReprojectionErrors2D( PreProcessedWirePositionIdType datasetType, const vnl_matrix_fixed<double, 4, 4>& imageToProbeTransformMatrix );
168 
174  void SetAndValidateImageToProbeTransform( const vnl_matrix_fixed<double, 4, 4>& imageToProbeTransformMatrix, vtkIGSIOTransformRepository* transformRepository );
175 
179  PlusStatus SaveCalibrationResultAndErrorReportToXML( vtkIGSIOTrackedFrameList* validationTrackedFrameList, int validationStartFrame, int validationEndFrame, vtkIGSIOTrackedFrameList* calibrationTrackedFrameList, int calibrationStartFrame, int calibrationEndFrame );
180 
184  PlusStatus ComputeImageToProbeTransformByLinearLeastSquaresMethod( vnl_matrix_fixed<double, 4, 4>& imageToProbeTransformMatrix, std::set<int>& outliers );
185 
188  void UpdateNonOutlierData( const std::set<int>& outliers );
189 
190  static double PointToWireDistance( const vnl_double_3& aPoint, const vnl_double_3& aLineEndPoint1, const vnl_double_3& aLineEndPoint2 );
191 
192 protected:
194  vtkSetStringMacro( ImageCoordinateFrame );
196  vtkSetStringMacro( ProbeCoordinateFrame );
198  vtkSetStringMacro( PhantomCoordinateFrame );
200  vtkSetStringMacro( ReferenceCoordinateFrame );
201 
202 protected:
204  virtual ~vtkPlusProbeCalibrationAlgo();
205 
206 protected:
209 
212 
215 
218 
221 
223  vnl_matrix_fixed<double, 4, 4> ImageToProbeTransformMatrix;
224 
226  std::vector<PlusNWire> NWires;
227 
230  {
235  std::vector< vnl_vector_fixed<double, 4> > AllWiresIntersectionPointsPos_Image;
240  std::vector< vnl_vector_fixed<double, 4> > MiddleWireIntersectionPointsPos_Probe;
241 
245  vnl_matrix_fixed<double, 4, 4> ProbeToPhantomTransform;
246  };
247 
249  {
255  std::vector< std::vector<double> > ReprojectionError3Ds;
256 
262  std::vector< std::vector< vnl_vector_fixed<double, 2> > > ReprojectionError2Ds;
263 
267  std::vector< vnl_vector_fixed<double, 2> > ReprojectionError2DMeans;
268 
272  std::vector< vnl_vector_fixed<double, 2> > ReprojectionError2DStdDevs;
273 
276 
279 
282 
283  double RmsError2D;
284 
286  : ReprojectionError3DMean( -1.0 )
287  , ReprojectionError3DStdDev( -1.0 )
288  , RmsError2D( -1.0 )
289  {}
290 
291  };
292 
294  {
295  std::vector<NWirePositionType> FramePositions;
297 
298  void Clear()
299  {
300  FramePositions.clear();
301 
302  NWireErrors.ReprojectionError3Ds.clear();
303  NWireErrors.ReprojectionError2Ds.clear();
304  NWireErrors.ReprojectionError2DStdDevs.clear();
305  NWireErrors.ReprojectionError2DMeans.clear();
306  }
307  };
308 
309  PreProcessedWirePositionsType PreProcessedWirePositions[LAST_PREPROCESSED_WIRE_POS_ID];
310 
316 
318 
319 private:
321  void operator=( const vtkPlusProbeCalibrationAlgo& );
322 };
323 
324 #endif // __vtkPlusProbeCalibrationAlgo_h
vnl_matrix_fixed< double, 4, 4 > ImageToProbeTransformMatrix
vtkPlusProbeCalibrationOptimizerAlgo * Optimizer
Refines the image to probe transform using non-linear optimization.
std::vector< vnl_vector_fixed< double, 2 > > ReprojectionError2DMeans
igsioStatus PlusStatus
Definition: PlusCommon.h:40
std::vector< vnl_vector_fixed< double, 4 > > MiddleWireIntersectionPointsPos_Probe
std::vector< std::vector< double > > ReprojectionError3Ds
vtkPlusProbeCalibrationOptimizerAlgo * GetOptimizer()
std::vector< std::vector< vnl_vector_fixed< double, 2 > > > ReprojectionError2Ds
std::vector< vnl_vector_fixed< double, 2 > > ReprojectionError2DStdDevs
std::vector< vnl_vector_fixed< double, 4 > > AllWiresIntersectionPointsPos_Image
Probe calibration algorithm class.