| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkTransform.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:48 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkTransform_h |
| 18 |
|
#define __itkTransform_h |
| 19 |
|
|
| 20 |
|
#include "itkTransformBase.h" |
| 21 |
|
#include "itkPoint.h" |
| 22 |
|
#include "itkVector.h" |
| 23 |
|
#include "itkCovariantVector.h" |
| 24 |
|
#include "vnl/vnl_vector_fixed.h" |
| 25 |
|
#include "itkArray.h" |
| 26 |
|
#include "itkArray2D.h" |
| 27 |
|
|
| 28 |
|
#include "itkObjectFactory.h" |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
namespace itk |
| 32 |
|
{ |
| 33 |
|
|
| 34 |
|
/** \class Transform |
| 35 |
|
* \brief Transform points and vector from an input space to an output space. |
| 36 |
|
* |
| 37 |
|
* This abstract class define the generic interface for a geometrical |
| 38 |
|
* transformation from one space to another. The class provides methods |
| 39 |
|
* for mapping points, vectors and covariant vectors from the input space |
| 40 |
|
* to the output space. |
| 41 |
|
* |
| 42 |
|
* Given that transformation are not necesarily invertible, this basic |
| 43 |
|
* class does not provide the methods for back transfromation. Back transform |
| 44 |
|
* methods are implemented in derived classes where appropriate. |
| 45 |
|
* |
| 46 |
|
* \par Registration Framework Support |
| 47 |
|
* Typically a Transform class has several methods for setting its |
| 48 |
|
* parameters. For use in the registration framework, the parameters must |
| 49 |
|
* also be represented by an array of doubles to allow communication |
| 50 |
|
* with generic optimizers. The Array of transformation parameters is set using |
| 51 |
|
* the SetParameters() method. |
| 52 |
|
* |
| 53 |
|
* Another requirement of the registration framework is the computation |
| 54 |
|
* of the transform Jacobian. In general, a ImageToImageMetric requires |
| 55 |
|
* the knowledge of the Jacobian in order to compute the metric derivatives. |
| 56 |
|
* The Jacobian is a matrix whose element are the partial derivatives |
| 57 |
|
* of the output point with respect to the array of parameters that defines |
| 58 |
|
* the transform. |
| 59 |
|
* |
| 60 |
|
* \ingroup Transforms |
| 61 |
|
* |
| 62 |
|
*/ |
| 63 |
|
template <class TScalarType, |
| 64 |
|
unsigned int NInputDimensions=3, |
| 65 |
|
unsigned int NOutputDimensions=3> |
| 66 |
|
class ITK_EXPORT Transform : public TransformBase |
| 67 |
|
{ |
| 68 |
|
public: |
| 69 |
|
/** Standard class typedefs. */ |
| 70 |
|
typedef Transform Self; |
| 71 |
TDA |
typedef TransformBase Superclass; |
| 72 |
TDA |
typedef SmartPointer< Self > Pointer; |
| 73 |
TDA |
typedef SmartPointer< const Self > ConstPointer; |
| 74 |
|
|
| 75 |
|
/** New method for creating an object using a factory. */ |
| 76 |
|
itkNewMacro(Self); |
| 77 |
|
|
| 78 |
|
/** Run-time type information (and related methods). */ |
| 79 |
|
itkTypeMacro( Transform, TransformBase ); |
| 80 |
|
|
| 81 |
|
/** Dimension of the domain space. */ |
| 82 |
|
itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions); |
| 83 |
|
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions); |
| 84 |
|
|
| 85 |
|
/** Get the size of the input space */ |
| 86 |
|
unsigned int GetInputSpaceDimension(void) const {return NInputDimensions;} |
| 87 |
|
|
| 88 |
|
/** Get the size of the output space */ |
| 89 |
|
unsigned int GetOutputSpaceDimension(void) const {return NOutputDimensions;} |
| 90 |
|
|
| 91 |
|
/** Type of the scalar representing coordinate and vector elements. */ |
| 92 |
|
typedef TScalarType ScalarType; |
| 93 |
|
|
| 94 |
|
/** Type of the input parameters. */ |
| 95 |
|
typedef typename Superclass::ParametersType ParametersType; |
| 96 |
|
|
| 97 |
|
/** Type of the Jacobian matrix. */ |
| 98 |
|
typedef Array2D< double > JacobianType; |
| 99 |
|
|
| 100 |
|
/** Standard vector type for this class. */ |
| 101 |
|
typedef Vector<TScalarType, NInputDimensions> InputVectorType; |
| 102 |
|
typedef Vector<TScalarType, NOutputDimensions> OutputVectorType; |
| 103 |
|
|
| 104 |
|
/** Standard covariant vector type for this class */ |
| 105 |
LEN |
typedef CovariantVector<TScalarType, NInputDimensions> InputCovariantVectorType; |
| 106 |
LEN |
typedef CovariantVector<TScalarType, NOutputDimensions> OutputCovariantVectorType; |
| 107 |
|
|
| 108 |
|
/** Standard vnl_vector type for this class. */ |
| 109 |
|
typedef vnl_vector_fixed<TScalarType, NInputDimensions> InputVnlVectorType; |
| 110 |
|
typedef vnl_vector_fixed<TScalarType, NOutputDimensions> OutputVnlVectorType; |
| 111 |
|
|
| 112 |
|
/** Standard coordinate point type for this class */ |
| 113 |
|
typedef Point<TScalarType, NInputDimensions> InputPointType; |
| 114 |
TDA |
typedef Point<TScalarType, NOutputDimensions> OutputPointType; |
| 115 |
|
|
| 116 |
|
/** Method to transform a point. */ |
| 117 |
|
virtual OutputPointType TransformPoint(const InputPointType & ) const |
| 118 |
|
{ return OutputPointType(); } |
| 119 |
|
|
| 120 |
|
/** Method to transform a vector. */ |
| 121 |
|
virtual OutputVectorType TransformVector(const InputVectorType &) const |
| 122 |
|
{ return OutputVectorType(); } |
| 123 |
|
|
| 124 |
|
/** Method to transform a vnl_vector. */ |
| 125 |
|
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const |
| 126 |
|
{ return OutputVnlVectorType(); } |
| 127 |
|
|
| 128 |
|
/** Method to transform a CovariantVector. */ |
| 129 |
|
virtual OutputCovariantVectorType TransformCovariantVector( |
| 130 |
|
const InputCovariantVectorType &) const |
| 131 |
|
{ return OutputCovariantVectorType(); } |
| 132 |
|
|
| 133 |
|
/** Set the transformation parameters and update internal transformation. |
| 134 |
|
* SetParameters gives the transform the option to set it's |
| 135 |
|
* parameters by keeping a reference to the parameters, or by |
| 136 |
|
* copying. To force the transform to copy it's parameters call |
| 137 |
|
* SetParametersByValue. |
| 138 |
|
* \sa SetParametersByValue |
| 139 |
|
*/ |
| 140 |
|
virtual void SetParameters( const ParametersType & ) |
| 141 |
|
{ itkExceptionMacro( << "Subclasses should override this method" ) }; |
| 142 |
|
|
| 143 |
|
/** Set the transformation parameters and update internal transformation. |
| 144 |
|
* This method forces the transform to copy the parameters. The |
| 145 |
|
* default implementation is to call SetParameters. This call must |
| 146 |
|
* be overridden if the transform normally implements SetParameters |
| 147 |
|
* by keeping a reference to the parameters. |
| 148 |
|
* \sa SetParameters |
| 149 |
|
*/ |
| 150 |
|
virtual void SetParametersByValue ( const ParametersType & p ) |
| 151 |
|
{ this->SetParameters ( p ); }; |
| 152 |
|
|
| 153 |
|
/** Get the Transformation Parameters. */ |
| 154 |
|
virtual const ParametersType& GetParameters(void) const |
| 155 |
|
{ itkExceptionMacro( << "Subclasses should override this method" ); |
| 156 |
IND |
******return m_Parameters; }; |
| 157 |
|
|
| 158 |
|
/** Set the fixed parameters and update internal transformation. */ |
| 159 |
|
virtual void SetFixedParameters( const ParametersType & ) |
| 160 |
|
{ itkExceptionMacro( << "Subclasses should override this method" ) }; |
| 161 |
|
|
| 162 |
|
/** Get the Fixed Parameters. */ |
| 163 |
|
virtual const ParametersType& GetFixedParameters(void) const |
| 164 |
|
{ itkExceptionMacro( << "Subclasses should override this method" ); |
| 165 |
IND |
******return m_Parameters; }; |
| 166 |
|
|
| 167 |
|
/** Compute the Jacobian of the transformation |
| 168 |
|
* |
| 169 |
|
* This method computes the Jacobian matrix of the transformation |
| 170 |
|
* at a given input point. The rank of the Jacobian will also indicate |
| 171 |
|
* if the transform is invertible at this point. |
| 172 |
|
* |
| 173 |
|
* The Jacobian is be expressed as a matrix of partial derivatives of the |
| 174 |
|
* output point components with respect to the parameters that defined |
| 175 |
|
* the transform: |
| 176 |
|
* |
| 177 |
|
* \f[ |
| 178 |
|
* |
| 179 |
IND |
******J=\left[ \begin{array}{cccc} |
| 180 |
IND |
******\frac{\partial x_{1}}{\partial p_{1}} & |
| 181 |
IND |
******\frac{\partial x_{1}}{\partial p_{2}} & |
| 182 |
IND |
******\cdots & \frac{\partial x_{1}}{\partial p_{m}}\\ |
| 183 |
IND |
******\frac{\partial x_{2}}{\partial p_{1}} & |
| 184 |
IND |
******\frac{\partial x_{2}}{\partial p_{2}} & |
| 185 |
IND |
******\cdots & \frac{\partial x_{2}}{\partial p_{m}}\\ |
| 186 |
IND |
******\vdots & \vdots & \ddots & \vdots \\ |
| 187 |
IND |
******\frac{\partial x_{n}}{\partial p_{1}} & |
| 188 |
IND |
******\frac{\partial x_{n}}{\partial p_{2}} & |
| 189 |
IND |
******\cdots & \frac{\partial x_{n}}{\partial p_{m}} |
| 190 |
IND |
******\end{array}\right] |
| 191 |
|
* |
| 192 |
|
* \f] |
| 193 |
|
* **/ |
| 194 |
|
virtual const JacobianType & GetJacobian(const InputPointType &) const |
| 195 |
|
{ itkExceptionMacro( << "Subclass should override this method" ); |
| 196 |
IND |
******return m_Jacobian; }; |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
/** Return the number of parameters that completely define the Transfom */ |
| 200 |
|
virtual unsigned int GetNumberOfParameters(void) const |
| 201 |
IND |
**********************{ return m_Parameters.Size(); } |
| 202 |
|
|
| 203 |
|
/** Return the inverse of the transform. |
| 204 |
|
* The inverse is recomputed if it has been modified */ |
| 205 |
|
bool GetInverse(Self*) const {return false;} |
| 206 |
|
|
| 207 |
|
/** Generate a platform independant name */ |
| 208 |
|
virtual std::string GetTransformTypeAsString() const; |
| 209 |
|
|
| 210 |
|
protected: |
| 211 |
|
Transform(); |
| 212 |
|
Transform(unsigned int Dimension, unsigned int NumberOfParameters); |
| 213 |
|
virtual ~Transform() {}; |
| 214 |
|
|
| 215 |
|
|
| 216 |
|
mutable ParametersType m_Parameters; |
| 217 |
|
mutable ParametersType m_FixedParameters; |
| 218 |
|
mutable JacobianType m_Jacobian; |
| 219 |
|
|
| 220 |
|
private: |
| 221 |
|
Transform(const Self&); //purposely not implemented |
| 222 |
|
void operator=(const Self&); //purposely not implemented |
| 223 |
|
|
| 224 |
|
|
| 225 |
|
}; |
| 226 |
|
|
| 227 |
|
} // end namespace itk |
| 228 |
|
|
| 229 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 230 |
|
#include "itkTransform.txx" |
| 231 |
|
#endif |
| 232 |
|
|
| 233 |
|
#endif |
| 234 |
|
|
| 235 |
EOF |
|
| 236 |
EOF,EML |
|
| 237 |
EOF,EML |
|