ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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{
57template <typename TInput, // LevelSetImageType
58 typename TFeature, // FeatureImageType
59 typename TSharedData>
60class ITK_TEMPLATE_EXPORT RegionBasedLevelSetFunction : public FiniteDifferenceFunction<TInput>
61{
62public:
63 ITK_DISALLOW_COPY_AND_MOVE(RegionBasedLevelSetFunction);
64
70
71 static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
72
73 // itkNewMacro() is not provided since this is an abstract class.
74
76 itkOverrideGetNameOfClassMacro(RegionBasedLevelSetFunction);
77
79 using TimeStepType = double;
80 using typename Superclass::ImageType;
81 using typename Superclass::PixelType;
83 using typename Superclass::RadiusType;
84 using typename Superclass::NeighborhoodType;
86 using typename Superclass::FloatOffsetType;
88
89 /* This structure is derived from LevelSetFunction and stores intermediate
90 values for computing time step sizes */
118
119 using InputImageType = TInput;
120 using InputImageConstPointer = typename InputImageType::ConstPointer;
121 using InputImagePointer = typename InputImageType::Pointer;
122 using InputPixelType = typename InputImageType::PixelType;
123 using InputIndexType = typename InputImageType::IndexType;
124 using InputIndexValueType = typename InputImageType::IndexValueType;
125 using InputSizeType = typename InputImageType::SizeType;
126 using InputSizeValueType = typename InputImageType::SizeValueType;
127 using InputRegionType = typename InputImageType::RegionType;
128 using InputPointType = typename InputImageType::PointType;
129
130 using FeatureImageType = TFeature;
131 using FeatureImageConstPointer = typename FeatureImageType::ConstPointer;
132 using FeaturePixelType = typename FeatureImageType::PixelType;
133 using FeatureIndexType = typename FeatureImageType::IndexType;
134 using FeatureSpacingType = typename FeatureImageType::SpacingType;
135 using FeatureOffsetType = typename FeatureImageType::OffsetType;
136
137 using SharedDataType = TSharedData;
138 using SharedDataPointer = typename SharedDataType::Pointer;
139
142
143 void
145 {
146 this->m_DomainFunction = f;
147 }
148
149 virtual void
151 {
152 this->SetRadius(r);
153
154 // Dummy neighborhood.
156 it.SetRadius(r);
157
158 // Find the center index of the neighborhood.
159 m_Center = it.Size() / 2;
160
161 // Get the stride length for each axis.
162 for (unsigned int i = 0; i < ImageDimension; ++i)
163 {
164 m_xStride[i] = it.GetStride(i);
165 }
166 }
167
168#if !defined(ITK_WRAPPING_PARSER)
169 void
171 {
172 this->m_SharedData = sharedDataIn;
173 }
174#endif
175
176 void
177 UpdateSharedData(bool forceUpdate);
178
179 void *
180 GetGlobalDataPointer() const override
181 {
182 return new GlobalDataStruct;
183 }
184
185 TimeStepType
186 ComputeGlobalTimeStep(void * GlobalData) const override;
187
190 ComputeUpdate(const NeighborhoodType & neighborhood,
191 void * globalData,
192 const FloatOffsetType & = FloatOffsetType(0.0)) override;
193
194 void
199
200 virtual const FeatureImageType *
202 {
203 return m_FeatureImage.GetPointer();
204 }
205 virtual void
207 {
208 m_FeatureImage = f;
209
210 FeatureSpacingType spacing = m_FeatureImage->GetSpacing();
211 for (unsigned int i = 0; i < ImageDimension; ++i)
212 {
213 this->m_InvSpacing[i] = 1 / spacing[i];
214 }
215 }
216
218 virtual VectorType
219 AdvectionField(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct * = 0) const
220 {
221 return this->m_ZeroVectorConstant;
222 }
223
225 void
227 {
228 this->m_AreaWeight = nu;
229 }
230 ScalarValueType
232 {
233 return this->m_AreaWeight;
234 }
235
236
238 void
240 {
241 this->m_Lambda1 = lambda1;
242 }
243 ScalarValueType
245 {
246 return this->m_Lambda1;
247 }
248
249
251 void
253 {
254 this->m_Lambda2 = lambda2;
255 }
256 ScalarValueType
258 {
259 return this->m_Lambda2;
260 }
261
262
264 void
266 {
267 this->m_OverlapPenaltyWeight = gamma;
268 }
269 ScalarValueType
271 {
272 return this->m_OverlapPenaltyWeight;
273 }
274
275
277 virtual void
282 ScalarValueType
284 {
285 return m_CurvatureWeight;
286 }
287
288
289 void
291 {
292 this->m_AdvectionWeight = iA;
293 }
294 ScalarValueType
296 {
297 return this->m_AdvectionWeight;
298 }
299
301 void
306 ScalarValueType
311
312
314 void
316 {
317 this->m_VolumeMatchingWeight = tau;
318 }
319 ScalarValueType
321 {
322 return this->m_VolumeMatchingWeight;
323 }
324
325
327 void
329 {
330 this->m_Volume = volume;
331 }
332 ScalarValueType
333 GetVolume() const
334 {
335 return this->m_Volume;
336 }
337
338
340 void
341 SetFunctionId(const unsigned int iFid)
342 {
343 this->m_FunctionId = iFid;
344 }
345
346 void
347 ReleaseGlobalDataPointer(void * GlobalData) const override
348 {
349 delete (GlobalDataStruct *)GlobalData;
350 }
351
352 virtual ScalarValueType
353 ComputeCurvature(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct * gd);
354
357 virtual ScalarValueType
358 LaplacianSmoothingSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct * = 0) const
359 {
361 }
362
365 virtual ScalarValueType
366 CurvatureSpeed(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct * = 0) const
367 {
369 }
370
375 virtual void
378
379protected:
381 ~RegionBasedLevelSetFunction() override = default;
382
385
388
390
392
395
398
401
404
407
410
413
415
418
419 unsigned int m_FunctionId{};
420
425
426 static double m_WaveDT;
427 static double m_DT;
428
429 void
431
435 ComputeGlobalTerm(const ScalarValueType & imagePixel, const InputIndexType & inputIndex);
436
441 virtual ScalarValueType
442 ComputeInternalTerm(const FeaturePixelType & iValue, const FeatureIndexType & iIdx) = 0;
443
447 virtual ScalarValueType
448 ComputeExternalTerm(const FeaturePixelType & iValue, const FeatureIndexType & iIdx) = 0;
449
454 virtual ScalarValueType
456
463
468
472 ComputeLaplacian(GlobalDataStruct * gd);
473
475 void
476 ComputeHessian(const NeighborhoodType & it, GlobalDataStruct * globalData);
477
479 virtual void
481
484 virtual void
486
487 bool m_UpdateC{};
488
491 static VectorType
493
496};
497} // end namespace itk
498
499#ifndef ITK_MANUAL_INSTANTIATION
500# include "itkRegionBasedLevelSetFunction.hxx"
501#endif
502
503#endif
ConstNeighborhoodIterator< TInput, DefaultBoundaryConditionType > NeighborhoodType
static constexpr unsigned int ImageDimension
Vector< float, Self::ImageDimension > FloatOffsetType
Vector< PixelRealType, Self::ImageDimension > NeighborhoodScalesType
typename ConstNeighborhoodIterator< TInput >::RadiusType RadiusType
void SetRadius(const RadiusType &r)
Simulate a standard C array with copy semantics.
Base class of the Heaviside function.
void SetRadius(const SizeType &)
NeighborIndexType Size() const
OffsetValueType GetStride(DimensionValueType axis) const
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.
HeavisideStepFunctionBase< InputPixelType, InputPixelType > HeavisideFunctionType
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
virtual VectorType AdvectionField(const NeighborhoodType &, const FloatOffsetType &, GlobalDataStruct *=0) const
PixelType ComputeUpdate(const NeighborhoodType &neighborhood, void *globalData, const FloatOffsetType &=FloatOffsetType(0.0)) override
FixedArray< ScalarValueType, Self::ImageDimension > VectorType
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)
FiniteDifferenceFunction< TInput > Superclass
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.
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long OffsetValueType
Definition itkIntTypes.h:97
vnl_matrix_fixed< ScalarValueType, Self::ImageDimension, Self::ImageDimension > m_dxy