cmtkImagePairNonrigidRegistrationFunctional.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 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: 2660 $
00026 //
00027 //  $LastChangedDate: 2010-12-14 12:35:50 -0800 (Tue, 14 Dec 2010) $
00028 //
00029 //  $LastChangedBy: torsten_at_home $
00030 //
00031 */
00032 
00033 #ifndef __cmtkImagePairNonrigidRegistrationFunctional_h_included_
00034 #define __cmtkImagePairNonrigidRegistrationFunctional_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Registration/cmtkImagePairRegistrationFunctional.h>
00039 #include <Registration/cmtkImagePairSimilarityMeasure.h>
00040 
00041 #include <System/cmtkThreads.h>
00042 #include <System/cmtkThreadPool.h>
00043 
00044 #include <Base/cmtkSplineWarpXform.h>
00045 #include <Base/cmtkJointHistogram.h>
00046 
00047 #ifdef HAVE_IEEEFP_H
00048 #  include <ieeefp.h>
00049 #endif
00050 
00051 #include <math.h>
00052 
00053 namespace
00054 cmtk
00055 {
00056 
00059 
00064 class ImagePairNonrigidRegistrationFunctional : 
00066   public ImagePairRegistrationFunctional 
00067 {
00068 public:
00070   typedef ImagePairNonrigidRegistrationFunctional Self;
00071 
00073   typedef SmartPointer<Self> SmartPtr;
00074 
00076   typedef ImagePairRegistrationFunctional Superclass;
00077 
00079   virtual ~ImagePairNonrigidRegistrationFunctional ();
00080 
00086   cmtkGetSetMacroDefault(bool,AdaptiveFixParameters,true);
00087 
00095   cmtkGetSetMacro(double,AdaptiveFixThreshFactor);
00096 
00099   cmtkGetSetMacroString(ActiveCoordinates);
00100 
00104   cmtkGetSetMacroDefault(double,JacobianConstraintWeight,0);
00105 
00110   cmtkGetSetMacroDefault(double,GridEnergyWeight,0);
00111 
00118   virtual void SetWarpXform( SplineWarpXform::SmartPtr& warp ) = 0;
00119 
00121   void SetInverseTransformation( SplineWarpXform::SmartPtr& inverseTransformation ) 
00122   {
00123     this->m_InverseTransformation = inverseTransformation;
00124   }
00125 
00127   void SetInverseConsistencyWeight( const double inverseConsistencyWeight ) 
00128   {
00129     this->m_InverseConsistencyWeight = inverseConsistencyWeight;
00130   }
00131 
00133   virtual Types::Coordinate GetParamStep( const size_t idx, const Types::Coordinate mmStep = 1 ) const 
00134   {
00135     return this->m_Warp->GetParamStep( idx, this->m_FloatingSize, mmStep );
00136   }
00137 
00139   virtual size_t ParamVectorDim() const 
00140   {
00141     return this->m_Warp->ParamVectorDim();
00142   }
00143 
00145   virtual size_t VariableParamVectorDim() const 
00146   {
00147     return this->m_Warp->VariableParamVectorDim();
00148   }
00149 
00151   virtual void GetParamVector ( CoordinateVector& v ) 
00152   {
00153     this->m_Warp->GetParamVector( v );
00154   }
00155 
00157   static ImagePairNonrigidRegistrationFunctional* Create
00158   ( const int metric, UniformVolume::SmartPtr& refVolume, UniformVolume::SmartPtr& fltVolume, const Interpolators::InterpolationEnum interpolation );
00159   
00160 protected:
00162   ImagePairNonrigidRegistrationFunctional( UniformVolume::SmartPtr& reference, UniformVolume::SmartPtr& floating );
00163 
00165   std::vector<SplineWarpXform::SmartPtr> m_ThreadWarp;
00166 
00168   Vector3D **m_ThreadVectorCache;
00169 
00175   size_t m_NumberOfThreads;
00176 
00178   size_t m_NumberOfTasks;
00179 
00181   Types::DataItem *m_WarpedVolume;
00182 
00184   DataGrid::IndexType::ValueType m_DimsX, m_DimsY, m_DimsZ;
00185   
00187   DataGrid::IndexType::ValueType m_FltDimsX, m_FltDimsY;
00188 
00190   SplineWarpXform::SmartPtr m_Warp;
00191 
00193   SplineWarpXform::SmartPtr m_InverseTransformation;
00194 
00196   double m_InverseConsistencyWeight;
00197 
00199   Self::ReturnType WeightedTotal( const Self::ReturnType metric, const SplineWarpXform& warp ) const 
00200   {
00201     double result = metric;
00202     if ( this->m_JacobianConstraintWeight > 0 ) 
00203       {
00204       result -= this->m_JacobianConstraintWeight * warp.GetJacobianConstraint();
00205       } 
00206     
00207     if ( this->m_GridEnergyWeight > 0 ) 
00208       {
00209       result -= this->m_GridEnergyWeight * warp.GetGridEnergy();
00210       }
00211     
00212     if ( !finite( result ) ) 
00213       return -FLT_MAX;
00214     
00215     if ( this->m_MatchedLandmarkList ) 
00216       {
00217       result -= this->m_LandmarkErrorWeight * warp.GetLandmarksMSD( this->m_MatchedLandmarkList );
00218       }
00219 
00220     if ( this->m_InverseTransformation ) 
00221       {
00222       result -= this->m_InverseConsistencyWeight * warp.GetInverseConsistencyError( this->m_InverseTransformation, this->m_ReferenceGrid );
00223       }
00224     
00225     return static_cast<Self::ReturnType>( result );
00226   }
00227   
00229   void WeightedDerivative( double& lower, double& upper, SplineWarpXform& warp, const int param, const Types::Coordinate step ) const;
00230 
00233   cmtkGetSetMacroDefault(bool,Regularize,false);
00234 
00236   size_t Dim;
00237 
00243   std::vector<Types::Coordinate> m_StepScaleVector;
00244 
00251   DataGrid::RegionType *VolumeOfInfluence;
00252 
00254   Vector3D ReferenceFrom;
00255 
00257   Vector3D ReferenceTo;
00258 
00260   friend class SmartPointer<Self>;
00261 };
00262 
00264 
00265 } // namespace cmtk
00266 
00267 #endif // __cmtkImagePairNonrigidRegistrationFunctional_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines