ITK  5.4.0
Insight Toolkit
itkTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkTransform_h
19 #define itkTransform_h
20 
21 #include <type_traits> // For std::enable_if
22 #include "itkTransformBase.h"
23 #include "itkVector.h"
25 #include "itkDiffusionTensor3D.h"
27 #include "vnl/vnl_vector_fixed.h"
28 #include "vnl/vnl_matrix_fixed.h"
29 #include "itkMatrix.h"
30 
31 namespace itk
32 {
82 template <typename TParametersValueType, unsigned int VInputDimension = 3, unsigned int VOutputDimension = 3>
83 class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersValueType>
84 {
85 public:
86  ITK_DISALLOW_COPY_AND_MOVE(Transform);
90  using Self = Transform;
94 
96  itkTypeMacro(Transform, TransformBaseTemplate);
97 
99  static constexpr unsigned int InputSpaceDimension = VInputDimension;
100  static constexpr unsigned int OutputSpaceDimension = VOutputDimension;
101 
103  itkCloneMacro(Self);
104 
106  unsigned int
107  GetInputSpaceDimension() const override
108  {
109  return VInputDimension;
110  }
111 
113  unsigned int
114  GetOutputSpaceDimension() const override
115  {
116  return VOutputDimension;
117  }
118 
119 
120  /* For storing the name of InputSpace */
121  itkSetMacro(InputSpaceName, std::string);
122  itkGetConstReferenceMacro(InputSpaceName, std::string);
123 
130  itkSetMacro(OutputSpaceName, std::string);
131  itkGetConstReferenceMacro(OutputSpaceName, std::string);
132 
134  using typename Superclass::FixedParametersType;
135  using typename Superclass::FixedParametersValueType;
136  using typename Superclass::ParametersType;
137  using typename Superclass::ParametersValueType;
139 
142 
145  using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, VOutputDimension, VInputDimension>;
146  using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, VInputDimension, VOutputDimension>;
147 
151 
156 
157  /* Standard symmetric second rank tenosr type for this class */
160 
161  /* Standard tensor type for this class */
164 
168 
170  using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, VInputDimension>;
171  using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, VOutputDimension>;
172 
176 
180 
182 
184 
188 
189  using typename Superclass::NumberOfParametersType;
190 
195  virtual OutputPointType
196  TransformPoint(const InputPointType &) const = 0;
197 
199  virtual OutputVectorType
201  {
202  itkExceptionMacro("TransformVector(const InputVectorType &)"
203  "is unimplemented for "
204  << this->GetNameOfClass());
205  }
206 
211  virtual OutputVectorType
212  TransformVector(const InputVectorType & vector, const InputPointType & point) const;
213 
215  virtual OutputVnlVectorType
217  {
218  itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is "
219  "unimplemented for "
220  << this->GetNameOfClass());
221  }
222 
227  virtual OutputVnlVectorType
228  TransformVector(const InputVnlVectorType & vector, const InputPointType & point) const;
229 
231  virtual OutputVectorPixelType
232  TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
233  {
234  itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is "
235  "unimplemented for "
236  << this->GetNameOfClass());
237  }
238 
243  virtual OutputVectorPixelType
244  TransformVector(const InputVectorPixelType & vector, const InputPointType & point) const;
245 
247  virtual OutputCovariantVectorType
249  {
250  itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is "
251  "unimplemented for "
252  << this->GetNameOfClass());
253  }
254 
260  virtual OutputCovariantVectorType
261  TransformCovariantVector(const InputCovariantVectorType & vector, const InputPointType & point) const;
262 
263 
265  virtual OutputVectorPixelType
266  TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
267  {
268  itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)"
269  "is unimplemented for "
270  << this->GetNameOfClass());
271  }
272 
278  virtual OutputVectorPixelType
279  TransformCovariantVector(const InputVectorPixelType & vector, const InputPointType & point) const;
280 
282  virtual OutputDiffusionTensor3DType
283  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & itkNotUsed(tensor)) const
284  {
285  itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
286  "unimplemented for "
287  << this->GetNameOfClass());
288  }
289 
295  virtual OutputDiffusionTensor3DType
296  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & inputTensor, const InputPointType & point) const;
297 
299  virtual OutputVectorPixelType
300  TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
301  {
302  itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is "
303  "unimplemented for "
304  << this->GetNameOfClass());
305  }
306 
307  virtual OutputVectorPixelType
308  TransformDiffusionTensor3D(const InputVectorPixelType & inputTensor, const InputPointType & point) const;
309 
315  virtual OutputSymmetricSecondRankTensorType
316  TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType & inputTensor,
317  const InputPointType & point) const;
318 
320  virtual OutputSymmetricSecondRankTensorType
322  {
323  itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
324  "unimplemented for "
325  << this->GetNameOfClass());
326  }
327 
329  virtual OutputVectorPixelType
331  {
332  itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
333  "unimplemented for "
334  << this->GetNameOfClass());
335  }
336 
343  virtual OutputVectorPixelType
344  TransformSymmetricSecondRankTensor(const InputVectorPixelType & inputTensor, const InputPointType & point) const;
345 
353  void
354  SetParameters(const ParametersType &) override = 0;
355 
363  void
365  {
366  this->SetParameters(p);
367  }
368 
373  void
374  CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
375 
380  void
381  CopyInFixedParameters(const FixedParametersValueType * const begin,
382  const FixedParametersValueType * const end) override;
383 
385  const ParametersType &
386  GetParameters() const override
387  {
388  return m_Parameters;
389  }
390 
392  void
393  SetFixedParameters(const FixedParametersType &) override = 0;
394 
396  const FixedParametersType &
397  GetFixedParameters() const override
398  {
399  return m_FixedParameters;
400  }
401 
409  virtual void
410  UpdateTransformParameters(const DerivativeType & update, ParametersValueType factor = 1.0);
411 
420  virtual NumberOfParametersType
422  {
423  return this->GetNumberOfParameters();
424  }
425 
427  NumberOfParametersType
428  GetNumberOfParameters() const override
429  {
430  return this->m_Parameters.Size();
431  }
432 
434  virtual NumberOfParametersType
436  {
437  return this->m_FixedParameters.Size();
438  }
439 
448  bool
449  GetInverse(Self * itkNotUsed(inverseTransform)) const
450  {
451  return false;
452  }
453 
460  virtual InverseTransformBasePointer
462  {
463  return nullptr;
464  }
465 
467  std::string
468  GetTransformTypeAsString() const override;
469 
470  using typename Superclass::TransformCategoryEnum;
471 
475  TransformCategoryEnum
476  GetTransformCategory() const override
477  {
478  return Superclass::TransformCategoryEnum::UnknownTransformCategory;
479  }
480 
481  virtual bool
482  IsLinear() const
483  {
484  return (this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear);
485  }
486 
521  virtual void
522  ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p),
523  JacobianType & itkNotUsed(jacobian)) const = 0;
526  virtual void
528  JacobianType & jacobian,
529  JacobianType & itkNotUsed(cachedJacobian)) const
530  {
531  // NOTE: default implementation is not optimized, and just falls back to original methods.
532  this->ComputeJacobianWithRespectToParameters(p, jacobian);
533  }
534 
535 
541  virtual void
543  JacobianPositionType & itkNotUsed(jacobian)) const
544  {
545  itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType )"
546  " is unimplemented for "
547  << this->GetNameOfClass());
548  }
549  itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
550  const);
559  virtual void
560  ComputeInverseJacobianWithRespectToPosition(const InputPointType & pnt, InverseJacobianPositionType & jacobian) const;
561  itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
562  JacobianType & jacobian) const);
574  template <typename TImage>
575  std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
576  ApplyToImageMetadata(TImage * image) const;
577  template <typename TImage>
578  std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
580  {
581  this->ApplyToImageMetadata(image.GetPointer()); // Delegate to the raw pointer signature
582  }
585 protected:
591  typename LightObject::Pointer
592  InternalClone() const override;
593 
595  Transform() = default;
596 
597  Transform(NumberOfParametersType numberOfParameters);
598 #if defined(__GNUC__)
599  // A bug in some versions of the GCC and Clang compilers
600  // result in an ICE or linker error when "= default" is requested.
601  // This was observed in at least gcc 4.8 and 5.4.0, and
602  // AppleClang 7.0.2 and 8.0.0. Probably others too.
603  // "= default" doesn't gain us much, so just don't use it here.
604  ~Transform() override{};
605 #else
606  ~Transform() override = default;
607 #endif
610 
612  PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType &,
613  const InverseJacobianPositionType &) const;
614 
615 private:
616  std::string m_InputSpaceName;
617  std::string m_OutputSpaceName;
618 
619  template <typename TType>
620  static std::string
622  {
623  std::string rval("other");
624 
625  return rval;
626  }
627 
628  static std::string
630  {
631  std::string rval("float");
632 
633  return rval;
634  }
635 
636  static std::string
638  {
639  std::string rval("double");
640 
641  return rval;
642  }
643 };
644 } // end namespace itk
645 
646 #ifndef ITK_MANUAL_INSTANTIATION
647 # include "itkTransform.hxx"
648 #endif
649 
650 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:92
itk::Transform::SetParametersByValue
void SetParametersByValue(const ParametersType &p) override
Definition: itkTransform.h:364
itk::OptimizerParameters
Class to hold and manage different parameter types used during optimization.
Definition: itkOptimizerParameters.h:36
itk::Transform::TransformVector
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:200
itk::Transform::GetInputSpaceDimension
unsigned int GetInputSpaceDimension() const override
Definition: itkTransform.h:107
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:637
itkMatrix.h
itk::Transform< TParametersValueType, VDimension, VDimension >::OutputVnlVectorType
vnl_vector_fixed< TParametersValueType, VOutputDimension > OutputVnlVectorType
Definition: itkTransform.h:171
itk::Transform< TParametersValueType, VDimension, VDimension >::InverseTransformBasePointer
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:181
itk::Transform::TransformCovariantVector
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:248
itk::Transform::GetTransformCategory
TransformCategoryEnum GetTransformCategory() const override
Definition: itkTransform.h:476
itkVariableLengthVector.h
itkDiffusionTensor3D.h
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::Transform::TransformDiffusionTensor3D
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &) const
Definition: itkTransform.h:300
itk::DiffusionTensor3D
Represent a diffusion tensor as used in DTI images.
Definition: itkDiffusionTensor3D.h:79
itk::Transform::GetNumberOfFixedParameters
virtual NumberOfParametersType GetNumberOfFixedParameters() const
Definition: itkTransform.h:435
itk::SmartPointer< Self >
itk::Transform::ComputeJacobianWithRespectToPosition
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const
Definition: itkTransform.h:542
itk::Transform::GetFixedParameters
const FixedParametersType & GetFixedParameters() const override
Definition: itkTransform.h:397
itk::Transform::m_InputSpaceName
std::string m_InputSpaceName
Definition: itkTransform.h:616
itk::SymmetricSecondRankTensor
Represent a symmetric tensor of second rank.
Definition: itkSymmetricSecondRankTensor.h:75
itk::Transform::TransformVector
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:216
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkSymmetricSecondRankTensor.h
itk::point
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
itk::Transform::TransformDiffusionTensor3D
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &) const
Definition: itkTransform.h:283
itk::SmartPointer::GetPointer
ObjectType * GetPointer() const noexcept
Definition: itkSmartPointer.h:132
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:621
GetNameOfClass
virtual const char * GetNameOfClass() const
itk::Transform::m_FixedParameters
FixedParametersType m_FixedParameters
Definition: itkTransform.h:609
itk::Transform< TParametersValueType, VDimension, VDimension >::ScalarType
ParametersValueType ScalarType
Definition: itkTransform.h:141
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::Matrix< TParametersValueType, Self::OutputSpaceDimension, Self::InputSpaceDimension >
itk::Transform::m_OutputSpaceName
std::string m_OutputSpaceName
Definition: itkTransform.h:617
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::Transform::TransformCovariantVector
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const
Definition: itkTransform.h:266
itk::Transform::ComputeJacobianWithRespectToParametersCachedTemporaries
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:527
itk::Transform::m_Parameters
ParametersType m_Parameters
Definition: itkTransform.h:608
itk::Transform< TParametersValueType, VDimension, VDimension >::JacobianPositionType
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
Definition: itkTransform.h:145
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Transform::TransformVector
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:232
itk::Transform::TransformSymmetricSecondRankTensor
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &) const
Definition: itkTransform.h:330
itk::Transform< TParametersValueType, VDimension, VDimension >::InverseJacobianPositionType
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
Definition: itkTransform.h:146
itkVector.h
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::Transform::GetParameters
const ParametersType & GetParameters() const override
Definition: itkTransform.h:386
itk::Transform::GetNumberOfLocalParameters
virtual NumberOfParametersType GetNumberOfLocalParameters() const
Definition: itkTransform.h:421
itk::Transform::IsLinear
virtual bool IsLinear() const
Definition: itkTransform.h:482
itk::TransformBaseTemplate::ParametersValueType
TParametersValueType ParametersValueType
Definition: itkTransformBase.h:81
itkTransformBase.h
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::Transform::GetNumberOfParameters
NumberOfParametersType GetNumberOfParameters() const override
Definition: itkTransform.h:428
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
itk::Array2D
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
itk::Transform::GetInverse
bool GetInverse(Self *) const
Definition: itkTransform.h:449
itk::Transform::TransformSymmetricSecondRankTensor
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:321
itk::Transform::ApplyToImageMetadata
std::enable_if_t< TImage::ImageDimension==VInputDimension &&TImage::ImageDimension==VOutputDimension, void > ApplyToImageMetadata(SmartPointer< TImage > image) const
Definition: itkTransform.h:579
itk::TransformBaseTemplate
Definition: itkTransformBase.h:68
itk::Transform::GetOutputSpaceDimension
unsigned int GetOutputSpaceDimension() const override
Definition: itkTransform.h:114
itk::Transform::GetInverseTransform
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:461
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(float *)
Definition: itkTransform.h:629
itk::Transform< TParametersValueType, VDimension, VDimension >::InputVnlVectorType
vnl_vector_fixed< TParametersValueType, VInputDimension > InputVnlVectorType
Definition: itkTransform.h:170