ITK  5.2.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 "itkTransformBase.h"
22 #include "itkVector.h"
24 #include "itkDiffusionTensor3D.h"
26 #include "vnl/vnl_vector_fixed.h"
27 #include "vnl/vnl_matrix_fixed.h"
28 #include "itkMatrix.h"
29 
30 namespace itk
31 {
81 template <typename TParametersValueType, unsigned int NInputDimensions = 3, unsigned int NOutputDimensions = 3>
82 class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersValueType>
83 {
84 public:
85  ITK_DISALLOW_COPY_AND_MOVE(Transform);
87 
89  using Self = Transform;
93 
95  itkTypeMacro(Transform, TransformBaseTemplate);
96 
98  static constexpr unsigned int InputSpaceDimension = NInputDimensions;
99  static constexpr unsigned int OutputSpaceDimension = NOutputDimensions;
100 
102  itkCloneMacro(Self);
103 
105  unsigned int
106  GetInputSpaceDimension() const override
107  {
108  return NInputDimensions;
109  }
110 
112  unsigned int
113  GetOutputSpaceDimension() const override
114  {
115  return NOutputDimensions;
116  }
117 
119  using FixedParametersType = typename Superclass::FixedParametersType;
120  using FixedParametersValueType = typename Superclass::FixedParametersValueType;
121  using ParametersType = typename Superclass::ParametersType;
122  using ParametersValueType = typename Superclass::ParametersValueType;
124 
127 
130  using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, NOutputDimensions, NInputDimensions>;
131  using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, NInputDimensions, NOutputDimensions>;
132 
136 
141 
142  /* Standard symmetric second rank tenosr type for this class */
145 
146  /* Standard tensor type for this class */
149 
153 
155  using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, NInputDimensions>;
156  using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, NOutputDimensions>;
157 
161 
165 
167 
169 
173 
174  using NumberOfParametersType = typename Superclass::NumberOfParametersType;
175 
180  virtual OutputPointType
181  TransformPoint(const InputPointType &) const = 0;
182 
184  virtual OutputVectorType
186  {
187  itkExceptionMacro("TransformVector(const InputVectorType &)"
188  "is unimplemented for "
189  << this->GetNameOfClass());
190  }
191 
196  virtual OutputVectorType
197  TransformVector(const InputVectorType & vector, const InputPointType & point) const;
198 
200  virtual OutputVnlVectorType
202  {
203  itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is "
204  "unimplemented for "
205  << this->GetNameOfClass());
206  }
207 
212  virtual OutputVnlVectorType
213  TransformVector(const InputVnlVectorType & vector, const InputPointType & point) const;
214 
216  virtual OutputVectorPixelType
217  TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
218  {
219  itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is "
220  "unimplemented for "
221  << this->GetNameOfClass());
222  }
223 
228  virtual OutputVectorPixelType
229  TransformVector(const InputVectorPixelType & vector, const InputPointType & point) const;
230 
232  virtual OutputCovariantVectorType
234  {
235  itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is "
236  "unimplemented for "
237  << this->GetNameOfClass());
238  }
239 
245  virtual OutputCovariantVectorType
246  TransformCovariantVector(const InputCovariantVectorType & vector, const InputPointType & point) const;
247 
248 
250  virtual OutputVectorPixelType
251  TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
252  {
253  itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)"
254  "is unimplemented for "
255  << this->GetNameOfClass());
256  }
257 
263  virtual OutputVectorPixelType
264  TransformCovariantVector(const InputVectorPixelType & vector, const InputPointType & point) const;
265 
267  virtual OutputDiffusionTensor3DType
268  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & itkNotUsed(tensor)) const
269  {
270  itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
271  "unimplemented for "
272  << this->GetNameOfClass());
273  }
274 
280  virtual OutputDiffusionTensor3DType
281  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & tensor, const InputPointType & point) const;
282 
284  virtual OutputVectorPixelType
285  TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
286  {
287  itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is "
288  "unimplemented for "
289  << this->GetNameOfClass());
290  }
291 
292  virtual OutputVectorPixelType
293  TransformDiffusionTensor3D(const InputVectorPixelType & tensor, const InputPointType & point) const;
294 
300  virtual OutputSymmetricSecondRankTensorType
301  TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType & tensor,
302  const InputPointType & point) const;
303 
305  virtual OutputSymmetricSecondRankTensorType
307  {
308  itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
309  "unimplemented for "
310  << this->GetNameOfClass());
311  }
312 
314  virtual OutputVectorPixelType
316  {
317  itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
318  "unimplemented for "
319  << this->GetNameOfClass());
320  }
321 
328  virtual OutputVectorPixelType
329  TransformSymmetricSecondRankTensor(const InputVectorPixelType & tensor, const InputPointType & point) const;
330 
338  void
339  SetParameters(const ParametersType &) override = 0;
340 
348  void
350  {
351  this->SetParameters(p);
352  }
353 
358  void
359  CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
360 
365  void
366  CopyInFixedParameters(const FixedParametersValueType * const begin,
367  const FixedParametersValueType * const end) override;
368 
370  const ParametersType &
371  GetParameters() const override
372  {
373  return m_Parameters;
374  }
375 
377  void
378  SetFixedParameters(const FixedParametersType &) override = 0;
379 
381  const FixedParametersType &
382  GetFixedParameters() const override
383  {
384  return m_FixedParameters;
385  }
386 
394  virtual void
395  UpdateTransformParameters(const DerivativeType & update, ParametersValueType factor = 1.0);
396 
405  virtual NumberOfParametersType
407  {
408  return this->GetNumberOfParameters();
409  }
410 
412  NumberOfParametersType
413  GetNumberOfParameters() const override
414  {
415  return this->m_Parameters.Size();
416  }
417 
419  virtual NumberOfParametersType
421  {
422  return this->m_FixedParameters.Size();
423  }
424 
433  bool
434  GetInverse(Self * itkNotUsed(inverseTransform)) const
435  {
436  return false;
437  }
438 
445  virtual InverseTransformBasePointer
447  {
448  return nullptr;
449  }
450 
452  std::string
453  GetTransformTypeAsString() const override;
454 
455  using TransformCategoryEnum = typename Superclass::TransformCategoryEnum;
456 
461  GetTransformCategory() const override
462  {
463  return Superclass::TransformCategoryEnum::UnknownTransformCategory;
464  }
465 
466  virtual bool
467  IsLinear() const
468  {
469  return (this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear);
470  }
471 
506  virtual void
507  ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p),
508  JacobianType & itkNotUsed(jacobian)) const = 0;
510 
511  virtual void
513  JacobianType & jacobian,
514  JacobianType & itkNotUsed(cachedJacobian)) const
515  {
516  // NOTE: default implementation is not optimized, and just falls back to original methods.
517  this->ComputeJacobianWithRespectToParameters(p, jacobian);
518  }
519 
520 
526  virtual void
528  JacobianPositionType & itkNotUsed(jacobian)) const
529  {
530  itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType )"
531  " is unimplemented for "
532  << this->GetNameOfClass());
533  }
534  itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
535  const);
537 
538 
544  virtual void
545  ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, InverseJacobianPositionType & jacobian) const;
546  itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
547  JacobianType & jacobian) const);
549 
550 protected:
556  typename LightObject::Pointer
557  InternalClone() const override;
558 
559  Transform();
560  Transform(NumberOfParametersType NumberOfParameters);
561 #if defined(__GNUC__)
562  // A bug in some versions of the GCC and Clang compilers
563  // result in an ICE or linker error when "= default" is requested.
564  // This was observed in at least gcc 4.8 and 5.4.0, and
565  // AppleClang 7.0.2 and 8.0.0. Probably others too.
566  // "= default" doesn't gain us much, so just don't use it here.
567  ~Transform() override{};
568 #else
569  ~Transform() override = default;
570 #endif
573 
575  PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType &,
576  const InverseJacobianPositionType &) const;
577 
579 
580 private:
581  template <typename TType>
582  static std::string
584  {
585  std::string rval("other");
586 
587  return rval;
588  }
589 
590  static std::string
592  {
593  std::string rval("float");
594 
595  return rval;
596  }
597 
598  static std::string
600  {
601  std::string rval("double");
602 
603  return rval;
604  }
605 };
606 } // end namespace itk
607 
608 #ifndef ITK_MANUAL_INSTANTIATION
609 # include "itkTransform.hxx"
610 #endif
611 
612 #endif
itk::Transform::GetNumberOfParameters
NumberOfParametersType GetNumberOfParameters() const override
Definition: itkTransform.h:413
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:599
itk::Transform::GetFixedParameters
const FixedParametersType & GetFixedParameters() const override
Definition: itkTransform.h:382
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:131
itk::Transform::GetTransformCategory
TransformCategoryEnum GetTransformCategory() const override
Definition: itkTransform.h:461
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::JacobianPositionType
vnl_matrix_fixed< ParametersValueType, NOutputDimensions, NInputDimensions > JacobianPositionType
Definition: itkTransform.h:130
itkMatrix.h
itkVariableLengthVector.h
itkDiffusionTensor3D.h
itk::Transform::m_DirectionChange
DirectionChangeMatrix m_DirectionChange
Definition: itkTransform.h:578
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:268
itk::Transform::GetNumberOfFixedParameters
virtual NumberOfParametersType GetNumberOfFixedParameters() const
Definition: itkTransform.h:420
itk::Transform::GetInputSpaceDimension
unsigned int GetInputSpaceDimension() const override
Definition: itkTransform.h:106
itk::Transform::IsLinear
virtual bool IsLinear() const
Definition: itkTransform.h:467
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:315
itk::Transform::ComputeJacobianWithRespectToPosition
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const
Definition: itkTransform.h:527
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:571
itkSymmetricSecondRankTensor.h
itk::Transform::SetParametersByValue
void SetParametersByValue(const ParametersType &p) override
Definition: itkTransform.h:349
itk::Transform::TransformCovariantVector
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:233
itk::Transform::TransformVector
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:201
itk::Transform::TransformVector
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:217
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(float *)
Definition: itkTransform.h:591
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::ScalarType
ParametersValueType ScalarType
Definition: itkTransform.h:126
itk::Transform::GetNumberOfLocalParameters
virtual NumberOfParametersType GetNumberOfLocalParameters() const
Definition: itkTransform.h:406
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:583
itk::Transform::ComputeJacobianWithRespectToParametersCachedTemporaries
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:512
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:306
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:155
itk::TransformBaseTemplate::FixedParametersValueType
double FixedParametersValueType
Definition: itkTransformBase.h:83
itk::Transform::TransformVector
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:185
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:251
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:572
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:446
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:82
itk::Transform::GetInverse
bool GetInverse(Self *) const
Definition: itkTransform.h:434
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:166
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::OutputVnlVectorType
vnl_vector_fixed< TParametersValueType, NOutputDimensions > OutputVnlVectorType
Definition: itkTransform.h:156
itk::Transform::GetOutputSpaceDimension
unsigned int GetOutputSpaceDimension() const override
Definition: itkTransform.h:113
itk::TransformBaseTemplate
Definition: itkTransformBase.h:68
itk::Transform::TransformDiffusionTensor3D
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &) const
Definition: itkTransform.h:285
itk::Transform::GetParameters
const ParametersType & GetParameters() const override
Definition: itkTransform.h:371