Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkRegionBasedLevelSetFunction.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkRegionBasedLevelSetFunction.h,v $
00005   Language:  C++
00006   Date:      $Date: 2010-02-24 22:42:16 $
00007   Version:   $Revision: 1.19 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifndef __itkRegionBasedLevelSetFunction_h
00019 #define __itkRegionBasedLevelSetFunction_h
00020 
00021 #include "itkFiniteDifferenceFunction.h"
00022 #include "itkRegularizedHeavisideStepFunction.h"
00023 #include "vnl/vnl_matrix_fixed.h"
00024 
00025 namespace itk {
00026 
00063 template < class TInput, // LevelSetImageType
00064   class TFeature, // FeatureImageType
00065   class TSharedData >
00066 class ITK_EXPORT RegionBasedLevelSetFunction: public
00067 FiniteDifferenceFunction< TInput >
00068 {
00069 public:
00071   typedef RegionBasedLevelSetFunction                Self;
00072   typedef FiniteDifferenceFunction< TInput >         Superclass;
00073   typedef SmartPointer<Self>                         Pointer;
00074   typedef SmartPointer<const Self>                   ConstPointer;
00075 
00076   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00077 
00078   // itkNewMacro() is purposely not provided since this is an abstract class.
00079 
00081   itkTypeMacro( RegionBasedLevelSetFunction, FiniteDifferenceFunction );
00082 
00084   typedef double                                          TimeStepType;
00085   typedef typename Superclass::ImageType                  ImageType;
00086   typedef typename Superclass::PixelType                  PixelType;
00087   typedef PixelType                                       ScalarValueType;
00088   typedef typename Superclass::RadiusType                 RadiusType;
00089   typedef typename Superclass::NeighborhoodType           NeighborhoodType;
00090   typedef typename Superclass::NeighborhoodScalesType     NeighborhoodScalesType;
00091   typedef typename Superclass::FloatOffsetType            FloatOffsetType;
00092   typedef FixedArray< ScalarValueType, itkGetStaticConstMacro(ImageDimension) >
00093                                                           VectorType;
00094 
00095   /* This structure is derived from LevelSetFunction and stores intermediate
00096   values for computing time step sizes */
00097   struct GlobalDataStruct
00098     {
00099     GlobalDataStruct()
00100       {
00101       ScalarValueType null_value = NumericTraits<ScalarValueType>::Zero;
00102 
00103       m_MaxCurvatureChange   = null_value;
00104       m_MaxAdvectionChange   = null_value;
00105       m_MaxGlobalChange      = null_value;
00106       }
00107 
00108     ~GlobalDataStruct() {}
00109 
00110     vnl_matrix_fixed<ScalarValueType,
00111       itkGetStaticConstMacro(ImageDimension),
00112       itkGetStaticConstMacro(ImageDimension)> m_dxy;
00113 
00114     ScalarValueType m_dx[itkGetStaticConstMacro(ImageDimension)];
00115 
00116     ScalarValueType m_dx_forward[ itkGetStaticConstMacro( ImageDimension ) ];
00117     ScalarValueType m_dx_backward[ itkGetStaticConstMacro( ImageDimension ) ];
00118 
00119     ScalarValueType m_GradMagSqr;
00120     ScalarValueType m_GradMag;
00121 
00122     ScalarValueType m_MaxCurvatureChange;
00123     ScalarValueType m_MaxAdvectionChange;
00124     ScalarValueType m_MaxGlobalChange;
00125     };
00126 
00127 
00128   typedef TInput                                    InputImageType;
00129   typedef typename InputImageType::ConstPointer     InputImageConstPointer;
00130   typedef typename InputImageType::Pointer          InputImagePointer;
00131   typedef typename InputImageType::PixelType        InputPixelType;
00132   typedef typename InputImageType::IndexType        InputIndexType;
00133   typedef typename InputImageType::IndexValueType   InputIndexValueType;
00134   typedef typename InputImageType::SizeType         InputSizeType;
00135   typedef typename InputImageType::SizeValueType    InputSizeValueType;
00136   typedef typename InputImageType::RegionType       InputRegionType;
00137   typedef typename InputImageType::PointType        InputPointType;
00138 
00139   typedef TFeature                                  FeatureImageType;
00140   typedef typename FeatureImageType::ConstPointer   FeatureImageConstPointer;
00141   typedef typename FeatureImageType::PixelType      FeaturePixelType;
00142   typedef typename FeatureImageType::IndexType      FeatureIndexType;
00143   typedef typename FeatureImageType::SpacingType    FeatureSpacingType;
00144   typedef typename FeatureImageType::OffsetType     FeatureOffsetType;
00145 
00146   typedef TSharedData                               SharedDataType;
00147   typedef typename SharedDataType::Pointer          SharedDataPointer;
00148 
00149   typedef HeavisideStepFunctionBase< InputPixelType, InputPixelType > HeavisideFunctionType;
00150   typedef typename HeavisideFunctionType::ConstPointer HeavisideFunctionConstPointer;
00151 
00152   void SetDomainFunction( const HeavisideFunctionType * f )
00153     {
00154     this->m_DomainFunction = f;
00155     }
00156 
00157   virtual void Initialize(const RadiusType &r)
00158     {
00159     this->SetRadius(r);
00160 
00161     // Dummy neighborhood.
00162     NeighborhoodType it;
00163     it.SetRadius( r );
00164 
00165     // Find the center index of the neighborhood.
00166     m_Center =  it.Size() / 2;
00167 
00168     // Get the stride length for each axis.
00169     for(unsigned int i = 0; i < ImageDimension; i++)
00170       {
00171       m_xStride[i] = it.GetStride(i);
00172       }
00173     }
00174 
00175 
00176   void SetSharedData( SharedDataPointer sharedDataIn )
00177     {
00178     this->m_SharedData = sharedDataIn;
00179     }
00180 
00181   void UpdateSharedData( bool forceUpdate );
00182 
00183   void *GetGlobalDataPointer() const
00184     {
00185     return new GlobalDataStruct;
00186     }
00187 
00188   TimeStepType ComputeGlobalTimeStep(void *GlobalData) const;
00189 
00191   virtual PixelType ComputeUpdate(const NeighborhoodType &neighborhood,
00192     void *globalData, const FloatOffsetType& = FloatOffsetType(0.0));
00193 
00194   void SetInitialImage(InputImageType *f)
00195     {
00196     m_InitialImage = f;
00197     }
00198 
00199   virtual const FeatureImageType *GetFeatureImage() const
00200     { return m_FeatureImage.GetPointer(); }
00201   virtual void SetFeatureImage(const FeatureImageType *f)
00202     {
00203     m_FeatureImage = f;
00204 
00205     FeatureSpacingType spacing = m_FeatureImage->GetSpacing();
00206     for(unsigned int i = 0; i < ImageDimension; i++)
00207       {
00208       this->m_InvSpacing[i] = 1/spacing[i];
00209       }
00210     }
00211 
00213   virtual VectorType AdvectionField(const NeighborhoodType &,
00214                                     const FloatOffsetType &, GlobalDataStruct * = 0)  const
00215     { return this->m_ZeroVectorConstant; }
00216 
00218   void SetAreaWeight( const ScalarValueType& nu)
00219     { this->m_AreaWeight = nu; }
00220   ScalarValueType GetAreaWeight() const
00221     { return this->m_AreaWeight; }
00223 
00225   void SetLambda1( const ScalarValueType& lambda1 )
00226     { this->m_Lambda1 = lambda1; }
00227   ScalarValueType GetLambda1() const
00228     { return this->m_Lambda1; }
00230 
00232   void SetLambda2( const ScalarValueType& lambda2 )
00233     { this->m_Lambda2 = lambda2; }
00234   ScalarValueType GetLambda2() const
00235     { return this->m_Lambda2; }
00237 
00239   void SetOverlapPenaltyWeight( const ScalarValueType& gamma )
00240     { this->m_OverlapPenaltyWeight = gamma; }
00241   ScalarValueType GetOverlapPenaltyWeight() const
00242     { return this->m_OverlapPenaltyWeight; }
00244 
00246   virtual void SetCurvatureWeight(const ScalarValueType c)
00247     { m_CurvatureWeight = c; }
00248   ScalarValueType GetCurvatureWeight() const
00249     { return m_CurvatureWeight; }
00251 
00252   void SetAdvectionWeight( const ScalarValueType& iA)
00253     { this->m_AdvectionWeight = iA; }
00254   ScalarValueType GetAdvectionWeight() const
00255     { return this->m_AdvectionWeight; }
00256 
00258   void SetReinitializationSmoothingWeight(const ScalarValueType c)
00259     { m_ReinitializationSmoothingWeight = c; }
00260   ScalarValueType GetReinitializationSmoothingWeight() const
00261     { return m_ReinitializationSmoothingWeight; }
00263 
00265   void SetVolumeMatchingWeight( const ScalarValueType& tau )
00266     { this->m_VolumeMatchingWeight = tau; }
00267   ScalarValueType GetVolumeMatchingWeight() const
00268     { return this->m_VolumeMatchingWeight; }
00270 
00272   void SetVolume( const ScalarValueType& volume )
00273     { this->m_Volume = volume; }
00274   ScalarValueType GetVolume() const
00275     { return this->m_Volume; }
00277 
00279   void SetFunctionId( const unsigned int& iFid )
00280     { this->m_FunctionId = iFid; }
00281 
00282   virtual void ReleaseGlobalDataPointer(void *GlobalData) const
00283   { delete (GlobalDataStruct *) GlobalData; }
00284 
00285   virtual ScalarValueType ComputeCurvature(const NeighborhoodType &,
00286     const FloatOffsetType &, GlobalDataStruct *gd );
00287 
00290   virtual ScalarValueType LaplacianSmoothingSpeed(
00291     const NeighborhoodType &,
00292     const FloatOffsetType &, GlobalDataStruct * = 0) const
00293     { return NumericTraits<ScalarValueType>::One; }
00294 
00297   virtual ScalarValueType CurvatureSpeed(const NeighborhoodType &,
00298                                          const FloatOffsetType &, GlobalDataStruct * = 0
00299                                          ) const
00300     { return NumericTraits<ScalarValueType>::One; }
00301 
00306   virtual void CalculateAdvectionImage() {}
00307 
00308 protected:
00309 
00310   RegionBasedLevelSetFunction();
00311   virtual ~RegionBasedLevelSetFunction() {}
00312 
00314   InputImageConstPointer m_InitialImage;
00315 
00317   FeatureImageConstPointer m_FeatureImage;
00318 
00319   SharedDataPointer                 m_SharedData;
00320   HeavisideFunctionConstPointer     m_DomainFunction;
00321 
00323   ScalarValueType           m_AreaWeight;
00324 
00326   ScalarValueType           m_Lambda1;
00327 
00329   ScalarValueType           m_Lambda2;
00330 
00332   ScalarValueType           m_OverlapPenaltyWeight;
00333 
00335   ScalarValueType           m_VolumeMatchingWeight;
00336 
00338   ScalarValueType           m_Volume;
00339 
00341   ScalarValueType           m_CurvatureWeight;
00342 
00343   ScalarValueType           m_AdvectionWeight;
00344 
00346   ScalarValueType           m_ReinitializationSmoothingWeight;
00347 
00348   unsigned int              m_FunctionId;
00349 
00350   std::slice x_slice[itkGetStaticConstMacro(ImageDimension)];
00351   ::size_t m_Center;
00352   ::size_t m_xStride[itkGetStaticConstMacro(ImageDimension)];
00353   double m_InvSpacing[itkGetStaticConstMacro(ImageDimension)];
00354 
00355   static double m_WaveDT;
00356   static double m_DT;
00357 
00358   void ComputeHImage();
00359 
00362   ScalarValueType ComputeGlobalTerm(
00363     const ScalarValueType& imagePixel,
00364     const InputIndexType& inputIndex );
00365 
00370   virtual ScalarValueType ComputeInternalTerm(const FeaturePixelType& iValue,
00371     const FeatureIndexType& iIdx ) = 0;
00372 
00378   virtual ScalarValueType ComputeExternalTerm(const FeaturePixelType& iValue,
00379     const FeatureIndexType& iIdx ) = 0;
00380 
00385   virtual ScalarValueType ComputeOverlapParameters( const FeatureIndexType& featIndex,
00386     ScalarValueType& pr ) = 0;
00387 
00392   ScalarValueType ComputeVolumeRegularizationTerm( );
00393 
00407   ScalarValueType ComputeLaplacian( GlobalDataStruct *gd );
00408 
00410   void ComputeHessian( const NeighborhoodType &it,
00411     GlobalDataStruct *globalData );
00412 
00414   virtual void ComputeParameters() = 0;
00415 
00418   virtual void UpdateSharedDataParameters() = 0;
00419 
00420   bool m_UpdateC;
00421 
00424   static VectorType InitializeZeroVectorConstant();
00425 
00427   static VectorType m_ZeroVectorConstant;
00428 
00429 private:
00430   RegionBasedLevelSetFunction(const Self&); //purposely not implemented
00431   void operator=(const Self&); //purposely not implemented
00432 };
00433 
00434 } // end namespace itk
00435 
00436 #ifndef ITK_MANUAL_INSTANTIATION
00437 #include "itkRegionBasedLevelSetFunction.txx"
00438 #endif
00439 
00440 #endif
00441 

Generated at Fri Apr 16 19:29:05 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000