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   itkTransformCloneMacro();
00073 
00075   typedef  TScalarType ScalarType;
00076 
00078   typedef  typename Superclass::ParametersType ParametersType;
00079 
00081   typedef  typename Superclass::JacobianType JacobianType;
00082 
00084   typedef Vector<TScalarType,
00085                  itkGetStaticConstMacro(InputSpaceDimension)>  InputVectorType;
00086   typedef Vector<TScalarType,
00087                  itkGetStaticConstMacro(OutputSpaceDimension)> OutputVectorType;
00089 
00091   typedef CovariantVector<TScalarType,
00092                           itkGetStaticConstMacro(InputSpaceDimension)>  InputCovariantVectorType;
00093   typedef CovariantVector<TScalarType,
00094                           itkGetStaticConstMacro(OutputSpaceDimension)> OutputCovariantVectorType;
00096 
00098   typedef vnl_vector_fixed<TScalarType,
00099                            itkGetStaticConstMacro(InputSpaceDimension)>  InputVnlVectorType;
00100   typedef vnl_vector_fixed<TScalarType,
00101                            itkGetStaticConstMacro(OutputSpaceDimension)> OutputVnlVectorType;
00103 
00105   typedef Point<TScalarType,
00106                 itkGetStaticConstMacro(InputSpaceDimension)> InputPointType;
00107   typedef Point<TScalarType,
00108                 itkGetStaticConstMacro(OutputSpaceDimension)> OutputPointType;
00110 
00113   typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType;
00114   typedef typename InverseTransformBaseType::Pointer    InverseTransformBasePointer;
00115 
00117   virtual OutputPointType TransformPoint(const InputPointType  & point) const
00118   {
00119     return point;
00120   }
00121 
00123   using Superclass::TransformVector;
00124   virtual OutputVectorType TransformVector(const InputVectorType & vector) const
00125   {
00126     return vector;
00127   }
00128 
00130   virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const
00131   {
00132     return vector;
00133   }
00134 
00136   using Superclass::TransformCovariantVector;
00137   virtual OutputCovariantVectorType TransformCovariantVector(
00138     const InputCovariantVectorType & vector) const
00139   {
00140     return vector;
00141   }
00142 
00147   void SetIdentity(void)
00148   {
00149   }
00150 
00179   virtual void ComputeJacobianWithRespectToParameters( const InputPointType &,
00180                                                        JacobianType & jacobian) const
00181   {
00182     jacobian = this->m_IdentityJacobian;
00183   }
00184 
00189   virtual void ComputeJacobianWithRespectToPosition(const InputPointType &,
00190                                                     JacobianType & jac) const
00191   {
00192     jac.SetSize( NDimensions, NDimensions );
00193     jac.Fill(0.0);
00194     for( unsigned int dim = 0; dim < NDimensions; dim++ )
00195       {
00196       jac[dim][dim] = 1.0;
00197       }
00198   }
00200 
00203   virtual InverseTransformBasePointer GetInverseTransform() const
00204   {
00205     return this->New().GetPointer();
00206   }
00207 
00213   virtual bool IsLinear() const
00214   {
00215     return true;
00216   }
00217 
00219   virtual const ParametersType & GetFixedParameters(void) const
00220   {
00221     return this->m_FixedParameters;
00222   }
00223 
00225   virtual void SetFixedParameters(const ParametersType &)
00226   {
00227   }
00228 
00230   virtual const ParametersType & GetParameters(void) const
00231   {
00232     return this->m_Parameters;
00233   }
00234 
00236   virtual void SetParameters(const ParametersType &)
00237   {
00238   }
00239 protected:
00240   IdentityTransform() : Transform<TScalarType, NDimensions, NDimensions>(0),
00241     m_IdentityJacobian(NDimensions, 0)
00242   {
00243     // The Jacobian is constant, therefore it can be initialized in the
00244     // constructor.
00245     this->m_IdentityJacobian.Fill(0.0);
00246   }
00248 
00249   virtual ~IdentityTransform()
00250   {
00251   }
00252 private:
00253   IdentityTransform(const Self &); // purposely not implemented
00254   void operator=(const Self &);    // purposely not implemented
00255 
00256   JacobianType m_IdentityJacobian;
00257 };
00258 } // end namespace itk
00259 
00260 #endif
00261