cmtkSymmetricElasticFunctional.cxx

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 #include <Registration/cmtkSymmetricElasticFunctional.h>
00034 
00035 #include <Registration/cmtkVoxelMatchingMutInf.h>
00036 #include <Registration/cmtkVoxelMatchingNormMutInf.h>
00037 #include <Registration/cmtkVoxelMatchingCorrRatio.h>
00038 #include <Registration/cmtkVoxelMatchingMeanSquaredDifference.h>
00039 #include <Registration/cmtkVoxelMatchingCrossCorrelation.h>
00040 
00041 #include <Base/cmtkSplineWarpXform.h>
00042 #include <Base/cmtkInterpolator.h>
00043 #include <Base/cmtkUniformVolume.h>
00044 
00045 namespace
00046 cmtk
00047 {
00048 
00051 
00052 template<class VM>
00053 void
00054 SymmetricElasticFunctional_Template<VM>::SetWarpXform
00055 ( SplineWarpXform::SmartPtr& warpFwd, SplineWarpXform::SmartPtr& warpBwd ) 
00056 {
00057   this->FwdFunctional.SetWarpXform( warpFwd );
00058   this->FwdFunctional.SetInverseTransformation( warpBwd );
00059   
00060   this->BwdFunctional.SetWarpXform( warpBwd );
00061   this->BwdFunctional.SetInverseTransformation( warpFwd );
00062 }
00063 
00064 template<class VM>
00065 typename SymmetricElasticFunctional_Template<VM>::ReturnType
00066 SymmetricElasticFunctional_Template<VM>
00067 ::EvaluateWithGradient( CoordinateVector& v, CoordinateVector& g, const Types::Coordinate step )
00068 {
00069   CoordinateVector vFwd( this->FwdFunctional.ParamVectorDim(), v.Elements, false /*freeElements*/ );
00070   CoordinateVector gFwd( this->FwdFunctional.ParamVectorDim(), g.Elements, false /*freeElements*/ );
00071 
00072   CoordinateVector vBwd( this->BwdFunctional.ParamVectorDim(), v.Elements+this->FwdFunctional.ParamVectorDim(), false /*freeElements*/ );
00073   CoordinateVector gBwd( this->BwdFunctional.ParamVectorDim(), g.Elements+this->FwdFunctional.ParamVectorDim(), false /*freeElements*/ );
00074 
00075   return this->FwdFunctional.EvaluateWithGradient( vFwd, gFwd, step ) + this->BwdFunctional.EvaluateWithGradient( vBwd, gBwd, step );
00076 }
00077 
00078 SymmetricElasticFunctional* 
00079 CreateSymmetricElasticFunctional( const int metric, UniformVolume::SmartPtr& refVolume,  UniformVolume::SmartPtr& fltVolume )
00080 {
00081   switch ( fltVolume->GetData()->GetDataClass() ) 
00082     {
00083     case DATACLASS_UNKNOWN :
00084     case DATACLASS_GREY :
00085       switch ( metric ) 
00086         {
00087         case 0:
00088           return new SymmetricElasticFunctional_Template< VoxelMatchingNormMutInf_Trilinear>( refVolume, fltVolume );
00089         case 1:
00090           return new SymmetricElasticFunctional_Template<VoxelMatchingMutInf_Trilinear>( refVolume, fltVolume );
00091         case 2:
00092           return new SymmetricElasticFunctional_Template<VoxelMatchingCorrRatio_Trilinear>( refVolume, fltVolume );
00093         case 3:
00094           return NULL; // masked NMI retired
00095         case 4:
00096           return new SymmetricElasticFunctional_Template<VoxelMatchingMeanSquaredDifference>( refVolume, fltVolume );
00097         case 5:
00098           return new SymmetricElasticFunctional_Template<VoxelMatchingCrossCorrelation>( refVolume, fltVolume );
00099         default:
00100           return NULL;
00101         }
00102     case DATACLASS_LABEL:
00103       switch ( metric ) 
00104         {
00105         case 0:
00106           return new SymmetricElasticFunctional_Template<VoxelMatchingNormMutInf_NearestNeighbor>( refVolume, fltVolume );
00107         case 1:
00108           return new SymmetricElasticFunctional_Template<VoxelMatchingMutInf_NearestNeighbor>( refVolume, fltVolume );
00109         case 2:
00110           return new SymmetricElasticFunctional_Template<VoxelMatchingCorrRatio_NearestNeighbor>( refVolume, fltVolume );
00111         case 3:
00112           return NULL; // masked NMI retired
00113         case 4:
00114           return new SymmetricElasticFunctional_Template<VoxelMatchingMeanSquaredDifference>( refVolume, fltVolume );
00115         case 5:
00116           return new SymmetricElasticFunctional_Template<VoxelMatchingCrossCorrelation>( refVolume, fltVolume );
00117         default:
00118           return NULL;
00119         }
00120     }
00121   
00122   return NULL;
00123 }
00124 
00125 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines