ITK  4.2.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 <class TScalarType,
80  unsigned int NInputDimensions = 3,
81  unsigned int NOutputDimensions = 3>
82 class ITK_EXPORT Transform : public TransformBase
83 {
84 public:
86  typedef Transform Self;
90 
92  itkTypeMacro(Transform, TransformBase);
93 
95  itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
96  itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
98 
100  itkCloneMacro(Self);
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 TScalarType ScalarType;
116 
118  typedef typename Superclass::ParametersType ParametersType;
119  typedef typename Superclass::ParametersValueType ParametersValueType;
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<TScalarType, NInputDimensions> InputVnlVectorType;
152  typedef vnl_vector_fixed<TScalarType, NOutputDimensions>
154 
158 
161  typedef Transform<
162  TScalarType, NOutputDimensions, NInputDimensions> InverseTransformBaseType;
163 
164  typedef typename InverseTransformBaseType::Pointer
166 
167  typedef Matrix<TScalarType,
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 Superclass::NumberOfParametersType NumberOfParametersType;
185 
190  virtual OutputPointType TransformPoint(const InputPointType &) const = 0;
191 
193  virtual OutputVectorType TransformVector(const InputVectorType &) const
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 
208  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
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 
223  virtual OutputVectorPixelType TransformVector(
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 
239  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
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 
256  virtual OutputVectorPixelType TransformCovariantVector(
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 
273  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
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 
292  virtual OutputVectorPixelType TransformDiffusionTensor3D(
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 
314  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
315  const InputSymmetricSecondRankTensorType & itkNotUsed(tensor) ) const
316  {
317  itkExceptionMacro(
318  "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
319  "unimplemented for " << this->GetNameOfClass() );
320  }
321 
323  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
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 &) = 0;
349 
357  virtual void SetParametersByValue(const ParametersType & p)
358  {
359  this->SetParameters(p);
360  }
361 
363  virtual const ParametersType & GetParameters(void) const
364  {
365  return m_Parameters;
366  }
367 
369  virtual void SetFixedParameters(const ParametersType &) = 0;
370 
372  virtual const ParametersType & GetFixedParameters(void) const
373  {
374  return m_FixedParameters;
375  }
376 
387  virtual void UpdateTransformParameters( const DerivativeType & update, TScalarType factor = 1.0 );
388 
397  virtual NumberOfParametersType GetNumberOfLocalParameters(void) const
398  {
399  return this->GetNumberOfParameters();
400  }
401 
403  virtual NumberOfParametersType GetNumberOfParameters(void) const
404  {
405  return this->m_Parameters.Size();
406  }
407 
416  bool GetInverse( Self *itkNotUsed(inverseTransform) ) const
417  {
418  return false;
419  }
420 
427  virtual InverseTransformBasePointer GetInverseTransform() const
428  {
429  return NULL;
430  }
431 
433  virtual std::string GetTransformTypeAsString() const;
434 
450  virtual bool IsLinear() const
451  {
452  return false;
453  }
454 
458  virtual bool HasLocalSupport() const
459  {
460  return false;
461  }
462 #ifdef ITKV3_COMPATIBILITY
463 
475  virtual const JacobianType & GetJacobian(const InputPointType & x) const
476  {
477  this->ComputeJacobianWithRespectToParameters(x, m_SharedLocalJacobian);
478  return m_SharedLocalJacobian;
479  }
481 
482 #endif
483 
518  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const
519  {
520  itkExceptionMacro(
521  "ComputeJacobianWithRespectToParamters( InputPointType, JacobianType"
522  " is unimplemented for " << this->GetNameOfClass() );
523  }
525 
526 
532  virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianType & itkNotUsed(jacobian) ) const
533  {
534  itkExceptionMacro(
535  "ComputeJacobianWithRespectToPosition( InputPointType, JacobianType"
536  " is unimplemented for " << this->GetNameOfClass() );
537  }
538 
539 
545  virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const;
546 
547 protected:
553  virtual typename LightObject::Pointer InternalClone() const;
554 
555  Transform();
556  Transform(NumberOfParametersType NumberOfParameters);
557  virtual ~Transform()
558  {
559  }
560 
563 
564  OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(
565  const InputDiffusionTensor3DType, const JacobianType ) const;
566 
567 #ifdef ITKV3_COMPATIBILITY
568  // This is only needed to provide the old interface that returns a reference to the Jacobian.
569  // It is NOT thread-safe and should be avoided whenever possible.
570  mutable JacobianType m_SharedLocalJacobian;
571 #endif
572 
574 private:
575  Transform(const Self &); // purposely not implemented
576  void operator=(const Self &); // purposely not implemented
577 
578  template <typename TType>
579  std::string GetTransformTypeAsString(TType *) const
580  {
581  std::string rval("other");
582 
583  return rval;
584  }
585 
586  std::string GetTransformTypeAsString(float *) const
587  {
588  std::string rval("float");
589 
590  return rval;
591  }
592 
593  std::string GetTransformTypeAsString(double *) const
594  {
595  std::string rval("double");
596 
597  return rval;
598  }
599 
600 };
601 } // end namespace itk
602 
603 // Define instantiation macro for this template.
604 #define ITK_TEMPLATE_Transform(_, EXPORT, TypeX, TypeY) \
605  namespace itk \
606  { \
607  _( 3 ( class EXPORT Transform<ITK_TEMPLATE_3 TypeX> ) ) \
608  namespace Templates \
609  { \
610  typedef Transform<ITK_TEMPLATE_3 TypeX> Transform##TypeY; \
611  } \
612  }
613 
614 #if ITK_TEMPLATE_EXPLICIT
615 #include "Templates/itkTransform+-.h"
616 #endif
617 
618 #if ITK_TEMPLATE_TXX
619 #include "itkTransform.hxx"
620 #endif
621 
622 #endif
623