ITK  5.2.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  * http://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 
82 
84  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
85 
87  using TimeStepType = double;
88  using ImageType = typename Superclass::ImageType;
89  using PixelType = typename Superclass::PixelType;
91  using PixelRealType = typename Superclass::PixelRealType;
92  using RadiusType = typename Superclass::RadiusType;
93  using NeighborhoodType = typename Superclass::NeighborhoodType;
94  using NeighborhoodScalesType = typename Superclass::NeighborhoodScalesType;
95  using FloatOffsetType = 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  {
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  }
167 
169  virtual void
171  {
172  m_PropagationWeight = p;
173  }
174  ScalarValueType
176  {
177  return m_PropagationWeight;
178  }
180 
182  virtual void
184  {
185  m_CurvatureWeight = c;
186  }
187  ScalarValueType
189  {
190  return m_CurvatureWeight;
191  }
193 
195  void
197  {
198  m_LaplacianSmoothingWeight = c;
199  }
200  ScalarValueType
202  {
203  return m_LaplacianSmoothingWeight;
204  }
206 
208  void
210  {
211  m_EpsilonMagnitude = e;
212  }
213  ScalarValueType
215  {
216  return m_EpsilonMagnitude;
217  }
219 
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 = NumericTraits<ScalarValueType>::ZeroValue();
248  ans->m_MaxPropagationChange = NumericTraits<ScalarValueType>::ZeroValue();
249  ans->m_MaxCurvatureChange = NumericTraits<ScalarValueType>::ZeroValue();
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(NumericTraits<ScalarValueType>::ZeroValue())
343  , m_PropagationWeight(NumericTraits<ScalarValueType>::ZeroValue())
344  , m_CurvatureWeight(NumericTraits<ScalarValueType>::ZeroValue())
345  , m_LaplacianSmoothingWeight(NumericTraits<ScalarValueType>::ZeroValue())
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 
377 
380 
383 
386 
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::FiniteDifferenceFunction::RadiusType
typename ConstNeighborhoodIterator< TImageType >::RadiusType RadiusType
Definition: itkFiniteDifferenceFunction.h:97
itk::LevelSetFunction::m_AdvectionWeight
ScalarValueType m_AdvectionWeight
Definition: itkLevelSetFunction.h:379
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::FiniteDifferenceFunction::PixelRealType
double PixelRealType
Definition: itkFiniteDifferenceFunction.h:84
itk::LevelSetFunction::GetCurvatureWeight
ScalarValueType GetCurvatureWeight() const
Definition: itkLevelSetFunction.h:188
itk::LevelSetFunction::GetMaximumPropagationTimeStep
static double GetMaximumPropagationTimeStep()
Definition: itkLevelSetFunction.h:334
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
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::FiniteDifferenceFunction::ImageType
TImageType ImageType
Definition: itkFiniteDifferenceFunction.h:82
itk::LevelSetFunction::AdvectionField
virtual VectorType AdvectionField(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
Definition: itkLevelSetFunction.h:126
itkFiniteDifferenceFunction.h
itk::LevelSetFunction::m_LaplacianSmoothingWeight
ScalarValueType m_LaplacianSmoothingWeight
Definition: itkLevelSetFunction.h:388
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:59
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:156
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::LevelSetFunction::SetLaplacianSmoothingWeight
void SetLaplacianSmoothingWeight(const ScalarValueType c)
Definition: itkLevelSetFunction.h:196
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:52
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
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: itkAnnulusOperator.h:24
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::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::LevelSetFunction::UseMinimalCurvatureOn
void UseMinimalCurvatureOn()
Definition: itkLevelSetFunction.h:296
itk::LevelSetFunction::m_CurvatureWeight
ScalarValueType m_CurvatureWeight
Definition: itkLevelSetFunction.h:385
itk::LevelSetFunction::m_EpsilonMagnitude
ScalarValueType m_EpsilonMagnitude
Definition: itkLevelSetFunction.h:376
itk::LevelSetFunction::GetAdvectionWeight
ScalarValueType GetAdvectionWeight() const
Definition: itkLevelSetFunction.h:162
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
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::PixelType
typename Superclass::PixelType PixelType
Definition: itkLevelSetFunction.h:89
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::LevelSetFunction::m_PropagationWeight
ScalarValueType m_PropagationWeight
Definition: itkLevelSetFunction.h:382
itk::FiniteDifferenceFunction::TimeStepType
double TimeStepType
Definition: itkFiniteDifferenceFunction.h:90