ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkIdentityTransform.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 __itkIdentityTransform_h
00019 #define __itkIdentityTransform_h
00020 
00021 #include "itkObject.h"
00022 #include "itkPoint.h"
00023 #include "itkCovariantVector.h"
00024 #include "vnl/vnl_vector_fixed.h"
00025 #include "itkArray2D.h"
00026 #include "itkTransform.h"
00027 
00028 namespace itk
00029 {
00049 template <class TScalarType,
00050           unsigned int NDimensions = 3>
00051 class ITK_EXPORT IdentityTransform : public Transform<TScalarType, NDimensions, NDimensions>
00052 {
00053 public:
00055   typedef IdentityTransform                                Self;
00056   typedef Transform<TScalarType, NDimensions, NDimensions> Superclass;
00057   typedef SmartPointer<Self>                               Pointer;
00058   typedef SmartPointer<const Self>                         ConstPointer;
00059 
00061   itkNewMacro(Self);
00062 
00064   itkTypeMacro(IdentityTransform, Transform);
00065 
00067   itkStaticConstMacro(InputSpaceDimension, unsigned int, NDimensions);
00068   itkStaticConstMacro(OutputSpaceDimension, unsigned int, NDimensions);
00070 
00072   typedef  TScalarType ScalarType;
00073 
00075   typedef  typename Superclass::ParametersType ParametersType;
00076 
00078   typedef  typename Superclass::JacobianType JacobianType;
00079 
00081   typedef Vector<TScalarType,
00082                  itkGetStaticConstMacro(InputSpaceDimension)>  InputVectorType;
00083   typedef Vector<TScalarType,
00084                  itkGetStaticConstMacro(OutputSpaceDimension)> OutputVectorType;
00086 
00088   typedef CovariantVector<TScalarType,
00089                           itkGetStaticConstMacro(InputSpaceDimension)>  InputCovariantVectorType;
00090   typedef CovariantVector<TScalarType,
00091                           itkGetStaticConstMacro(OutputSpaceDimension)> OutputCovariantVectorType;
00093 
00095   typedef vnl_vector_fixed<TScalarType,
00096                            itkGetStaticConstMacro(InputSpaceDimension)>  InputVnlVectorType;
00097   typedef vnl_vector_fixed<TScalarType,
00098                            itkGetStaticConstMacro(OutputSpaceDimension)> OutputVnlVectorType;
00100 
00102   typedef Point<TScalarType,
00103                 itkGetStaticConstMacro(InputSpaceDimension)> InputPointType;
00104   typedef Point<TScalarType,
00105                 itkGetStaticConstMacro(OutputSpaceDimension)> OutputPointType;
00107 
00110   typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType;
00111   typedef typename InverseTransformBaseType::Pointer    InverseTransformBasePointer;
00112 
00114   virtual OutputPointType TransformPoint(const InputPointType  & point) const
00115   {
00116     return point;
00117   }
00118 
00120   using Superclass::TransformVector;
00121   virtual OutputVectorType TransformVector(const InputVectorType & vector) const
00122   {
00123     return vector;
00124   }
00125 
00127   virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const
00128   {
00129     return vector;
00130   }
00131 
00133   using Superclass::TransformCovariantVector;
00134   virtual OutputCovariantVectorType TransformCovariantVector(
00135     const InputCovariantVectorType & vector) const
00136   {
00137     return vector;
00138   }
00139 
00144   void SetIdentity(void)
00145   {
00146   }
00147 
00176   virtual void ComputeJacobianWithRespectToParameters( const InputPointType &,
00177                                                        JacobianType & jacobian) const
00178   {
00179     jacobian = this->m_IdentityJacobian;
00180   }
00181 
00186   virtual void ComputeJacobianWithRespectToPosition(const InputPointType &,
00187                                                     JacobianType & jac) const
00188   {
00189     jac.SetSize( NDimensions, NDimensions );
00190     jac.Fill(0.0);
00191     for( unsigned int dim = 0; dim < NDimensions; dim++ )
00192       {
00193       jac[dim][dim] = 1.0;
00194       }
00195   }
00197 
00200   virtual InverseTransformBasePointer GetInverseTransform() const
00201   {
00202     return this->New().GetPointer();
00203   }
00204 
00210   virtual bool IsLinear() const
00211   {
00212     return true;
00213   }
00214 
00216   virtual const ParametersType & GetFixedParameters(void) const
00217   {
00218     return this->m_FixedParameters;
00219   }
00220 
00222   virtual void SetFixedParameters(const ParametersType &)
00223   {
00224   }
00225 
00227   virtual const ParametersType & GetParameters(void) const
00228   {
00229     return this->m_Parameters;
00230   }
00231 
00233   virtual void SetParameters(const ParametersType &)
00234   {
00235   }
00236 protected:
00237   IdentityTransform() : Transform<TScalarType, NDimensions, NDimensions>(0),
00238     m_IdentityJacobian(NDimensions, 0)
00239   {
00240     // The Jacobian is constant, therefore it can be initialized in the
00241     // constructor.
00242     this->m_IdentityJacobian.Fill(0.0);
00243   }
00245 
00246   virtual ~IdentityTransform()
00247   {
00248   }
00249 private:
00250   IdentityTransform(const Self &); // purposely not implemented
00251   void operator=(const Self &);    // purposely not implemented
00252 
00253   JacobianType m_IdentityJacobian;
00254 };
00255 } // end namespace itk
00256 
00257 #endif
00258