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));
00103
00104
00106 typedef typename Superclass::ParametersType ParametersType;
00107
00109 typedef typename Superclass::JacobianType JacobianType;
00110
00112 typedef typename Superclass::ScalarType ScalarType;
00113
00115 typedef Vector<TScalarType,
00116 itkGetStaticConstMacro(InputSpaceDimension)> InputVectorType;
00117 typedef Vector<TScalarType,
00118 itkGetStaticConstMacro(OutputSpaceDimension)> OutputVectorType;
00119
00121 typedef CovariantVector<TScalarType,
00122 itkGetStaticConstMacro(InputSpaceDimension)>
00123 InputCovariantVectorType;
00124 typedef CovariantVector<TScalarType,
00125 itkGetStaticConstMacro(OutputSpaceDimension)>
00126 OutputCovariantVectorType;
00127
00129 typedef vnl_vector_fixed<TScalarType,
00130 itkGetStaticConstMacro(InputSpaceDimension)>
00131 InputVnlVectorType;
00132 typedef vnl_vector_fixed<TScalarType,
00133 itkGetStaticConstMacro(OutputSpaceDimension)>
00134 OutputVnlVectorType;
00135
00137 typedef Point<TScalarType,
00138 itkGetStaticConstMacro(InputSpaceDimension)>
00139 InputPointType;
00140 typedef Point<TScalarType,
00141 itkGetStaticConstMacro(OutputSpaceDimension)>
00142 OutputPointType;
00143
00145 typedef Matrix<TScalarType, itkGetStaticConstMacro(OutputSpaceDimension),
00146 itkGetStaticConstMacro(InputSpaceDimension)>
00147 MatrixType;
00148
00150 typedef Matrix<TScalarType, itkGetStaticConstMacro(InputSpaceDimension),
00151 itkGetStaticConstMacro(OutputSpaceDimension)>
00152 InverseMatrixType;
00153
00154 typedef InputPointType CenterType;
00155
00156 typedef OutputVectorType OffsetType;
00157
00158 typedef OutputVectorType TranslationType;
00159
00163 virtual void SetIdentity( void );
00164
00176 virtual void SetMatrix(const MatrixType &matrix)
00177 { m_Matrix = matrix; this->ComputeOffset();
00178 this->ComputeMatrixParameters();
00179 m_MatrixMTime.Modified(); this->Modified(); return; }
00180
00187 const MatrixType & GetMatrix() const
00188 { return m_Matrix; }
00189
00198 void SetOffset(const OutputVectorType &offset)
00199 { m_Offset = offset; this->ComputeTranslation();
00200 this->Modified(); return; }
00201
00207 const OutputVectorType & GetOffset(void) const
00208 { return m_Offset; }
00209
00232 void SetCenter(const InputPointType & center)
00233 { m_Center = center; this->ComputeOffset();
00234 this->Modified(); return; }
00235
00242 const InputPointType & GetCenter() const
00243 { return m_Center; }
00244
00251 void SetTranslation(const OutputVectorType & translation)
00252 { m_Translation = translation; this->ComputeOffset();
00253 this->Modified(); return; }
00254
00261 const OutputVectorType & GetTranslation(void) const
00262 { return m_Translation; }
00263
00264
00269 void SetParameters( const ParametersType & parameters );
00270
00272 const ParametersType& GetParameters(void) const;
00273
00275 virtual void SetFixedParameters( const ParametersType & );
00276
00278 virtual const ParametersType& GetFixedParameters(void) const;
00279
00280
00292 void Compose(const Self * other, bool pre=0);
00293
00301 OutputPointType TransformPoint(const InputPointType & point) const;
00302 OutputVectorType TransformVector(const InputVectorType & vector) const;
00303 OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const;
00304 OutputCovariantVectorType TransformCovariantVector(
00305 const InputCovariantVectorType &vector) const;
00306
00313 const JacobianType & GetJacobian(const InputPointType & point ) const;
00314
00331 bool GetInverse(Self * inverse) const;
00332
00336 const InverseMatrixType & GetInverseMatrix( void ) const;
00337
00338 protected:
00346 MatrixOffsetTransformBase(const MatrixType &matrix,
00347 const OutputVectorType &offset);
00348 MatrixOffsetTransformBase(unsigned int outputDims,
00349 unsigned int paramDims);
00350 MatrixOffsetTransformBase();
00351
00353 virtual ~MatrixOffsetTransformBase();
00354
00356 void PrintSelf(std::ostream &s, Indent indent) const;
00357
00358 InverseMatrixType GetVarInverseMatrix( void ) const
00359 { return m_InverseMatrix; };
00360 void SetVarInverseMatrix(const InverseMatrixType & matrix) const
00361 { m_InverseMatrix = matrix; m_InverseMatrixMTime.Modified(); };
00362 bool InverseMatrixIsOld(void) const
00363 { if(m_MatrixMTime != m_InverseMatrixMTime)
00364 { return true; } else { return false; } };
00365
00366 virtual void ComputeMatrixParameters(void);
00367
00368 virtual void ComputeMatrix(void);
00369 void SetVarMatrix(const MatrixType & matrix)
00370 { m_Matrix = matrix; m_MatrixMTime.Modified(); };
00371
00372 virtual void ComputeTranslation(void);
00373 void SetVarTranslation(const OutputVectorType & translation)
00374 { m_Translation = translation; };
00375
00376 virtual void ComputeOffset(void);
00377 void SetVarOffset(const OutputVectorType & offset)
00378 { m_Offset = offset; };
00379
00380 void SetVarCenter(const InputPointType & center)
00381 { m_Center = center; };
00382
00383 private:
00384
00385 MatrixOffsetTransformBase(const Self & other);
00386 const Self & operator=( const Self & );
00387
00388
00389 MatrixType m_Matrix;
00390 OutputVectorType m_Offset;
00391 mutable InverseMatrixType m_InverseMatrix;
00392 mutable bool m_Singular;
00393
00394 InputPointType m_Center;
00395 OutputVectorType m_Translation;
00396
00398 TimeStamp m_MatrixMTime;
00399 mutable TimeStamp m_InverseMatrixMTime;
00400
00401 };
00402
00403 }
00404
00405
00406 #ifndef ITK_MANUAL_INSTANTIATION
00407 #include "itkMatrixOffsetTransformBase.txx"
00408 #endif
00409
00410 #endif
00411