ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkRegionBasedLevelSetFunction.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 itkRegionBasedLevelSetFunction_h
19 #define itkRegionBasedLevelSetFunction_h
20 
23 #include "vnl/vnl_matrix_fixed.h"
24 
25 namespace itk
26 {
64 template< typename TInput, // LevelSetImageType
65  typename TFeature, // FeatureImageType
66  typename TSharedData >
67 class ITK_TEMPLATE_EXPORT RegionBasedLevelSetFunction:public
68  FiniteDifferenceFunction< TInput >
69 {
70 public:
71  ITK_DISALLOW_COPY_AND_ASSIGN(RegionBasedLevelSetFunction);
72 
78 
79  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
80 
81  // itkNewMacro() is not provided since this is an abstract class.
82 
85 
87  using TimeStepType = double;
88  using ImageType = typename Superclass::ImageType;
89  using PixelType = typename Superclass::PixelType;
91  using RadiusType = typename Superclass::RadiusType;
92  using NeighborhoodType = typename Superclass::NeighborhoodType;
93  using NeighborhoodScalesType = typename Superclass::NeighborhoodScalesType;
94  using FloatOffsetType = typename Superclass::FloatOffsetType;
95  using VectorType =
97 
98  /* This structure is derived from LevelSetFunction and stores intermediate
99  values for computing time step sizes */
102  {
104 
105  m_MaxCurvatureChange = null_value;
106  m_MaxAdvectionChange = null_value;
107  m_MaxGlobalChange = null_value;
108  }
109 
111 
112  vnl_matrix_fixed< ScalarValueType,
113  Self::ImageDimension,
114  Self::ImageDimension > m_dxy;
115 
116  ScalarValueType m_dx[Self::ImageDimension];
117 
118  ScalarValueType m_dx_forward[Self::ImageDimension];
119  ScalarValueType m_dx_backward[Self::ImageDimension];
120 
123 
127  };
128 
129  using InputImageType = TInput;
130  using InputImageConstPointer = typename InputImageType::ConstPointer;
131  using InputImagePointer = typename InputImageType::Pointer;
132  using InputPixelType = typename InputImageType::PixelType;
139 
140  using FeatureImageType = TFeature;
141  using FeatureImageConstPointer = typename FeatureImageType::ConstPointer;
142  using FeaturePixelType = typename FeatureImageType::PixelType;
144  using FeatureSpacingType = typename FeatureImageType::SpacingType;
145  using FeatureOffsetType = typename FeatureImageType::OffsetType;
146 
147  using SharedDataType = TSharedData;
148  using SharedDataPointer = typename SharedDataType::Pointer;
149 
152 
154  {
155  this->m_DomainFunction = f;
156  }
157 
158  virtual void Initialize(const RadiusType & r)
159  {
160  this->SetRadius(r);
161 
162  // Dummy neighborhood.
163  NeighborhoodType it;
164  it.SetRadius(r);
165 
166  // Find the center index of the neighborhood.
167  m_Center = it.Size() / 2;
168 
169  // Get the stride length for each axis.
170  for ( unsigned int i = 0; i < ImageDimension; i++ )
171  {
172  m_xStride[i] = it.GetStride(i);
173  }
174  }
175 
176 #if !defined( ITK_WRAPPING_PARSER )
177  void SetSharedData(SharedDataPointer sharedDataIn)
178  {
179  this->m_SharedData = sharedDataIn;
180  }
181 #endif
182 
183  void UpdateSharedData(bool forceUpdate);
184 
185  void * GetGlobalDataPointer() const override
186  {
187  return new GlobalDataStruct;
188  }
189 
190  TimeStepType ComputeGlobalTimeStep(void *GlobalData) const override;
191 
193  PixelType ComputeUpdate( const NeighborhoodType & neighborhood,
194  void *globalData, const FloatOffsetType & = FloatOffsetType(0.0) ) override;
195 
197  {
198  m_InitialImage = f;
199  }
200 
201  virtual const FeatureImageType * GetFeatureImage() const
202  { return m_FeatureImage.GetPointer(); }
203  virtual void SetFeatureImage(const FeatureImageType *f)
204  {
205  m_FeatureImage = f;
206 
207  FeatureSpacingType spacing = m_FeatureImage->GetSpacing();
208  for ( unsigned int i = 0; i < ImageDimension; i++ )
209  {
210  this->m_InvSpacing[i] = 1 / spacing[i];
211  }
212  }
213 
216  const FloatOffsetType &, GlobalDataStruct * = 0) const
217  { return this->m_ZeroVectorConstant; }
218 
221  { this->m_AreaWeight = nu; }
223  { return this->m_AreaWeight; }
225 
227  void SetLambda1(const ScalarValueType & lambda1)
228  { this->m_Lambda1 = lambda1; }
230  { return this->m_Lambda1; }
232 
234  void SetLambda2(const ScalarValueType & lambda2)
235  { this->m_Lambda2 = lambda2; }
237  { return this->m_Lambda2; }
239 
242  { this->m_OverlapPenaltyWeight = gamma; }
244  { return this->m_OverlapPenaltyWeight; }
246 
248  virtual void SetCurvatureWeight(const ScalarValueType c)
249  { m_CurvatureWeight = c; }
251  { return m_CurvatureWeight; }
253 
255  { this->m_AdvectionWeight = iA; }
257  { return this->m_AdvectionWeight; }
258 
261  { m_ReinitializationSmoothingWeight = c; }
263  { return m_ReinitializationSmoothingWeight; }
265 
268  { this->m_VolumeMatchingWeight = tau; }
270  { return this->m_VolumeMatchingWeight; }
272 
274  void SetVolume(const ScalarValueType & volume)
275  { this->m_Volume = volume; }
277  { return this->m_Volume; }
279 
281  void SetFunctionId(const unsigned int & iFid)
282  { this->m_FunctionId = iFid; }
283 
284  void ReleaseGlobalDataPointer(void *GlobalData) const override
285  { delete (GlobalDataStruct *)GlobalData; }
286 
287  virtual ScalarValueType ComputeCurvature(const NeighborhoodType &,
288  const FloatOffsetType &, GlobalDataStruct *gd);
289 
293  const NeighborhoodType &,
294  const FloatOffsetType &, GlobalDataStruct * = 0) const
296 
300  const FloatOffsetType &, GlobalDataStruct * = 0
301  ) const
303 
308  virtual void CalculateAdvectionImage() {}
309 
310 protected:
311 
314 
317 
320 
322 
324 
327 
330 
333 
336 
339 
342 
345 
347 
350 
351  unsigned int m_FunctionId;
352 
353  std::slice x_slice[Self::ImageDimension];
355  OffsetValueType m_xStride[Self::ImageDimension];
356  double m_InvSpacing[Self::ImageDimension];
357 
358  static double m_WaveDT;
359  static double m_DT;
360 
361  void ComputeHImage();
362 
365  ScalarValueType ComputeGlobalTerm(
366  const ScalarValueType & imagePixel,
367  const InputIndexType & inputIndex);
368 
373  virtual ScalarValueType ComputeInternalTerm(const FeaturePixelType & iValue,
374  const FeatureIndexType & iIdx) = 0;
375 
379  virtual ScalarValueType ComputeExternalTerm(const FeaturePixelType & iValue,
380  const FeatureIndexType & iIdx) = 0;
381 
386  virtual ScalarValueType ComputeOverlapParameters(const FeatureIndexType & featIndex,
387  ScalarValueType & pr) = 0;
388 
393  ScalarValueType ComputeVolumeRegularizationTerm();
394 
407  ScalarValueType ComputeLaplacian(GlobalDataStruct *gd);
408 
410  void ComputeHessian(const NeighborhoodType & it,
411  GlobalDataStruct *globalData);
412 
414  virtual void ComputeParameters() = 0;
415 
418  virtual void UpdateSharedDataParameters() = 0;
419 
420  bool m_UpdateC;
421 
424  static VectorType InitializeZeroVectorConstant();
425 
428 };
429 } // end namespace itk
430 
431 #ifndef ITK_MANUAL_INSTANTIATION
432 #include "itkRegionBasedLevelSetFunction.hxx"
433 #endif
434 
435 #endif
virtual ScalarValueType LaplacianSmoothingSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
Laplacian smoothing speed can be used to spatially modify the effects of laplacian smoothing of the l...
Light weight base class for most itk classes.
Define numeric traits for std::vector.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
void SetVolume(const ScalarValueType &volume)
OffsetValueType GetStride(DimensionValueType axis) const
void SetAreaWeight(const ScalarValueType &nu)
void SetReinitializationSmoothingWeight(const ScalarValueType c)
virtual void SetCurvatureWeight(const ScalarValueType c)
virtual const FeatureImageType * GetFeatureImage() const
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
void SetAdvectionWeight(const ScalarValueType &iA)
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:51
NeighborIndexType Size() const
typename ConstNeighborhoodIterator< TInputImage >::RadiusType RadiusType
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
signed long IndexValueType
Definition: itkIntTypes.h:90
void SetLambda1(const ScalarValueType &lambda1)
virtual ScalarValueType CurvatureSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
Curvature speed can be used to spatially modify the effects of curvature . The default implementation...
HeavisideFunctionConstPointer m_DomainFunction
void SetSharedData(SharedDataPointer sharedDataIn)
virtual void Initialize(const RadiusType &r)
void SetVolumeMatchingWeight(const ScalarValueType &tau)
virtual void SetFeatureImage(const FeatureImageType *f)
vnl_matrix_fixed< ScalarValueType, Self::ImageDimension, Self::ImageDimension > m_dxy
void SetLambda2(const ScalarValueType &lambda2)
void SetFunctionId(const unsigned int &iFid)
virtual VectorType AdvectionField(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
void ReleaseGlobalDataPointer(void *GlobalData) const override
void SetDomainFunction(const HeavisideFunctionType *f)
void SetRadius(const SizeType &)
void SetOverlapPenaltyWeight(const ScalarValueType &gamma)
signed long OffsetValueType
Definition: itkIntTypes.h:94
ScalarValueType GetReinitializationSmoothingWeight() const
LevelSet function that computes a speed image based on regional integrals.
Base class of the Heaviside function.