00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkAffineTransform_h
00019 #define __itkAffineTransform_h
00020
00021 #include <iostream>
00022
00023 #include "itkMatrix.h"
00024 #include "itkTransform.h"
00025 #include "itkExceptionObject.h"
00026 #include "itkMacro.h"
00027
00028 namespace itk
00029 {
00030
00031
00112 template <
00113 class TScalarType=double,
00114
00115 unsigned int NDimensions=3>
00116 class AffineTransform : public Transform< TScalarType,
00117 NDimensions,
00118 NDimensions >
00119 {
00120 public:
00122 typedef AffineTransform Self;
00123 typedef Transform< TScalarType, NDimensions, NDimensions > Superclass;
00124 typedef SmartPointer<Self> Pointer;
00125 typedef SmartPointer<const Self> ConstPointer;
00126
00128 itkTypeMacro( AffineTransform, Transform );
00129
00131 itkNewMacro( Self );
00132
00134 itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
00135 itkStaticConstMacro(ParametersDimension, unsigned int,
00136 NDimensions*(NDimensions+1));
00137
00138
00140 typedef typename Superclass::ParametersType ParametersType;
00141
00143 typedef typename Superclass::JacobianType JacobianType;
00144
00146 typedef typename Superclass::ScalarType ScalarType;
00147
00149 typedef Vector<TScalarType,
00150 itkGetStaticConstMacro(SpaceDimension)> InputVectorType;
00151 typedef Vector<TScalarType,
00152 itkGetStaticConstMacro(SpaceDimension)> OutputVectorType;
00153
00155 typedef CovariantVector<TScalarType,
00156 itkGetStaticConstMacro(SpaceDimension)>
00157 InputCovariantVectorType;
00158 typedef CovariantVector<TScalarType,
00159 itkGetStaticConstMacro(SpaceDimension)>
00160 OutputCovariantVectorType;
00161
00163 typedef vnl_vector_fixed<TScalarType,
00164 itkGetStaticConstMacro(SpaceDimension)>
00165 InputVnlVectorType;
00166 typedef vnl_vector_fixed<TScalarType,
00167 itkGetStaticConstMacro(SpaceDimension)>
00168 OutputVnlVectorType;
00169
00171 typedef Point<TScalarType,
00172 itkGetStaticConstMacro(SpaceDimension)> InputPointType;
00173 typedef Point<TScalarType,
00174 itkGetStaticConstMacro(SpaceDimension)> OutputPointType;
00175
00177 typedef Matrix<TScalarType, itkGetStaticConstMacro(SpaceDimension),
00178 itkGetStaticConstMacro(SpaceDimension)> MatrixType;
00179
00181 typedef OutputVectorType OffsetType;
00182
00188 const OffsetType & GetOffset(void) const
00189 { return m_Offset; }
00190
00197 const MatrixType & GetMatrix() const
00198 { return m_Matrix; }
00199
00206 const InputPointType & GetCenter() const
00207 { return m_Center; }
00208
00215 const OutputVectorType & GetTranslation(void) const
00216 { return m_Translation; }
00217
00221 void SetIdentity( void )
00222 { m_Matrix.SetIdentity();
00223 m_Offset.Fill( 0.0 );
00224 m_Translation.Fill( 0.0 );
00225 m_Center.Fill( 0.0 );
00226 m_MatrixMTime.Modified();
00227 this->Modified();
00228 }
00229
00238 bool GetInverse(Self* inverse) const;
00239
00247 void SetOffset(const OffsetType &offset)
00248 { m_Offset = offset; this->ComputeTranslation();
00249 this->Modified(); return; }
00250
00259 void SetMatrix(const MatrixType &matrix)
00260 { m_Matrix = matrix; this->ComputeOffset();
00261 m_MatrixMTime.Modified(); this->Modified(); return; }
00262
00271 void SetCenter(const InputPointType & center)
00272 { m_Center = center; this->ComputeTranslation();
00273 this->Modified(); return; }
00274
00281 void SetTranslation(const OutputVectorType & translation)
00282 { m_Translation = translation; this->ComputeOffset();
00283 this->Modified(); return; }
00284
00285
00290 void SetParameters( const ParametersType & parameters );
00291
00293 const ParametersType& GetParameters(void) const;
00294
00306 void Compose(const Self * other, bool pre=0);
00307
00314 void Translate(const OutputVectorType &offset, bool pre=0);
00315
00327 void Scale(const OutputVectorType &factor, bool pre=0);
00328 void Scale(const TScalarType &factor, bool pre=0);
00329
00345 void Rotate(int axis1, int axis2, TScalarType angle, bool pre=0);
00346
00360 void Rotate2D(TScalarType angle, bool pre=0);
00361
00375 void Rotate3D(const OutputVectorType &axis, TScalarType angle, bool pre=0);
00376
00388 void Shear(int axis1, int axis2, TScalarType coef, bool pre=0);
00389
00397 OutputPointType TransformPoint (const InputPointType &point ) const;
00398 OutputVectorType TransformVector(const InputVectorType &vector) const;
00399 OutputVnlVectorType TransformVector(const InputVnlVectorType &vector) const;
00400 OutputCovariantVectorType TransformCovariantVector(
00401 const InputCovariantVectorType &vector) const;
00402
00408 inline InputPointType BackTransform(const OutputPointType &point ) const;
00409 inline InputVectorType BackTransform(const OutputVectorType &vector) const;
00410 inline InputVnlVectorType BackTransform(
00411 const OutputVnlVectorType &vector) const;
00412
00413 inline InputCovariantVectorType BackTransform(
00414 const OutputCovariantVectorType &vector) const;
00415
00422 InputPointType BackTransformPoint(const OutputPointType &point) const;
00423
00435 ScalarType Metric(const Self * other) const;
00436
00440 ScalarType Metric(void) const;
00441
00448 const JacobianType & GetJacobian(const InputPointType &point ) const;
00449
00452 MatrixType GetInverseMatrix() const;
00453
00462 typename AffineTransform::Pointer Inverse(void) const;
00463
00464
00465 protected:
00473 AffineTransform(const MatrixType &matrix, const OutputVectorType &offset);
00474 AffineTransform(unsigned int outputSpaceDimension,
00475 unsigned int parametersDimension);
00476 AffineTransform();
00477
00479 virtual ~AffineTransform();
00480
00482 void PrintSelf(std::ostream &s, Indent indent) const;
00483
00484 virtual void ComputeTranslation(void);
00485
00486 virtual void ComputeOffset(void);
00487
00489 mutable TimeStamp m_InverseMatrixMTime;
00490 TimeStamp m_MatrixMTime;
00491
00492 private:
00493
00494 AffineTransform(const Self & other);
00495 const Self & operator=( const Self & );
00496
00497
00498 MatrixType m_Matrix;
00499 OffsetType m_Offset;
00500 mutable MatrixType m_InverseMatrix;
00501 mutable bool m_Singular;
00502
00503 InputPointType m_Center;
00504 OutputVectorType m_Translation;
00505
00506 };
00507
00508 }
00509
00510
00511 #ifndef ITK_MANUAL_INSTANTIATION
00512 #include "itkAffineTransform.txx"
00513 #endif
00514
00515 #endif
00516
00517
00518
00519
00520