ITK  4.8.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 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 
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 
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 
185 
190  virtual OutputPointType TransformPoint(const InputPointType &) const = 0;
191 
194  {
195  itkExceptionMacro( "TransformVector(const InputVectorType &)"
196  "is unimplemented for " << this->GetNameOfClass() );
197  }
198 
204  const InputVectorType & vector,
205  const InputPointType & point ) const;
206 
209  {
210  itkExceptionMacro( "TransformVector( const InputVnlVectorType & ) is "
211  "unimplemented for " << this->GetNameOfClass() );
212  }
213 
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 
235  const InputVectorPixelType & vector,
236  const InputPointType & point ) const;
237 
240  {
241  itkExceptionMacro( "TransformCovariantVector( const InputCovariantVectorType & ) is "
242  "unimplemented for " << this->GetNameOfClass() );
243  }
244 
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 
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 
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 
301  const InputVectorPixelType & tensor,
302  const InputPointType & point ) const;
303 
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 
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  {
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()
564  {
565  }
566 
569 
571  const InputDiffusionTensor3DType, const JacobianType ) const;
572 
573 #ifdef ITKV3_COMPATIBILITY
574  // This is only needed to provide the old interface that returns a reference to the Jacobian.
575  // It is NOT thread-safe and should be avoided whenever possible.
576  mutable JacobianType m_SharedLocalJacobian;
577 #endif
578 
580 
581 
582 private:
583  Transform(const Self &); // purposely not implemented
584  void operator=(const Self &); // purposely not implemented
585 
586  template <typename TType>
587  std::string GetTransformTypeAsString(TType *) const
588  {
589  std::string rval("other");
590 
591  return rval;
592  }
593 
594  std::string GetTransformTypeAsString(float *) const
595  {
596  std::string rval("float");
597 
598  return rval;
599  }
600 
601  std::string GetTransformTypeAsString(double *) const
602  {
603  std::string rval("double");
604 
605  return rval;
606  }
607 
608 };
609 } // end namespace itk
610 
611 #ifndef ITK_MANUAL_INSTANTIATION
612 #include "itkTransform.hxx"
613 #endif
614 
615 #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:46
static const unsigned int InputSpaceDimension
Definition: itkTransform.h:95
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
virtual void ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const =0
DirectionChangeMatrix m_DirectionChange
Definition: itkTransform.h:579
OptimizerParameters< FixedParametersValueType > FixedParametersType
Point< TParametersValueType, NInputDimensions > InputPointType
Definition: itkTransform.h:157
Superclass::ParametersType ParametersType
Definition: itkTransform.h:117
IdentifierType NumberOfParametersType
virtual const FixedParametersType & GetFixedParameters(void) const override
Definition: itkTransform.h:386
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:567
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 void SetParameters(const ParametersType &) override=0
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
static const unsigned int OutputSpaceDimension
Definition: itkTransform.h:96
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
std::string GetTransformTypeAsString(TType *) const
Definition: itkTransform.h:587
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:568
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
ParametersValueType FixedParametersValueType
std::string GetTransformTypeAsString(float *) const
Definition: itkTransform.h:594
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.
virtual void CopyInParameters(const ParametersValueType *const begin, const ParametersValueType *const end) override
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 operator=(const Self &)
Array2D< ParametersValueType > JacobianType
Definition: itkTransform.h:125
Matrix< double, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> DirectionChangeMatrix
Definition: itkTransform.h:182
virtual OutputPointType TransformPoint(const InputPointType &) const =0
virtual const ParametersType & GetParameters(void) const override
Definition: itkTransform.h:377
virtual void SetFixedParameters(const FixedParametersType &) override=0
DiffusionTensor3D< TParametersValueType > InputDiffusionTensor3DType
Definition: itkTransform.h:143
SmartPointer< Self > Pointer
Definition: itkTransform.h:88
virtual void SetParametersByValue(const ParametersType &p) override
Definition: itkTransform.h:357
Matrix< double, itkGetStaticConstMacro(InputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> InputDirectionMatrix
Definition: itkTransform.h:178
virtual TransformCategoryType GetTransformCategory() const override
Definition: itkTransform.h:458
vnl_vector_fixed< TParametersValueType, NInputDimensions > InputVnlVectorType
Definition: itkTransform.h:153
unsigned int GetOutputSpaceDimension(void) const override
Definition: itkTransform.h:109
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &tensor, const InputPointType &point) const
virtual void CopyInFixedParameters(const FixedParametersValueType *const begin, const FixedParametersValueType *const end) override
std::string GetTransformTypeAsString(double *) const
Definition: itkTransform.h:601
virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType &x, JacobianType &jacobian) const
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:445
virtual bool IsLinear() const
Definition: itkTransform.h:463
OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType, const JacobianType) const
OptimizerParameters< ParametersValueType > ParametersType
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
SizeValueType Size(void) const
Definition: itkArray.h:124
Vector< TParametersValueType, NOutputDimensions > OutputVectorType
Definition: itkTransform.h:129
Superclass::ParametersValueType ParametersValueType
Definition: itkTransform.h:118
TransformBaseTemplate< TParametersValueType > Superclass
Definition: itkTransform.h:87
virtual LightObject::Pointer InternalClone() const override
CovariantVector< TParametersValueType, NInputDimensions > InputCovariantVectorType
Definition: itkTransform.h:148
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:51
virtual std::string GetTransformTypeAsString() const override
Represent a diffusion tensor as used in DTI images.
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
virtual void UpdateTransformParameters(const DerivativeType &update, ParametersValueType factor=1.0)
virtual const char * GetNameOfClass() const