ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkTranslationTransform.h
Go to the documentation of this file.
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 __itkTranslationTransform_h
00019 #define __itkTranslationTransform_h
00020 
00021 #include <iostream>
00022 #include "itkTransform.h"
00023 #include "itkMacro.h"
00024 #include "itkMatrix.h"
00025 
00026 namespace itk
00027 {
00043 template <
00044   class TScalarType = double,          // Data type for scalars (float or
00045                                        // double)
00046   unsigned int NDimensions = 3>
00047 // Number of dimensions
00048 class ITK_EXPORT TranslationTransform :
00049   public Transform<TScalarType, NDimensions, NDimensions>
00050 {
00051 public:
00053   typedef TranslationTransform                             Self;
00054   typedef Transform<TScalarType, NDimensions, NDimensions> Superclass;
00055   typedef SmartPointer<Self>                               Pointer;
00056   typedef SmartPointer<const Self>                         ConstPointer;
00057 
00059   itkNewMacro(Self);
00060 
00062   itkTypeMacro(TranslationTransform, 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 typename Superclass::NumberOfParametersType NumberOfParametersType;
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 
00104   const OutputVectorType & GetOffset(void) const
00105   {
00106     return m_Offset;
00107   }
00108 
00111   void SetParameters(const ParametersType & parameters);
00112 
00114   virtual const ParametersType & GetParameters(void) const;
00115 
00119   void SetOffset(const OutputVectorType & offset)
00120   {
00121     m_Offset = offset; return;
00122   }
00123 
00125   void Compose(const Self *other, bool pre = 0);
00126 
00131   void Translate(const OutputVectorType & offset, bool pre = 0);
00132 
00137   OutputPointType     TransformPoint(const InputPointType  & point) const;
00138 
00139   using Superclass::TransformVector;
00140   OutputVectorType    TransformVector(const InputVectorType & vector) const;
00141 
00142   OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const;
00143 
00144   using Superclass::TransformCovariantVector;
00145   OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & vector) const;
00146 
00150   inline InputPointType    BackTransform(const OutputPointType  & point) const;
00151 
00152   inline InputVectorType   BackTransform(const OutputVectorType & vector) const;
00153 
00154   inline InputVnlVectorType BackTransform(const OutputVnlVectorType & vector) const;
00155 
00156   inline InputCovariantVectorType BackTransform(const OutputCovariantVectorType & vector) const;
00157 
00162   bool GetInverse(Self *inverse) const;
00163 
00165   virtual InverseTransformBasePointer GetInverseTransform() const;
00166 
00168   virtual void ComputeJacobianWithRespectToParameters(const InputPointType  & point, JacobianType & j) const;
00169 
00174   virtual void ComputeJacobianWithRespectToPosition(const InputPointType  & x, JacobianType & jac) const;
00175 
00177   void SetIdentity(void);
00178 
00180   virtual NumberOfParametersType GetNumberOfParameters(void) const
00181   {
00182     return NDimensions;
00183   }
00184 
00190   virtual bool IsLinear() const
00191   {
00192     return true;
00193   }
00194 
00198   virtual void SetFixedParameters(const ParametersType &)
00199   {
00200   }
00201 
00205   virtual const ParametersType & GetFixedParameters(void) const
00206   {
00207     this->m_FixedParameters.SetSize(0);
00208     return this->m_FixedParameters;
00209   }
00211 
00212 protected:
00213   TranslationTransform();
00214   ~TranslationTransform();
00216   void PrintSelf(std::ostream & os, Indent indent) const;
00217 
00218 private:
00219   TranslationTransform(const Self &); // purposely not implemented
00220   void operator=(const Self &);       // purposely not implemented
00221 
00222   JacobianType     m_IdentityJacobian;
00223   OutputVectorType m_Offset; // Offset of the transformation
00224 };                           // class TranslationTransform
00225 
00226 // Back transform a point
00227 template <class TScalarType, unsigned int NDimensions>
00228 inline
00229 typename TranslationTransform<TScalarType, NDimensions>::InputPointType
00230 TranslationTransform<TScalarType, NDimensions>::BackTransform(const OutputPointType & point) const
00231 {
00232   return point - m_Offset;
00233 }
00234 
00235 // Back transform a vector
00236 template <class TScalarType, unsigned int NDimensions>
00237 inline
00238 typename TranslationTransform<TScalarType, NDimensions>::InputVectorType
00239 TranslationTransform<TScalarType, NDimensions>::BackTransform(const OutputVectorType & vect) const
00240 {
00241   return vect;
00242 }
00243 
00244 // Back transform a vnl_vector
00245 template <class TScalarType, unsigned int NDimensions>
00246 inline
00247 typename TranslationTransform<TScalarType, NDimensions>::InputVnlVectorType
00248 TranslationTransform<TScalarType, NDimensions>::BackTransform(const OutputVnlVectorType & vect) const
00249 {
00250   return vect;
00251 }
00252 
00253 // Back Transform a CovariantVector
00254 template <class TScalarType, unsigned int NDimensions>
00255 inline
00256 typename TranslationTransform<TScalarType, NDimensions>::InputCovariantVectorType
00257 TranslationTransform<TScalarType, NDimensions>::BackTransform(const OutputCovariantVectorType & vect) const
00258 {
00259   return vect;
00260 }
00261 
00262 }  // namespace itk
00263 
00264 // Define instantiation macro for this template.
00265 #define ITK_TEMPLATE_TranslationTransform(_, EXPORT, TypeX, TypeY)                    \
00266   namespace itk                                                                       \
00267   {                                                                                   \
00268   _( 2 ( class EXPORT TranslationTransform<ITK_TEMPLATE_2 TypeX> ) )                \
00269   namespace Templates                                                                 \
00270   {                                                                                   \
00271   typedef TranslationTransform<ITK_TEMPLATE_2 TypeX> TranslationTransform##TypeY; \
00272   }                                                                                   \
00273   }
00274 
00275 #if ITK_TEMPLATE_EXPLICIT
00276 #include "Templates/itkTranslationTransform+-.h"
00277 #endif
00278 
00279 #if ITK_TEMPLATE_TXX
00280 #include "itkTranslationTransform.hxx"
00281 #endif
00282 
00283 #endif /* __itkTranslationTransform_h */
00284