ITK  5.4.0
Insight Toolkit
itkRegionBasedLevelSetFunction.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 itkRegionBasedLevelSetFunction_h
19#define itkRegionBasedLevelSetFunction_h
20
23#include "vnl/vnl_matrix_fixed.h"
24
25namespace itk
26{
61template <typename TInput, // LevelSetImageType
62 typename TFeature, // FeatureImageType
63 typename TSharedData>
64class ITK_TEMPLATE_EXPORT RegionBasedLevelSetFunction : public FiniteDifferenceFunction<TInput>
65{
66public:
67 ITK_DISALLOW_COPY_AND_MOVE(RegionBasedLevelSetFunction);
68
74
75 static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
76
77 // itkNewMacro() is not provided since this is an abstract class.
78
80 itkOverrideGetNameOfClassMacro(RegionBasedLevelSetFunction);
81
83 using TimeStepType = double;
84 using typename Superclass::ImageType;
85 using typename Superclass::PixelType;
87 using typename Superclass::RadiusType;
88 using typename Superclass::NeighborhoodType;
90 using typename Superclass::FloatOffsetType;
92
93 /* This structure is derived from LevelSetFunction and stores intermediate
94 values for computing time step sizes */
96 {
98 {
99 ScalarValueType null_value{};
100
101 m_MaxCurvatureChange = null_value;
102 m_MaxAdvectionChange = null_value;
103 m_MaxGlobalChange = null_value;
104 }
105
106 ~GlobalDataStruct() = default;
107
108 vnl_matrix_fixed<ScalarValueType, Self::ImageDimension, Self::ImageDimension> m_dxy;
109
110 ScalarValueType m_dx[Self::ImageDimension];
111
112 ScalarValueType m_dx_forward[Self::ImageDimension];
113 ScalarValueType m_dx_backward[Self::ImageDimension];
114
117
121 };
122
123 using InputImageType = TInput;
126 using InputPixelType = typename InputImageType::PixelType;
133
134 using FeatureImageType = TFeature;
136 using FeaturePixelType = typename FeatureImageType::PixelType;
138 using FeatureSpacingType = typename FeatureImageType::SpacingType;
139 using FeatureOffsetType = typename FeatureImageType::OffsetType;
140
141 using SharedDataType = TSharedData;
143
146
147 void
149 {
150 this->m_DomainFunction = f;
151 }
152
153 virtual void
155 {
156 this->SetRadius(r);
157
158 // Dummy neighborhood.
160 it.SetRadius(r);
161
162 // Find the center index of the neighborhood.
163 m_Center = it.Size() / 2;
164
165 // Get the stride length for each axis.
166 for (unsigned int i = 0; i < ImageDimension; ++i)
167 {
168 m_xStride[i] = it.GetStride(i);
169 }
170 }
171
172#if !defined(ITK_WRAPPING_PARSER)
173 void
175 {
176 this->m_SharedData = sharedDataIn;
177 }
178#endif
179
180 void
181 UpdateSharedData(bool forceUpdate);
182
183 void *
184 GetGlobalDataPointer() const override
185 {
186 return new GlobalDataStruct;
187 }
188
189 TimeStepType
190 ComputeGlobalTimeStep(void * GlobalData) const override;
191
194 ComputeUpdate(const NeighborhoodType & neighborhood,
195 void * globalData,
196 const FloatOffsetType & = FloatOffsetType(0.0)) override;
197
198 void
200 {
201 m_InitialImage = f;
202 }
203
204 virtual const FeatureImageType *
206 {
207 return m_FeatureImage.GetPointer();
208 }
209 virtual void
211 {
212 m_FeatureImage = f;
213
214 FeatureSpacingType spacing = m_FeatureImage->GetSpacing();
215 for (unsigned int i = 0; i < ImageDimension; ++i)
216 {
217 this->m_InvSpacing[i] = 1 / spacing[i];
218 }
219 }
220
222 virtual VectorType
224 {
225 return this->m_ZeroVectorConstant;
226 }
227
229 void
231 {
232 this->m_AreaWeight = nu;
233 }
234 ScalarValueType
236 {
237 return this->m_AreaWeight;
238 }
242 void
244 {
245 this->m_Lambda1 = lambda1;
246 }
247 ScalarValueType
249 {
250 return this->m_Lambda1;
251 }
255 void
257 {
258 this->m_Lambda2 = lambda2;
259 }
260 ScalarValueType
262 {
263 return this->m_Lambda2;
264 }
268 void
270 {
271 this->m_OverlapPenaltyWeight = gamma;
272 }
273 ScalarValueType
275 {
276 return this->m_OverlapPenaltyWeight;
277 }
281 virtual void
283 {
284 m_CurvatureWeight = c;
285 }
286 ScalarValueType
288 {
289 return m_CurvatureWeight;
290 }
293 void
295 {
296 this->m_AdvectionWeight = iA;
297 }
298 ScalarValueType
300 {
301 return this->m_AdvectionWeight;
302 }
303
305 void
307 {
308 m_ReinitializationSmoothingWeight = c;
309 }
310 ScalarValueType
312 {
313 return m_ReinitializationSmoothingWeight;
314 }
318 void
320 {
321 this->m_VolumeMatchingWeight = tau;
322 }
323 ScalarValueType
325 {
326 return this->m_VolumeMatchingWeight;
327 }
331 void
333 {
334 this->m_Volume = volume;
335 }
336 ScalarValueType
337 GetVolume() const
338 {
339 return this->m_Volume;
340 }
344 void
345 SetFunctionId(const unsigned int iFid)
346 {
347 this->m_FunctionId = iFid;
348 }
349
350 void
351 ReleaseGlobalDataPointer(void * GlobalData) const override
352 {
353 delete (GlobalDataStruct *)GlobalData;
354 }
355
356 virtual ScalarValueType
358
361 virtual ScalarValueType
363 {
365 }
366
369 virtual ScalarValueType
371 {
373 }
374
379 virtual void
381 {}
382
383protected:
385 ~RegionBasedLevelSetFunction() override = default;
386
388 InputImageConstPointer m_InitialImage{};
389
391 FeatureImageConstPointer m_FeatureImage{};
392
393 SharedDataPointer m_SharedData{};
394
396
398 ScalarValueType m_AreaWeight{};
399
401 ScalarValueType m_Lambda1{};
402
404 ScalarValueType m_Lambda2{};
405
407 ScalarValueType m_OverlapPenaltyWeight{};
408
410 ScalarValueType m_VolumeMatchingWeight{};
411
413 ScalarValueType m_Volume{};
414
416 ScalarValueType m_CurvatureWeight{};
417
418 ScalarValueType m_AdvectionWeight{};
419
421 ScalarValueType m_ReinitializationSmoothingWeight{};
422
423 unsigned int m_FunctionId{};
424
425 std::slice x_slice[Self::ImageDimension];
426 OffsetValueType m_Center{};
427 OffsetValueType m_xStride[Self::ImageDimension]{};
428 double m_InvSpacing[Self::ImageDimension]{};
429
430 static double m_WaveDT;
431 static double m_DT;
432
433 void
435
439 ComputeGlobalTerm(const ScalarValueType & imagePixel, const InputIndexType & inputIndex);
440
445 virtual ScalarValueType
446 ComputeInternalTerm(const FeaturePixelType & iValue, const FeatureIndexType & iIdx) = 0;
447
451 virtual ScalarValueType
452 ComputeExternalTerm(const FeaturePixelType & iValue, const FeatureIndexType & iIdx) = 0;
453
458 virtual ScalarValueType
460
467
482
484 void
486
488 virtual void
490
493 virtual void
495
496 bool m_UpdateC{};
497
500 static VectorType
502
505};
506} // end namespace itk
507
508#ifndef ITK_MANUAL_INSTANTIATION
509# include "itkRegionBasedLevelSetFunction.hxx"
510#endif
511
512#endif
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
typename ConstNeighborhoodIterator< TInput >::RadiusType RadiusType
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:54
Base class of the Heaviside function.
Light weight base class for most itk classes.
void SetRadius(const SizeType &)
NeighborIndexType Size() const
OffsetValueType GetStride(DimensionValueType axis) const
LevelSet function that computes a speed image based on regional integrals.
void SetSharedData(SharedDataPointer sharedDataIn)
typename InputImageType::SizeType InputSizeType
typename FeatureImageType::SpacingType FeatureSpacingType
virtual ScalarValueType ComputeInternalTerm(const FeaturePixelType &iValue, const FeatureIndexType &iIdx)=0
Compute the internal term.
typename InputImageType::ConstPointer InputImageConstPointer
typename InputImageType::PixelType InputPixelType
~RegionBasedLevelSetFunction() override=default
virtual void SetFeatureImage(const FeatureImageType *f)
void SetOverlapPenaltyWeight(const ScalarValueType &gamma)
typename InputImageType::RegionType InputRegionType
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...
ScalarValueType ComputeVolumeRegularizationTerm()
Compute the overlap term.
TimeStepType ComputeGlobalTimeStep(void *GlobalData) const override
typename InputImageType::Pointer InputImagePointer
typename FeatureImageType::PixelType FeaturePixelType
typename FeatureImageType::IndexType FeatureIndexType
typename InputImageType::SizeValueType InputSizeValueType
void ReleaseGlobalDataPointer(void *GlobalData) const override
typename SharedDataType::Pointer SharedDataPointer
virtual const FeatureImageType * GetFeatureImage() const
ScalarValueType ComputeGlobalTerm(const ScalarValueType &imagePixel, const InputIndexType &inputIndex)
Compute the global term as a combination of the internal, external, overlapping and volume regulariza...
typename InputImageType::IndexType InputIndexType
virtual ScalarValueType ComputeExternalTerm(const FeaturePixelType &iValue, const FeatureIndexType &iIdx)=0
Compute the external term.
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...
void SetLambda2(const ScalarValueType &lambda2)
void SetVolumeMatchingWeight(const ScalarValueType &tau)
typename FeatureImageType::ConstPointer FeatureImageConstPointer
ScalarValueType GetReinitializationSmoothingWeight() const
virtual VectorType AdvectionField(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
PixelType ComputeUpdate(const NeighborhoodType &neighborhood, void *globalData, const FloatOffsetType &=FloatOffsetType(0.0)) override
void SetLambda1(const ScalarValueType &lambda1)
virtual ScalarValueType ComputeCurvature(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *gd)
void UpdateSharedData(bool forceUpdate)
void SetReinitializationSmoothingWeight(const ScalarValueType c)
void SetAdvectionWeight(const ScalarValueType &iA)
typename HeavisideFunctionType::ConstPointer HeavisideFunctionConstPointer
virtual void Initialize(const RadiusType &r)
typename InputImageType::IndexValueType InputIndexValueType
virtual void ComputeParameters()=0
Compute Parameters for the inner and outer parts.
void SetVolume(const ScalarValueType &volume)
void SetAreaWeight(const ScalarValueType &nu)
static VectorType InitializeZeroVectorConstant()
virtual void SetCurvatureWeight(const ScalarValueType c)
typename InputImageType::PointType InputPointType
virtual void UpdateSharedDataParameters()=0
Update and save the inner and outer parameters in the shared data structure.
void SetDomainFunction(const HeavisideFunctionType *f)
typename FeatureImageType::OffsetType FeatureOffsetType
virtual ScalarValueType ComputeOverlapParameters(const FeatureIndexType &featIndex, ScalarValueType &pr)=0
Compute the overlap term.
void ComputeHessian(const NeighborhoodType &it, GlobalDataStruct *globalData)
Compute Hessian Matrix.
ScalarValueType ComputeLaplacian(GlobalDataStruct *gd)
Compute the laplacian term.
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:63
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long IndexValueType
Definition: itkIntTypes.h:90
unsigned long SizeValueType
Definition: itkIntTypes.h:83
long OffsetValueType
Definition: itkIntTypes.h:94
vnl_matrix_fixed< ScalarValueType, Self::ImageDimension, Self::ImageDimension > m_dxy