cmtkSymmetricElasticFunctional.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: 2454 $
00026 //
00027 //  $LastChangedDate: 2010-10-18 13:08:48 -0700 (Mon, 18 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkSymmetricElasticFunctional_h_included_
00034 #define __cmtkSymmetricElasticFunctional_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkMacros.h>
00039 #include <Base/cmtkFunctional.h>
00040 
00041 #ifdef CMTK_BUILD_SMP
00042 #  include <Registration/cmtkParallelElasticFunctional.h>
00043 #else
00044 #  include <Registration/cmtkVoxelMatchingElasticFunctional.h>
00045 #endif
00046 
00047 namespace
00048 cmtk
00049 {
00050 
00053 
00055 class SymmetricElasticFunctional :
00057   public Functional
00058 {
00059 public:
00061   typedef SymmetricElasticFunctional Self;
00062 
00064   typedef SmartPointer<Self> SmartPtr;
00065 
00067   typedef Functional Superclass;
00068 
00070   virtual void SetInverseConsistencyWeight( const Self::ReturnType ) = 0;
00071   
00073   virtual void SetAdaptiveFixParameters( const bool ) = 0;
00074 
00076   virtual void SetAdaptiveFixThreshFactor( const Self::ReturnType ) = 0;
00077 
00079   virtual void SetJacobianConstraintWeight( const Self::ReturnType ) = 0;
00080   
00082   virtual void SetRigidityConstraintWeight( const Self::ReturnType ) = 0;
00083   
00085   virtual void SetGridEnergyWeight( const Self::ReturnType ) = 0;
00086 
00088   virtual void SetWarpXform( SplineWarpXform::SmartPtr& warpFwd, SplineWarpXform::SmartPtr& warpBwd ) = 0;
00089 };
00090 
00092 template<class VM>
00093 class SymmetricElasticFunctional_Template :
00095   public SymmetricElasticFunctional
00096 {
00097 public:
00099   typedef SymmetricElasticFunctional_Template<VM> Self;
00100 
00102   typedef SmartPointer<Self> SmartPtr;
00103 
00105   typedef SymmetricElasticFunctional Superclass;
00106 
00108 #ifdef CMTK_BUILD_SMP
00109   ParallelElasticFunctional<VM> FwdFunctional;
00110 #else
00111   VoxelMatchingElasticFunctional_Template<VM> FwdFunctional;
00112 #endif
00113 
00115 #ifdef CMTK_BUILD_SMP
00116   ParallelElasticFunctional<VM> BwdFunctional;
00117 #else
00118   VoxelMatchingElasticFunctional_Template<VM> BwdFunctional;
00119 #endif
00120 
00122   SymmetricElasticFunctional_Template( UniformVolume::SmartPtr& reference, UniformVolume::SmartPtr& floating )
00123     : FwdFunctional( reference, floating ),
00124       BwdFunctional( floating, reference )
00125   {}
00126 
00128   virtual void SetInverseConsistencyWeight( const typename Self::ReturnType inverseConsistencyWeight ) 
00129   {
00130     this->FwdFunctional.SetInverseConsistencyWeight( inverseConsistencyWeight );
00131     this->BwdFunctional.SetInverseConsistencyWeight( inverseConsistencyWeight );
00132   }
00133   
00135   virtual void SetAdaptiveFixParameters( const bool adaptiveFixParameters ) 
00136   {
00137     this->FwdFunctional.SetAdaptiveFixParameters( adaptiveFixParameters );
00138     this->BwdFunctional.SetAdaptiveFixParameters( adaptiveFixParameters );
00139   }
00140 
00142   virtual void SetAdaptiveFixThreshFactor( const typename Self::ReturnType threshFactor ) 
00143   {
00144     this->FwdFunctional.SetAdaptiveFixThreshFactor( threshFactor );
00145     this->BwdFunctional.SetAdaptiveFixThreshFactor( threshFactor );
00146   }
00147 
00149   virtual void SetJacobianConstraintWeight( const typename Self::ReturnType jacobianConstraintWeight ) 
00150   {
00151     this->FwdFunctional.SetJacobianConstraintWeight( jacobianConstraintWeight );
00152     this->BwdFunctional.SetJacobianConstraintWeight( jacobianConstraintWeight );
00153   }
00154   
00156   virtual void SetRigidityConstraintWeight( const typename Self::ReturnType rigidityConstraintWeight ) 
00157   {
00158     this->FwdFunctional.SetRigidityConstraintWeight( rigidityConstraintWeight );
00159     this->BwdFunctional.SetRigidityConstraintWeight( rigidityConstraintWeight );
00160   }
00161   
00163   virtual void SetGridEnergyWeight( const typename Self::ReturnType gridEnergyWeight ) 
00164   {
00165     this->FwdFunctional.SetGridEnergyWeight( gridEnergyWeight );
00166     this->BwdFunctional.SetGridEnergyWeight( gridEnergyWeight );
00167   }
00168   
00170   virtual void SetWarpXform( SplineWarpXform::SmartPtr& warpFwd, SplineWarpXform::SmartPtr& warpBwd );
00171 
00173   virtual void GetParamVector ( CoordinateVector& v )  
00174   {
00175     CoordinateVector vFwd, vBwd;
00176     this->FwdFunctional.GetParamVector( vFwd );
00177     this->BwdFunctional.GetParamVector( vBwd );
00178 
00179     v.SetDim( vFwd.Dim + vBwd.Dim );
00180     v.CopyToOffset( vFwd );
00181     v.CopyToOffset( vBwd, vFwd.Dim );
00182   }
00183 
00185   virtual typename Self::ReturnType EvaluateWithGradient( CoordinateVector& v, CoordinateVector& g, const Types::Coordinate step = 1 );
00186     
00188   virtual typename Self::ReturnType EvaluateAt ( CoordinateVector& v ) 
00189   {
00190     CoordinateVector vFwd( this->FwdFunctional.ParamVectorDim(), v.Elements, false /*freeElements*/ );
00191     CoordinateVector vBwd( this->BwdFunctional.ParamVectorDim(), v.Elements+this->FwdFunctional.ParamVectorDim(), false /*freeElements*/ );
00192     return this->FwdFunctional.EvaluateAt( vFwd ) + this->BwdFunctional.EvaluateAt( vBwd );
00193   }
00194   
00195   virtual typename Self::ReturnType Evaluate () 
00196   {
00197     return this->FwdFunctional.Evaluate() + this->BwdFunctional.Evaluate();
00198   }
00199   
00201   virtual Types::Coordinate GetParamStep( const size_t idx, const Types::Coordinate mmStep = 1 ) const 
00202   {
00203     if ( idx < this->FwdFunctional.ParamVectorDim() )
00204       return this->FwdFunctional.GetParamStep( idx, mmStep );
00205     else
00206       return this->BwdFunctional.GetParamStep( idx - this->FwdFunctional.ParamVectorDim(), mmStep );
00207   }
00208   
00210   virtual size_t ParamVectorDim() const
00211   {
00212     return this->FwdFunctional.ParamVectorDim() + this->BwdFunctional.ParamVectorDim();
00213   }
00214   
00216   virtual size_t VariableParamVectorDim() const 
00217   {
00218     return this->FwdFunctional.VariableParamVectorDim() + this->BwdFunctional.VariableParamVectorDim();
00219   }
00220 };
00221 
00223 SymmetricElasticFunctional*
00224 CreateSymmetricElasticFunctional( const int metric, UniformVolume::SmartPtr& refVolume, UniformVolume::SmartPtr& fltVolume );
00225 
00227 
00228 } // namespace cmtk
00229 
00230 #endif // #ifndef __cmtkSymmetricElasticFunctional_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines