ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkScaleTransform_h 00019 #define __itkScaleTransform_h 00020 00021 #include <iostream> 00022 #include "itkMatrixOffsetTransformBase.h" 00023 #include "itkMacro.h" 00024 #include "itkMatrix.h" 00025 00026 namespace itk 00027 { 00041 template < 00042 class TScalarType = float, // Type for cordinate representation type (float or 00043 // double) 00044 unsigned int NDimensions = 3> 00045 // Number of dimensions 00046 // class ITK_EXPORT ScaleTransform:public Transform< TScalarType, 00047 class ITK_EXPORT ScaleTransform : public MatrixOffsetTransformBase<TScalarType, 00048 NDimensions, 00049 NDimensions> 00050 { 00051 public: 00053 typedef ScaleTransform Self; 00054 typedef MatrixOffsetTransformBase<TScalarType, NDimensions, NDimensions> Superclass; 00055 typedef SmartPointer<Self> Pointer; 00056 typedef SmartPointer<const Self> ConstPointer; 00057 00059 itkNewMacro(Self); 00060 00062 itkTypeMacro(ScaleTransform, Transform); 00063 00065 itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions); 00066 itkStaticConstMacro(ParametersDimension, unsigned int, NDimensions); 00068 00070 typedef typename Superclass::ScalarType ScalarType; 00071 00073 typedef typename Superclass::ParametersType ParametersType; 00074 00076 typedef typename Superclass::JacobianType JacobianType; 00077 00079 typedef FixedArray<TScalarType, NDimensions> ScaleType; 00080 00082 typedef Vector<TScalarType, NDimensions> InputVectorType; 00083 typedef Vector<TScalarType, NDimensions> OutputVectorType; 00084 00086 typedef CovariantVector<TScalarType, NDimensions> InputCovariantVectorType; 00087 typedef CovariantVector<TScalarType, NDimensions> OutputCovariantVectorType; 00088 00090 typedef vnl_vector_fixed<TScalarType, NDimensions> InputVnlVectorType; 00091 typedef vnl_vector_fixed<TScalarType, NDimensions> OutputVnlVectorType; 00092 00094 typedef Point<TScalarType, NDimensions> InputPointType; 00095 typedef Point<TScalarType, NDimensions> OutputPointType; 00096 00099 typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType; 00100 typedef typename InverseTransformBaseType::Pointer InverseTransformBasePointer; 00101 00102 typedef typename Superclass::MatrixType MatrixType; 00103 00108 void SetParameters(const ParametersType & parameters); 00109 00114 const ParametersType & GetParameters(void) const; 00115 00119 virtual void SetFixedParameters(const ParametersType &) 00120 { 00121 } 00122 00124 virtual const ParametersType & GetFixedParameters(void) const; 00125 00127 virtual void ComputeJacobianWithRespectToParameters(const InputPointType & point, JacobianType & j) const; 00128 00133 virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jac) const; 00134 00143 void SetScale(const ScaleType & scale) 00144 { 00145 m_Scale = scale; this->ComputeMatrix(); this->Modified(); 00146 } 00147 00148 virtual void ComputeMatrix(void); 00149 00151 void Compose(const Self *other, bool pre = false); 00152 00156 void Scale(const ScaleType & scale, bool pre = false); 00157 00162 OutputPointType TransformPoint(const InputPointType & point) const; 00163 00164 using Superclass::TransformVector; 00165 OutputVectorType TransformVector(const InputVectorType & vector) const; 00166 00167 OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const; 00168 00169 using Superclass::TransformCovariantVector; 00170 OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & vector) const; 00171 00176 inline InputPointType BackTransform(const OutputPointType & point) const; 00177 00178 inline InputVectorType BackTransform(const OutputVectorType & vector) const; 00179 00180 inline InputVnlVectorType BackTransform(const OutputVnlVectorType & vector) const; 00181 00182 inline InputCovariantVectorType BackTransform(const OutputCovariantVectorType & vector) const; 00183 00188 bool GetInverse(Self *inverse) const; 00189 00191 virtual InverseTransformBasePointer GetInverseTransform() const; 00192 00196 void SetIdentity(void) 00197 { 00198 m_Scale.Fill(1.0); 00199 } 00200 00202 itkSetMacro(Center, InputPointType); 00203 itkGetConstReferenceMacro(Center, InputPointType); 00205 00207 itkGetConstReferenceMacro(Scale, ScaleType); 00208 00214 virtual bool IsLinear() const 00215 { 00216 return true; 00217 } 00218 protected: 00219 00221 ScaleTransform(); 00222 00224 ~ScaleTransform(); 00225 00227 void PrintSelf(std::ostream & os, Indent indent) const; 00228 00229 private: 00230 ScaleTransform(const Self & other); // purposely not implemented 00231 const Self & operator=(const Self &); // purposely not implemented 00232 00233 ScaleType m_Scale; // Scales of the transformation 00234 00235 InputPointType m_Center; // Scaling center 00236 mutable ParametersType m_FixedParameters; 00237 }; // class ScaleTransform 00238 00239 // Back transform a point 00240 template <class ScalarType, unsigned int NDimensions> 00241 inline 00242 typename ScaleTransform<ScalarType, NDimensions>::InputPointType 00243 ScaleTransform<ScalarType, NDimensions>::BackTransform(const OutputPointType & point) const 00244 { 00245 InputPointType result; 00246 00247 for( unsigned int i = 0; i < SpaceDimension; i++ ) 00248 { 00249 result[i] = ( point[i] + m_Center[i] ) / m_Scale[i] - m_Center[i]; 00250 } 00251 return result; 00252 } 00253 00254 // Back transform a vector 00255 template <class ScalarType, unsigned int NDimensions> 00256 inline 00257 typename ScaleTransform<ScalarType, NDimensions>::InputVectorType 00258 ScaleTransform<ScalarType, NDimensions>::BackTransform(const OutputVectorType & vect) const 00259 { 00260 InputVectorType result; 00261 00262 for( unsigned int i = 0; i < SpaceDimension; i++ ) 00263 { 00264 result[i] = vect[i] / m_Scale[i]; 00265 } 00266 return result; 00267 } 00268 00269 // Back transform a vnl_vector 00270 template <class ScalarType, unsigned int NDimensions> 00271 inline 00272 typename ScaleTransform<ScalarType, NDimensions>::InputVnlVectorType 00273 ScaleTransform<ScalarType, NDimensions>::BackTransform(const OutputVnlVectorType & vect) const 00274 { 00275 InputVnlVectorType result; 00276 00277 for( unsigned int i = 0; i < SpaceDimension; i++ ) 00278 { 00279 result[i] = vect[i] / m_Scale[i]; 00280 } 00281 return result; 00282 } 00283 00284 // Back Transform a CovariantVector 00285 template <class ScalarType, unsigned int NDimensions> 00286 inline 00287 typename ScaleTransform<ScalarType, NDimensions>::InputCovariantVectorType 00288 ScaleTransform<ScalarType, NDimensions>::BackTransform(const OutputCovariantVectorType & vect) const 00289 { 00290 // Covariant Vectors are scaled by the inverse 00291 InputCovariantVectorType result; 00292 00293 for( unsigned int i = 0; i < SpaceDimension; i++ ) 00294 { 00295 result[i] = vect[i] * m_Scale[i]; 00296 } 00297 return result; 00298 } 00299 00300 } // namespace itk 00301 00302 // Define instantiation macro for this template. 00303 #define ITK_TEMPLATE_ScaleTransform(_, EXPORT, TypeX, TypeY) \ 00304 namespace itk \ 00305 { \ 00306 _( 2 ( class EXPORT ScaleTransform<ITK_TEMPLATE_2 TypeX> ) ) \ 00307 namespace Templates \ 00308 { \ 00309 typedef ScaleTransform<ITK_TEMPLATE_2 TypeX> ScaleTransform##TypeY; \ 00310 } \ 00311 } 00312 00313 #if ITK_TEMPLATE_EXPLICIT 00314 #include "Templates/itkScaleTransform+-.h" 00315 #endif 00316 00317 #if ITK_TEMPLATE_TXX 00318 #include "itkScaleTransform.hxx" 00319 #endif 00320 00321 #endif /* __itkScaleTransform_h */ 00322