Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkAffineTransform.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkAffineTransform.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-06-17 12:17:33 $
00007   Version:   $Revision: 1.71 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifndef __itkAffineTransform_h
00019 #define __itkAffineTransform_h
00020 
00021 #include <iostream>
00022 
00023 #include "itkMatrix.h"
00024 #include "itkMatrixOffsetTransformBase.h"
00025 #include "itkExceptionObject.h"
00026 #include "itkMacro.h"
00027 
00028 namespace itk
00029 {
00030 
00031 
00104 
00105 template <
00106  class TScalarType=double,         // Data type for scalars 
00107                                    //    (e.g. float or double)
00108  unsigned int NDimensions=3>       // Number of dimensions in the input space
00109 class AffineTransform 
00110 : public MatrixOffsetTransformBase< TScalarType, NDimensions, NDimensions >
00111 {
00112 public:
00114   typedef AffineTransform                           Self;
00115   typedef MatrixOffsetTransformBase< TScalarType,
00116                                      NDimensions,
00117                                      NDimensions >  Superclass;
00118   typedef SmartPointer<Self>                        Pointer;
00119   typedef SmartPointer<const Self>                  ConstPointer;
00120 
00122   itkTypeMacro( AffineTransform, MatrixOffsetTransformBase );
00123 
00125   itkNewMacro( Self );
00126 
00128   itkStaticConstMacro(InputSpaceDimension, unsigned int, NDimensions);
00129   itkStaticConstMacro(OutputSpaceDimension, unsigned int, NDimensions);
00130   itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
00131   itkStaticConstMacro(ParametersDimension, unsigned int,
00132                                            NDimensions*(NDimensions+1));
00134 
00135   
00137   typedef typename Superclass::ParametersType         ParametersType;
00138   typedef typename Superclass::JacobianType           JacobianType;
00139   typedef typename Superclass::ScalarType             ScalarType;
00140   typedef typename Superclass::InputPointType         InputPointType;
00141   typedef typename Superclass::OutputPointType        OutputPointType;
00142   typedef typename Superclass::InputVectorType        InputVectorType;
00143   typedef typename Superclass::OutputVectorType       OutputVectorType;
00144   typedef typename Superclass::InputVnlVectorType     InputVnlVectorType;
00145   typedef typename Superclass::OutputVnlVectorType    OutputVnlVectorType;
00146   typedef typename Superclass::InputCovariantVectorType 
00147                                                       InputCovariantVectorType;
00148   typedef typename Superclass::OutputCovariantVectorType
00149                                                       OutputCovariantVectorType;
00150   typedef typename Superclass::MatrixType             MatrixType;
00151   typedef typename Superclass::InverseMatrixType      InverseMatrixType;
00152   typedef typename Superclass::CenterType             CenterType;
00153   typedef typename Superclass::OffsetType             OffsetType;
00154   typedef typename Superclass::TranslationType        TranslationType;
00155 
00158   typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType;
00159   typedef typename InverseTransformBaseType::Pointer    InverseTransformBasePointer;
00160 
00167   void Translate(const OutputVectorType &offset, bool pre=0);
00168 
00180   void Scale(const OutputVectorType &factor, bool pre=0);
00181   void Scale(const TScalarType &factor, bool pre=0);
00183 
00199   void Rotate(int axis1, int axis2, TScalarType angle, bool pre=0);
00201 
00215   void Rotate2D(TScalarType angle, bool pre=0);
00216 
00230   void Rotate3D(const OutputVectorType &axis, TScalarType angle, bool pre=0);
00231 
00243   void Shear(int axis1, int axis2, TScalarType coef, bool pre=0);
00244 
00246   bool GetInverse(Self* inverse) const;
00247 
00249   virtual InverseTransformBasePointer GetInverseTransform() const;
00250 
00259   inline InputPointType   BackTransform(const OutputPointType  &point ) const;
00260   inline InputVectorType  BackTransform(const OutputVectorType &vector) const;
00261   inline InputVnlVectorType BackTransform(
00262                                      const OutputVnlVectorType &vector) const;
00263   inline InputCovariantVectorType BackTransform(
00264                               const OutputCovariantVectorType &vector) const;
00266 
00276   inline InputPointType BackTransformPoint(const OutputPointType  &point) const;
00277 
00289   ScalarType Metric(const Self * other) const;
00290 
00294   ScalarType Metric(void) const;
00295 
00296 protected:
00304   AffineTransform(const MatrixType &matrix,
00305                   const OutputVectorType &offset);
00306   AffineTransform(unsigned int outputDims,
00307                   unsigned int paramDims);
00308   AffineTransform();
00310 
00312   virtual ~AffineTransform();
00313 
00315   void PrintSelf(std::ostream &s, Indent indent) const;
00316 
00317 private:
00318 
00319   AffineTransform(const Self & other);
00320   const Self & operator=( const Self & );
00321 
00322 }; //class AffineTransform
00323 
00325 template<class TScalarType, unsigned int NDimensions>
00326 inline
00327 typename AffineTransform<TScalarType, NDimensions>::InputVectorType
00328 AffineTransform<TScalarType, NDimensions>::
00329 BackTransform(const OutputVectorType &vect ) const 
00330 {
00331   itkWarningMacro(<<"BackTransform(): This method is slated to be removed\
00332    from ITK. Instead, please use GetInverse() to generate an inverse\
00333    transform and then perform the transform using that inverted transform.");
00334   return this->GetInverseMatrix() * vect;
00335 }
00337 
00338 
00340 template<class TScalarType, unsigned int NDimensions>
00341 inline
00342 typename AffineTransform<TScalarType, NDimensions>::InputVnlVectorType
00343 AffineTransform<TScalarType, NDimensions>::
00344 BackTransform(const OutputVnlVectorType &vect ) const 
00345 {
00346   itkWarningMacro(<<"BackTransform(): This method is slated to be removed\
00347    from ITK. Instead, please use GetInverse() to generate an inverse\
00348     transform and then perform the transform using that inverted transform.");
00349   return this->GetInverseMatrix() * vect;
00350 }
00352 
00353 
00355 template<class TScalarType, unsigned int NDimensions>
00356 inline
00357 typename AffineTransform<TScalarType, NDimensions>::InputCovariantVectorType
00358 AffineTransform<TScalarType, NDimensions>::
00359 BackTransform(const OutputCovariantVectorType &vec) const 
00360 {
00361   itkWarningMacro(<<"BackTransform(): This method is slated to be removed\
00362    from ITK. Instead, please use GetInverse() to generate an inverse\
00363    transform and then perform the transform using that inverted transform.");
00364 
00365   InputCovariantVectorType result;    // Converted vector
00366 
00367   for (unsigned int i = 0; i < NDimensions; i++) 
00368     {
00369     result[i] = NumericTraits<ScalarType>::Zero;
00370     for (unsigned int j = 0; j < NDimensions; j++) 
00371       {
00372       result[i] += this->GetMatrix()[j][i]*vec[j]; // Direct matrix transposed
00373       }
00374     }
00375   return result;
00376 }
00377 
00378 
00380 template<class TScalarType, unsigned int NDimensions>
00381 inline
00382 typename AffineTransform<TScalarType, NDimensions>::InputPointType
00383 AffineTransform<TScalarType, NDimensions>::
00384 BackTransformPoint(const OutputPointType &point) const
00385 {
00386   return this->BackTransform(point);
00387 }
00388 
00390 template<class TScalarType, unsigned int NDimensions>
00391 inline
00392 typename AffineTransform<TScalarType, NDimensions>::InputPointType
00393 AffineTransform<TScalarType, NDimensions>::
00394 BackTransform(const OutputPointType &point) const 
00395 {
00396   itkWarningMacro(<<"BackTransform(): This method is slated to be removed\
00397    from ITK.  Instead, please use GetInverse() to generate an inverse\
00398    transform and then perform the transform using that inverted transform.");
00399   InputPointType result;       // Converted point
00400   ScalarType temp[NDimensions];
00401   unsigned int i, j;
00403 
00404   for (j = 0; j < NDimensions; j++) 
00405     {
00406     temp[j] = point[j] - this->GetOffset()[j];
00407     }
00408 
00409   for (i = 0; i < NDimensions; i++) 
00410     {
00411     result[i] = 0.0;
00412     for (j = 0; j < NDimensions; j++) 
00413       {
00414       result[i] += this->GetInverseMatrix()[i][j]*temp[j];
00415       }
00416     }
00417   return result;
00418 }
00419 
00420 }  // namespace itk
00421 
00422 // Define instantiation macro for this template.
00423 #define ITK_TEMPLATE_AffineTransform(_, EXPORT, x, y) namespace itk { \
00424   _(2(class EXPORT AffineTransform< ITK_TEMPLATE_2 x >)) \
00425   namespace Templates { typedef AffineTransform< ITK_TEMPLATE_2 x > \
00426                                                   AffineTransform##y; } \
00427   }
00428 
00429 #if ITK_TEMPLATE_EXPLICIT
00430 # include "Templates/itkAffineTransform+-.h"
00431 #endif
00432 
00433 #if ITK_TEMPLATE_TXX
00434 # include "itkAffineTransform.txx"
00435 #endif
00436 
00437 #endif /* __itkAffineTransform_h */
00438 

Generated at Tue Sep 15 02:06:55 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000