00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkMatrixOffsetTransformBase_h
00019 #define __itkMatrixOffsetTransformBase_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
00076 template <
00077 class TScalarType=double,
00078 unsigned int NInputDimensions=3,
00079 unsigned int NOutputDimensions=3>
00080 class MatrixOffsetTransformBase
00081 : public Transform< TScalarType, NInputDimensions, NOutputDimensions >
00082 {
00083 public:
00085 typedef MatrixOffsetTransformBase Self;
00086 typedef Transform< TScalarType,
00087 NInputDimensions,
00088 NOutputDimensions > Superclass;
00089 typedef SmartPointer<Self> Pointer;
00090 typedef SmartPointer<const Self> ConstPointer;
00091
00093 itkTypeMacro( MatrixOffsetTransformBase, Transform );
00094
00096 itkNewMacro( Self );
00097
00099 itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
00100 itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
00101 itkStaticConstMacro(ParametersDimension, unsigned int,
00102 NOutputDimensions*(NInputDimensions+1));
00104
00105
00107 typedef typename Superclass::ParametersType ParametersType;
00108
00110 typedef typename Superclass::JacobianType JacobianType;
00111
00113 typedef typename Superclass::ScalarType ScalarType;
00114
00116 typedef Vector<TScalarType,
00117 itkGetStaticConstMacro(InputSpaceDimension)> InputVectorType;
00118 typedef Vector<TScalarType,
00119 itkGetStaticConstMacro(OutputSpaceDimension)> OutputVectorType;
00121
00123 typedef CovariantVector<TScalarType,
00124 itkGetStaticConstMacro(InputSpaceDimension)>
00125 InputCovariantVectorType;
00126 typedef CovariantVector<TScalarType,
00127 itkGetStaticConstMacro(OutputSpaceDimension)>
00128 OutputCovariantVectorType;
00130
00132 typedef vnl_vector_fixed<TScalarType,
00133 itkGetStaticConstMacro(InputSpaceDimension)>
00134 InputVnlVectorType;
00135 typedef vnl_vector_fixed<TScalarType,
00136 itkGetStaticConstMacro(OutputSpaceDimension)>
00137 OutputVnlVectorType;
00139
00141 typedef Point<TScalarType,
00142 itkGetStaticConstMacro(InputSpaceDimension)>
00143 InputPointType;
00144 typedef Point<TScalarType,
00145 itkGetStaticConstMacro(OutputSpaceDimension)>
00146 OutputPointType;
00148
00150 typedef Matrix<TScalarType, itkGetStaticConstMacro(OutputSpaceDimension),
00151 itkGetStaticConstMacro(InputSpaceDimension)>
00152 MatrixType;
00153
00155 typedef Matrix<TScalarType, itkGetStaticConstMacro(InputSpaceDimension),
00156 itkGetStaticConstMacro(OutputSpaceDimension)>
00157 InverseMatrixType;
00158
00159 typedef InputPointType CenterType;
00160
00161 typedef OutputVectorType OffsetType;
00162
00163 typedef OutputVectorType TranslationType;
00164
00168 virtual void SetIdentity( void );
00169
00181 virtual void SetMatrix(const MatrixType &matrix)
00182 { m_Matrix = matrix; this->ComputeOffset();
00183 this->ComputeMatrixParameters();
00184 m_MatrixMTime.Modified(); this->Modified(); return; }
00186
00193 const MatrixType & GetMatrix() const
00194 { return m_Matrix; }
00195
00204 void SetOffset(const OutputVectorType &offset)
00205 { m_Offset = offset; this->ComputeTranslation();
00206 this->Modified(); return; }
00208
00214 const OutputVectorType & GetOffset(void) const
00215 { return m_Offset; }
00216
00239 void SetCenter(const InputPointType & center)
00240 { m_Center = center; this->ComputeOffset();
00241 this->Modified(); return; }
00243
00250 const InputPointType & GetCenter() const
00251 { return m_Center; }
00252
00259 void SetTranslation(const OutputVectorType & translation)
00260 { m_Translation = translation; this->ComputeOffset();
00261 this->Modified(); return; }
00263
00270 const OutputVectorType & GetTranslation(void) const
00271 { return m_Translation; }
00272
00273
00278 void SetParameters( const ParametersType & parameters );
00279
00281 const ParametersType& GetParameters(void) const;
00282
00284 virtual void SetFixedParameters( const ParametersType & );
00285
00287 virtual const ParametersType& GetFixedParameters(void) const;
00288
00289
00301 void Compose(const Self * other, bool pre=0);
00302
00310 OutputPointType TransformPoint(const InputPointType & point) const;
00311 OutputVectorType TransformVector(const InputVectorType & vector) const;
00312 OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const;
00313 OutputCovariantVectorType TransformCovariantVector(
00314 const InputCovariantVectorType &vector) const;
00316
00323 const JacobianType & GetJacobian(const InputPointType & point ) const;
00324
00343 bool GetInverse(Self * inverse) const;
00345
00346
00350 const InverseMatrixType & GetInverseMatrix( void ) const;
00351
00357 virtual bool IsLinear() const { return true; }
00358
00359 protected:
00367 MatrixOffsetTransformBase(const MatrixType &matrix,
00368 const OutputVectorType &offset);
00369 MatrixOffsetTransformBase(unsigned int outputDims,
00370 unsigned int paramDims);
00371 MatrixOffsetTransformBase();
00373
00375 virtual ~MatrixOffsetTransformBase();
00376
00378 void PrintSelf(std::ostream &s, Indent indent) const;
00379
00380 const InverseMatrixType & GetVarInverseMatrix( void ) const
00381 { return m_InverseMatrix; };
00382 void SetVarInverseMatrix(const InverseMatrixType & matrix) const
00383 { m_InverseMatrix = matrix; m_InverseMatrixMTime.Modified(); };
00384 bool InverseMatrixIsOld(void) const
00385 { if(m_MatrixMTime != m_InverseMatrixMTime)
00386 { return true; } else { return false; } };
00387
00388 virtual void ComputeMatrixParameters(void);
00389
00390 virtual void ComputeMatrix(void);
00391 void SetVarMatrix(const MatrixType & matrix)
00392 { m_Matrix = matrix; m_MatrixMTime.Modified(); };
00393
00394 virtual void ComputeTranslation(void);
00395 void SetVarTranslation(const OutputVectorType & translation)
00396 { m_Translation = translation; };
00397
00398 virtual void ComputeOffset(void);
00399 void SetVarOffset(const OutputVectorType & offset)
00400 { m_Offset = offset; };
00401
00402 void SetVarCenter(const InputPointType & center)
00403 { m_Center = center; };
00404
00405 private:
00406
00407 MatrixOffsetTransformBase(const Self & other);
00408 const Self & operator=( const Self & );
00409
00410
00411 MatrixType m_Matrix;
00412 OutputVectorType m_Offset;
00413 mutable InverseMatrixType m_InverseMatrix;
00414 mutable bool m_Singular;
00415
00416 InputPointType m_Center;
00417 OutputVectorType m_Translation;
00418
00420 TimeStamp m_MatrixMTime;
00421 mutable TimeStamp m_InverseMatrixMTime;
00422
00423 };
00424
00425 }
00426
00427
00428 #define ITK_TEMPLATE_MatrixOffsetTransformBase(_, EXPORT, x, y) namespace itk { \
00429 _(3(class EXPORT MatrixOffsetTransformBase< ITK_TEMPLATE_3 x >)) \
00430 namespace Templates { typedef MatrixOffsetTransformBase< ITK_TEMPLATE_3 x > MatrixOffsetTransformBase##y; } \
00431 }
00432
00433 #if ITK_TEMPLATE_EXPLICIT
00434 # include "Templates/itkMatrixOffsetTransformBase+-.h"
00435 #endif
00436
00437 #if ITK_TEMPLATE_TXX
00438 # include "itkMatrixOffsetTransformBase.txx"
00439 #endif
00440
00441 #endif
00442
00443