cmtkDeformationField.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2010 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2453 $
00026 //
00027 //  $LastChangedDate: 2010-10-18 10:33:06 -0700 (Mon, 18 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkDeformationField_h_included_
00034 #define __cmtkDeformationField_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkWarpXform.h>
00039 #include <Base/cmtkMacros.h>
00040 #include <Base/cmtkVector.h>
00041 #include <Base/cmtkUniformVolume.h>
00042 #include <Base/cmtkAffineXform.h>
00043 
00044 #include <System/cmtkSmartPtr.h>
00045 
00046 namespace
00047 cmtk
00048 {
00049 
00052 
00057 class DeformationField : 
00059   public WarpXform 
00060 {
00061 public:
00063   typedef DeformationField Self;
00064 
00066   typedef WarpXform Superclass;
00067 
00069   typedef SmartPointer<Self> SmartPtr;
00070 
00071 public:
00073   DeformationField( const UniformVolume* volume ) 
00074   {
00075     this->InitGrid( volume->Size, volume->m_Dims );
00076     this->m_Offset = volume->m_Offset;
00077   }
00078   
00080   DeformationField( const FixedVector<3,Types::Coordinate>& domain, const DataGrid::IndexType& dims, const Types::Coordinate* offset = NULL ) 
00081   {
00082     this->InitGrid( domain, dims );
00083     if ( offset )
00084       {
00085       for ( int dim = 0; dim < 3; ++dim )
00086         this->m_Offset[dim] = offset[dim];
00087       }
00088   }
00089   
00091   virtual ~DeformationField () {}
00092 
00094   virtual void InitGrid( const FixedVector<3,Types::Coordinate>& domain, const DataGrid::IndexType& dims )
00095   {
00096     this->Superclass::InitGrid( domain, dims );
00097     for ( int dim = 0; dim < 3; ++dim )
00098       {
00099       if ( dims[dim] > 1 )
00100         this->Spacing[dim] = domain[dim] / (dims[dim]-1);
00101       else
00102         this->Spacing[dim] = 1.0;
00103       this->InverseSpacing[dim] = 1.0 / this->Spacing[dim];
00104       }
00105     this->InverseAffineScaling[0] = this->InverseAffineScaling[1] = this->InverseAffineScaling[2] = this->GlobalScaling = 1.0;
00106   }
00107   
00109   void InitControlPoints( const AffineXform* affineXform = NULL );
00110 
00112   virtual void ApplyInPlace ( Self::SpaceVectorType& ) const;
00113 
00116   virtual bool ApplyInverse ( const Self::SpaceVectorType&, Self::SpaceVectorType&, const Types::Coordinate = 0.01  ) const 
00117   {
00118     // not implemented
00119     return false;
00120   }
00121 
00124   virtual bool ApplyInverseInPlace( Self::SpaceVectorType&, const Types::Coordinate = 0.01  ) const 
00125   {
00126     // not implemented
00127     return false;
00128   }
00129 
00131   virtual void GetTransformedGrid( Self::SpaceVectorType& v, const int idxX, const int idxY, const int idxZ ) const;
00132   
00134   virtual void GetTransformedGridRow( Self::SpaceVectorType *const v, const int numPoints, const int idxX, const int idxY, const int idxZ ) const;
00135   
00137   virtual void GetJacobian( const Self::SpaceVectorType& v, CoordinateMatrix3x3& J ) const;
00138 
00140   virtual Types::Coordinate GetJacobianDeterminant ( const Self::SpaceVectorType& v ) const
00141   {
00142     CoordinateMatrix3x3 J;
00143     this->GetJacobian( v, J );
00144     return J.Determinant();
00145   }
00146   
00148   virtual Types::Coordinate GetParamStep( const size_t, const Self::SpaceVectorType&, const Types::Coordinate mmStep = 1 ) const
00149   {
00150     return mmStep;
00151   }
00152 
00153 protected:
00157   virtual Self* CloneVirtual () const { return NULL; }
00158 };
00159 
00161 
00162 } // namespace cmtk
00163 
00164 #endif // #ifndef __cmtkDeformationField_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines