ITK  5.3.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  * http://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 NInputDimensions = 3, unsigned int NOutputDimensions = 3>
83 class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersValueType>
84 {
85 public:
86  ITK_DISALLOW_COPY_AND_MOVE(Transform);
88 
90  using Self = Transform;
94 
96  itkTypeMacro(Transform, TransformBaseTemplate);
97 
99  static constexpr unsigned int InputSpaceDimension = NInputDimensions;
100  static constexpr unsigned int OutputSpaceDimension = NOutputDimensions;
101 
103  itkCloneMacro(Self);
104 
106  unsigned int
107  GetInputSpaceDimension() const override
108  {
109  return NInputDimensions;
110  }
111 
113  unsigned int
114  GetOutputSpaceDimension() const override
115  {
116  return NOutputDimensions;
117  }
118 
120  using FixedParametersType = typename Superclass::FixedParametersType;
121  using FixedParametersValueType = typename Superclass::FixedParametersValueType;
122  using ParametersType = typename Superclass::ParametersType;
123  using ParametersValueType = typename Superclass::ParametersValueType;
125 
128 
131  using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, NOutputDimensions, NInputDimensions>;
132  using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, NInputDimensions, NOutputDimensions>;
133 
137 
142 
143  /* Standard symmetric second rank tenosr type for this class */
146 
147  /* Standard tensor type for this class */
150 
154 
156  using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, NInputDimensions>;
157  using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, NOutputDimensions>;
158 
162 
166 
168 
170 
174 
175  using NumberOfParametersType = 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
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 TransformCategoryEnum = typename Superclass::TransformCategoryEnum;
457 
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;
511 
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);
538 
539 
545  virtual void
546  ComputeInverseJacobianWithRespectToPosition(const InputPointType & pnt, InverseJacobianPositionType & jacobian) const;
547  itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
548  JacobianType & jacobian) const);
550 
560  template <typename TImage>
561  std::enable_if_t<TImage::ImageDimension == NInputDimensions && TImage::ImageDimension == NOutputDimensions, void>
562  ApplyToImageMetadata(TImage * image) const;
563  template <typename TImage>
564  std::enable_if_t<TImage::ImageDimension == NInputDimensions && TImage::ImageDimension == NOutputDimensions, void>
566  {
567  this->ApplyToImageMetadata(image.GetPointer()); // Delegate to the raw pointer signature
568  }
570 
571 protected:
577  typename LightObject::Pointer
578  InternalClone() const override;
579 
580  Transform();
581  Transform(NumberOfParametersType numberOfParameters);
582 #if defined(__GNUC__)
583  // A bug in some versions of the GCC and Clang compilers
584  // result in an ICE or linker error when "= default" is requested.
585  // This was observed in at least gcc 4.8 and 5.4.0, and
586  // AppleClang 7.0.2 and 8.0.0. Probably others too.
587  // "= default" doesn't gain us much, so just don't use it here.
588  ~Transform() override{};
589 #else
590  ~Transform() override = default;
591 #endif
594 
596  PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType &,
597  const InverseJacobianPositionType &) const;
598 
600 
601 private:
602  template <typename TType>
603  static std::string
605  {
606  std::string rval("other");
607 
608  return rval;
609  }
610 
611  static std::string
613  {
614  std::string rval("float");
615 
616  return rval;
617  }
618 
619  static std::string
621  {
622  std::string rval("double");
623 
624  return rval;
625  }
626 };
627 } // end namespace itk
628 
629 #ifndef ITK_MANUAL_INSTANTIATION
630 # include "itkTransform.hxx"
631 #endif
632 
633 #endif
itk::Transform::GetNumberOfParameters
NumberOfParametersType GetNumberOfParameters() const override
Definition: itkTransform.h:414
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:620
itk::Transform::GetFixedParameters
const FixedParametersType & GetFixedParameters() const override
Definition: itkTransform.h:383
itk::OptimizerParameters
Class to hold and manage different parameter types used during optimization.
Definition: itkOptimizerParameters.h:36
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::InverseJacobianPositionType
vnl_matrix_fixed< ParametersValueType, NInputDimensions, NOutputDimensions > InverseJacobianPositionType
Definition: itkTransform.h:132
itk::Transform::GetTransformCategory
TransformCategoryEnum GetTransformCategory() const override
Definition: itkTransform.h:462
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::JacobianPositionType
vnl_matrix_fixed< ParametersValueType, NOutputDimensions, NInputDimensions > JacobianPositionType
Definition: itkTransform.h:131
itkMatrix.h
itkVariableLengthVector.h
itkDiffusionTensor3D.h
itk::Transform::m_DirectionChange
DirectionChangeMatrix m_DirectionChange
Definition: itkTransform.h:599
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::Transform::TransformDiffusionTensor3D
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &) const
Definition: itkTransform.h:269
itk::Transform::GetNumberOfFixedParameters
virtual NumberOfParametersType GetNumberOfFixedParameters() const
Definition: itkTransform.h:421
itk::Transform::GetInputSpaceDimension
unsigned int GetInputSpaceDimension() const override
Definition: itkTransform.h:107
itk::Transform::IsLinear
virtual bool IsLinear() const
Definition: itkTransform.h:468
itk::DiffusionTensor3D
Represent a diffusion tensor as used in DTI images.
Definition: itkDiffusionTensor3D.h:79
itk::SmartPointer< Self >
itk::Transform::TransformSymmetricSecondRankTensor
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &) const
Definition: itkTransform.h:316
itk::Transform::ComputeJacobianWithRespectToPosition
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const
Definition: itkTransform.h:528
itk::SymmetricSecondRankTensor
Represent a symmetric tensor of second rank.
Definition: itkSymmetricSecondRankTensor.h:75
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Transform::m_Parameters
ParametersType m_Parameters
Definition: itkTransform.h:592
itkSymmetricSecondRankTensor.h
itk::Transform::SetParametersByValue
void SetParametersByValue(const ParametersType &p) override
Definition: itkTransform.h:350
itk::Transform::TransformCovariantVector
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:234
itk::SmartPointer::GetPointer
ObjectType * GetPointer() const noexcept
Definition: itkSmartPointer.h:132
itk::Transform::TransformVector
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:202
itk::Transform::TransformVector
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:218
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(float *)
Definition: itkTransform.h:612
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::ScalarType
ParametersValueType ScalarType
Definition: itkTransform.h:127
itk::Transform::GetNumberOfLocalParameters
virtual NumberOfParametersType GetNumberOfLocalParameters() const
Definition: itkTransform.h:407
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:604
itk::Transform::ComputeJacobianWithRespectToParametersCachedTemporaries
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:513
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::TransformBaseTemplateEnums::TransformCategory
TransformCategory
Definition: itkTransformBase.h:45
itk::Matrix< TParametersValueType, Self::OutputSpaceDimension, Self::InputSpaceDimension >
itk::Transform::TransformSymmetricSecondRankTensor
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:307
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::InputVnlVectorType
vnl_vector_fixed< TParametersValueType, NInputDimensions > InputVnlVectorType
Definition: itkTransform.h:156
itk::TransformBaseTemplate::FixedParametersValueType
double FixedParametersValueType
Definition: itkTransformBase.h:83
itk::Transform::TransformVector
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:186
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Transform::TransformCovariantVector
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const
Definition: itkTransform.h:252
itkVector.h
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::Transform::m_FixedParameters
FixedParametersType m_FixedParameters
Definition: itkTransform.h:593
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::GetInverseTransform
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:447
itk::Transform::ApplyToImageMetadata
std::enable_if_t< TImage::ImageDimension==NInputDimensions &&TImage::ImageDimension==NOutputDimensions, void > ApplyToImageMetadata(SmartPointer< TImage > image) const
Definition: itkTransform.h:565
itk::TransformBaseTemplate::NumberOfParametersType
IdentifierType NumberOfParametersType
Definition: itkTransformBase.h:91
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
itk::Transform::GetInverse
bool GetInverse(Self *) const
Definition: itkTransform.h:435
itk::Array2D
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::InverseTransformBasePointer
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:167
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::OutputVnlVectorType
vnl_vector_fixed< TParametersValueType, NOutputDimensions > OutputVnlVectorType
Definition: itkTransform.h:157
itk::Transform::GetOutputSpaceDimension
unsigned int GetOutputSpaceDimension() const override
Definition: itkTransform.h:114
itk::TransformBaseTemplate
Definition: itkTransformBase.h:68
itk::Transform::TransformDiffusionTensor3D
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &) const
Definition: itkTransform.h:286
itk::Transform::GetParameters
const ParametersType & GetParameters() const override
Definition: itkTransform.h:372