ITK  6.0.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  itkOverrideGetNameOfClassMacro(Transform);
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 
120  using typename Superclass::FixedParametersType;
121  using typename Superclass::FixedParametersValueType;
122  using typename Superclass::ParametersType;
123  using typename Superclass::ParametersValueType;
125 
127  using ScalarType = ParametersValueType;
128 
131  using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, VOutputDimension, VInputDimension>;
132  using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, VInputDimension, VOutputDimension>;
133 
137 
142 
143  /* Standard symmetric second rank tensor type for this class */
146 
147  /* Standard tensor type for this class */
150 
154 
156  using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, VInputDimension>;
157  using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, VOutputDimension>;
158 
162 
166 
168 
170 
174 
175  using typename Superclass::NumberOfParametersType;
176 
181  virtual OutputPointType
182  TransformPoint(const InputPointType &) const = 0;
183 
185  virtual OutputVectorType
187  {
188  itkExceptionMacro("TransformVector(const InputVectorType &)"
189  "is unimplemented for "
190  << this->GetNameOfClass());
191  }
192 
197  virtual OutputVectorType
198  TransformVector(const InputVectorType & vector, const InputPointType & point) const;
199 
201  virtual OutputVnlVectorType
203  {
204  itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is "
205  "unimplemented for "
206  << this->GetNameOfClass());
207  }
208 
213  virtual OutputVnlVectorType
214  TransformVector(const InputVnlVectorType & vector, const InputPointType & point) const;
215 
217  virtual OutputVectorPixelType
218  TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
219  {
220  itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is "
221  "unimplemented for "
222  << this->GetNameOfClass());
223  }
224 
229  virtual OutputVectorPixelType
230  TransformVector(const InputVectorPixelType & vector, const InputPointType & point) const;
231 
233  virtual OutputCovariantVectorType
235  {
236  itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is "
237  "unimplemented for "
238  << this->GetNameOfClass());
239  }
240 
246  virtual OutputCovariantVectorType
247  TransformCovariantVector(const InputCovariantVectorType & vector, const InputPointType & point) const;
248 
249 
251  virtual OutputVectorPixelType
252  TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
253  {
254  itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)"
255  "is unimplemented for "
256  << this->GetNameOfClass());
257  }
258 
264  virtual OutputVectorPixelType
265  TransformCovariantVector(const InputVectorPixelType & vector, const InputPointType & point) const;
266 
268  virtual OutputDiffusionTensor3DType
269  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & itkNotUsed(tensor)) const
270  {
271  itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
272  "unimplemented for "
273  << this->GetNameOfClass());
274  }
275 
281  virtual OutputDiffusionTensor3DType
282  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & inputTensor, const InputPointType & point) const;
283 
285  virtual OutputVectorPixelType
286  TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
287  {
288  itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is "
289  "unimplemented for "
290  << this->GetNameOfClass());
291  }
292 
293  virtual OutputVectorPixelType
294  TransformDiffusionTensor3D(const InputVectorPixelType & inputTensor, const InputPointType & point) const;
295 
301  virtual OutputSymmetricSecondRankTensorType
302  TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType & inputTensor,
303  const InputPointType & point) const;
304 
306  virtual OutputSymmetricSecondRankTensorType
308  {
309  itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
310  "unimplemented for "
311  << this->GetNameOfClass());
312  }
313 
315  virtual OutputVectorPixelType
317  {
318  itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
319  "unimplemented for "
320  << this->GetNameOfClass());
321  }
322 
329  virtual OutputVectorPixelType
330  TransformSymmetricSecondRankTensor(const InputVectorPixelType & inputTensor, const InputPointType & point) const;
331 
339  void
340  SetParameters(const ParametersType &) override = 0;
341 
349  void
350  SetParametersByValue(const ParametersType & p) override
351  {
352  this->SetParameters(p);
353  }
354 
359  void
360  CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
361 
366  void
367  CopyInFixedParameters(const FixedParametersValueType * const begin,
368  const FixedParametersValueType * const end) override;
369 
371  const ParametersType &
372  GetParameters() const override
373  {
374  return m_Parameters;
375  }
376 
378  void
379  SetFixedParameters(const FixedParametersType &) override = 0;
380 
382  const FixedParametersType &
383  GetFixedParameters() const override
384  {
385  return m_FixedParameters;
386  }
387 
395  virtual void
396  UpdateTransformParameters(const DerivativeType & update, ParametersValueType factor = 1.0);
397 
406  virtual NumberOfParametersType
408  {
409  return this->GetNumberOfParameters();
410  }
411 
413  NumberOfParametersType
414  GetNumberOfParameters() const override
415  {
416  return this->m_Parameters.Size();
417  }
418 
420  virtual NumberOfParametersType
422  {
423  return this->m_FixedParameters.Size();
424  }
425 
434  bool
435  GetInverse(Self * itkNotUsed(inverseTransform)) const
436  {
437  return false;
438  }
439 
446  virtual InverseTransformBasePointer
448  {
449  return nullptr;
450  }
451 
453  std::string
454  GetTransformTypeAsString() const override;
455 
456  using typename Superclass::TransformCategoryEnum;
457 
461  TransformCategoryEnum
462  GetTransformCategory() const override
463  {
464  return Superclass::TransformCategoryEnum::UnknownTransformCategory;
465  }
466 
467  virtual bool
468  IsLinear() const
469  {
470  return (this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear);
471  }
472 
507  virtual void
508  ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p),
509  JacobianType & itkNotUsed(jacobian)) const = 0;
512  virtual void
514  JacobianType & jacobian,
515  JacobianType & itkNotUsed(cachedJacobian)) const
516  {
517  // NOTE: default implementation is not optimized, and just falls back to original methods.
518  this->ComputeJacobianWithRespectToParameters(p, jacobian);
519  }
520 
521 
527  virtual void
529  JacobianPositionType & itkNotUsed(jacobian)) const
530  {
531  itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType )"
532  " is unimplemented for "
533  << this->GetNameOfClass());
534  }
535  itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
536  const;)
545  virtual void
546  ComputeInverseJacobianWithRespectToPosition(const InputPointType & pnt, InverseJacobianPositionType & jacobian) const;
547  itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
548  JacobianType & jacobian) const;)
560  template <typename TImage>
561  std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
562  ApplyToImageMetadata(TImage * image) const;
563  template <typename TImage>
564  std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
566  {
567  this->ApplyToImageMetadata(image.GetPointer()); // Delegate to the raw pointer signature
568  }
571 protected:
577  typename LightObject::Pointer
578  InternalClone() const override;
579 
581  Transform() = default;
582 
583  Transform(NumberOfParametersType numberOfParameters);
584  ~Transform() override = default;
585 
586  mutable ParametersType m_Parameters{};
587  mutable FixedParametersType m_FixedParameters{};
588 
589  OutputDiffusionTensor3DType
590  PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType &,
591  const InverseJacobianPositionType &) const;
592 
595  template <typename TTransform>
596  static InverseTransformBasePointer
597  InvertTransform(const TTransform & transform)
598  {
599  const auto inverse = TTransform::New();
600  return transform.GetInverse(inverse) ? inverse.GetPointer() : nullptr;
601  }
604 private:
605  template <typename TType>
606  static std::string
608  {
609  std::string rval("other");
610 
611  return rval;
612  }
613 
614  static std::string
616  {
617  std::string rval("float");
618 
619  return rval;
620  }
621 
622  static std::string
624  {
625  std::string rval("double");
626 
627  return rval;
628  }
629 };
630 } // end namespace itk
631 
632 #ifndef ITK_MANUAL_INSTANTIATION
633 # include "itkTransform.hxx"
634 #endif
635 
636 #endif
TransformBaseTemplate
Definition: itkTransformBase.h:85
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Transform::SetParametersByValue
void SetParametersByValue(const ParametersType &p) override
Definition: itkTransform.h:350
GetNameOfClass
const char * GetNameOfClass() const override
itk::Transform::TransformVector
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:186
itk::Transform::GetInputSpaceDimension
unsigned int GetInputSpaceDimension() const override
Definition: itkTransform.h:107
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:623
itkMatrix.h
itk::Transform< TParametersValueType, VDimension, VDimension >::OutputVnlVectorType
vnl_vector_fixed< TParametersValueType, VOutputDimension > OutputVnlVectorType
Definition: itkTransform.h:157
itk::Transform< TParametersValueType, VDimension, VDimension >::InverseTransformBasePointer
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:167
itk::Transform::TransformCovariantVector
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:234
itk::Transform::GetTransformCategory
TransformCategoryEnum GetTransformCategory() const override
Definition: itkTransform.h:462
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:286
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:421
itk::SmartPointer< Self >
itk::Transform::ComputeJacobianWithRespectToPosition
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const
Definition: itkTransform.h:528
itk::Transform::GetFixedParameters
const FixedParametersType & GetFixedParameters() const override
Definition: itkTransform.h:383
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:202
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:269
itk::SmartPointer::GetPointer
ObjectType * GetPointer() const noexcept
Definition: itkSmartPointer.h:144
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:607
itk::Transform< TParametersValueType, VDimension, VDimension >::ScalarType
ParametersValueType ScalarType
Definition: itkTransform.h:127
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::InvertTransform
static InverseTransformBasePointer InvertTransform(const TTransform &transform)
Definition: itkTransform.h:597
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:252
itk::Transform::ComputeJacobianWithRespectToParametersCachedTemporaries
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:513
itk::Transform< TParametersValueType, VDimension, VDimension >::JacobianPositionType
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
Definition: itkTransform.h:131
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Transform::TransformVector
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:218
itk::Transform::TransformSymmetricSecondRankTensor
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &) const
Definition: itkTransform.h:316
itk::Transform< TParametersValueType, VDimension, VDimension >::InverseJacobianPositionType
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
Definition: itkTransform.h:132
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:372
itk::Transform::GetNumberOfLocalParameters
virtual NumberOfParametersType GetNumberOfLocalParameters() const
Definition: itkTransform.h:407
itk::Transform::IsLinear
virtual bool IsLinear() const
Definition: itkTransform.h:468
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:414
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
New
static Pointer New()
itk::Array2D
Array2D class representing a 2D array.
Definition: itkArray2D.h:42
itk::Transform::GetInverse
bool GetInverse(Self *) const
Definition: itkTransform.h:435
itk::Transform::TransformSymmetricSecondRankTensor
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:307
itk::Transform::GetOutputSpaceDimension
unsigned int GetOutputSpaceDimension() const override
Definition: itkTransform.h:114
itk::Transform::ApplyToImageMetadata
template< typename TImage > std std::enable_if_t< TImage::ImageDimension==VInputDimension &&TImage::ImageDimension==VOutputDimension, void > ApplyToImageMetadata(SmartPointer< TImage > image) const
Definition: itkTransform.h:565
itk::Transform::GetInverseTransform
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:447
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(float *)
Definition: itkTransform.h:615
itk::Transform< TParametersValueType, VDimension, VDimension >::InputVnlVectorType
vnl_vector_fixed< TParametersValueType, VInputDimension > InputVnlVectorType
Definition: itkTransform.h:156