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: 2008-10-07 08:18:58 $
00007   Version:   $Revision: 1.69 $
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 
00162   void Translate(const OutputVectorType &offset, bool pre=0);
00163 
00175   void Scale(const OutputVectorType &factor, bool pre=0);
00176   void Scale(const TScalarType &factor, bool pre=0);
00178 
00194   void Rotate(int axis1, int axis2, TScalarType angle, bool pre=0);
00196 
00210   void Rotate2D(TScalarType angle, bool pre=0);
00211 
00225   void Rotate3D(const OutputVectorType &axis, TScalarType angle, bool pre=0);
00226 
00238   void Shear(int axis1, int axis2, TScalarType coef, bool pre=0);
00239 
00248   inline InputPointType   BackTransform(const OutputPointType  &point ) const;
00249   inline InputVectorType  BackTransform(const OutputVectorType &vector) const;
00250   inline InputVnlVectorType BackTransform(
00251                                      const OutputVnlVectorType &vector) const;
00252   inline InputCovariantVectorType BackTransform(
00253                               const OutputCovariantVectorType &vector) const;
00255 
00265   inline InputPointType BackTransformPoint(const OutputPointType  &point) const;
00266 
00278   ScalarType Metric(const Self * other) const;
00279 
00283   ScalarType Metric(void) const;
00284 
00285 protected:
00293   AffineTransform(const MatrixType &matrix,
00294                   const OutputVectorType &offset);
00295   AffineTransform(unsigned int outputDims,
00296                   unsigned int paramDims);
00297   AffineTransform();
00299 
00301   virtual ~AffineTransform();
00302 
00304   void PrintSelf(std::ostream &s, Indent indent) const;
00305 
00306 private:
00307 
00308   AffineTransform(const Self & other);
00309   const Self & operator=( const Self & );
00310 
00311 }; //class AffineTransform
00312 
00314 template<class TScalarType, unsigned int NDimensions>
00315 inline
00316 typename AffineTransform<TScalarType, NDimensions>::InputVectorType
00317 AffineTransform<TScalarType, NDimensions>::
00318 BackTransform(const OutputVectorType &vect ) const 
00319 {
00320   itkWarningMacro(<<"BackTransform(): This method is slated to be removed\
00321    from ITK. Instead, please use GetInverse() to generate an inverse\
00322    transform and then perform the transform using that inverted transform.");
00323   return this->GetInverseMatrix() * vect;
00324 }
00326 
00327 
00329 template<class TScalarType, unsigned int NDimensions>
00330 inline
00331 typename AffineTransform<TScalarType, NDimensions>::InputVnlVectorType
00332 AffineTransform<TScalarType, NDimensions>::
00333 BackTransform(const OutputVnlVectorType &vect ) const 
00334 {
00335   itkWarningMacro(<<"BackTransform(): This method is slated to be removed\
00336    from ITK. Instead, please use GetInverse() to generate an inverse\
00337     transform and then perform the transform using that inverted transform.");
00338   return this->GetInverseMatrix() * vect;
00339 }
00341 
00342 
00344 template<class TScalarType, unsigned int NDimensions>
00345 inline
00346 typename AffineTransform<TScalarType, NDimensions>::InputCovariantVectorType
00347 AffineTransform<TScalarType, NDimensions>::
00348 BackTransform(const OutputCovariantVectorType &vec) const 
00349 {
00350   itkWarningMacro(<<"BackTransform(): This method is slated to be removed\
00351    from ITK. Instead, please use GetInverse() to generate an inverse\
00352    transform and then perform the transform using that inverted transform.");
00353 
00354   InputCovariantVectorType result;    // Converted vector
00355 
00356   for (unsigned int i = 0; i < NDimensions; i++) 
00357     {
00358     result[i] = NumericTraits<ScalarType>::Zero;
00359     for (unsigned int j = 0; j < NDimensions; j++) 
00360       {
00361       result[i] += this->GetMatrix()[j][i]*vec[j]; // Direct matrix transposed
00362       }
00363     }
00364   return result;
00365 }
00366 
00367 
00369 template<class TScalarType, unsigned int NDimensions>
00370 inline
00371 typename AffineTransform<TScalarType, NDimensions>::InputPointType
00372 AffineTransform<TScalarType, NDimensions>::
00373 BackTransformPoint(const OutputPointType &point) const
00374 {
00375   return this->BackTransform(point);
00376 }
00377 
00379 template<class TScalarType, unsigned int NDimensions>
00380 inline
00381 typename AffineTransform<TScalarType, NDimensions>::InputPointType
00382 AffineTransform<TScalarType, NDimensions>::
00383 BackTransform(const OutputPointType &point) const 
00384 {
00385   itkWarningMacro(<<"BackTransform(): This method is slated to be removed\
00386    from ITK.  Instead, please use GetInverse() to generate an inverse\
00387    transform and then perform the transform using that inverted transform.");
00388   InputPointType result;       // Converted point
00389   ScalarType temp[NDimensions];
00390   unsigned int i, j;
00392 
00393   for (j = 0; j < NDimensions; j++) 
00394     {
00395     temp[j] = point[j] - this->GetOffset()[j];
00396     }
00397 
00398   for (i = 0; i < NDimensions; i++) 
00399     {
00400     result[i] = 0.0;
00401     for (j = 0; j < NDimensions; j++) 
00402       {
00403       result[i] += this->GetInverseMatrix()[i][j]*temp[j];
00404       }
00405     }
00406   return result;
00407 }
00408 
00409 }  // namespace itk
00410 
00411 // Define instantiation macro for this template.
00412 #define ITK_TEMPLATE_AffineTransform(_, EXPORT, x, y) namespace itk { \
00413   _(2(class EXPORT AffineTransform< ITK_TEMPLATE_2 x >)) \
00414   namespace Templates { typedef AffineTransform< ITK_TEMPLATE_2 x > \
00415                                                   AffineTransform##y; } \
00416   }
00417 
00418 #if ITK_TEMPLATE_EXPLICIT
00419 # include "Templates/itkAffineTransform+-.h"
00420 #endif
00421 
00422 #if ITK_TEMPLATE_TXX
00423 # include "itkAffineTransform.txx"
00424 #endif
00425 
00426 #endif /* __itkAffineTransform_h */
00427 

Generated at Wed Nov 5 20:14:38 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000