ITK  5.0.0
Insight Segmentation and Registration 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,
81  unsigned int NInputDimensions = 3,
82  unsigned int NOutputDimensions = 3>
83 class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersValueType>
84 {
85 public:
86  ITK_DISALLOW_COPY_AND_ASSIGN(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 GetInputSpaceDimension() const override
106  {
107  return NInputDimensions;
108  }
109 
111  unsigned int 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 */
145 
146  /* Standard tensor type for this class */
149 
155 
157  using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, NInputDimensions>;
158  using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, NOutputDimensions>;
159 
163 
166  using InverseTransformBaseType = Transform<TParametersValueType,
167  NOutputDimensions, NInputDimensions>;
168 
170 
171  using MatrixType = Matrix<TParametersValueType,
172  Self::OutputSpaceDimension,
173  Self::InputSpaceDimension>;
174 
175  using OutputDirectionMatrix = Matrix<double,
176  Self::OutputSpaceDimension,
177  Self::OutputSpaceDimension>;
178  using InputDirectionMatrix = Matrix<double,
179  Self::InputSpaceDimension,
180  Self::InputSpaceDimension>;
181  using DirectionChangeMatrix = Matrix<double,
182  Self::OutputSpaceDimension,
183  Self::InputSpaceDimension>;
184 
185  using NumberOfParametersType = typename Superclass::NumberOfParametersType;
186 
191  virtual OutputPointType TransformPoint(const InputPointType &) const = 0;
192 
195  {
196  itkExceptionMacro( "TransformVector(const InputVectorType &)"
197  "is unimplemented for " << this->GetNameOfClass() );
198  }
199 
204  virtual OutputVectorType TransformVector(
205  const InputVectorType & vector,
206  const InputPointType & point ) const;
207 
210  {
211  itkExceptionMacro( "TransformVector( const InputVnlVectorType & ) is "
212  "unimplemented for " << this->GetNameOfClass() );
213  }
214 
219  virtual OutputVnlVectorType TransformVector(
220  const InputVnlVectorType & vector,
221  const InputPointType & point ) const;
222 
225  const InputVectorPixelType & itkNotUsed(vector) ) const
226  {
227  itkExceptionMacro( "TransformVector( const InputVectorPixelType & ) is "
228  "unimplemented for " << this->GetNameOfClass() );
229  }
230 
235  virtual OutputVectorPixelType TransformVector(
236  const InputVectorPixelType & vector,
237  const InputPointType & point ) const;
238 
241  {
242  itkExceptionMacro( "TransformCovariantVector( const InputCovariantVectorType & ) is "
243  "unimplemented for " << this->GetNameOfClass() );
244  }
245 
251  virtual OutputCovariantVectorType TransformCovariantVector(
252  const InputCovariantVectorType & vector,
253  const InputPointType & point ) const;
254 
255 
258  const InputVectorPixelType & itkNotUsed(vector) ) const
259  {
260  itkExceptionMacro( "TransformCovariantVector(const InputVectorPixelType &)"
261  "is unimplemented for " << this->GetNameOfClass() );
262  }
263 
269  virtual OutputVectorPixelType TransformCovariantVector(
270  const InputVectorPixelType & vector,
271  const InputPointType & point ) const;
272 
275  const InputDiffusionTensor3DType & itkNotUsed(tensor) )
276  const
277  {
278  itkExceptionMacro(
279  "TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
280  "unimplemented for " << this->GetNameOfClass() );
281  }
282 
288  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
289  const InputDiffusionTensor3DType & tensor,
290  const InputPointType & point ) const;
291 
294  const InputVectorPixelType & itkNotUsed(tensor) ) const
295  {
296  itkExceptionMacro(
297  "TransformDiffusionTensor( const InputVectorPixelType & ) is "
298  "unimplemented for " << this->GetNameOfClass() );
299  }
300 
301  virtual OutputVectorPixelType TransformDiffusionTensor3D(
302  const InputVectorPixelType & tensor,
303  const InputPointType & point ) const;
304 
310  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
311  const InputSymmetricSecondRankTensorType & tensor,
312  const InputPointType & point ) const;
313 
316  const InputSymmetricSecondRankTensorType & itkNotUsed(tensor) ) const
317  {
318  itkExceptionMacro(
319  "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
320  "unimplemented for " << this->GetNameOfClass() );
321  }
322 
325  const InputVectorPixelType & itkNotUsed(tensor) ) const
326  {
327  itkExceptionMacro(
328  "TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
329  "unimplemented for " << this->GetNameOfClass() );
330  }
331 
338  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
339  const InputVectorPixelType & tensor,
340  const InputPointType & point ) const;
341 
349  void SetParameters(const ParametersType &) override = 0;
350 
358  void SetParametersByValue(const ParametersType & p) override
359  {
360  this->SetParameters(p);
361  }
362 
367  void CopyInParameters(const ParametersValueType * const begin,
368  const ParametersValueType * const end) override;
369 
374  void CopyInFixedParameters(const FixedParametersValueType * const begin,
375  const FixedParametersValueType * const end) override;
376 
378  const ParametersType & GetParameters() const override
379  {
380  return m_Parameters;
381  }
382 
384  void SetFixedParameters(const FixedParametersType &) override = 0;
385 
387  const FixedParametersType & GetFixedParameters() const override
388  {
389  return m_FixedParameters;
390  }
391 
399  virtual void UpdateTransformParameters( const DerivativeType & update,
400  ParametersValueType factor = 1.0 );
401 
411  {
412  return this->GetNumberOfParameters();
413  }
414 
417  {
418  return this->m_Parameters.Size();
419  }
420 
423  {
424  return this->m_FixedParameters.Size();
425  }
426 
435  bool GetInverse( Self *itkNotUsed(inverseTransform) ) const
436  {
437  return false;
438  }
439 
447  {
448  return nullptr;
449  }
450 
452  std::string GetTransformTypeAsString() const override;
453 
454  using TransformCategoryType = typename Superclass::TransformCategoryType;
455 
460  {
461  return Superclass::UnknownTransformCategory;
462  }
463 
464  virtual bool IsLinear() const
465  {
466  return ( this->GetTransformCategory() == Superclass::Linear );
467  }
468 
503  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const = 0;
504 
505  virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType & p, JacobianType & jacobian, JacobianType & itkNotUsed(cachedJacobian) ) const
506  {
507  //NOTE: default implementation is not optimized, and just falls back to original methods.
508  this->ComputeJacobianWithRespectToParameters(p, jacobian);
509  }
510 
511 
517  virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianPositionType & itkNotUsed(jacobian) ) const
518  {
519  itkExceptionMacro(
520  "ComputeJacobianWithRespectToPosition( InputPointType, JacobianType )"
521  " is unimplemented for " << this->GetNameOfClass() );
522  }
523  itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const);
525 
526 
532  virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
533  InverseJacobianPositionType & jacobian ) const;
534  itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const);
536 
537 protected:
543  typename LightObject::Pointer InternalClone() const override;
544 
545  Transform();
546  Transform(NumberOfParametersType NumberOfParameters);
547 #if defined(__GNUC__) && __GNUC__ < 6
548  ~Transform() override {};
549 #else
550  ~Transform() override = default;
551 #endif
554 
555  OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(
557  const InverseJacobianPositionType &) const;
558 
560 
561 private:
562  template <typename TType>
563  static std::string GetTransformTypeAsString(TType *)
564  {
565  std::string rval("other");
566 
567  return rval;
568  }
569 
570  static std::string GetTransformTypeAsString(float *)
571  {
572  std::string rval("float");
573 
574  return rval;
575  }
576 
577  static std::string GetTransformTypeAsString(double *)
578  {
579  std::string rval("double");
580 
581  return rval;
582  }
583 
584 };
585 } // end namespace itk
586 
587 #ifndef ITK_MANUAL_INSTANTIATION
588 #include "itkTransform.hxx"
589 #endif
590 
591 #endif
Array class with size defined at construction time.
Definition: itkArray.h:46
bool GetInverse(Self *) const
Definition: itkTransform.h:435
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:505
vnl_vector_fixed< TParametersValueType, NOutputDimensions > OutputVnlVectorType
Definition: itkTransform.h:158
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &) const
Definition: itkTransform.h:293
Light weight base class for most itk classes.
DirectionChangeMatrix m_DirectionChange
Definition: itkTransform.h:559
vnl_matrix_fixed< ParametersValueType, NInputDimensions, NOutputDimensions > InverseJacobianPositionType
Definition: itkTransform.h:129
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:315
NumberOfParametersType GetNumberOfParameters() const override
Definition: itkTransform.h:416
Represent a symmetric tensor of second rank.
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const
Definition: itkTransform.h:257
ParametersType m_Parameters
Definition: itkTransform.h:552
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:194
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const
Definition: itkTransform.h:517
unsigned int GetOutputSpaceDimension() const override
Definition: itkTransform.h:111
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:209
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &) const
Definition: itkTransform.h:274
unsigned int GetInputSpaceDimension() const override
Definition: itkTransform.h:105
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:224
virtual NumberOfParametersType GetNumberOfFixedParameters() const
Definition: itkTransform.h:422
FixedParametersType m_FixedParameters
Definition: itkTransform.h:553
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
Represents an array whose length can be defined at run-time.
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
Class to hold and manage different parameter types used during optimization.
void SetParametersByValue(const ParametersType &p) override
Definition: itkTransform.h:358
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:169
vnl_vector_fixed< TParametersValueType, NInputDimensions > InputVnlVectorType
Definition: itkTransform.h:157
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:446
virtual bool IsLinear() const
Definition: itkTransform.h:464
TransformCategoryType GetTransformCategory() const override
Definition: itkTransform.h:459
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &) const
Definition: itkTransform.h:324
const FixedParametersType & GetFixedParameters() const override
Definition: itkTransform.h:387
IdentifierType NumberOfParametersType
virtual NumberOfParametersType GetNumberOfLocalParameters() const
Definition: itkTransform.h:410
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:240
const ParametersType & GetParameters() const override
Definition: itkTransform.h:378
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:577
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:563
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
Represent a diffusion tensor as used in DTI images.
static std::string GetTransformTypeAsString(float *)
Definition: itkTransform.h:570
A templated class holding a n-Dimensional covariant vector.
vnl_matrix_fixed< ParametersValueType, NOutputDimensions, NInputDimensions > JacobianPositionType
Definition: itkTransform.h:128
TParametersValueType ParametersValueType