NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkDeformableTransform.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 itkDeformableTransform_h
16 #define itkDeformableTransform_h
17 
18 #include <itkTransform.h>
19 #include <itkImage.h>
20 #include <itkVector.h>
21 #include <itkImageRegionIterator.h>
22 #include <itkDisplacementFieldJacobianDeterminantFilter.h>
24 
25 namespace itk
26 {
27 
64 template <
65  class TFixedImage, // Templated over the image type.
66  class TScalarType, // Data type for scalars
67  unsigned int NDimensions, // Number of Dimensions i.e. 2D or 3D
68  class TDeformationScalar> // Data type in the deformation field.
69 class ITK_EXPORT DeformableTransform : public Transform< TScalarType, NDimensions, NDimensions >
70 {
71 public:
72 
75  typedef Transform< TScalarType, NDimensions, NDimensions > Superclass;
76  typedef SmartPointer<Self> Pointer;
77  typedef SmartPointer<const Self> ConstPointer;
78 
80  itkTypeMacro( DeformableTransform, Transform );
81 
83  itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
84 
86  typedef typename Superclass::ScalarType ScalarType;
87 
89  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
90  typedef typename Superclass::ParametersType ParametersType;
91  typedef typename Superclass::ParametersValueType ParametersValueType;
92  typedef Array<ParametersValueType> DerivativeType;
93 
97 
99  typedef typename Superclass::InputVectorType InputVectorType;
100  typedef typename Superclass::OutputVectorType OutputVectorType;
101 
103  typedef typename Superclass::InputCovariantVectorType InputCovariantVectorType;
104  typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType;
105 
107  typedef typename Superclass::InputVnlVectorType InputVnlVectorType;
108  typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
109 
111  typedef Vector< TDeformationScalar, NDimensions > VectorFieldPixelType;
113  typedef typename VectorFieldImageType::Pointer VectorFieldImagePointer;
115  typedef ImageRegionIterator<VectorFieldImageType> VectorFieldIteratorType;
116  typedef ImageRegionConstIterator<VectorFieldImageType> VectorFieldConstIteratorType;
121  typedef VectorFieldPixelType DeformationFieldPixelType;
122  typedef VectorFieldImageType DeformationFieldType;
123  typedef typename DeformationFieldType::Pointer DeformationFieldPointer;
124  typedef ImageRegion<NDimensions> DeformationFieldRegionType;
127  typedef typename DeformationFieldType::SpacingType DeformationFieldSpacingType;
128  typedef typename DeformationFieldType::DirectionType DeformationFieldDirectionType;
129  typedef typename DeformationFieldType::PointType DeformationFieldOriginType;
131 
133  typedef TFixedImage FixedImageType;
134  typedef typename FixedImageType::ConstPointer FixedImagePointer;
135 
137  typedef Transform<TScalarType,
138  itkGetStaticConstMacro(SpaceDimension),
139  itkGetStaticConstMacro(SpaceDimension)> GlobalTransformType;
140  typedef typename GlobalTransformType::ConstPointer GlobalTransformPointer;
141 
143  typedef DisplacementFieldJacobianDeterminantFilter<
144  DeformationFieldType,
146  typedef typename JacobianDeterminantFilterType::Pointer JacobianDeterminantFilterPointer;
147 
149 
153  itkSetConstObjectMacro( GlobalTransform, GlobalTransformType );
154  itkGetConstObjectMacro( GlobalTransform, GlobalTransformType );
155 
159  itkSetMacro(InverseSearchRadius, double);
160  itkGetMacro(InverseSearchRadius, double);
161 
165  virtual const ParametersType& GetParameters(void) const { return this->m_Parameters; }
166 
170  virtual void SetParameters(const ParametersType& parameters) { this->m_Parameters = parameters; }
171 
175  virtual NumberOfParametersType GetNumberOfParameters(void) const { return this->m_Parameters.Size(); }
176 
183  virtual void SetParametersFromField(const VectorFieldImagePointer& image, bool force=false);
184 
188  virtual DeformationFieldType* GetDeformationField() const { return this->m_DeformationField.GetPointer(); }
189 
194  TScalarType ComputeMaxDeformation();
195 
200  TScalarType ComputeMinDeformation();
201 
203  TScalarType ComputeMaxJacobian();
204 
206  TScalarType ComputeMinJacobian();
207 
209  TScalarType GetSumLogJacobianDeterminant();
210 
212  virtual void WriteTransform(std::string filename) { this->WriteVectorImage(filename); }
213 
215  virtual void WriteParameters(std::string filename) { this->WriteVectorImage(filename); }
216 
218  void WriteJacobianImage(std::string filename);
219 
221  void WriteMidasStrImage(std::string filename, int origin[NDimensions], typename TFixedImage::RegionType paddedDesiredRegion, const typename JacobianDeterminantFilterType::OutputImageType* jacobianImage);
222 
224  void ReadMidasStrImage(std::string filename, int origin[NDimensions], typename TFixedImage::RegionType paddedDesiredRegion, typename JacobianDeterminantFilterType::OutputImageType* jacobianImage);
225 
227  void WriteMidasVecImage(std::string filename, int origin[NDimensions], typename TFixedImage::RegionType paddedDesiredRegion);
228 
230  void WriteVectorImage(std::string filename);
231 
237  virtual void SetIdentity();
238 
244  void Initialize(FixedImagePointer image);
245 
247  virtual OutputPointType TransformPoint(const InputPointType &point ) const;
248 
250  virtual OutputVectorType TransformVector(const InputVectorType &) const
251  {
252  itkExceptionMacro( << "Method not applicable for deformable transform." );
253  return OutputVectorType();
254  }
255 
257  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
258  {
259  itkExceptionMacro(<< "Method not applicable for deformable transform. ");
260  return OutputVnlVectorType();
261  }
262 
264  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
265  {
266  itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
267  return OutputCovariantVectorType();
268  }
269 
276  virtual bool IsLinear() const { return false; }
277 
279  virtual bool IsIdentity();
280 
282  virtual const ParametersType& GetFixedParameters(void) const;
283 
285  virtual void SetFixedParameters(const ParametersType& parameters);
286 
292  bool GetInverse(Self* inverse) const;
296  void ConcatenateAfterGivenTransform(Self* givenTransform);
301  virtual bool IsRegridable() const { return false; }
305  virtual void UpdateRegriddedDeformationParameters(ParametersType& regriddedParameters, const ParametersType& currentPosition)
306  {
307  itkExceptionMacro( << "Method Regrid not implemented for deformable transform." );
308  }
314  {
316  this->m_JacobianFilter = FilterType::New();
317  this->m_JacobianFilter->SetInput(this->m_DeformationField);
318  this->m_JacobianFilter->SetUseImageSpacingOff();
319  }
323  void InitialiseGlobalTransformation();
324 
328  typename JacobianDeterminantFilterType::OutputImageType* GetJacobianImage() const { return m_JacobianFilter->GetOutput(); }
329 
333  void ExtractComponents();
334 
343  void InvertUsingIterativeFixedPoint(typename Self::Pointer invertedTransform, int maxIterations, int maxOuterIterations, double tol);
344 
345  virtual void ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const
346  {
347  // TODO
348  itkExceptionMacro( << "Not Implemented" );
349  }
350 
351 protected:
352 
354  virtual ~DeformableTransform();
355 
357  void PrintSelf(std::ostream &os, Indent indent) const;
358 
360  unsigned long int GetNumberOfParametersImpliedByImage(const VectorFieldImagePointer image);
361 
363  void ResizeParametersArray(const VectorFieldImagePointer image);
364 
366  void MarshallParametersToImage(VectorFieldImagePointer image);
367 
369  void MarshallImageToParameters(const VectorFieldImagePointer image, ParametersType& parameters);
370 
372  virtual typename JacobianDeterminantFilterType::OutputImageRegionType GetValidJacobianRegion() const { return this->m_JacobianFilter->GetOutput()->GetLargestPossibleRegion(); }
373 
375  typename DeformationFieldType::Pointer m_DeformationField;
376 
378  GlobalTransformPointer m_GlobalTransform;
379 
381  JacobianDeterminantFilterPointer m_JacobianFilter;
382 
385 
388 
391 
394 
398  typename DeformationFieldComponentImageType::Pointer m_DeformationFieldComponent[NDimensions];
399 
400 private:
401 
402  DeformableTransform(const Self&); // purposefully not implemented
403  void operator=(const Self&); // purposefully not implemented
404 
406  mutable DeformationFieldIndexType m_TemporaryIndex;
407 
409  void ForceJacobianUpdate();
410 
411 };
412 
413 } // namespace itk.
414 
415 #ifndef ITK_MANUAL_INSTANTIATION
416 #include "itkDeformableTransform.txx"
417 #endif
418 
419 #endif /*ITKDEFORMABLETRANSFORM_H_*/
GlobalTransformPointer m_GlobalTransform
Definition: itkDeformableTransform.h:378
DeformableTransform Self
Definition: itkDeformableTransform.h:74
void SetUseForwardDifferenceJacobianCalculation()
Definition: itkDeformableTransform.h:313
Transform< TScalarType, NDimensions, NDimensions > Superclass
Definition: itkDeformableTransform.h:75
JacobianDeterminantFilterType::OutputImageType * GetJacobianImage() const
Definition: itkDeformableTransform.h:328
virtual bool IsLinear() const
Definition: itkDeformableTransform.h:276
ImageType::SizeType SizeType
Definition: niftkMakeLapUSProbeBasicModel.cxx:31
DeformationFieldType::Pointer m_DeformationField
Definition: itkDeformableTransform.h:375
Superclass::OutputVectorType OutputVectorType
Definition: itkDeformableTransform.h:100
DisplacementFieldJacobianDeterminantFilter< DeformationFieldType, TScalarType > JacobianDeterminantFilterType
Definition: itkDeformableTransform.h:145
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkDeformableTransform.h:250
VectorFieldImageType::SizeType VectorFieldSizeType
Definition: itkDeformableTransform.h:114
double m_InverseIterationTolerance
Definition: itkDeformableTransform.h:390
Vector< TDeformationScalar, NDimensions > VectorFieldPixelType
Definition: itkDeformableTransform.h:111
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:4052
DeformationFieldType::SpacingType DeformationFieldSpacingType
Definition: itkDeformableTransform.h:127
Image< TDeformationScalar, NDimensions > DeformationFieldComponentImageType
Definition: itkDeformableTransform.h:130
JacobianDeterminantFilterPointer m_JacobianFilter
Definition: itkDeformableTransform.h:381
Transform< TScalarType, itkGetStaticConstMacro(SpaceDimension), itkGetStaticConstMacro(SpaceDimension)> GlobalTransformType
Definition: itkDeformableTransform.h:139
Base class for deformable transforms.
Definition: itkDeformableTransform.h:69
virtual void WriteTransform(std::string filename)
Definition: itkDeformableTransform.h:212
VectorFieldImageType::Pointer VectorFieldImagePointer
Definition: itkDeformableTransform.h:113
Definition: niftkITKAffineResampleImage.cxx:74
ImageType::IndexType IndexType
Definition: niftkMakeLapUSProbeBasicModel.cxx:32
itk::Point< double, 2 > InputPointType
Definition: EulerAffine2DJacobianTest.cxx:34
Superclass::OutputPointType OutputPointType
Definition: itkDeformableTransform.h:95
virtual NumberOfParametersType GetNumberOfParameters(void) const
Definition: itkDeformableTransform.h:175
DeformationFieldType::DirectionType DeformationFieldDirectionType
Definition: itkDeformableTransform.h:128
Image< VectorFieldPixelType, NDimensions > VectorFieldImageType
Definition: itkDeformableTransform.h:112
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkDeformableTransform.h:257
virtual void SetParameters(const ParametersType &parameters)
Definition: itkDeformableTransform.h:170
Superclass::InputVnlVectorType InputVnlVectorType
Definition: itkDeformableTransform.h:107
virtual bool IsRegridable() const
Definition: itkDeformableTransform.h:301
SmartPointer< Self > Pointer
Definition: itkDeformableTransform.h:76
Superclass::InputPointType InputPointType
Definition: itkDeformableTransform.h:96
Superclass::OutputVnlVectorType OutputVnlVectorType
Definition: itkDeformableTransform.h:108
ImageRegion< NDimensions > DeformationFieldRegionType
Definition: itkDeformableTransform.h:124
VectorFieldPixelType DeformationFieldPixelType
Definition: itkDeformableTransform.h:121
DeformationFieldRegionType::SizeType DeformationFieldSizeType
Definition: itkDeformableTransform.h:126
ImageRegionIterator< VectorFieldImageType > VectorFieldIteratorType
Definition: itkDeformableTransform.h:115
ImageType::RegionType RegionType
Definition: niftkMakeLapUSProbeBasicModel.cxx:30
SmartPointer< const Self > ConstPointer
Definition: itkDeformableTransform.h:77
double m_MaxNumberOfInverseIterations
Definition: itkDeformableTransform.h:393
Superclass::JacobianType JacobianType
Definition: itkDeformableTransform.h:148
virtual void WriteParameters(std::string filename)
Definition: itkDeformableTransform.h:215
DeformationFieldType::PointType DeformationFieldOriginType
Definition: itkDeformableTransform.h:129
VectorFieldImageType DeformationFieldType
Definition: itkDeformableTransform.h:122
Superclass::InputCovariantVectorType InputCovariantVectorType
Definition: itkDeformableTransform.h:103
virtual void ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const
Definition: itkDeformableTransform.h:345
double m_InverseSearchRadius
Definition: itkDeformableTransform.h:384
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkDeformableTransform.h:264
virtual void UpdateRegriddedDeformationParameters(ParametersType &regriddedParameters, const ParametersType &currentPosition)
Definition: itkDeformableTransform.h:305
DeformationFieldRegionType::IndexType DeformationFieldIndexType
Definition: itkDeformableTransform.h:125
DeformationFieldType::Pointer DeformationFieldPointer
Definition: itkDeformableTransform.h:123
Simultaneous itk::Image and itk::Array (and hence vnl_vector) class.
Definition: itkForwardDifferenceDisplacementFieldJacobianDeterminantFilter.h:28
FixedImageType::ConstPointer FixedImagePointer
Definition: itkDeformableTransform.h:134
TFixedImage FixedImageType
Definition: itkDeformableTransform.h:133
GlobalTransformType::ConstPointer GlobalTransformPointer
Definition: itkDeformableTransform.h:140
virtual JacobianDeterminantFilterType::OutputImageRegionType GetValidJacobianRegion() const
Definition: itkDeformableTransform.h:372
itk::AddImageFilter< ImageType, ImageType > FilterType
Definition: ReceptorMemberCommandTest.cxx:40
Superclass::OutputCovariantVectorType OutputCovariantVectorType
Definition: itkDeformableTransform.h:104
Superclass::ParametersValueType ParametersValueType
Definition: itkDeformableTransform.h:91
ImageRegionConstIterator< VectorFieldImageType > VectorFieldConstIteratorType
Definition: itkDeformableTransform.h:116
JacobianDeterminantFilterType::Pointer JacobianDeterminantFilterPointer
Definition: itkDeformableTransform.h:146
double m_InverseVoxelTolerance
Definition: itkDeformableTransform.h:387
virtual const ParametersType & GetParameters(void) const
Definition: itkDeformableTransform.h:165
itk::Point< double, 2 > OutputPointType
Definition: EulerAffine2DJacobianTest.cxx:35
Superclass::ParametersType ParametersType
Definition: itkDeformableTransform.h:90
GLsizei const GLcharARB ** string
Definition: glew.h:5194
itk::Array2D< double > JacobianType
Definition: EulerAffine2DJacobianTest.cxx:28
Superclass::InputVectorType InputVectorType
Definition: itkDeformableTransform.h:99
Array< ParametersValueType > DerivativeType
Definition: itkDeformableTransform.h:92
Superclass::ScalarType ScalarType
Definition: itkDeformableTransform.h:86
virtual DeformationFieldType * GetDeformationField() const
Definition: itkDeformableTransform.h:188
Superclass::NumberOfParametersType NumberOfParametersType
Definition: itkDeformableTransform.h:89