00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkMatrixOffsetTransformBase_h
00018 #define __itkMatrixOffsetTransformBase_h
00019
00020 #include <iostream>
00021
00022 #include "itkMatrix.h"
00023 #include "itkTransform.h"
00024 #include "itkExceptionObject.h"
00025 #include "itkMacro.h"
00026
00027 namespace itk
00028 {
00029
00030
00075 template <
00076 class TScalarType=double,
00077 unsigned int NInputDimensions=3,
00078 unsigned int NOutputDimensions=3>
00079 class MatrixOffsetTransformBase
00080 : public Transform< TScalarType, NInputDimensions, NOutputDimensions >
00081 {
00082 public:
00084 typedef MatrixOffsetTransformBase Self;
00085 typedef Transform< TScalarType,
00086 NInputDimensions,
00087 NOutputDimensions > Superclass;
00088 typedef SmartPointer<Self> Pointer;
00089 typedef SmartPointer<const Self> ConstPointer;
00090
00092 itkTypeMacro( MatrixOffsetTransformBase, Transform );
00093
00095 itkNewMacro( Self );
00096
00098 itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
00099 itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
00100 itkStaticConstMacro(ParametersDimension, unsigned int,
00101 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;
00120
00122 typedef CovariantVector<TScalarType,
00123 itkGetStaticConstMacro(InputSpaceDimension)>
00124 InputCovariantVectorType;
00125 typedef CovariantVector<TScalarType,
00126 itkGetStaticConstMacro(OutputSpaceDimension)>
00127 OutputCovariantVectorType;
00129
00131 typedef vnl_vector_fixed<TScalarType,
00132 itkGetStaticConstMacro(InputSpaceDimension)>
00133 InputVnlVectorType;
00134 typedef vnl_vector_fixed<TScalarType,
00135 itkGetStaticConstMacro(OutputSpaceDimension)>
00136 OutputVnlVectorType;
00138
00140 typedef Point<TScalarType,
00141 itkGetStaticConstMacro(InputSpaceDimension)>
00142 InputPointType;
00143 typedef Point<TScalarType,
00144 itkGetStaticConstMacro(OutputSpaceDimension)>
00145 OutputPointType;
00147
00149 typedef Matrix<TScalarType, itkGetStaticConstMacro(OutputSpaceDimension),
00150 itkGetStaticConstMacro(InputSpaceDimension)>
00151 MatrixType;
00152
00154 typedef Matrix<TScalarType, itkGetStaticConstMacro(InputSpaceDimension),
00155 itkGetStaticConstMacro(OutputSpaceDimension)>
00156 InverseMatrixType;
00157
00158 typedef InputPointType CenterType;
00159
00160 typedef OutputVectorType OffsetType;
00161
00162 typedef OutputVectorType TranslationType;
00163
00166 typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType;
00167 typedef typename InverseTransformBaseType::Pointer InverseTransformBasePointer;
00168
00172 virtual void SetIdentity( void );
00173
00185 virtual void SetMatrix(const MatrixType &matrix)
00186 {
00187 m_Matrix = matrix; this->ComputeOffset();
00188 this->ComputeMatrixParameters();
00189 m_MatrixMTime.Modified(); this->Modified(); return;
00190 }
00192
00199 const MatrixType & GetMatrix() const
00200 { return m_Matrix; }
00201
00210 void SetOffset(const OutputVectorType &offset)
00211 {
00212 m_Offset = offset; this->ComputeTranslation();
00213 this->Modified(); return;
00214 }
00216
00222 const OutputVectorType & GetOffset(void) const
00223 { return m_Offset; }
00224
00247 void SetCenter(const InputPointType & center)
00248 {
00249 m_Center = center; this->ComputeOffset();
00250 this->Modified(); return;
00251 }
00253
00260 const InputPointType & GetCenter() const
00261 { return m_Center; }
00262
00269 void SetTranslation(const OutputVectorType & translation)
00270 {
00271 m_Translation = translation; this->ComputeOffset();
00272 this->Modified(); return;
00273 }
00275
00282 const OutputVectorType & GetTranslation(void) const
00283 {
00284 return m_Translation;
00285 }
00286
00291 void SetParameters( const ParametersType & parameters );
00292
00294 const ParametersType& GetParameters(void) const;
00295
00297 virtual void SetFixedParameters( const ParametersType & );
00298
00300 virtual const ParametersType& GetFixedParameters(void) const;
00301
00302
00314 void Compose(const Self * other, bool pre=0);
00315
00323 OutputPointType TransformPoint(const InputPointType & point) const;
00324 OutputVectorType TransformVector(const InputVectorType & vector) const;
00325 OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const;
00326 OutputCovariantVectorType TransformCovariantVector(
00327 const InputCovariantVectorType &vector) const;
00329
00336 const JacobianType & GetJacobian(const InputPointType & point ) const;
00337
00356 bool GetInverse(Self * inverse) const;
00358
00360 virtual InverseTransformBasePointer GetInverseTransform() const;
00361
00365 const InverseMatrixType & GetInverseMatrix( void ) const;
00366
00372 virtual bool IsLinear() const { return true; }
00373
00374 protected:
00382 MatrixOffsetTransformBase(const MatrixType &matrix,
00383 const OutputVectorType &offset);
00384 MatrixOffsetTransformBase(unsigned int outputDims,
00385 unsigned int paramDims);
00386 MatrixOffsetTransformBase();
00388
00390 virtual ~MatrixOffsetTransformBase();
00391
00393 void PrintSelf(std::ostream &s, Indent indent) const;
00394
00395 const InverseMatrixType & GetVarInverseMatrix( void ) const
00396 { return m_InverseMatrix; }
00397 void SetVarInverseMatrix(const InverseMatrixType & matrix) const
00398 { m_InverseMatrix = matrix; m_InverseMatrixMTime.Modified(); }
00399 bool InverseMatrixIsOld(void) const
00400 {
00401 if(m_MatrixMTime != m_InverseMatrixMTime)
00402 {
00403 return true;
00404 }
00405 else
00406 {
00407 return false;
00408 }
00409 }
00410
00411 virtual void ComputeMatrixParameters(void);
00412
00413 virtual void ComputeMatrix(void);
00414 void SetVarMatrix(const MatrixType & matrix)
00415 { m_Matrix = matrix; m_MatrixMTime.Modified(); }
00416
00417 virtual void ComputeTranslation(void);
00418 void SetVarTranslation(const OutputVectorType & translation)
00419 { m_Translation = translation; }
00420
00421 virtual void ComputeOffset(void);
00422 void SetVarOffset(const OutputVectorType & offset)
00423 { m_Offset = offset; }
00424
00425 void SetVarCenter(const InputPointType & center)
00426 { m_Center = center; }
00427
00428 private:
00429
00430 MatrixOffsetTransformBase(const Self & other);
00431 const Self & operator=( const Self & );
00432
00433
00434 MatrixType m_Matrix;
00435 OutputVectorType m_Offset;
00436 mutable InverseMatrixType m_InverseMatrix;
00437 mutable bool m_Singular;
00438
00439 InputPointType m_Center;
00440 OutputVectorType m_Translation;
00441
00443 TimeStamp m_MatrixMTime;
00444 mutable TimeStamp m_InverseMatrixMTime;
00445
00446 };
00447
00448 }
00449
00450
00451 #define ITK_TEMPLATE_MatrixOffsetTransformBase(_, EXPORT, x, y) namespace itk { \
00452 _(3(class EXPORT MatrixOffsetTransformBase< ITK_TEMPLATE_3 x >)) \
00453 namespace Templates { typedef MatrixOffsetTransformBase< ITK_TEMPLATE_3 x > MatrixOffsetTransformBase##y; } \
00454 }
00455
00456 #if ITK_TEMPLATE_EXPLICIT
00457 # include "Templates/itkMatrixOffsetTransformBase+-.h"
00458 #endif
00459
00460 #if ITK_TEMPLATE_TXX
00461 # include "itkMatrixOffsetTransformBase.txx"
00462 #endif
00463
00464 #endif
00465