ITK  6.0.0
Insight Toolkit
itkLevelSetFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkLevelSetFunction_h
19 #define itkLevelSetFunction_h
20 
22 #include "vnl/vnl_matrix_fixed.h"
23 
24 namespace itk
25 {
65 template <typename TImageType>
66 class ITK_TEMPLATE_EXPORT LevelSetFunction : public FiniteDifferenceFunction<TImageType>
67 {
68 public:
69  ITK_DISALLOW_COPY_AND_MOVE(LevelSetFunction);
70 
76 
78  itkNewMacro(Self);
79 
81  itkOverrideGetNameOfClassMacro(LevelSetFunction);
82 
84  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
85 
87  using TimeStepType = double;
88  using typename Superclass::ImageType;
89  using typename Superclass::PixelType;
91  using typename Superclass::PixelRealType;
92  using typename Superclass::RadiusType;
93  using typename Superclass::NeighborhoodType;
94  using typename Superclass::NeighborhoodScalesType;
95  using typename Superclass::FloatOffsetType;
96 
98  // typedef
100 
107  {
111 
113  vnl_matrix_fixed<ScalarValueType, Self::ImageDimension, Self::ImageDimension> m_dxy;
114 
116  ScalarValueType m_dx[Self::ImageDimension];
117 
118  ScalarValueType m_dx_forward[Self::ImageDimension];
119  ScalarValueType m_dx_backward[Self::ImageDimension];
120 
122  };
123 
125  virtual VectorType
127  {
128  return m_ZeroVectorConstant;
129  }
130 
133  virtual ScalarValueType
135  {
136  return ScalarValueType{};
137  }
138 
141  virtual ScalarValueType
143  {
145  }
146 
149  virtual ScalarValueType
151  {
153  }
154 
156  virtual void
158  {
159  m_AdvectionWeight = a;
160  }
161  ScalarValueType
163  {
164  return m_AdvectionWeight;
165  }
169  virtual void
171  {
172  m_PropagationWeight = p;
173  }
174  ScalarValueType
176  {
177  return m_PropagationWeight;
178  }
182  virtual void
184  {
185  m_CurvatureWeight = c;
186  }
187  ScalarValueType
189  {
190  return m_CurvatureWeight;
191  }
195  void
197  {
198  m_LaplacianSmoothingWeight = c;
199  }
200  ScalarValueType
202  {
203  return m_LaplacianSmoothingWeight;
204  }
208  void
210  {
211  m_EpsilonMagnitude = e;
212  }
213  ScalarValueType
215  {
216  return m_EpsilonMagnitude;
217  }
221  PixelType
222  ComputeUpdate(const NeighborhoodType & it,
223  void * globalData,
224  const FloatOffsetType & = FloatOffsetType(0.0)) override;
225 
232  TimeStepType
233  ComputeGlobalTimeStep(void * GlobalData) const override;
234 
242  void *
243  GetGlobalDataPointer() const override
244  {
245  auto * ans = new GlobalDataStruct();
246 
247  ans->m_MaxAdvectionChange = ScalarValueType{};
248  ans->m_MaxPropagationChange = ScalarValueType{};
249  ans->m_MaxCurvatureChange = ScalarValueType{};
250  return ans;
251  }
252 
256  virtual void
257  Initialize(const RadiusType & r);
258 
263  void
264  ReleaseGlobalDataPointer(void * GlobalData) const override
265  {
266  delete (GlobalDataStruct *)GlobalData;
267  }
268 
270  virtual ScalarValueType
271  ComputeCurvatureTerm(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct * gd = 0);
272 
273  virtual ScalarValueType
274  ComputeMeanCurvature(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct * gd = 0);
275 
276  virtual ScalarValueType
277  ComputeMinimalCurvature(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct * gd = 0);
278 
279  virtual ScalarValueType
280  Compute3DMinimalCurvature(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct * gd = 0);
281 
283  void
285  {
286  m_UseMinimalCurvature = b;
287  }
288 
289  bool
291  {
292  return m_UseMinimalCurvature;
293  }
294 
295  void
297  {
298  this->SetUseMinimalCurvature(true);
299  }
300 
301  void
303  {
304  this->SetUseMinimalCurvature(false);
305  }
306 
311  static void
313  {
314  m_DT = n;
315  }
316 
317  static double
319  {
320  return m_DT;
321  }
322 
327  static void
329  {
330  m_WaveDT = n;
331  }
332 
333  static double
335  {
336  return m_WaveDT;
337  }
338 
339 protected:
341  : m_EpsilonMagnitude(static_cast<ScalarValueType>(1.0e-5))
342  , m_AdvectionWeight(ScalarValueType{})
343  , m_PropagationWeight(ScalarValueType{})
344  , m_CurvatureWeight(ScalarValueType{})
345  , m_LaplacianSmoothingWeight(ScalarValueType{})
346  {}
347 
348  ~LevelSetFunction() override = default;
349  void
350  PrintSelf(std::ostream & os, Indent indent) const override;
351 
353  static double m_WaveDT;
354  static double m_DT;
355 
357  std::slice x_slice[Self::ImageDimension];
358 
360  OffsetValueType m_Center{ 0 };
361 
363  OffsetValueType m_xStride[Self::ImageDimension]{};
364 
365  bool m_UseMinimalCurvature{ false };
366 
369  static VectorType
370  InitializeZeroVectorConstant();
371 
374 
376  ScalarValueType m_EpsilonMagnitude{};
377 
379  ScalarValueType m_AdvectionWeight{};
380 
382  ScalarValueType m_PropagationWeight{};
383 
385  ScalarValueType m_CurvatureWeight{};
386 
388  ScalarValueType m_LaplacianSmoothingWeight{};
389 };
390 } // namespace itk
391 
392 #ifndef ITK_MANUAL_INSTANTIATION
393 # include "itkLevelSetFunction.hxx"
394 #endif
395 
396 #endif
itk::LevelSetFunction::GetPropagationWeight
ScalarValueType GetPropagationWeight() const
Definition: itkLevelSetFunction.h:175
itk::LevelSetFunction::GetUseMinimalCurvature
bool GetUseMinimalCurvature() const
Definition: itkLevelSetFunction.h:290
itk::LevelSetFunction::PropagationSpeed
virtual ScalarValueType PropagationSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
Definition: itkLevelSetFunction.h:134
itk::LevelSetFunction::GetEpsilonMagnitude
ScalarValueType GetEpsilonMagnitude() const
Definition: itkLevelSetFunction.h:214
itk::LevelSetFunction::SetUseMinimalCurvature
void SetUseMinimalCurvature(bool b)
Definition: itkLevelSetFunction.h:284
itk::LevelSetFunction::GlobalDataStruct::m_GradMagSqr
ScalarValueType m_GradMagSqr
Definition: itkLevelSetFunction.h:121
itk::LevelSetFunction::m_WaveDT
static double m_WaveDT
Definition: itkLevelSetFunction.h:353
itk::LevelSetFunction::SetAdvectionWeight
virtual void SetAdvectionWeight(const ScalarValueType a)
Definition: itkLevelSetFunction.h:157
itk::LevelSetFunction::GetLaplacianSmoothingWeight
ScalarValueType GetLaplacianSmoothingWeight() const
Definition: itkLevelSetFunction.h:201
itk::LevelSetFunction::SetMaximumCurvatureTimeStep
static void SetMaximumCurvatureTimeStep(double n)
Definition: itkLevelSetFunction.h:312
itk::LevelSetFunction::GlobalDataStruct
Definition: itkLevelSetFunction.h:106
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::LevelSetFunction::GlobalDataStruct::m_MaxPropagationChange
ScalarValueType m_MaxPropagationChange
Definition: itkLevelSetFunction.h:109
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::LevelSetFunction::SetCurvatureWeight
virtual void SetCurvatureWeight(const ScalarValueType c)
Definition: itkLevelSetFunction.h:183
itk::LevelSetFunction::GetCurvatureWeight
ScalarValueType GetCurvatureWeight() const
Definition: itkLevelSetFunction.h:188
itk::LevelSetFunction::GetMaximumPropagationTimeStep
static double GetMaximumPropagationTimeStep()
Definition: itkLevelSetFunction.h:334
itk::SmartPointer< Self >
itk::LevelSetFunction::CurvatureSpeed
virtual ScalarValueType CurvatureSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=nullptr) const
Definition: itkLevelSetFunction.h:142
itk::LevelSetFunction::SetEpsilonMagnitude
void SetEpsilonMagnitude(const ScalarValueType e)
Definition: itkLevelSetFunction.h:209
itk::LevelSetFunction::AdvectionField
virtual VectorType AdvectionField(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
Definition: itkLevelSetFunction.h:126
itkFiniteDifferenceFunction.h
itk::LevelSetFunction::m_DT
static double m_DT
Definition: itkLevelSetFunction.h:354
itk::LevelSetFunction::LevelSetFunction
LevelSetFunction()
Definition: itkLevelSetFunction.h:340
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::LevelSetFunction::GlobalDataStruct::m_dxy
vnl_matrix_fixed< ScalarValueType, Self::ImageDimension, Self::ImageDimension > m_dxy
Definition: itkLevelSetFunction.h:113
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:158
itk::LevelSetFunction::GlobalDataStruct::m_MaxCurvatureChange
ScalarValueType m_MaxCurvatureChange
Definition: itkLevelSetFunction.h:110
itk::LevelSetFunction::LaplacianSmoothingSpeed
virtual ScalarValueType LaplacianSmoothingSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
Definition: itkLevelSetFunction.h:150
itk::FiniteDifferenceFunction::PixelType
typename ImageType::PixelType PixelType
Definition: itkFiniteDifferenceFunction.h:83
itk::LevelSetFunction::SetLaplacianSmoothingWeight
void SetLaplacianSmoothingWeight(const ScalarValueType c)
Definition: itkLevelSetFunction.h:196
itk::OffsetValueType
long OffsetValueType
Definition: itkIntTypes.h:97
itk::LevelSetFunction::GlobalDataStruct::m_MaxAdvectionChange
ScalarValueType m_MaxAdvectionChange
Definition: itkLevelSetFunction.h:108
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::LevelSetFunction::SetPropagationWeight
virtual void SetPropagationWeight(const ScalarValueType p)
Definition: itkLevelSetFunction.h:170
itk::LevelSetFunction::ScalarValueType
PixelType ScalarValueType
Definition: itkLevelSetFunction.h:90
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::LevelSetFunction::m_ZeroVectorConstant
static VectorType m_ZeroVectorConstant
Definition: itkLevelSetFunction.h:373
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:51
itk::LevelSetFunction::SetMaximumPropagationTimeStep
static void SetMaximumPropagationTimeStep(double n)
Definition: itkLevelSetFunction.h:328
itk::LevelSetFunction::UseMinimalCurvatureOn
void UseMinimalCurvatureOn()
Definition: itkLevelSetFunction.h:296
itk::LevelSetFunction::GetAdvectionWeight
ScalarValueType GetAdvectionWeight() const
Definition: itkLevelSetFunction.h:162
itk::Math::e
static constexpr double e
Definition: itkMath.h:56
itk::FiniteDifferenceFunction
Definition: itkFiniteDifferenceFunction.h:66
itk::LevelSetFunction
The LevelSetFunction class is a generic function object which can be used to create a level set metho...
Definition: itkLevelSetFunction.h:66
itk::LevelSetFunction::GetGlobalDataPointer
void * GetGlobalDataPointer() const override
Definition: itkLevelSetFunction.h:243
itk::LevelSetFunction::UseMinimalCurvatureOff
void UseMinimalCurvatureOff()
Definition: itkLevelSetFunction.h:302
itk::LevelSetFunction::ReleaseGlobalDataPointer
void ReleaseGlobalDataPointer(void *GlobalData) const override
Definition: itkLevelSetFunction.h:264
itk::LevelSetFunction::GetMaximumCurvatureTimeStep
static double GetMaximumCurvatureTimeStep()
Definition: itkLevelSetFunction.h:318
itk::FiniteDifferenceFunction::TimeStepType
double TimeStepType
Definition: itkFiniteDifferenceFunction.h:90