NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkUCLBSplineTransform.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 itkUCLBSplineTransform_h
16 #define itkUCLBSplineTransform_h
17 
18 #include <iostream>
19 #include "itkDeformableTransform.h"
20 #include <itkImage.h>
21 #include <itkImageRegion.h>
22 #include <itkVector.h>
23 #include <itkArray2D.h>
24 
25 #include <itkContinuousIndex.h>
26 #include <itkImageRegionIterator.h>
27 #include <itkSingleValuedCostFunction.h>
29 
30 namespace itk
31 {
32 
50 template <
51  class TFixedImage, // Templated over the image type.
52  class TScalarType, // Data type for scalars
53  unsigned int NDimensions, // Number of Dimensions i.e. 2D or 3D
54  class TDeformationScalar // Data type in the deformation field.
55  >
56 class ITK_EXPORT UCLBSplineTransform :
57  public DeformableTransform< TFixedImage, TScalarType, NDimensions, TDeformationScalar >
58 {
59 public:
60 
64  typedef SmartPointer<Self> Pointer;
65  typedef SmartPointer<const Self> ConstPointer;
66 
68  itkNewMacro( Self );
69 
72 
74  itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
75 
77  typedef typename Superclass::ScalarType ScalarType;
78 
80  typedef typename Superclass::ParametersType ParametersType;
81  typedef typename Superclass::DerivativeType DerivativeType;
83 
87 
89  typedef typename Superclass::DeformationFieldPixelType DeformationFieldPixelType;
90  typedef typename Superclass::DeformationFieldType DeformationFieldType;
91  typedef typename Superclass::DeformationFieldPointer DeformationFieldPointer;
92  typedef typename Superclass::DeformationFieldRegionType DeformationFieldRegionType;
93  typedef typename Superclass::DeformationFieldIndexType DeformationFieldIndexType;
94  typedef typename Superclass::DeformationFieldSizeType DeformationFieldSizeType;
95  typedef typename Superclass::DeformationFieldSpacingType DeformationFieldSpacingType;
96  typedef typename Superclass::DeformationFieldDirectionType DeformationFieldDirectionType;
97  typedef typename Superclass::DeformationFieldOriginType DeformationFieldOriginType;
98 
100  typedef Vector< TDeformationScalar, NDimensions > GridPixelType;
102  typedef typename GridImageType::Pointer GridImagePointer;
103  typedef ImageRegion<NDimensions> GridRegionType;
106  typedef typename GridImageType::SpacingType GridSpacingType;
107  typedef typename GridImageType::DirectionType GridDirectionType;
108  typedef typename GridImageType::PointType GridOriginType;
109 
111  typedef TDeformationScalar BendingEnergyPixelType;
113  typedef ImageRegion<NDimensions> BendingEnergyImageRegionType;
115  typedef typename BendingEnergyImageType::Pointer BendingEnergyImagePointer;
116  typedef const BendingEnergyImageType* BendingEnergyImageConstPointer;
117  typedef ImageRegionIterator<BendingEnergyImageType> BendingEnergyIteratorType;
118  typedef ScalarImageToNormalizedGradientVectorImageFilter<BendingEnergyImageType,
123  typedef ImageRegionConstIterator<BendingEnergyDerivativeImageType> BendingEnergyDerivativeIteratorType;
124 
126  typedef TFixedImage FixedImageType;
127  typedef typename FixedImageType::ConstPointer FixedImagePointer;
128 
130  typedef itk::ContinuousIndex<TDeformationScalar, NDimensions> GridVoxelCoordinateType;
131  typedef itk::ImageRegionIterator<DeformationFieldType> DeformationFieldIteratorType;
132  typedef itk::ImageRegionConstIteratorWithIndex<GridImageType> GridConstIteratorType;
133  typedef itk::ImageRegionIterator<GridImageType> GridIteratorType;
134 
136  typedef SingleValuedCostFunction::MeasureType MeasureType;
137 
143  virtual void SetIdentity();
144 
150  void Initialize(FixedImagePointer fixedImage, GridSpacingType finalGridSpacingInMillimetres, int numberOfLevels);
151 
153  void InterpolateNextGrid(FixedImagePointer fixedImage);
154 
166  void SetParameters(const ParametersType & parameters);
167 
169  virtual const ParametersType& GetFixedParameters(void) const;
170 
172  virtual void SetFixedParameters(const ParametersType& parameters);
173 
175  MeasureType GetBendingEnergy();
176 
178  itkGetMacro(BendingEnergyHasBeenUpdatedFlag, bool);
179 
181  void GetBendingEnergyDerivative(DerivativeType & derivative);
182 
184  void GetBendingEnergyDerivativeDaniel(DerivativeType & derivative);
185 
187  void GetBendingEnergyDerivativeMarc(DerivativeType & derivative);
188 
190  itkGetObjectMacro(Grid, GridImageType);
191 
194  virtual void WriteParameters(std::string filename) { this->WriteControlPointImage(filename); }
195 
197  void WriteControlPointImage(std::string filename);
198 
200  virtual OutputPointType TransformPoint(const InputPointType &point ) const;
201 
202 protected:
203 
205  virtual ~UCLBSplineTransform();
206 
208  void PrintSelf(std::ostream &os, Indent indent) const;
209 
210 private:
211  UCLBSplineTransform(const Self&); // purposely not implemented
212  void operator=(const Self&); // purposely not implemented
213 
215  const static unsigned int s_LookupTableRows = 1000;
216  const static unsigned int s_LookupTableSize = s_LookupTableRows - 1;
217  const static unsigned int s_LookupTableCols = 4;
218 
220  GridImagePointer m_Grid;
221  GridImagePointer m_OldGrid;
222 
224  bool m_BendingEnergyHasBeenUpdatedFlag;
225  BendingEnergyImagePointer m_BendingEnergyGrid;
226  BendingEnergyDerivativeFilterPointer m_BendingEnergyDerivativeFilter;
227 
229  void InterpolateDeformationField2D();
230 
232  void InterpolateDeformationField3DDaniel();
233 
235  void InterpolateDeformationField3DMarc();
236 
238  MeasureType GetBendingEnergy2D(TScalarType divisor) const;
239 
241  MeasureType GetBendingEnergy3DDaniel(TScalarType divisor) const;
242 
244  MeasureType GetBendingEnergy3DMarc(TScalarType divisor) const;
245 
247  void InterpolateNextGrid2D(GridImagePointer& oldGrid, GridImagePointer &newGrid);
248 
250  void InterpolateNextGrid3D(GridImagePointer& oldGrid, GridImagePointer &newGrid);
251 
253  TScalarType GetNewOrigin(TScalarType oldSize, TScalarType oldSpacing, TScalarType oldOrigin, TScalarType newSize, TScalarType newSpacing);
254 
256  void InitializeGrid(FixedImagePointer fixedImage,
257  GridRegionType gridRegion,
258  GridSpacingType gridSpacing,
259  GridDirectionType gridDirection,
260  GridOriginType gridOrigin);
261 
263  Array2D<TScalarType> m_Lookup;
264  Array2D<TScalarType> m_Lookup1stDerivative;
265  Array2D<TScalarType> m_Lookup2ndDerivative;
266 
267  TScalarType B0(TScalarType u) { return ((1-u)*(1-u)*(1-u))/6.0; }
268  TScalarType B1(TScalarType u) { return (3*u*u*u - 6*u*u + 4)/6.0; }
269  TScalarType B2(TScalarType u) { return (-3*u*u*u + 3*u*u + 3*u + 1)/6.0; }
270  TScalarType B3(TScalarType u) { return (u*u*u)/6.0; }
271  TScalarType B01(TScalarType u) { return -(1-u)*(1-u)/2.0; }
272  TScalarType B11(TScalarType u) { return (9*u*u - 12*u)/6.0; }
273  TScalarType B21(TScalarType u) { return (-9*u*u + 6*u + 3)/6.0; }
274  TScalarType B31(TScalarType u) { return (u*u)/2.0; }
275  TScalarType B02(TScalarType u) { return 1-u; }
276  TScalarType B12(TScalarType u) { return 3*u - 2; }
277  TScalarType B22(TScalarType u) { return -3*u + 1; }
278  TScalarType B32(TScalarType u) { return u; }
279 
280  TScalarType B(int i, TScalarType u)
281  {
282  switch (i) {
283  case 0: return B0(u);
284  case 1: return B1(u);
285  case 2: return B2(u);
286  case 3: return B3(u);
287  }
288  return 0;
289  }
290 
291  TScalarType B1(int i, TScalarType u)
292  {
293  switch (i) {
294  case 0: return B01(u);
295  case 1: return B11(u);
296  case 2: return B21(u);
297  case 3: return B31(u);
298  }
299  return 0;
300  }
301 
302  TScalarType B2(int i, TScalarType u)
303  {
304  switch (i) {
305  case 0: return B02(u);
306  case 1: return B12(u);
307  case 2: return B22(u);
308  case 3: return B32(u);
309  }
310  return 0;
311  }
312 
313  TScalarType B(int i, int derivative, TScalarType u)
314  {
315  switch(derivative) {
316  case 0: return B(i, u);
317  case 1: return B1(i, u);
318  case 2: return B2(i, u);
319  }
320  return 0;
321  }
322 
323 }; // class UCLBSplineTransform
324 
325 
326 } // namespace itk
327 
328 #ifndef ITK_MANUAL_INSTANTIATION
329 #include "itkUCLBSplineTransform.txx"
330 #endif
331 
332 #endif /* itkUCLBSplineTransform_h */
ImageRegionIterator< BendingEnergyImageType > BendingEnergyIteratorType
Definition: itkUCLBSplineTransform.h:117
BendingEnergyDerivativeFilterType::OutputImageType BendingEnergyDerivativeImageType
Definition: itkUCLBSplineTransform.h:122
Superclass::DeformationFieldSpacingType DeformationFieldSpacingType
Definition: itkUCLBSplineTransform.h:95
ImageType::SizeType SizeType
Definition: niftkMakeLapUSProbeBasicModel.cxx:31
Deformable transform using a BSpline representation.
Definition: itkUCLBSplineTransform.h:56
Superclass::ParametersType ParametersType
Definition: itkUCLBSplineTransform.h:80
GridImageType::PointType GridOriginType
Definition: itkUCLBSplineTransform.h:108
GridImageType::DirectionType GridDirectionType
Definition: itkUCLBSplineTransform.h:107
Superclass::InputPointType InputPointType
Definition: itkUCLBSplineTransform.h:85
SmartPointer< Self > Pointer
Definition: itkScalarImageToNormalizedGradientVectorImageFilter.h:82
DeformableTransform< TFixedImage, TScalarType, NDimensions, TDeformationScalar > Superclass
Definition: itkUCLBSplineTransform.h:63
BendingEnergyDerivativeFilterType::OutputPixelType BendingEnergyDerivativePixelType
Definition: itkUCLBSplineTransform.h:121
Superclass::DeformationFieldPixelType DeformationFieldPixelType
Definition: itkUCLBSplineTransform.h:89
Vector< VectorDataType, itkGetStaticConstMacro(Dimension) > OutputPixelType
Definition: itkScalarImageToNormalizedGradientVectorImageFilter.h:98
Vector< TDeformationScalar, NDimensions > GridPixelType
Definition: itkUCLBSplineTransform.h:100
UCLBSplineTransform Self
Definition: itkUCLBSplineTransform.h:62
Base class for deformable transforms.
Definition: itkDeformableTransform.h:69
GridRegionType::SizeType GridSizeType
Definition: itkUCLBSplineTransform.h:105
Superclass::OutputPointType OutputPointType
Definition: itkUCLBSplineTransform.h:86
GLuint divisor
Definition: glew.h:2372
Definition: niftkITKAffineResampleImage.cxx:74
ImageRegionConstIterator< BendingEnergyDerivativeImageType > BendingEnergyDerivativeIteratorType
Definition: itkUCLBSplineTransform.h:123
BendingEnergyImageRegionType::SizeType BendingEnergyImageSizeType
Definition: itkUCLBSplineTransform.h:114
ImageType::IndexType IndexType
Definition: niftkMakeLapUSProbeBasicModel.cxx:32
itk::Point< double, 2 > InputPointType
Definition: EulerAffine2DJacobianTest.cxx:34
SmartPointer< const Self > ConstPointer
Definition: itkUCLBSplineTransform.h:65
Superclass::DeformationFieldDirectionType DeformationFieldDirectionType
Definition: itkUCLBSplineTransform.h:96
Superclass::DeformationFieldType DeformationFieldType
Definition: itkUCLBSplineTransform.h:90
TDeformationScalar BendingEnergyPixelType
Definition: itkUCLBSplineTransform.h:111
Superclass::ScalarType ScalarType
Definition: itkUCLBSplineTransform.h:77
ImageRegion< NDimensions > GridRegionType
Definition: itkUCLBSplineTransform.h:103
SmartPointer< Self > Pointer
Definition: itkUCLBSplineTransform.h:64
GridImageType::SpacingType GridSpacingType
Definition: itkUCLBSplineTransform.h:106
Image< GridPixelType, NDimensions > GridImageType
Definition: itkUCLBSplineTransform.h:101
FixedImageType::ConstPointer FixedImagePointer
Definition: itkUCLBSplineTransform.h:127
Superclass::DeformationFieldPointer DeformationFieldPointer
Definition: itkUCLBSplineTransform.h:91
Image< TDeformationScalar, NDimensions > BendingEnergyImageType
Definition: itkUCLBSplineTransform.h:112
itk::ImageRegionIterator< DeformationFieldType > DeformationFieldIteratorType
Definition: itkUCLBSplineTransform.h:131
BendingEnergyImageType::Pointer BendingEnergyImagePointer
Definition: itkUCLBSplineTransform.h:115
Superclass::JacobianType JacobianType
Definition: itkUCLBSplineTransform.h:82
Superclass::DerivativeType DerivativeType
Definition: itkUCLBSplineTransform.h:81
Superclass::DeformationFieldSizeType DeformationFieldSizeType
Definition: itkUCLBSplineTransform.h:94
Superclass::DeformationFieldRegionType DeformationFieldRegionType
Definition: itkUCLBSplineTransform.h:92
GridImageType::Pointer GridImagePointer
Definition: itkUCLBSplineTransform.h:102
BendingEnergyDerivativeFilterType::Pointer BendingEnergyDerivativeFilterPointer
Definition: itkUCLBSplineTransform.h:120
Superclass::DeformationFieldIndexType DeformationFieldIndexType
Definition: itkUCLBSplineTransform.h:93
GridRegionType::IndexType GridIndexType
Definition: itkUCLBSplineTransform.h:104
itk::ContinuousIndex< TDeformationScalar, NDimensions > GridVoxelCoordinateType
Definition: itkUCLBSplineTransform.h:130
virtual void WriteParameters(std::string filename)
Definition: itkUCLBSplineTransform.h:194
TFixedImage FixedImageType
Definition: itkUCLBSplineTransform.h:126
SingleValuedCostFunction::MeasureType MeasureType
Definition: itkUCLBSplineTransform.h:136
Simultaneous itk::Image and itk::Array (and hence vnl_vector) class.
const BendingEnergyImageType * BendingEnergyImageConstPointer
Definition: itkUCLBSplineTransform.h:116
Superclass::DeformationFieldOriginType DeformationFieldOriginType
Definition: itkUCLBSplineTransform.h:97
itk::ImageRegionConstIteratorWithIndex< GridImageType > GridConstIteratorType
Definition: itkUCLBSplineTransform.h:132
ImageRegion< NDimensions > BendingEnergyImageRegionType
Definition: itkUCLBSplineTransform.h:113
This class takes scalar image as input, and outputs a vector field of image gradient.
Definition: itkScalarImageToNormalizedGradientVectorImageFilter.h:67
ScalarImageToNormalizedGradientVectorImageFilter< BendingEnergyImageType, TDeformationScalar > BendingEnergyDerivativeFilterType
Definition: itkUCLBSplineTransform.h:119
itk::Point< double, 2 > OutputPointType
Definition: EulerAffine2DJacobianTest.cxx:35
GLsizei const GLcharARB ** string
Definition: glew.h:5194
itk::ImageRegionIterator< GridImageType > GridIteratorType
Definition: itkUCLBSplineTransform.h:133
itk::Array2D< double > JacobianType
Definition: EulerAffine2DJacobianTest.cxx:28