ITK  4.6.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 TScalar,
80  unsigned int NInputDimensions = 3,
81  unsigned int NOutputDimensions = 3>
82 class Transform : public TransformBaseTemplate< TScalar >
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
104  {
105  return NInputDimensions;
106  }
107 
109  unsigned int GetOutputSpaceDimension(void) const
110  {
111  return NOutputDimensions;
112  }
113 
115  typedef TScalar ScalarType;
116 
121 
124 
128 
133 
134  /* Standard symmetric second rank tenosr type for this class */
139 
140  /* Standard tensor type for this class */
143 
149 
151  typedef vnl_vector_fixed<TScalar, NInputDimensions> InputVnlVectorType;
152  typedef vnl_vector_fixed<TScalar, NOutputDimensions> OutputVnlVectorType;
153 
157 
160  typedef Transform<
161  TScalar, NOutputDimensions, NInputDimensions> InverseTransformBaseType;
162 
163  typedef typename InverseTransformBaseType::Pointer
165 
166  typedef Matrix<TScalar,
167  itkGetStaticConstMacro(OutputSpaceDimension),
168  itkGetStaticConstMacro(InputSpaceDimension)> MatrixType;
169 
170  typedef Matrix<double,
171  itkGetStaticConstMacro(OutputSpaceDimension),
172  itkGetStaticConstMacro(OutputSpaceDimension)>
174  typedef Matrix<double,
175  itkGetStaticConstMacro(InputSpaceDimension),
176  itkGetStaticConstMacro(InputSpaceDimension)>
178  typedef Matrix<double,
179  itkGetStaticConstMacro(OutputSpaceDimension),
180  itkGetStaticConstMacro(InputSpaceDimension)>
182 
184 
189  virtual OutputPointType TransformPoint(const InputPointType &) const = 0;
190 
193  {
194  itkExceptionMacro( "TransformVector(const InputVectorType &)"
195  "is unimplemented for " << this->GetNameOfClass() );
196  }
197 
203  const InputVectorType & vector,
204  const InputPointType & point ) const;
205 
208  {
209  itkExceptionMacro( "TransformVector( const InputVnlVectorType & ) is "
210  "unimplemented for " << this->GetNameOfClass() );
211  }
212 
218  const InputVnlVectorType & vector,
219  const InputPointType & point ) const;
220 
223  const InputVectorPixelType & itkNotUsed(vector) ) const
224  {
225  itkExceptionMacro( "TransformVector( const InputVectorPixelType & ) is "
226  "unimplemented for " << this->GetNameOfClass() );
227  }
228 
234  const InputVectorPixelType & vector,
235  const InputPointType & point ) const;
236 
239  {
240  itkExceptionMacro( "TransformCovariantVector( const InputCovariantVectorType & ) is "
241  "unimplemented for " << this->GetNameOfClass() );
242  }
243 
250  const InputCovariantVectorType & vector,
251  const InputPointType & point ) const;
252 
253 
256  const InputVectorPixelType & itkNotUsed(vector) ) const
257  {
258  itkExceptionMacro( "TransformCovariantVector(const InputVectorPixelType &)"
259  "is unimplemented for " << this->GetNameOfClass() );
260  }
261 
268  const InputVectorPixelType & vector,
269  const InputPointType & point ) const;
270 
273  const InputDiffusionTensor3DType & itkNotUsed(tensor) )
274  const
275  {
276  itkExceptionMacro(
277  "TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
278  "unimplemented for " << this->GetNameOfClass() );
279  }
280 
287  const InputDiffusionTensor3DType & tensor,
288  const InputPointType & point ) const;
289 
292  const InputVectorPixelType & itkNotUsed(tensor) ) const
293  {
294  itkExceptionMacro(
295  "TransformDiffusionTensor( const InputVectorPixelType & ) is "
296  "unimplemented for " << this->GetNameOfClass() );
297  }
298 
300  const InputVectorPixelType & tensor,
301  const InputPointType & point ) const;
302 
309  const InputSymmetricSecondRankTensorType & tensor,
310  const InputPointType & point ) const;
311 
314  const InputSymmetricSecondRankTensorType & itkNotUsed(tensor) ) const
315  {
316  itkExceptionMacro(
317  "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
318  "unimplemented for " << this->GetNameOfClass() );
319  }
320 
323  const InputVectorPixelType & itkNotUsed(tensor) ) const
324  {
325  itkExceptionMacro(
326  "TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
327  "unimplemented for " << this->GetNameOfClass() );
328  }
329 
337  const InputVectorPixelType & tensor,
338  const InputPointType & point ) const;
339 
347  virtual void SetParameters(const ParametersType &) = 0;
348 
356  virtual void SetParametersByValue(const ParametersType & p)
357  {
358  this->SetParameters(p);
359  }
360 
362  virtual const ParametersType & GetParameters(void) const
363  {
364  return m_Parameters;
365  }
366 
368  virtual void SetFixedParameters(const ParametersType &) = 0;
369 
371  virtual const ParametersType & GetFixedParameters(void) const
372  {
373  return m_FixedParameters;
374  }
375 
383  virtual void UpdateTransformParameters( const DerivativeType & update, TScalar factor = 1.0 );
384 
394  {
395  return this->GetNumberOfParameters();
396  }
397 
400  {
401  return this->m_Parameters.Size();
402  }
403 
412  bool GetInverse( Self *itkNotUsed(inverseTransform) ) const
413  {
414  return false;
415  }
416 
424  {
425  return ITK_NULLPTR;
426  }
427 
429  virtual std::string GetTransformTypeAsString() const;
430 
432 
437  {
439  }
440 
441  virtual bool IsLinear() const
442  {
443  return ( this->GetTransformCategory() == Superclass::Linear );
444  }
445 
446 
447 #ifdef ITKV3_COMPATIBILITY
448 
459  virtual const JacobianType & GetJacobian(const InputPointType & x) const
460  {
461  this->ComputeJacobianWithRespectToParameters(x, m_SharedLocalJacobian);
462  return m_SharedLocalJacobian;
463  }
465 
466 #endif
467 
502  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const = 0;
503 
504  virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType & p, JacobianType & jacobian, JacobianType & itkNotUsed(jacobianWithRespectToPosition) ) const
505  {
506  //NOTE: default implementation is not optimized, and just falls back to original methods.
507  this->ComputeJacobianWithRespectToParameters(p, jacobian);
508  }
509 
510 
516  virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianType & itkNotUsed(jacobian) ) const
517  {
518  itkExceptionMacro(
519  "ComputeJacobianWithRespectToPosition( InputPointType, JacobianType"
520  " is unimplemented for " << this->GetNameOfClass() );
521  }
522 
523 
529  virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const;
530 
531 protected:
537  virtual typename LightObject::Pointer InternalClone() const;
538 
539  Transform();
540  Transform(NumberOfParametersType NumberOfParameters);
541  virtual ~Transform()
542  {
543  }
544 
547 
549  const InputDiffusionTensor3DType, const JacobianType ) const;
550 
551 #ifdef ITKV3_COMPATIBILITY
552  // This is only needed to provide the old interface that returns a reference to the Jacobian.
553  // It is NOT thread-safe and should be avoided whenever possible.
554  mutable JacobianType m_SharedLocalJacobian;
555 #endif
556 
558 
559 private:
560  Transform(const Self &); // purposely not implemented
561  void operator=(const Self &); // purposely not implemented
562 
563  template <typename TType>
564  std::string GetTransformTypeAsString(TType *) const
565  {
566  std::string rval("other");
567 
568  return rval;
569  }
570 
571  std::string GetTransformTypeAsString(float *) const
572  {
573  std::string rval("float");
574 
575  return rval;
576  }
577 
578  std::string GetTransformTypeAsString(double *) const
579  {
580  std::string rval("double");
581 
582  return rval;
583  }
584 
585 };
586 } // end namespace itk
587 
588 #ifndef ITK_MANUAL_INSTANTIATION
589 #include "itkTransform.hxx"
590 #endif
591 
592 #endif
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:238
Superclass::NumberOfParametersType NumberOfParametersType
Definition: itkTransform.h:183
Array class with size defined at construction time.
Definition: itkArray.h:50
bool GetInverse(Self *) const
Definition: itkTransform.h:412
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:46
Transform Self
Definition: itkTransform.h:86
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:222
DiffusionTensor3D< TScalar > OutputDiffusionTensor3DType
Definition: itkTransform.h:142
SmartPointer< const Self > ConstPointer
Definition: itkTransform.h:89
Vector< TScalar, NInputDimensions > InputVectorType
Definition: itkTransform.h:126
vnl_vector_fixed< TScalar, NInputDimensions > InputVnlVectorType
Definition: itkTransform.h:151
Light weight base class for most itk classes.
Array2D< ParametersValueType > JacobianType
Definition: itkTransform.h:123
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:504
Vector< TScalar, NOutputDimensions > OutputVectorType
Definition: itkTransform.h:127
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:207
InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:164
SymmetricSecondRankTensor< TScalar, NOutputDimensions > OutputSymmetricSecondRankTensorType
Definition: itkTransform.h:138
Matrix< double, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(OutputSpaceDimension)> OutputDirectionMatrix
Definition: itkTransform.h:173
virtual void SetFixedParameters(const ParametersType &)=0
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &tensor, const InputPointType &point) const
Represent a symmetric tensor of second rank.
virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType &x, JacobianType &jacobian) const
Transform< TScalar, NOutputDimensions, NInputDimensions > InverseTransformBaseType
Definition: itkTransform.h:161
virtual LightObject::Pointer InternalClone() const
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &) const
Definition: itkTransform.h:291
Point< TScalar, NInputDimensions > InputPointType
Definition: itkTransform.h:155
Superclass::ParametersType ParametersType
Definition: itkTransform.h:118
virtual void ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const =0
virtual const ParametersType & GetParameters(void) const
Definition: itkTransform.h:362
std::string GetTransformTypeAsString(double *) const
Definition: itkTransform.h:578
virtual const char * GetNameOfClass() const
VariableLengthVector< TScalar > InputVectorPixelType
Definition: itkTransform.h:131
virtual std::string GetTransformTypeAsString() const
VariableLengthVector< TScalar > OutputVectorPixelType
Definition: itkTransform.h:132
OptimizerParameters< ParametersValueType > ParametersType
DiffusionTensor3D< TScalar > InputDiffusionTensor3DType
Definition: itkTransform.h:141
Array< ParametersValueType > DerivativeType
Definition: itkTransform.h:120
virtual OutputPointType TransformPoint(const InputPointType &) const =0
virtual void SetParameters(const ParametersType &)=0
CovariantVector< TScalar, NOutputDimensions > OutputCovariantVectorType
Definition: itkTransform.h:148
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianType &) const
Definition: itkTransform.h:516
CovariantVector< TScalar, NInputDimensions > InputCovariantVectorType
Definition: itkTransform.h:146
IdentifierType NumberOfParametersType
ParametersType m_FixedParameters
Definition: itkTransform.h:546
virtual const ParametersType & GetFixedParameters(void) const
Definition: itkTransform.h:371
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.
static const unsigned int InputSpaceDimension
Definition: itkTransform.h:95
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:44
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
Superclass::ParametersValueType ParametersValueType
Definition: itkTransform.h:119
DirectionChangeMatrix m_DirectionChange
Definition: itkTransform.h:557
Class to hold and manage different parameter types used during optimization.
SymmetricSecondRankTensor< TScalar, NInputDimensions > InputSymmetricSecondRankTensorType
Definition: itkTransform.h:136
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:423
virtual NumberOfParametersType GetNumberOfParameters(void) const
Definition: itkTransform.h:399
virtual void SetParametersByValue(const ParametersType &p)
Definition: itkTransform.h:356
SmartPointer< Self > Pointer
Definition: itkTransform.h:88
virtual TransformCategoryType GetTransformCategory() const
Definition: itkTransform.h:436
TransformBaseTemplate< TScalar > Superclass
Definition: itkTransform.h:87
void operator=(const Self &)
std::string GetTransformTypeAsString(float *) const
Definition: itkTransform.h:571
OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType, const JacobianType) const
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:192
static const unsigned int OutputSpaceDimension
Definition: itkTransform.h:96
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &) const
Definition: itkTransform.h:322
ParametersType m_Parameters
Definition: itkTransform.h:545
Point< TScalar, NOutputDimensions > OutputPointType
Definition: itkTransform.h:156
virtual NumberOfParametersType GetNumberOfLocalParameters(void) const
Definition: itkTransform.h:393
Matrix< double, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> DirectionChangeMatrix
Definition: itkTransform.h:181
std::string GetTransformTypeAsString(TType *) const
Definition: itkTransform.h:564
Matrix< double, itkGetStaticConstMacro(InputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> InputDirectionMatrix
Definition: itkTransform.h:177
Superclass::TransformCategoryType TransformCategoryType
Definition: itkTransform.h:431
vnl_vector_fixed< TScalar, NOutputDimensions > OutputVnlVectorType
Definition: itkTransform.h:152
Matrix< TScalar, itkGetStaticConstMacro(OutputSpaceDimension), itkGetStaticConstMacro(InputSpaceDimension)> MatrixType
Definition: itkTransform.h:168
virtual void UpdateTransformParameters(const DerivativeType &update, TScalar factor=1.0)
unsigned int GetInputSpaceDimension(void) const
Definition: itkTransform.h:103
unsigned int GetOutputSpaceDimension(void) const
Definition: itkTransform.h:109
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:51
TScalar ScalarType
Definition: itkTransform.h:115
Represent a diffusion tensor as used in DTI images.
A templated class holding a n-Dimensional covariant vector.
virtual ~Transform()
Definition: itkTransform.h:541
virtual bool IsLinear() const
Definition: itkTransform.h:441
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:313
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const
Definition: itkTransform.h:255
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &) const
Definition: itkTransform.h:272