00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __vtkTransRectalFiducialCalibrationAlgo_h
00019 #define __vtkTransRectalFiducialCalibrationAlgo_h
00020
00021 #include "vtkObject.h"
00022 #include "vtkProstateNavWin32Header.h"
00023
00024 class vtkMatrix4x4;
00025 class vtkImageData;
00026 class vtkProstateNavTargetDescriptor;
00027 struct NeedleDescriptorStruct;
00028 class vtkMRMLTRProstateBiopsyModuleNode;
00029 class vtkPoints;
00030
00031 #include <vector>
00032 #include "itkPoint.h"
00033
00034 const unsigned int CALIB_MARKER_COUNT=4;
00035
00036
00037 struct TRProstateBiopsyCalibrationFromImageInput
00038 {
00039 double MarkerInitialPositions[CALIB_MARKER_COUNT][3];
00040 double MarkerSegmentationThreshold[CALIB_MARKER_COUNT];
00041 double MarkerDimensionsMm[3];
00042 double MarkerRadiusMm;
00043 double RobotInitialAngle;
00044 vtkMatrix4x4 *VolumeIJKToRASMatrix;
00045 vtkImageData *VolumeImageData;
00046 std::string FoR;
00047 };
00048
00049 struct TRProstateBiopsyCalibrationData
00050 {
00051 bool CalibrationValid;
00052 double AxesDistance;
00053 double RobotRegistrationAngleDegrees;
00054 double AxesAngleDegrees;
00055 double I1[3];
00056 double I2[3];
00057 double v1[3];
00058 double v2[3];
00059 std::string FoR;
00060 };
00061
00062 struct TRProstateBiopsyTargetingParams
00063 {
00064 std::string GetReachableString() const
00065 {
00066 if (this->IsOutsideReach)
00067 return "No";
00068 else
00069 return "Yes";
00070 }
00071
00073 bool TargetingParametersValid;
00074 double AxisRotation;
00075 double NeedleAngle;
00076 double DepthCM;
00077 bool IsOutsideReach;
00078 double HingePosition[3];
00079
00080 };
00081
00082
00083
00084 class VTK_PROSTATENAV_EXPORT vtkTransRectalFiducialCalibrationAlgo :
00085 public vtkObject
00086 {
00087 public:
00088
00089 static vtkTransRectalFiducialCalibrationAlgo *New();
00090 vtkTypeRevisionMacro(vtkTransRectalFiducialCalibrationAlgo,vtkObject);
00091 void PrintSelf(ostream& os, vtkIndent indent);
00092
00093
00094 typedef itk::Point<double, 3> PointType;
00095
00096
00097
00098 bool CalibrateFromImage(const TRProstateBiopsyCalibrationFromImageInput &input);
00099
00100
00101 static bool FindTargetingParams(vtkProstateNavTargetDescriptor *target, const TRProstateBiopsyCalibrationData &calibrationData, NeedleDescriptorStruct *needle, TRProstateBiopsyTargetingParams *targetingParams);
00102
00103
00104
00105 bool GetMarkerFound(int i);
00106
00107
00108
00109 double* GetMarkerPositions(int i);
00110
00111 vtkImageData *GetCalibMarkerPreProcOutput(int i);
00112 vtkMatrix4x4* GetCalibMarkerPreProcOutputIJKToRAS();
00113 void GetAxisCenterpoints(vtkPoints *points, int i);
00114
00115 const TRProstateBiopsyCalibrationData& GetCalibrationData() { return this->CalibrationData; }
00116
00117
00118
00119
00120
00121
00122 void SetEnableMarkerCenterpointAdjustment(bool enable);
00123
00124 protected:
00125
00126 static bool RotatePoint(double H_before[3], double rotation_rad, double alpha_rad, double mainaxis[3], double I[3], double H_after[3]);
00127
00128
00129 void SegmentAxis(const double initPos1[3], const double initPos2[3], vtkMatrix4x4 *volumeIJKToRASMatrix, vtkImageData* calibVol,
00130 double thresh1, double thresh2, const double fidDimsMm[3], double radius, double initialAngle,
00131 double P1[3], double v1[3], double finalPos1[3], double finalPos2[3], bool &found1, bool &found2, vtkImageData* img1, vtkImageData* img2, std::vector<PointType> *CoordinatesVectorAxis);
00132
00133 bool SegmentCircle(double markerCenterGuessRas[3],const double normalRas[3], double thresh, const double fidDimsMm[3], double radius, vtkMatrix4x4 *ijkToRAS, vtkImageData *calibVol, std::vector<PointType> &CoordinatesVector, vtkImageData *preprocOutput=NULL);
00134
00135 bool CalculateCircleCenter(vtkImageData *inData, unsigned int *tempStorage, int tempStorageSize, double nThersholdVal, double nRadius, double &gx, double &gy, int nVotedNeeded, bool lDebug);
00136 bool CalculateCircleCenterMean(vtkImageData *inData, double nRadius, double threshold, double &gx, double &gy);
00137
00138 void RemoveOutliners(double P_[3], double v_[3], const double def1[3], const double def2[3], std::vector<PointType> &CoordinatesVector);
00139
00140 bool FindProbe(const double P1[3], const double P2[3], double v1[3], double v2[3],
00141 double I1[3], double I2[3], double &axesAngleDegrees, double &axesDistance);
00142
00143 void Linefinder(double P_[3], double v_[3], std::vector<itk::Point<double,3> > CoordVector);
00144
00145
00146 void CropWithCylinder(vtkImageData* output, vtkImageData* input, const double linePoint_RAS[3],const double normal_RAS[3], vtkMatrix4x4 *ijkToRAS, double radiusMm);
00147
00148 bool DoubleEqual(double val1, double val2);
00149
00150 vtkTransRectalFiducialCalibrationAlgo();
00151 virtual ~vtkTransRectalFiducialCalibrationAlgo();
00152
00153
00154 std::vector<PointType> CoordinatesVectorAxis1;
00155 std::vector<PointType> CoordinatesVectorAxis2;
00156 std::vector<vtkImageData*> CalibMarkerPreProcOutput;
00157 vtkMatrix4x4* CalibMarkerPreProcOutputIJKToRAS;
00158 bool MarkerFound[CALIB_MARKER_COUNT];
00159 double MarkerPositions[CALIB_MARKER_COUNT][3];
00160
00161
00162 TRProstateBiopsyCalibrationData CalibrationData;
00163
00164 bool EnableMarkerCenterpointAdjustment;
00165
00166 private:
00167 vtkTransRectalFiducialCalibrationAlgo(const vtkTransRectalFiducialCalibrationAlgo&);
00168 void operator=(const vtkTransRectalFiducialCalibrationAlgo&);
00169 };
00170
00171 #endif