NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkRay.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef itkRay_h
16 #define itkRay_h
17 
18 #include <itkMatrix.h>
19 
20 namespace itk {
21 
25 template <class TInputImage, class TCoordRep = double>
26 class ITK_EXPORT Ray
27 {
28 public:
29 
31  Ray();
32 
34  virtual ~Ray() {};
35 
36  typedef itk::Point<TCoordRep, 3> InputPointType;
37  typedef itk::Point<TCoordRep, 2> OutputPointType;
38 
39  typedef TInputImage InputImageType;
43  typedef typename InputImageType::OffsetValueType OffsetValueType;
44 
48  typedef itk::Matrix<double, 4, 4> ProjectionMatrixType;
49 
51  void SetProjectionMatrix(const ProjectionMatrixType input) { m_ProjectionMatrix = input; }
52 
53 
57  void SetImage(const InputImageType *input) {
58  m_Image = input;
59  Initialise();
60  }
61 
70  bool SetRay(OutputPointType RayPosn);
71 
76  void SetProjectionResolution2Dmm(double xRes, double yRes) {
77  m_ProjectionResolution2Dmm[0] = xRes;
78  m_ProjectionResolution2Dmm[1] = yRes;
79  }
80 
82  double GetCurrentIntensity(void) const;
83 
85  double GetRayPointSpacing(void) const {
86  typename InputImageType::SpacingType spacing=this->m_Image->GetSpacing();
87 
88  if (m_ValidRay)
89  return vcl_sqrt(m_VoxelIncrement[0]*spacing[0]*m_VoxelIncrement[0]*spacing[0]
90  + m_VoxelIncrement[1]*spacing[1]*m_VoxelIncrement[1]*spacing[1]
91  + m_VoxelIncrement[2]*spacing[2]*m_VoxelIncrement[2]*spacing[2] );
92  else
93  return 0.;
94  };
95 
97  int GetNumberOfRayPoints(void) {return m_TotalRayVoxelPlanes;}
98 
100  void GetBilinearCoefficients(double &y, double &z) const;
101 
102  PixelType **GetRayIntersectionVoxels(void) {return m_RayIntersectionVoxels;}
103 
105  const int *GetRayIntersectionVoxelIndex(void) const {return m_RayIntersectionVoxelIndex;}
106 
108  int GetTraversalDirection(void) {return m_TraversalDirection;}
109 
123  bool Integrate(double &integral)
124  {
125  return IntegrateAboveThreshold(integral, 0);
126  };
127 
128 
143  bool IntegrateAboveThreshold(double &integral, double threshold);
144 
151  bool IncrementRayVoxelIntensities(double increment);
152 
159  void IncrementIntensities(double increment);
160 
165  void IncrementIntensities(void);
166 
168  void Reset(void);
169 
179  bool NextPoint(void);
180 
181 
182 protected:
183 
185  void ZeroState();
186 
188  void Initialise(void);
189 
191  void EndPointsInVoxels(void);
192 
197  void CalcDirnVector(void);
198 
205  bool AdjustRayLength(void);
206 
211  void InitialiseVoxelPointers(void);
212 
214  void IncrementVoxelPointers(void);
215 
217  void RecordVolumeDimensions(void);
218 
220  void DefineCorners(void);
221 
233  void CalcPlanesAndCorners(void);
234 
244  bool CalcRayIntercepts(void);
245 
247  void Line3D(double x2D, double y2D, double r[3], double u[3]);
248 
249 
250 
256  typedef enum {
257  UNDEFINED_DIRECTION=0,
261  LAST_DIRECTION
262  } TraversalDirection;
263 
264  // Cache the image in the structure. Skip the smart pointer for
265  // efficiency. This inner class will go in/out of scope with every
266  // call to Evaluate()
267  const InputImageType *m_Image;
268 
271 
273  double m_RayPosition2Dmm[2];
274 
276  double m_ProjectionResolution2Dmm[2];
277 
286  double m_RayVoxelStartPosition[3];
287 
296  double m_RayVoxelEndPosition[3];
297 
298 
307  double m_Position3Dvox[3];
308 
310  double m_VoxelIncrement[3];
311 
314 
317 
320 
322  PixelType *m_RayIntersectionVoxels[4];
323 
328  int m_RayIntersectionVoxelIndex[3];
329 
336 
343 
345  double m_RayStartCoordInMM[3];
347  double m_RayEndCoordInMM[3];
348 
349 
353  double m_BoundingPlane[6][4];
355  double m_BoundingCorner[8][3];
356 
358  double m_CurrentRayPositionInMM[3];
359 
361  double m_RayDirectionInMM[3];
362 
364  ProjectionMatrixType m_ProjectionMatrix;
365 };
366 
367 } // end namespace itk
368 
369 #ifndef ITK_MANUAL_INSTANTIATION
370 #include "itkRay.txx"
371 #endif
372 
373 #endif
GLdouble GLdouble z
Definition: glew.h:1543
double m_VoxelDimensionInX
Voxel dimension in x.
Definition: itkRay.h:338
ImageType::SizeType SizeType
Definition: niftkMakeLapUSProbeBasicModel.cxx:31
z
Definition: itkRay.h:260
GLenum GLenum GLenum input
Definition: glew.h:12016
int m_NumberOfVoxelsInY
The dimension in voxels of the 3D volume in along the y axis.
Definition: itkRay.h:333
void SetProjectionMatrix(const ProjectionMatrixType input)
Set the combined affine and projection matrix.
Definition: itkRay.h:51
virtual ~Ray()
Destructor.
Definition: itkRay.h:34
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1236
Definition: niftkITKAffineResampleImage.cxx:74
double m_VoxelDimensionInZ
Voxel dimension in z.
Definition: itkRay.h:342
ImageType::IndexType IndexType
Definition: niftkMakeLapUSProbeBasicModel.cxx:32
itk::Point< double, 2 > InputPointType
Definition: EulerAffine2DJacobianTest.cxx:34
TInputImage InputImageType
Definition: itkRay.h:39
int m_NumberOfVoxelsInZ
The dimension in voxels of the 3D volume in along the z axis.
Definition: itkRay.h:335
int m_NumVoxelPlanesTraversed
The current number of planes of voxels traversed by the ray.
Definition: itkRay.h:319
InputImageType::SizeType SizeType
Definition: itkRay.h:42
InputImageType::IndexType IndexType
Definition: itkRay.h:41
double GetRayPointSpacing(void) const
Return the ray point spacing in mm.
Definition: itkRay.h:85
Class to project a ray through a 3D volume.
Definition: itkRay.h:26
int GetNumberOfRayPoints(void)
Return the number of points on the ray.
Definition: itkRay.h:97
double m_VoxelDimensionInY
Voxel dimension in y.
Definition: itkRay.h:340
float PixelType
Definition: niftkBreastDCEandADC.cxx:88
const InputImageType * m_Image
Definition: itkRay.h:267
itk::Matrix< double, 4, 4 > ProjectionMatrixType
Definition: itkRay.h:48
int GetTraversalDirection(void)
Get the traversal direction.
Definition: itkRay.h:108
InputImageType::PixelType PixelType
Definition: itkRay.h:40
itk::Point< TCoordRep, 2 > OutputPointType
Definition: itkRay.h:37
y
Definition: itkRay.h:259
InputImageType::OffsetValueType OffsetValueType
Definition: itkRay.h:43
bool Integrate(double &integral)
Integrate the interpolated intensities along the ray and return the result.
Definition: itkRay.h:123
GLdouble GLdouble GLdouble r
Definition: glew.h:1390
void SetImage(const InputImageType *input)
Definition: itkRay.h:57
PixelType ** GetRayIntersectionVoxels(void)
Definition: itkRay.h:102
int m_NumberOfVoxelsInX
The dimension in voxels of the 3D volume in along the x axis.
Definition: itkRay.h:331
void SetProjectionResolution2Dmm(double xRes, double yRes)
Definition: itkRay.h:76
TraversalDirection m_TraversalDirection
The direction in which the ray is incremented thorough the volume (x, y or z).
Definition: itkRay.h:313
ProjectionMatrixType m_ProjectionMatrix
The combined affine and perspective transformation.
Definition: itkRay.h:364
x
Definition: itkRay.h:258
const int * GetRayIntersectionVoxelIndex(void) const
Get the voxel index of the intersection.
Definition: itkRay.h:105
bool m_ValidRay
Flag indicating whether the current ray is valid.
Definition: itkRay.h:270
TraversalDirection
Definition: itkRay.h:256
int m_TotalRayVoxelPlanes
The total number of planes of voxels traversed by the ray.
Definition: itkRay.h:316