ITK  4.13.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 "itkMatrix.h"
28 
29 namespace itk
30 {
79 template<typename TParametersValueType,
80  unsigned int NInputDimensions = 3,
81  unsigned int NOutputDimensions = 3>
82 class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersValueType>
83 {
84 public:
86  typedef Transform Self;
90 
92  itkTypeMacro(Transform, TransformBaseTemplate);
93 
95  itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
96  itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
98 
100  itkCloneMacro(Self);
101 
103  unsigned int GetInputSpaceDimension(void) const ITK_OVERRIDE
104  {
105  return NInputDimensions;
106  }
107 
109  unsigned int GetOutputSpaceDimension(void) const ITK_OVERRIDE
110  {
111  return NOutputDimensions;
112  }
113 
115  typedef typename Superclass::FixedParametersType FixedParametersType;
116  typedef typename Superclass::FixedParametersValueType FixedParametersValueType;
117  typedef typename Superclass::ParametersType ParametersType;
118  typedef typename Superclass::ParametersValueType ParametersValueType;
120 
123 
126 
130 
135 
136  /* Standard symmetric second rank tenosr type for this class */
141 
142  /* Standard tensor type for this class */
145 
151 
153  typedef vnl_vector_fixed<TParametersValueType, NInputDimensions> InputVnlVectorType;
154  typedef vnl_vector_fixed<TParametersValueType, NOutputDimensions> OutputVnlVectorType;
155 
159 
162  typedef Transform<TParametersValueType,
163  NOutputDimensions, NInputDimensions> InverseTransformBaseType;
164 
166 
167  typedef Matrix<TParametersValueType,
168  itkGetStaticConstMacro(OutputSpaceDimension),
169  itkGetStaticConstMacro(InputSpaceDimension)> MatrixType;
170 
171  typedef Matrix<double,
172  itkGetStaticConstMacro(OutputSpaceDimension),
173  itkGetStaticConstMacro(OutputSpaceDimension)>
175  typedef Matrix<double,
176  itkGetStaticConstMacro(InputSpaceDimension),
177  itkGetStaticConstMacro(InputSpaceDimension)>
179  typedef Matrix<double,
180  itkGetStaticConstMacro(OutputSpaceDimension),
181  itkGetStaticConstMacro(InputSpaceDimension)>
183 
184  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
185 
190  virtual OutputPointType TransformPoint(const InputPointType &) const = 0;
191 
194  {
195  itkExceptionMacro( "TransformVector(const InputVectorType &)"
196  "is unimplemented for " << this->GetNameOfClass() );
197  }
198 
203  virtual OutputVectorType TransformVector(
204  const InputVectorType & vector,
205  const InputPointType & point ) const;
206 
209  {
210  itkExceptionMacro( "TransformVector( const InputVnlVectorType & ) is "
211  "unimplemented for " << this->GetNameOfClass() );
212  }
213 
218  virtual OutputVnlVectorType TransformVector(
219  const InputVnlVectorType & vector,
220  const InputPointType & point ) const;
221 
224  const InputVectorPixelType & itkNotUsed(vector) ) const
225  {
226  itkExceptionMacro( "TransformVector( const InputVectorPixelType & ) is "
227  "unimplemented for " << this->GetNameOfClass() );
228  }
229 
234  virtual OutputVectorPixelType TransformVector(
235  const InputVectorPixelType & vector,
236  const InputPointType & point ) const;
237 
240  {
241  itkExceptionMacro( "TransformCovariantVector( const InputCovariantVectorType & ) is "
242  "unimplemented for " << this->GetNameOfClass() );
243  }
244 
250  virtual OutputCovariantVectorType TransformCovariantVector(
251  const InputCovariantVectorType & vector,
252  const InputPointType & point ) const;
253 
254 
257  const InputVectorPixelType & itkNotUsed(vector) ) const
258  {
259  itkExceptionMacro( "TransformCovariantVector(const InputVectorPixelType &)"
260  "is unimplemented for " << this->GetNameOfClass() );
261  }
262 
268  virtual OutputVectorPixelType TransformCovariantVector(
269  const InputVectorPixelType & vector,
270  const InputPointType & point ) const;
271 
274  const InputDiffusionTensor3DType & itkNotUsed(tensor) )
275  const
276  {
277  itkExceptionMacro(
278  "TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
279  "unimplemented for " << this->GetNameOfClass() );
280  }
281 
287  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
288  const InputDiffusionTensor3DType & tensor,
289  const InputPointType & point ) const;
290 
293  const InputVectorPixelType & itkNotUsed(tensor) ) const
294  {
295  itkExceptionMacro(
296  "TransformDiffusionTensor( const InputVectorPixelType & ) is "
297  "unimplemented for " << this->GetNameOfClass() );
298  }
299 
300  virtual OutputVectorPixelType TransformDiffusionTensor3D(
301  const InputVectorPixelType & tensor,
302  const InputPointType & point ) const;
303 
309  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
310  const InputSymmetricSecondRankTensorType & tensor,
311  const InputPointType & point ) const;
312 
315  const InputSymmetricSecondRankTensorType & itkNotUsed(tensor) ) const
316  {
317  itkExceptionMacro(
318  "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
319  "unimplemented for " << this->GetNameOfClass() );
320  }
321 
324  const InputVectorPixelType & itkNotUsed(tensor) ) const
325  {
326  itkExceptionMacro(
327  "TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
328  "unimplemented for " << this->GetNameOfClass() );
329  }
330 
337  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
338  const InputVectorPixelType & tensor,
339  const InputPointType & point ) const;
340 
348  virtual void SetParameters(const ParametersType &) ITK_OVERRIDE = 0;
349 
357  virtual void SetParametersByValue(const ParametersType & p) ITK_OVERRIDE
358  {
359  this->SetParameters(p);
360  }
361 
366  virtual void CopyInParameters(const ParametersValueType * const begin,
367  const ParametersValueType * const end) ITK_OVERRIDE;
368 
373  virtual void CopyInFixedParameters(const FixedParametersValueType * const begin,
374  const FixedParametersValueType * const end) ITK_OVERRIDE;
375 
377  virtual const ParametersType & GetParameters(void) const ITK_OVERRIDE
378  {
379  return m_Parameters;
380  }
381 
383  virtual void SetFixedParameters(const FixedParametersType &) ITK_OVERRIDE = 0;
384 
386  virtual const FixedParametersType & GetFixedParameters(void) const ITK_OVERRIDE
387  {
388  return m_FixedParameters;
389  }
390 
398  virtual void UpdateTransformParameters( const DerivativeType & update,
399  ParametersValueType factor = 1.0 );
400 
410  {
411  return this->GetNumberOfParameters();
412  }
413 
415  virtual NumberOfParametersType GetNumberOfParameters(void) const ITK_OVERRIDE
416  {
417  return this->m_Parameters.Size();
418  }
419 
422  {
423  return this->m_FixedParameters.Size();
424  }
425 
434  bool GetInverse( Self *itkNotUsed(inverseTransform) ) const
435  {
436  return false;
437  }
438 
446  {
447  return ITK_NULLPTR;
448  }
449 
451  virtual std::string GetTransformTypeAsString() const ITK_OVERRIDE;
452 
454 
458  virtual TransformCategoryType GetTransformCategory() const ITK_OVERRIDE
459  {
460  return Superclass::UnknownTransformCategory;
461  }
462 
463  virtual bool IsLinear() const
464  {
465  return ( this->GetTransformCategory() == Superclass::Linear );
466  }
467 
468 
469 #ifdef ITKV3_COMPATIBILITY
470 
481  virtual const JacobianType & GetJacobian(const InputPointType & x) const
482  {
483  this->ComputeJacobianWithRespectToParameters(x, m_SharedLocalJacobian);
484  return m_SharedLocalJacobian;
485  }
487 
488 #endif
489 
524  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const = 0;
525 
526  virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType & p, JacobianType & jacobian, JacobianType & itkNotUsed(jacobianWithRespectToPosition) ) const
527  {
528  //NOTE: default implementation is not optimized, and just falls back to original methods.
529  this->ComputeJacobianWithRespectToParameters(p, jacobian);
530  }
531 
532 
538  virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianType & itkNotUsed(jacobian) ) const
539  {
540  itkExceptionMacro(
541  "ComputeJacobianWithRespectToPosition( InputPointType, JacobianType"
542  " is unimplemented for " << this->GetNameOfClass() );
543  }
544 
545 
551  virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const;
552 
553 protected:
559  virtual typename LightObject::Pointer InternalClone() const ITK_OVERRIDE;
560 
561  Transform();
562  Transform(NumberOfParametersType NumberOfParameters);
563  virtual ~Transform() ITK_OVERRIDE { }
564 
567 
568  OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(
569  const InputDiffusionTensor3DType, const JacobianType ) const;
570 
571 #ifdef ITKV3_COMPATIBILITY
572  // This is only needed to provide the old interface that returns a reference to the Jacobian.
573  // It is NOT thread-safe and should be avoided whenever possible.
574  mutable JacobianType m_SharedLocalJacobian;
575 #endif
576 
578 
579 
580 private:
581  ITK_DISALLOW_COPY_AND_ASSIGN(Transform);
582 
583  template <typename TType>
584  static std::string GetTransformTypeAsString(TType *)
585  {
586  std::string rval("other");
587 
588  return rval;
589  }
590 
591  static std::string GetTransformTypeAsString(float *)
592  {
593  std::string rval("float");
594 
595  return rval;
596  }
597 
598  static std::string GetTransformTypeAsString(double *)
599  {
600  std::string rval("double");
601 
602  return rval;
603  }
604 
605 };
606 } // end namespace itk
607 
608 #ifndef ITK_MANUAL_INSTANTIATION
609 #include "itkTransform.hxx"
610 #endif
611 
612 #endif
Array class with size defined at construction time.
Definition: itkArray.h:50
SymmetricSecondRankTensor< TParametersValueType, NOutputDimensions > OutputSymmetricSecondRankTensorType
Definition: itkTransform.h:140
bool GetInverse(Self *) const
Definition: itkTransform.h:434
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:53
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:526
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &) const
Definition: itkTransform.h:292
Light weight base class for most itk classes.
DiffusionTensor3D< TParametersValueType > OutputDiffusionTensor3DType
Definition: itkTransform.h:144
Transform Self
Definition: itkTransform.h:86
DirectionChangeMatrix m_DirectionChange
Definition: itkTransform.h:577
Point< TParametersValueType, NInputDimensions > InputPointType
Definition: itkTransform.h:157
Superclass::ParametersType ParametersType
Definition: itkTransform.h:117
IdentifierType NumberOfParametersType
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianType &) const
Definition: itkTransform.h:538
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:314
virtual NumberOfParametersType GetNumberOfLocalParameters(void) const
Definition: itkTransform.h:409
Represent a symmetric tensor of second rank.
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const
Definition: itkTransform.h:256
ParametersType m_Parameters
Definition: itkTransform.h:565
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:193
TParametersValueType ParametersValueType
CovariantVector< TParametersValueType, NOutputDimensions > OutputCovariantVectorType
Definition: itkTransform.h:150
vnl_vector_fixed< TParametersValueType, NOutputDimensions > OutputVnlVectorType
Definition: itkTransform.h:154
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:208
VariableLengthVector< TParametersValueType > InputVectorPixelType
Definition: itkTransform.h:133
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &) const
Definition: itkTransform.h:273
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:223
Point< TParametersValueType, NOutputDimensions > OutputPointType
Definition: itkTransform.h:158
virtual NumberOfParametersType GetNumberOfParameters(void) const override
Definition: itkTransform.h:415
Superclass::NumberOfParametersType NumberOfParametersType
Definition: itkTransform.h:184
SmartPointer< const Self > ConstPointer
Definition: itkTransform.h:89
VariableLengthVector< TParametersValueType > OutputVectorPixelType
Definition: itkTransform.h:134
virtual NumberOfParametersType GetNumberOfFixedParameters() const
Definition: itkTransform.h:421
Matrix< double, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(OutputSpaceDimension)> OutputDirectionMatrix
Definition: itkTransform.h:174
FixedParametersType m_FixedParameters
Definition: itkTransform.h:566
SymmetricSecondRankTensor< TParametersValueType, NInputDimensions > InputSymmetricSecondRankTensorType
Definition: itkTransform.h:138
unsigned int GetInputSpaceDimension(void) const override
Definition: itkTransform.h:103
Superclass::FixedParametersType FixedParametersType
Definition: itkTransform.h:115
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
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.
Array2D< ParametersValueType > JacobianType
Definition: itkTransform.h:125
Matrix< double, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> DirectionChangeMatrix
Definition: itkTransform.h:182
virtual const ParametersType & GetParameters(void) const override
Definition: itkTransform.h:377
DiffusionTensor3D< TParametersValueType > InputDiffusionTensor3DType
Definition: itkTransform.h:143
SmartPointer< Self > Pointer
Definition: itkTransform.h:88
Matrix< double, itkGetStaticConstMacro(InputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> InputDirectionMatrix
Definition: itkTransform.h:178
vnl_vector_fixed< TParametersValueType, NInputDimensions > InputVnlVectorType
Definition: itkTransform.h:153
unsigned int GetOutputSpaceDimension(void) const override
Definition: itkTransform.h:109
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:445
virtual bool IsLinear() const
Definition: itkTransform.h:463
ParametersValueType ScalarType
Definition: itkTransform.h:122
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &) const
Definition: itkTransform.h:323
Vector< TParametersValueType, NInputDimensions > InputVectorType
Definition: itkTransform.h:128
Superclass::FixedParametersValueType FixedParametersValueType
Definition: itkTransform.h:116
InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:165
Transform< TParametersValueType, NOutputDimensions, NInputDimensions > InverseTransformBaseType
Definition: itkTransform.h:163
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:239
Vector< TParametersValueType, NOutputDimensions > OutputVectorType
Definition: itkTransform.h:129
Superclass::ParametersValueType ParametersValueType
Definition: itkTransform.h:118
TransformBaseTemplate< TParametersValueType > Superclass
Definition: itkTransform.h:87
CovariantVector< TParametersValueType, NInputDimensions > InputCovariantVectorType
Definition: itkTransform.h:148
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:598
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:584
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:591
A templated class holding a n-Dimensional covariant vector.
Matrix< TParametersValueType, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> MatrixType
Definition: itkTransform.h:169
Array< ParametersValueType > DerivativeType
Definition: itkTransform.h:119