cmtkSplineWarpMultiChannelRegistrationFunctional.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: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkSplineWarpMultiChannelRegistrationFunctional_h_included_
00034 #define __cmtkSplineWarpMultiChannelRegistrationFunctional_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Registration/cmtkMultiChannelRMIRegistrationFunctional.h>
00039 #include <Registration/cmtkTemplateMultiChannelRegistrationFunctional.h>
00040 #include <Registration/cmtkAffineMultiChannelRegistrationFunctional.h>
00041 
00042 #include <Base/cmtkSplineWarpXform.h>
00043 
00044 #include <System/cmtkThreads.h>
00045 #include <System/cmtkMutexLock.h>
00046 
00047 #include <list>
00048 
00049 namespace
00050 cmtk
00051 {
00052 
00055 
00057 template<class MetricFunctionalClass> 
00058 class SplineWarpMultiChannelIntensityCorrectionRegistrationFunctional;
00059 
00061 template<class TMetricFunctional = MultiChannelRMIRegistrationFunctional<> >
00062 class SplineWarpMultiChannelRegistrationFunctional :
00064   public TemplateMultiChannelRegistrationFunctional<SplineWarpXform, TMetricFunctional >
00065 {
00066 public:
00068   typedef SplineWarpMultiChannelRegistrationFunctional Self;
00069 
00071   typedef SmartPointer<Self> SmartPtr;
00072 
00074   typedef TemplateMultiChannelRegistrationFunctional<SplineWarpXform, TMetricFunctional > Superclass;
00075 
00077   typedef typename Superclass::MetricData MetricData;
00078 
00080   SplineWarpMultiChannelRegistrationFunctional();
00081 
00083   template<class TAffineMetricFunctional>
00084   SplineWarpMultiChannelRegistrationFunctional
00085   ( AffineMultiChannelRegistrationFunctional<TAffineMetricFunctional>& affineFunctional );
00086 
00088   virtual void SetInitialAffineTransformation( const AffineXform& initialAffine )
00089   {
00090     this->m_InitialAffineTransformation = initialAffine;
00091   }
00092 
00094   void SetAdaptiveFixEntropyThreshold( const bool flag )
00095   {
00096     this->m_AdaptiveFixEntropyThreshold = flag;
00097   }
00098 
00100   void SetAdaptiveFixThreshFactor( const float factor )
00101   {
00102     this->m_AdaptiveFixThreshFactor = factor;
00103   }
00104 
00106   void ClearFixedCoordinateDimensions()
00107   {
00108     this->m_FixedCoordinateDimensions.clear();
00109   }
00110 
00112   void AddFixedCoordinateDimension( const int dim )
00113   {
00114     this->m_FixedCoordinateDimensions.push_back( dim );
00115   }
00116 
00118   void SetJacobianConstraintWeight( const float weight )
00119   {
00120     this->m_JacobianConstraintWeight = weight;
00121   }
00122 
00124   virtual void InitTransformation( const Vector3D& domain, const Types::Coordinate gridSpacing, const bool exact );
00125 
00127   virtual void RefineTransformation();
00128 
00130   virtual void ClearAllChannels()
00131   {
00132     this->ClearReformattedFloatingChannels();
00133     Superclass::ClearAllChannels();
00134   }
00135 
00137   virtual typename Self::ReturnType Evaluate();
00138   
00140   virtual typename Self::ReturnType EvaluateWithGradient( CoordinateVector& v, CoordinateVector& g, const Types::Coordinate step = 1 );
00141 
00142 protected:
00144   virtual void NewReferenceChannelGeometry() 
00145   {
00146     this->UpdateTransformationData();
00147   }
00148 
00149 private:
00151   AffineXform m_InitialAffineTransformation;
00152 
00154   virtual void UpdateTransformationData();
00155 
00157   std::vector< std::vector<float> > m_ReformattedFloatingChannels;
00158   
00160   virtual void AllocateReformattedFloatingChannels();
00161 
00163   virtual void ClearReformattedFloatingChannels();
00164 
00166   typename Self::ReturnType EvaluateIncremental( const SplineWarpXform* warp, MetricData& metricData, const DataGrid::RegionType& region );
00167 
00169   virtual void ContinueMetricStoreReformatted( MetricData& metricData, const size_t rindex, const Vector3D& fvector );
00170 
00172   virtual void BacktraceMetric( MetricData& metricData, const DataGrid::RegionType& voi );
00173 
00175   std::vector<Types::Coordinate> m_StepScaleVector;
00176 
00178   std::vector<DataGrid::RegionType> m_VolumeOfInfluenceVector;
00179 
00181   bool m_AdaptiveFixEntropyThreshold;
00182 
00184   float m_AdaptiveFixThreshFactor;
00185 
00187   std::list<int> m_FixedCoordinateDimensions;
00188 
00190   float m_JacobianConstraintWeight;
00191 
00193   virtual void UpdateTransformationFixedControlPoints();
00194 
00196   bool m_UpdateTransformationFixedControlPointsRequired;
00197 
00199   const size_t m_NumberOfThreads;
00200 
00202   static void EvaluateThreadFunction( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00203 
00205   MutexLock m_MetricDataMutex;
00206 
00208   std::vector<SplineWarpXform::SmartPtr> m_ThreadTransformations;
00209 
00211   class EvaluateGradientThreadParameters : 
00213     public ThreadParameters<Self>
00214   {
00215   public:
00217     Types::Coordinate m_Step;
00218 
00220     Types::Coordinate* m_Gradient;
00221 
00223     const CoordinateVector* m_ParameterVector;
00224 
00226     typename Self::ReturnType m_MetricBaseValue;
00227   };
00228 
00230   static void EvaluateWithGradientThreadFunction( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00231 
00233   template<class MetricFunctionalClass> friend class SplineWarpMultiChannelIntensityCorrectionRegistrationFunctional;
00234 };
00235 
00237 
00238 } // namespace cmtk
00239 
00240 #include "cmtkSplineWarpMultiChannelRegistrationFunctional.txx"
00241 #include "cmtkSplineWarpMultiChannelRegistrationFunctionalThreadFunctions.txx"
00242 
00243 #endif // #ifndef __cmtkSplineWarpMultiChannelRegistrationFunctional_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines