00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkLevelSetFunction_h_
00018 #define __itkLevelSetFunction_h_
00019
00020 #include "itkFiniteDifferenceFunction.h"
00021 #include "vnl/vnl_matrix_fixed.h"
00022
00023 namespace itk {
00024
00063 template <class TImageType>
00064 class ITK_EXPORT LevelSetFunction
00065 : public FiniteDifferenceFunction<TImageType>
00066 {
00067 public:
00069 typedef LevelSetFunction Self;
00070 typedef FiniteDifferenceFunction<TImageType> Superclass;
00071 typedef SmartPointer<Self> Pointer;
00072 typedef SmartPointer<const Self> ConstPointer;
00073
00075 itkNewMacro(Self);
00076
00078 itkTypeMacro( LevelSetFunction, FiniteDifferenceFunction );
00079
00081 itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
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::FloatOffsetType FloatOffsetType;
00091
00093
00094 typedef FixedArray<ScalarValueType, itkGetStaticConstMacro(ImageDimension)> VectorType;
00095
00101 struct GlobalDataStruct
00102 {
00103 ScalarValueType m_MaxAdvectionChange;
00104 ScalarValueType m_MaxPropagationChange;
00105 ScalarValueType m_MaxCurvatureChange;
00106
00108 vnl_matrix_fixed<ScalarValueType,
00109 itkGetStaticConstMacro(ImageDimension),
00110 itkGetStaticConstMacro(ImageDimension)> m_dxy;
00111
00113 ScalarValueType m_dx[itkGetStaticConstMacro(ImageDimension)];
00114
00115 ScalarValueType m_dx_forward[itkGetStaticConstMacro(ImageDimension)];
00116 ScalarValueType m_dx_backward[itkGetStaticConstMacro(ImageDimension)];
00117
00118 ScalarValueType m_GradMagSqr;
00119 };
00120
00122 virtual VectorType AdvectionField(const NeighborhoodType &,
00123 const FloatOffsetType &, GlobalDataStruct * = 0) const
00124 { return m_ZeroVectorConstant; }
00125
00128 virtual ScalarValueType PropagationSpeed(
00129 const NeighborhoodType& ,
00130 const FloatOffsetType &, GlobalDataStruct * = 0 ) const
00131 { return NumericTraits<ScalarValueType>::Zero; }
00132
00135 virtual ScalarValueType CurvatureSpeed(const NeighborhoodType &,
00136 const FloatOffsetType &, GlobalDataStruct * = 0
00137 ) const
00138 { return NumericTraits<ScalarValueType>::One; }
00139
00142 virtual ScalarValueType LaplacianSmoothingSpeed(
00143 const NeighborhoodType &,
00144 const FloatOffsetType &, GlobalDataStruct * = 0) const
00145 { return NumericTraits<ScalarValueType>::One; }
00146
00148 virtual void SetAdvectionWeight(const ScalarValueType a)
00149 { m_AdvectionWeight = a; }
00150 ScalarValueType GetAdvectionWeight() const
00151 { return m_AdvectionWeight; }
00153
00155 virtual void SetPropagationWeight(const ScalarValueType p)
00156 { m_PropagationWeight = p; }
00157 ScalarValueType GetPropagationWeight() const
00158 { return m_PropagationWeight; }
00160
00162 virtual void SetCurvatureWeight(const ScalarValueType c)
00163 { m_CurvatureWeight = c; }
00164 ScalarValueType GetCurvatureWeight() const
00165 { return m_CurvatureWeight; }
00167
00169 void SetLaplacianSmoothingWeight(const ScalarValueType c)
00170 { m_LaplacianSmoothingWeight = c; }
00171 ScalarValueType GetLaplacianSmoothingWeight() const
00172 { return m_LaplacianSmoothingWeight; }
00174
00176 void SetEpsilonMagnitude(const ScalarValueType e)
00177 { m_EpsilonMagnitude = e; }
00178 ScalarValueType GetEpsilonMagnitude() const
00179 { return m_EpsilonMagnitude; }
00181
00183 virtual PixelType ComputeUpdate(const NeighborhoodType &neighborhood,
00184 void *globalData,
00185 const FloatOffsetType& = FloatOffsetType(0.0));
00186
00193 virtual TimeStepType ComputeGlobalTimeStep(void *GlobalData) const;
00194
00202 virtual void *GetGlobalDataPointer() const
00203 {
00204 GlobalDataStruct *ans = new GlobalDataStruct();
00205 ans->m_MaxAdvectionChange = NumericTraits<ScalarValueType>::Zero;
00206 ans->m_MaxPropagationChange = NumericTraits<ScalarValueType>::Zero;
00207 ans->m_MaxCurvatureChange = NumericTraits<ScalarValueType>::Zero;
00208 return ans;
00209 }
00211
00215 virtual void Initialize(const RadiusType &r);
00216
00221 virtual void ReleaseGlobalDataPointer(void *GlobalData) const
00222 { delete (GlobalDataStruct *) GlobalData; }
00223
00225 virtual ScalarValueType ComputeCurvatureTerm(const NeighborhoodType &,
00226 const FloatOffsetType &,
00227 GlobalDataStruct *gd = 0
00228 );
00229 virtual ScalarValueType ComputeMeanCurvature(const NeighborhoodType &,
00230 const FloatOffsetType &,
00231 GlobalDataStruct *gd = 0
00232 );
00234
00235 virtual ScalarValueType ComputeMinimalCurvature(const NeighborhoodType &,
00236 const FloatOffsetType &,
00237 GlobalDataStruct *gd = 0
00238 );
00239
00240 virtual ScalarValueType Compute3DMinimalCurvature(const NeighborhoodType &,
00241 const FloatOffsetType &,
00242 GlobalDataStruct *gd = 0
00243 );
00244
00246 void SetUseMinimalCurvature( bool b )
00247 {
00248 m_UseMinimalCurvature = b;
00249 }
00250 bool GetUseMinimalCurvature() const
00251 {
00252 return m_UseMinimalCurvature;
00253 }
00254 void UseMinimalCurvatureOn()
00255 {
00256 this->SetUseMinimalCurvature(true);
00257 }
00258 void UseMinimalCurvatureOff()
00259 {
00260 this->SetUseMinimalCurvature(false);
00261 }
00263
00268 static void SetMaximumCurvatureTimeStep(double n)
00269 {
00270 m_DT = n;
00271 }
00272 static double GetMaximumCurvatureTimeStep()
00273 {
00274 return m_DT;
00275 }
00277
00282 static void SetMaximumPropagationTimeStep(double n)
00283 {
00284 m_WaveDT = n;
00285 }
00286 static double GetMaximumPropagationTimeStep()
00287 {
00288 return m_WaveDT;
00289 }
00291
00292 protected:
00293 LevelSetFunction()
00294 {
00295 m_EpsilonMagnitude = 1.0e-5;
00296 m_AdvectionWeight = m_PropagationWeight
00297 = m_CurvatureWeight = m_LaplacianSmoothingWeight
00298 = NumericTraits<ScalarValueType>::Zero;
00299 m_UseMinimalCurvature = false;
00300 }
00301 virtual ~LevelSetFunction() {}
00302 void PrintSelf(std::ostream &s, Indent indent) const;
00303
00305 static double m_WaveDT;
00306 static double m_DT;
00307
00309 std::slice x_slice[itkGetStaticConstMacro(ImageDimension)];
00310
00312 ::size_t m_Center;
00313
00315 ::size_t m_xStride[itkGetStaticConstMacro(ImageDimension)];
00316
00317 bool m_UseMinimalCurvature;
00318
00321 static VectorType InitializeZeroVectorConstant();
00322
00324 static VectorType m_ZeroVectorConstant;
00325
00327 ScalarValueType m_EpsilonMagnitude;
00328
00330 ScalarValueType m_AdvectionWeight;
00331
00333 ScalarValueType m_PropagationWeight;
00334
00336 ScalarValueType m_CurvatureWeight;
00337
00339 ScalarValueType m_LaplacianSmoothingWeight;
00340
00341 private:
00342 LevelSetFunction(const Self&);
00343 void operator=(const Self&);
00344 };
00345
00346 }
00347
00348
00349 #define ITK_TEMPLATE_LevelSetFunction(_, EXPORT, x, y) namespace itk { \
00350 _(1(class EXPORT LevelSetFunction< ITK_TEMPLATE_1 x >)) \
00351 namespace Templates { typedef LevelSetFunction< ITK_TEMPLATE_1 x > \
00352 LevelSetFunction##y; } \
00353 }
00354
00355 #if ITK_TEMPLATE_EXPLICIT
00356 # include "Templates/itkLevelSetFunction+-.h"
00357 #endif
00358
00359 #if ITK_TEMPLATE_TXX
00360 # include "itkLevelSetFunction.txx"
00361 #endif
00362
00363 #endif
00364
00365