ITK  4.3.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 
384  virtual void UpdateTransformParameters( const DerivativeType & update, TScalarType factor = 1.0 );
385 
394  virtual NumberOfParametersType GetNumberOfLocalParameters(void) const
395  {
396  return this->GetNumberOfParameters();
397  }
398 
400  virtual NumberOfParametersType GetNumberOfParameters(void) const
401  {
402  return this->m_Parameters.Size();
403  }
404 
413  bool GetInverse( Self *itkNotUsed(inverseTransform) ) const
414  {
415  return false;
416  }
417 
424  virtual InverseTransformBasePointer GetInverseTransform() const
425  {
426  return NULL;
427  }
428 
430  virtual std::string GetTransformTypeAsString() const;
431 
435  virtual TransformCategoryType GetTransformCategory() const
436  {
437  return UnknownTransformCategory;
438  }
439 
440  virtual bool IsLinear() const
441  {
442  return ( this->GetTransformCategory() == Linear );
443  }
444 
445 
446 #ifdef ITKV3_COMPATIBILITY
447 
458  virtual const JacobianType & GetJacobian(const InputPointType & x) const
459  {
460  this->ComputeJacobianWithRespectToParameters(x, m_SharedLocalJacobian);
461  return m_SharedLocalJacobian;
462  }
464 
465 #endif
466 
501  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & itkNotUsed(p), JacobianType & itkNotUsed(jacobian) ) const
502  {
503  itkExceptionMacro(
504  "ComputeJacobianWithRespectToParamters( InputPointType, JacobianType"
505  " is unimplemented for " << this->GetNameOfClass() );
506  }
508 
509 
515  virtual void ComputeJacobianWithRespectToPosition(const InputPointType & itkNotUsed(x), JacobianType & itkNotUsed(jacobian) ) const
516  {
517  itkExceptionMacro(
518  "ComputeJacobianWithRespectToPosition( InputPointType, JacobianType"
519  " is unimplemented for " << this->GetNameOfClass() );
520  }
521 
522 
528  virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian ) const;
529 
530 protected:
536  virtual typename LightObject::Pointer InternalClone() const;
537 
538  Transform();
539  Transform(NumberOfParametersType NumberOfParameters);
540  virtual ~Transform()
541  {
542  }
543 
546 
547  OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(
548  const InputDiffusionTensor3DType, const JacobianType ) const;
549 
550 #ifdef ITKV3_COMPATIBILITY
551  // This is only needed to provide the old interface that returns a reference to the Jacobian.
552  // It is NOT thread-safe and should be avoided whenever possible.
553  mutable JacobianType m_SharedLocalJacobian;
554 #endif
555 
557 
558 private:
559  Transform(const Self &); // purposely not implemented
560  void operator=(const Self &); // purposely not implemented
561 
562  template <typename TType>
563  std::string GetTransformTypeAsString(TType *) const
564  {
565  std::string rval("other");
566 
567  return rval;
568  }
569 
570  std::string GetTransformTypeAsString(float *) const
571  {
572  std::string rval("float");
573 
574  return rval;
575  }
576 
577  std::string GetTransformTypeAsString(double *) const
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
592