00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkScaleTransform_h
00019 #define __itkScaleTransform_h
00020
00021 #include <iostream>
00022 #include "itkTransform.h"
00023 #include "itkExceptionObject.h"
00024 #include "itkMatrix.h"
00025
00026 namespace itk
00027 {
00028
00037 template <
00038 class TScalarType=float,
00039 unsigned int NDimensions=3 >
00040 class ITK_EXPORT ScaleTransform : public Transform< TScalarType,
00041 NDimensions,
00042 NDimensions >
00043 {
00044 public:
00046 typedef ScaleTransform Self;
00047 typedef Transform< TScalarType, NDimensions, NDimensions > Superclass;
00048 typedef SmartPointer<Self> Pointer;
00049 typedef SmartPointer<const Self> ConstPointer;
00050
00052 itkNewMacro( Self );
00053
00055 itkTypeMacro( ScaleTransform, Transform );
00056
00058 itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
00059 itkStaticConstMacro(ParametersDimension, unsigned int, NDimensions);
00061
00063 typedef typename Superclass::ScalarType ScalarType;
00064
00066 typedef typename Superclass::ParametersType ParametersType;
00067
00069 typedef typename Superclass::JacobianType JacobianType;
00070
00072 typedef FixedArray<TScalarType, itkGetStaticConstMacro(SpaceDimension)> ScaleType;
00073
00075 typedef Vector<TScalarType, itkGetStaticConstMacro(SpaceDimension)> InputVectorType;
00076 typedef Vector<TScalarType, itkGetStaticConstMacro(SpaceDimension)> OutputVectorType;
00078
00080 typedef CovariantVector<TScalarType, itkGetStaticConstMacro(SpaceDimension)> InputCovariantVectorType;
00081 typedef CovariantVector<TScalarType, itkGetStaticConstMacro(SpaceDimension)> OutputCovariantVectorType;
00083
00085 typedef vnl_vector_fixed<TScalarType, itkGetStaticConstMacro(SpaceDimension)> InputVnlVectorType;
00086 typedef vnl_vector_fixed<TScalarType, itkGetStaticConstMacro(SpaceDimension)> OutputVnlVectorType;
00088
00090 typedef Point<TScalarType, itkGetStaticConstMacro(SpaceDimension)> InputPointType;
00091 typedef Point<TScalarType, itkGetStaticConstMacro(SpaceDimension)> OutputPointType;
00093
00098 void SetParameters(const ParametersType & parameters);
00099
00104 const ParametersType & GetParameters( void ) const;
00105
00107 const JacobianType & GetJacobian( const InputPointType & point ) const;
00108
00117 void SetScale( const ScaleType & scale )
00118 { this->Modified(); m_Scale = scale; }
00119
00121 void Compose(const Self * other, bool pre=false);
00122
00126 void Scale(const ScaleType & scale, bool pre=false );
00127
00132 OutputPointType TransformPoint(const InputPointType &point ) const;
00133 OutputVectorType TransformVector(const InputVectorType &vector) const;
00134 OutputVnlVectorType TransformVector(const InputVnlVectorType &vector) const;
00135 OutputCovariantVectorType TransformCovariantVector(
00136 const InputCovariantVectorType &vector) const;
00138
00143 inline InputPointType BackTransform(const OutputPointType &point ) const;
00144 inline InputVectorType BackTransform(const OutputVectorType &vector) const;
00145 inline InputVnlVectorType BackTransform(const OutputVnlVectorType &vector) const;
00146 inline InputCovariantVectorType BackTransform(
00147 const OutputCovariantVectorType &vector) const;
00149
00154 bool GetInverse(Self* inverse) const;
00155
00159 void SetIdentity( void )
00160 { m_Scale.Fill( 1.0 ); }
00161
00162
00164 itkSetMacro( Center, InputPointType );
00165 itkGetConstReferenceMacro( Center, InputPointType );
00167
00168
00170 itkGetConstReferenceMacro( Scale, ScaleType );
00171
00177 virtual bool IsLinear() const { return true; }
00178
00179 protected:
00181 ScaleTransform();
00182
00184 ~ScaleTransform();
00185
00187 void PrintSelf(std::ostream &os, Indent indent) const;
00188
00189
00190 private:
00191 ScaleTransform(const Self & other);
00192 const Self & operator=( const Self & );
00193
00194 ScaleType m_Scale;
00195
00196 InputPointType m_Center;
00197
00198 };
00199
00200
00201 template<class ScalarType, unsigned int NDimensions>
00202 inline
00203 typename ScaleTransform<ScalarType, NDimensions>::InputPointType
00204 ScaleTransform<ScalarType, NDimensions>::
00205 BackTransform(const OutputPointType &point) const {
00206 InputPointType result;
00207 for( unsigned int i=0; i<SpaceDimension; i++ )
00208 {
00209 result[i] = ( point[i] + m_Center[i] ) / m_Scale[i] - m_Center[i];
00210 }
00211 return result;
00212 }
00213
00214
00215
00216
00217
00218 template<class ScalarType, unsigned int NDimensions>
00219 inline
00220 typename ScaleTransform<ScalarType, NDimensions>::InputVectorType
00221 ScaleTransform<ScalarType, NDimensions>::
00222 BackTransform(const OutputVectorType &vect ) const
00223 {
00224 InputVectorType result;
00225 for( unsigned int i=0; i<SpaceDimension; i++ )
00226 {
00227 result[i] = vect[i] / m_Scale[i];
00228 }
00229 return result;
00230 }
00231
00232
00233
00234
00235
00236 template<class ScalarType, unsigned int NDimensions>
00237 inline
00238 typename ScaleTransform<ScalarType, NDimensions>::InputVnlVectorType
00239 ScaleTransform<ScalarType, NDimensions>::
00240 BackTransform(const OutputVnlVectorType &vect ) const
00241 {
00242 InputVnlVectorType result;
00243 for( unsigned int i=0; i<SpaceDimension; i++ )
00244 {
00245 result[i] = vect[i] / m_Scale[i];
00246 }
00247 return result;
00248 }
00249
00250
00251
00252 template<class ScalarType, unsigned int NDimensions>
00253 inline
00254 typename ScaleTransform<ScalarType, NDimensions>::InputCovariantVectorType
00255 ScaleTransform<ScalarType, NDimensions>::
00256 BackTransform(const OutputCovariantVectorType &vect) const
00257 {
00258
00259 InputCovariantVectorType result;
00260 for( unsigned int i=0; i<SpaceDimension; i++ )
00261 {
00262 result[i] = vect[i] * m_Scale[i];
00263 }
00264 return result;
00265 }
00266
00267 }
00268
00269
00270 #define ITK_TEMPLATE_ScaleTransform(_, EXPORT, x, y) namespace itk { \
00271 _(2(class EXPORT ScaleTransform< ITK_TEMPLATE_2 x >)) \
00272 namespace Templates { typedef ScaleTransform< ITK_TEMPLATE_2 x > ScaleTransform##y; } \
00273 }
00274
00275 #if ITK_TEMPLATE_EXPLICIT
00276 # include "Templates/itkScaleTransform+-.h"
00277 #endif
00278
00279 #if ITK_TEMPLATE_TXX
00280 # include "itkScaleTransform.txx"
00281 #endif
00282
00283
00284 #endif
00285