00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _itkRayCastInterpolateImageFunction_h
00018 #define _itkRayCastInterpolateImageFunction_h
00019
00020 #include "itkInterpolateImageFunction.h"
00021 #include "itkTransform.h"
00022 #include "itkVector.h"
00023
00024 namespace itk
00025 {
00026
00038 template <class TInputImage, class TCoordRep = float>
00039 class ITK_EXPORT RayCastInterpolateImageFunction :
00040 public InterpolateImageFunction<TInputImage,TCoordRep>
00041 {
00042 public:
00044 typedef RayCastInterpolateImageFunction Self;
00045 typedef InterpolateImageFunction<TInputImage,TCoordRep> Superclass;
00046 typedef SmartPointer<Self> Pointer;
00047 typedef SmartPointer<const Self> ConstPointer;
00048
00050 itkStaticConstMacro(InputImageDimension, unsigned int,
00051 TInputImage::ImageDimension);
00052
00057 typedef Transform<TCoordRep,3,3> TransformType;
00058
00059 typedef typename TransformType::Pointer TransformPointer;
00060 typedef typename TransformType::InputPointType InputPointType;
00061 typedef typename TransformType::OutputPointType OutputPointType;
00062 typedef typename TransformType::ParametersType TransformParametersType;
00063 typedef typename TransformType::JacobianType TransformJacobianType;
00064
00065 typedef typename Superclass::InputPixelType PixelType;
00066
00067 typedef typename TInputImage::SizeType SizeType;
00068
00069 typedef itk::Vector<TCoordRep, 3> DirectionType;
00070
00072 typedef InterpolateImageFunction<TInputImage,TCoordRep> InterpolatorType;
00073
00074 typedef typename InterpolatorType::Pointer InterpolatorPointer;
00075
00076
00078 itkTypeMacro(RayCastInterpolateImageFunction, InterpolateImageFunction);
00079
00081 itkNewMacro(Self);
00082
00084 typedef typename Superclass::OutputType OutputType;
00085
00087 typedef typename Superclass::InputImageType InputImageType;
00088
00090 typedef typename Superclass::RealType RealType;
00091
00093 itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
00094
00096 typedef typename Superclass::PointType PointType;
00097
00099 typedef typename Superclass::IndexType IndexType;
00100
00102 typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
00103
00104
00105
00116 virtual OutputType Evaluate( const PointType& point ) const;
00117
00129 virtual OutputType EvaluateAtContinuousIndex(
00130 const ContinuousIndexType & ) const {return 0; };
00131
00132
00134 itkSetObjectMacro( Transform, TransformType );
00136 itkGetObjectMacro( Transform, TransformType );
00137
00139 itkSetObjectMacro( Interpolator, InterpolatorType );
00141 itkGetObjectMacro( Interpolator, InterpolatorType );
00142
00144 itkSetMacro( FocalPoint, InputPointType );
00146 itkGetMacro( FocalPoint, InputPointType );
00147
00149 itkSetMacro( Threshold, double );
00151 itkGetMacro( Threshold, double );
00152
00156 inline bool IsInsideBuffer( const PointType & ) const
00157 {
00158 return true;
00159 }
00160 bool IsInsideBuffer( const ContinuousIndexType & index ) const
00161 {
00162 return Superclass::IsInsideBuffer(index);
00163 }
00164 bool IsInsideBuffer( const IndexType & index ) const
00165 {
00166 return Superclass::IsInsideBuffer(index);
00167 }
00168
00177 bool SetRay(OutputPointType RayPosn, DirectionType RayDirn) const;
00178
00179
00193 bool Integrate(double &integral) const {
00194 return IntegrateAboveThreshold(integral, 0);
00195 };
00196
00197
00212 bool IntegrateAboveThreshold(double &integral, double threshold) const;
00213
00220 void IncrementIntensities(double increment=1) const;
00221
00222
00232 bool NextPoint(void) const;
00233
00235 void Reset(void) const;
00236
00246 void GetCurrentCoord3D(double &x, double &y, double &z) const;
00247
00255 void GetCurrentVoxelCoord3D(double &x, double &y, double &z) const;
00256
00258 double GetCurrentIntensity(void) const;
00259
00274 double GetCurrentDensity(double threshold=0.) const;
00275
00277 void GetCurrentVoxels(PixelType &voxel1, PixelType &voxel2,
00278 PixelType &voxel3, PixelType &voxel4) const;
00279
00281 int GetNumberOfVoxels(void) const {return m_NumVoxelPlanesTraversed;};
00282
00284 double GetRayPointSpacing(void) const {
00285 typename InputImageType::SpacingType spacing=this->m_Image->GetSpacing();
00286
00287 if (m_ValidRay)
00288 return sqrt( m_VoxelIncrement[0]*spacing[0]*m_VoxelIncrement[0]*spacing[0]
00289 + m_VoxelIncrement[1]*spacing[1]*m_VoxelIncrement[1]*spacing[1]
00290 + m_VoxelIncrement[2]*spacing[2]*m_VoxelIncrement[2]*spacing[2] );
00291 else
00292 return 0.;
00293 };
00294
00301 void SetBoundingBox(double position[3], double size[3]) const;
00302
00303
00304 protected:
00305
00307 RayCastInterpolateImageFunction();
00308
00310 ~RayCastInterpolateImageFunction(){};
00311
00313 void PrintSelf(std::ostream& os, Indent indent) const;
00314
00315
00321 typedef enum {
00322 UNDEFINED_DIRECTION=0,
00323 TRANSVERSE_IN_X,
00324 TRANSVERSE_IN_Y,
00325 TRANSVERSE_IN_Z,
00326 LAST_DIRECTION
00327 } TraversalDirection;
00328
00329
00331 TransformPointer m_Transform;
00332
00334 InputPointType m_FocalPoint;
00335
00337 double m_Threshold;
00338
00340 mutable bool m_ValidRay;
00341
00350 mutable double m_RayVoxelStartPosition[3];
00351
00360 mutable double m_RayVoxelEndPosition[3];
00361
00362
00371 mutable double m_Position3Dvox[3];
00372
00374 mutable double m_VoxelIncrement[3];
00375
00377 mutable TraversalDirection m_TraversalDirection;
00378
00380 mutable int m_TotalRayVoxelPlanes;
00381
00383 mutable int m_NumVoxelPlanesTraversed;
00384
00386 mutable const PixelType *m_RayIntersectionVoxels[4];
00387
00392 mutable int m_RayIntersectionVoxelIndex[3];
00393
00394
00396 mutable int m_NumberOfVoxelsInX;
00398 mutable int m_NumberOfVoxelsInY;
00400 mutable int m_NumberOfVoxelsInZ;
00401
00403 mutable double m_VoxelDimensionInX;
00405 mutable double m_VoxelDimensionInY;
00407 mutable double m_VoxelDimensionInZ;
00408
00410 mutable double m_RayStartCoordInMM[3];
00412 mutable double m_RayEndCoordInMM[3];
00413
00414
00418 mutable double m_BoundingPlane[6][4];
00420 mutable double m_BoundingCorner[8][3];
00421
00423 mutable double m_CurrentRayPositionInMM[3];
00424
00426 mutable double m_RayDirectionInMM[3];
00427
00429 InterpolatorPointer m_Interpolator;
00430
00431
00433 void EndPointsInVoxels(void) const;
00434
00439 void CalcDirnVector(void) const;
00440
00447 bool AdjustRayLength(void) const;
00448
00453 void InitialiseVoxelPointers(void) const;
00454
00456 void IncrementVoxelPointers(void) const;
00457
00459 void Initialise(void) const;
00460
00462 void RecordVolumeDimensions(void) const;
00463
00465 void DefineCorners(void) const;
00466
00478 void CalcPlanesAndCorners(void) const;
00479
00489 bool CalcRayIntercepts(void) const;
00490
00491
00492 private:
00493 RayCastInterpolateImageFunction( const Self& );
00494 void operator=( const Self& );
00495
00497 void ZeroState() const;
00498
00499
00500 };
00501
00502 }
00503
00504 #ifndef ITK_MANUAL_INSTANTIATION
00505 #include "itkRayCastInterpolateImageFunction.txx"
00506 #endif
00507
00508 #endif