ITK  5.1.0
Insight Toolkit
itkTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
80 template <typename TParametersValueType, unsigned int NInputDimensions = 3, unsigned int NOutputDimensions = 3>
81 class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersValueType>
82 {
83 public:
84  ITK_DISALLOW_COPY_AND_ASSIGN(Transform);
85 
87  using Self = Transform;
91 
93  itkTypeMacro(Transform, TransformBaseTemplate);
94 
96  static constexpr unsigned int InputSpaceDimension = NInputDimensions;
97  static constexpr unsigned int OutputSpaceDimension = NOutputDimensions;
98 
100  itkCloneMacro(Self);
101 
103  unsigned int
104  GetInputSpaceDimension() const override
105  {
106  return NInputDimensions;
107  }
108 
110  unsigned int
111  GetOutputSpaceDimension() const override
112  {
113  return NOutputDimensions;
114  }
115 
117  using FixedParametersType = typename Superclass::FixedParametersType;
118  using FixedParametersValueType = typename Superclass::FixedParametersValueType;
119  using ParametersType = typename Superclass::ParametersType;
120  using ParametersValueType = typename Superclass::ParametersValueType;
122 
125 
128  using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, NOutputDimensions, NInputDimensions>;
129  using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, NInputDimensions, NOutputDimensions>;
130 
134 
139 
140  /* Standard symmetric second rank tenosr type for this class */
143 
144  /* Standard tensor type for this class */
147 
151 
153  using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, NInputDimensions>;
154  using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, NOutputDimensions>;
155 
159 
163 
165 
167 
171 
172  using NumberOfParametersType = typename Superclass::NumberOfParametersType;
173 
178  virtual OutputPointType
179  TransformPoint(const InputPointType &) const = 0;
180 
182  virtual OutputVectorType
184  {
185  itkExceptionMacro("TransformVector(const InputVectorType &)"
186  "is unimplemented for "
187  << this->GetNameOfClass());
188  }
189 
194  virtual OutputVectorType
195  TransformVector(const InputVectorType & vector, const InputPointType & point) const;
196 
198  virtual OutputVnlVectorType
200  {
201  itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is "
202  "unimplemented for "
203  << this->GetNameOfClass());
204  }
205 
210  virtual OutputVnlVectorType
211  TransformVector(const InputVnlVectorType & vector, const InputPointType & point) const;
212 
214  virtual OutputVectorPixelType
215  TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
216  {
217  itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is "
218  "unimplemented for "
219  << this->GetNameOfClass());
220  }
221 
226  virtual OutputVectorPixelType
227  TransformVector(const InputVectorPixelType & vector, const InputPointType & point) const;
228 
230  virtual OutputCovariantVectorType
232  {
233  itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is "
234  "unimplemented for "
235  << this->GetNameOfClass());
236  }
237 
243  virtual OutputCovariantVectorType
244  TransformCovariantVector(const InputCovariantVectorType & vector, const InputPointType & point) const;
245 
246 
248  virtual OutputVectorPixelType
249  TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
250  {
251  itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)"
252  "is unimplemented for "
253  << this->GetNameOfClass());
254  }
255 
261  virtual OutputVectorPixelType
262  TransformCovariantVector(const InputVectorPixelType & vector, const InputPointType & point) const;
263 
265  virtual OutputDiffusionTensor3DType
266  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & itkNotUsed(tensor)) const
267  {
268  itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
269  "unimplemented for "
270  << this->GetNameOfClass());
271  }
272 
278  virtual OutputDiffusionTensor3DType
279  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & tensor, const InputPointType & point) const;
280 
282  virtual OutputVectorPixelType
283  TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
284  {
285  itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is "
286  "unimplemented for "
287  << this->GetNameOfClass());
288  }
289 
290  virtual OutputVectorPixelType
291  TransformDiffusionTensor3D(const InputVectorPixelType & tensor, const InputPointType & point) const;
292 
298  virtual OutputSymmetricSecondRankTensorType
299  TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType & tensor,
300  const InputPointType & point) const;
301 
303  virtual OutputSymmetricSecondRankTensorType
305  {
306  itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
307  "unimplemented for "
308  << this->GetNameOfClass());
309  }
310 
312  virtual OutputVectorPixelType
314  {
315  itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
316  "unimplemented for "
317  << this->GetNameOfClass());
318  }
319 
326  virtual OutputVectorPixelType
327  TransformSymmetricSecondRankTensor(const InputVectorPixelType & tensor, const InputPointType & point) const;
328 
336  void
337  SetParameters(const ParametersType &) override = 0;
338 
346  void
348  {
349  this->SetParameters(p);
350  }
351 
356  void
357  CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
358 
363  void
364  CopyInFixedParameters(const FixedParametersValueType * const begin,
365  const FixedParametersValueType * const end) override;
366 
368  const ParametersType &
369  GetParameters() const override
370  {
371  return m_Parameters;
372  }
373 
375  void
376  SetFixedParameters(const FixedParametersType &) override = 0;
377 
379  const FixedParametersType &
380  GetFixedParameters() const override
381  {
382  return m_FixedParameters;
383  }
384 
392  virtual void
393  UpdateTransformParameters(const DerivativeType & update, ParametersValueType factor = 1.0);
394 
403  virtual NumberOfParametersType
405  {
406  return this->GetNumberOfParameters();
407  }
408 
410  NumberOfParametersType
411  GetNumberOfParameters() const override
412  {
413  return this->m_Parameters.Size();
414  }
415 
417  virtual NumberOfParametersType
419  {
420  return this->m_FixedParameters.Size();
421  }
422 
431  bool
432  GetInverse(Self * itkNotUsed(inverseTransform)) const
433  {
434  return false;
435  }
436 
443  virtual InverseTransformBasePointer
445  {
446  return nullptr;
447  }
448 
450  std::string
451  GetTransformTypeAsString() const override;
452 
453  using TransformCategoryEnum = typename Superclass::TransformCategoryEnum;
454 
459  GetTransformCategory() const override
460  {
461  return Superclass::TransformCategoryEnum::UnknownTransformCategory;
462  }
463 
464  virtual bool
465  IsLinear() const
466  {
467  return (this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear);
468  }
469 
504  virtual void
505  ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p),
506  JacobianType & itkNotUsed(jacobian)) const = 0;
508 
509  virtual void
511  JacobianType & jacobian,
512  JacobianType & itkNotUsed(cachedJacobian)) const
513  {
514  // NOTE: default implementation is not optimized, and just falls back to original methods.
515  this->ComputeJacobianWithRespectToParameters(p, jacobian);
516  }
517 
518 
524  virtual void
526  JacobianPositionType & itkNotUsed(jacobian)) const
527  {
528  itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType )"
529  " is unimplemented for "
530  << this->GetNameOfClass());
531  }
532  itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
533  const);
535 
536 
542  virtual void
543  ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, InverseJacobianPositionType & jacobian) const;
544  itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
545  JacobianType & jacobian) const);
547 
548 protected:
554  typename LightObject::Pointer
555  InternalClone() const override;
556 
557  Transform();
558  Transform(NumberOfParametersType NumberOfParameters);
559 #if defined(__GNUC__) && __GNUC__ < 6 && !defined(__clang__)
560  ~Transform() override{};
561 #else
562  ~Transform() override = default;
563 #endif
566 
568  PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType &,
569  const InverseJacobianPositionType &) const;
570 
572 
573 private:
574  template <typename TType>
575  static std::string
577  {
578  std::string rval("other");
579 
580  return rval;
581  }
582 
583  static std::string
585  {
586  std::string rval("float");
587 
588  return rval;
589  }
590 
591  static std::string
593  {
594  std::string rval("double");
595 
596  return rval;
597  }
598 };
599 } // end namespace itk
600 
601 #ifndef ITK_MANUAL_INSTANTIATION
602 # include "itkTransform.hxx"
603 #endif
604 
605 #endif
itk::Transform::GetNumberOfParameters
NumberOfParametersType GetNumberOfParameters() const override
Definition: itkTransform.h:411
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:592
itk::Transform::GetFixedParameters
const FixedParametersType & GetFixedParameters() const override
Definition: itkTransform.h:380
itk::OptimizerParameters
Class to hold and manage different parameter types used during optimization.
Definition: itkOptimizerParameters.h:34
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::InverseJacobianPositionType
vnl_matrix_fixed< ParametersValueType, NInputDimensions, NOutputDimensions > InverseJacobianPositionType
Definition: itkTransform.h:129
itk::Transform::GetTransformCategory
TransformCategoryEnum GetTransformCategory() const override
Definition: itkTransform.h:459
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::JacobianPositionType
vnl_matrix_fixed< ParametersValueType, NOutputDimensions, NInputDimensions > JacobianPositionType
Definition: itkTransform.h:128
itkMatrix.h
itkVariableLengthVector.h
itkDiffusionTensor3D.h
itk::Transform::m_DirectionChange
DirectionChangeMatrix m_DirectionChange
Definition: itkTransform.h:571
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:266
itk::Transform::GetNumberOfFixedParameters
virtual NumberOfParametersType GetNumberOfFixedParameters() const
Definition: itkTransform.h:418
itk::Transform::GetInputSpaceDimension
unsigned int GetInputSpaceDimension() const override
Definition: itkTransform.h:104
itk::Transform::IsLinear
virtual bool IsLinear() const
Definition: itkTransform.h:465
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:313
itk::Transform::ComputeJacobianWithRespectToPosition
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const
Definition: itkTransform.h:525
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:564
itkSymmetricSecondRankTensor.h
itk::Transform::SetParametersByValue
void SetParametersByValue(const ParametersType &p) override
Definition: itkTransform.h:347
itk::Transform::TransformCovariantVector
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:231
itk::Transform::TransformVector
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:199
itk::Transform::TransformVector
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:215
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(float *)
Definition: itkTransform.h:584
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::ScalarType
ParametersValueType ScalarType
Definition: itkTransform.h:124
itk::Transform::GetNumberOfLocalParameters
virtual NumberOfParametersType GetNumberOfLocalParameters() const
Definition: itkTransform.h:404
itk::Transform::GetTransformTypeAsString
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:576
itk::Transform::ComputeJacobianWithRespectToParametersCachedTemporaries
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:510
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::TransformBaseTemplate::TransformCategoryEnum
TransformCategoryEnum
Definition: itkTransformBase.h:126
itk::Transform::TransformSymmetricSecondRankTensor
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:304
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:68
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::InputVnlVectorType
vnl_vector_fixed< TParametersValueType, NInputDimensions > InputVnlVectorType
Definition: itkTransform.h:153
itk::TransformBaseTemplate::FixedParametersValueType
double FixedParametersValueType
Definition: itkTransformBase.h:60
itk::Transform::TransformVector
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:183
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Transform::TransformCovariantVector
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const
Definition: itkTransform.h:249
itkVector.h
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:46
itk::Transform::m_FixedParameters
FixedParametersType m_FixedParameters
Definition: itkTransform.h:565
itk::TransformBaseTemplate::ParametersValueType
TParametersValueType ParametersValueType
Definition: itkTransformBase.h:58
itkTransformBase.h
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
itk::Transform::GetInverseTransform
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:444
itk::TransformBaseTemplate::NumberOfParametersType
IdentifierType NumberOfParametersType
Definition: itkTransformBase.h:68
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:81
itk::Transform::GetInverse
bool GetInverse(Self *) const
Definition: itkTransform.h:432
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:164
itk::Transform< TParametersValueType, NDimensions, NSubDimensions >::OutputVnlVectorType
vnl_vector_fixed< TParametersValueType, NOutputDimensions > OutputVnlVectorType
Definition: itkTransform.h:154
itk::Transform::GetOutputSpaceDimension
unsigned int GetOutputSpaceDimension() const override
Definition: itkTransform.h:111
itk::TransformBaseTemplate
Definition: itkTransformBase.h:45
itk::Transform::TransformDiffusionTensor3D
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &) const
Definition: itkTransform.h:283
itk::Transform::GetParameters
const ParametersType & GetParameters() const override
Definition: itkTransform.h:369