ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLevelSetFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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:
67  public FiniteDifferenceFunction< TImageType >
68 {
69 public:
70  ITK_DISALLOW_COPY_AND_ASSIGN(LevelSetFunction);
71 
77 
79  itkNewMacro(Self);
80 
83 
85  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
86 
88  using TimeStepType = double;
89  using ImageType = typename Superclass::ImageType;
90  using PixelType = typename Superclass::PixelType;
92  using PixelRealType = typename Superclass::PixelRealType;
93  using RadiusType = typename Superclass::RadiusType;
94  using NeighborhoodType = typename Superclass::NeighborhoodType;
95  using NeighborhoodScalesType = typename Superclass::NeighborhoodScalesType;
96  using FloatOffsetType = typename Superclass::FloatOffsetType;
97 
99  // typedef
101 
111 
113  vnl_matrix_fixed< ScalarValueType,
114  Self::ImageDimension,
115  Self::ImageDimension > m_dxy;
116 
118  ScalarValueType m_dx[Self::ImageDimension];
119 
120  ScalarValueType m_dx_forward[Self::ImageDimension];
121  ScalarValueType m_dx_backward[Self::ImageDimension];
122 
124  };
125 
128  const FloatOffsetType &, GlobalDataStruct * = 0) const
129  { return m_ZeroVectorConstant; }
130 
134  const NeighborhoodType &,
135  const FloatOffsetType &, GlobalDataStruct * = 0) const
137 
141  const FloatOffsetType &, GlobalDataStruct * = nullptr
142  ) const
144 
148  const NeighborhoodType &,
149  const FloatOffsetType &, GlobalDataStruct * = 0) const
151 
153  virtual void SetAdvectionWeight(const ScalarValueType a)
154  { m_AdvectionWeight = a; }
156  { return m_AdvectionWeight; }
158 
160  virtual void SetPropagationWeight(const ScalarValueType p)
161  { m_PropagationWeight = p; }
163  { return m_PropagationWeight; }
165 
167  virtual void SetCurvatureWeight(const ScalarValueType c)
168  { m_CurvatureWeight = c; }
170  { return m_CurvatureWeight; }
172 
175  { m_LaplacianSmoothingWeight = c; }
177  { return m_LaplacianSmoothingWeight; }
179 
182  { m_EpsilonMagnitude = e; }
184  { return m_EpsilonMagnitude; }
186 
188  PixelType ComputeUpdate( const NeighborhoodType & neighborhood,
189  void *globalData,
190  const FloatOffsetType & = FloatOffsetType(0.0) ) override;
191 
198  TimeStepType ComputeGlobalTimeStep(void *GlobalData) const override;
199 
207  void * GetGlobalDataPointer() const override
208  {
209  auto * ans = new GlobalDataStruct();
210 
211  ans->m_MaxAdvectionChange = NumericTraits< ScalarValueType >::ZeroValue();
212  ans->m_MaxPropagationChange = NumericTraits< ScalarValueType >::ZeroValue();
213  ans->m_MaxCurvatureChange = NumericTraits< ScalarValueType >::ZeroValue();
214  return ans;
215  }
216 
220  virtual void Initialize(const RadiusType & r);
221 
226  void ReleaseGlobalDataPointer(void *GlobalData) const override
227  { delete (GlobalDataStruct *)GlobalData; }
228 
230  virtual ScalarValueType ComputeCurvatureTerm(const NeighborhoodType &,
231  const FloatOffsetType &,
232  GlobalDataStruct *gd = 0
233  );
234 
235  virtual ScalarValueType ComputeMeanCurvature(const NeighborhoodType &,
236  const FloatOffsetType &,
237  GlobalDataStruct *gd = 0
238  );
239 
240  virtual ScalarValueType ComputeMinimalCurvature(const NeighborhoodType &,
241  const FloatOffsetType &,
242  GlobalDataStruct *gd = 0
243  );
244 
245  virtual ScalarValueType Compute3DMinimalCurvature(const NeighborhoodType &,
246  const FloatOffsetType &,
247  GlobalDataStruct *gd = 0
248  );
249 
252  {
253  m_UseMinimalCurvature = b;
254  }
255 
257  {
258  return m_UseMinimalCurvature;
259  }
260 
262  {
263  this->SetUseMinimalCurvature(true);
264  }
265 
267  {
268  this->SetUseMinimalCurvature(false);
269  }
270 
275  static void SetMaximumCurvatureTimeStep(double n)
276  {
277  m_DT = n;
278  }
279 
281  {
282  return m_DT;
283  }
284 
289  static void SetMaximumPropagationTimeStep(double n)
290  {
291  m_WaveDT = n;
292  }
293 
295  {
296  return m_WaveDT;
297  }
298 
299 protected:
301  m_EpsilonMagnitude(static_cast< ScalarValueType >( 1.0e-5 )),
302  m_AdvectionWeight(NumericTraits< ScalarValueType >::ZeroValue()),
303  m_PropagationWeight(NumericTraits< ScalarValueType >::ZeroValue()),
304  m_CurvatureWeight(NumericTraits< ScalarValueType >::ZeroValue()),
305  m_LaplacianSmoothingWeight(NumericTraits< ScalarValueType >::ZeroValue())
306  {
307  }
308 
309  ~LevelSetFunction() override = default;
310  void PrintSelf(std::ostream & s, Indent indent) const override;
311 
313  static double m_WaveDT;
314  static double m_DT;
315 
317  std::slice x_slice[Self::ImageDimension];
318 
320  OffsetValueType m_Center{0};
321 
323  OffsetValueType m_xStride[Self::ImageDimension];
324 
325  bool m_UseMinimalCurvature{false};
326 
329  static VectorType InitializeZeroVectorConstant();
330 
333 
336 
339 
342 
345 
348 };
349 } // namespace itk
350 
351 #ifndef ITK_MANUAL_INSTANTIATION
352 #include "itkLevelSetFunction.hxx"
353 #endif
354 
355 #endif
static void SetMaximumCurvatureTimeStep(double n)
static VectorType m_ZeroVectorConstant
void * GetGlobalDataPointer() const override
Light weight base class for most itk classes.
The LevelSetFunction class is a generic function object which can be used to create a level set metho...
void ReleaseGlobalDataPointer(void *GlobalData) const override
Define numeric traits for std::vector.
static double GetMaximumCurvatureTimeStep()
ScalarValueType GetEpsilonMagnitude() const
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
ScalarValueType m_AdvectionWeight
bool GetUseMinimalCurvature() const
virtual ScalarValueType PropagationSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
virtual ScalarValueType LaplacianSmoothingSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
virtual ScalarValueType CurvatureSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=nullptr) const
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:51
ScalarValueType m_PropagationWeight
typename ConstNeighborhoodIterator< TImageType >::RadiusType RadiusType
static double GetMaximumPropagationTimeStep()
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
virtual void SetPropagationWeight(const ScalarValueType p)
ScalarValueType m_EpsilonMagnitude
ScalarValueType m_CurvatureWeight
typename Superclass::PixelType PixelType
ScalarValueType GetLaplacianSmoothingWeight() const
vnl_matrix_fixed< ScalarValueType, Self::ImageDimension, Self::ImageDimension > m_dxy
static constexpr double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:53
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ScalarValueType GetAdvectionWeight() const
virtual void SetCurvatureWeight(const ScalarValueType c)
virtual void SetAdvectionWeight(const ScalarValueType a)
ScalarValueType GetCurvatureWeight() const
static void SetMaximumPropagationTimeStep(double n)
void SetLaplacianSmoothingWeight(const ScalarValueType c)
signed long OffsetValueType
Definition: itkIntTypes.h:94
void SetUseMinimalCurvature(bool b)
void SetEpsilonMagnitude(const ScalarValueType e)
ScalarValueType GetPropagationWeight() const
virtual VectorType AdvectionField(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
ScalarValueType m_LaplacianSmoothingWeight