18 #ifndef itkMultiphaseFiniteDifferenceImageFilter_h
19 #define itkMultiphaseFiniteDifferenceImageFilter_h
23 #include "vnl/vnl_vector.h"
157 template <
typename TInputImage,
158 typename TFeatureImage,
159 typename TOutputImage,
160 typename TFiniteDifferenceFunction = FiniteDifferenceFunction<TOutputImage>,
161 typename TIdCell =
unsigned int>
177 static constexpr
unsigned int ImageDimension = TOutputImage::ImageDimension;
218 using TimeStepType =
typename FiniteDifferenceFunctionType::TimeStepType;
220 using RadiusType =
typename FiniteDifferenceFunctionType::RadiusType;
236 if (functionIndex < m_FunctionCount)
238 return (this->m_DifferenceFunctions[functionIndex]);
254 if (functionIndex < m_FunctionCount)
256 this->m_DifferenceFunctions[functionIndex] =
function;
262 itkSetMacro(NumberOfIterations,
unsigned int);
263 itkGetConstReferenceMacro(NumberOfIterations,
unsigned int);
268 itkSetMacro(UseImageSpacing,
bool);
269 itkBooleanMacro(UseImageSpacing);
270 itkGetConstReferenceMacro(UseImageSpacing,
bool);
275 itkSetMacro(MaximumRMSError,
double);
276 itkGetConstReferenceMacro(MaximumRMSError,
double);
281 itkSetMacro(RMSChange,
double);
282 itkGetConstReferenceMacro(RMSChange,
double);
286 itkSetMacro(InitializedState,
bool);
287 itkGetConstReferenceMacro(InitializedState,
bool);
288 itkBooleanMacro(InitializedState);
293 itkSetMacro(ManualReinitialization,
bool);
294 itkGetConstReferenceMacro(ManualReinitialization,
bool);
295 itkBooleanMacro(ManualReinitialization);
299 itkSetMacro(ElapsedIterations,
unsigned int);
302 itkGetConstReferenceMacro(ElapsedIterations,
unsigned int);
308 m_LevelSet[i]->SetRequestedRegion(levelSet->GetRequestedRegion());
309 m_LevelSet[i]->SetBufferedRegion(levelSet->GetBufferedRegion());
310 m_LevelSet[i]->SetLargestPossibleRegion(levelSet->GetLargestPossibleRegion());
311 m_LevelSet[i]->Allocate();
312 m_LevelSet[i]->CopyInformation(levelSet);
320 while (!in.IsAtEnd())
331 if (i >= m_FunctionCount)
333 itkExceptionMacro(
"Request for level set #" << i <<
" but there are only " << m_FunctionCount);
337 return m_LevelSet[i];
344 this->m_Lookup = lookup;
350 this->m_KdTree = kdtree;
358 m_DifferenceFunctions.resize(m_FunctionCount,
nullptr);
360 constexpr
auto radius = MakeFilled<RadiusType>(1);
362 for (
unsigned int i = 0; i < this->m_FunctionCount; ++i)
365 this->m_DifferenceFunctions[i]->Initialize(radius);
369 m_LevelSet.resize(m_FunctionCount,
nullptr);
372 this->m_Lookup.resize(m_FunctionCount);
377 auto it = this->m_Lookup.begin();
378 auto _end = this->m_Lookup.end();
391 this->m_KdTree =
nullptr;
392 this->m_ElapsedIterations = 0;
395 this->m_UseImageSpacing =
true;
396 this->m_ManualReinitialization =
false;
397 this->m_InitializedState =
false;
399 this->m_FunctionCount = 0;
406 std::vector<InputImagePointer> m_LevelSet{};
410 unsigned int m_ElapsedIterations{};
411 double m_MaximumRMSError{};
412 double m_RMSChange{};
413 unsigned int m_NumberOfIterations{};
416 std::vector<FiniteDifferenceFunctionPointer> m_DifferenceFunctions{};
420 bool m_UseImageSpacing{};
423 PrintSelf(std::ostream & os,
Indent indent)
const override;
427 AllocateUpdateBuffer() = 0;
433 ApplyUpdate(TimeStepType dt) = 0;
441 CalculateChange() = 0;
447 CopyInputToOutput() = 0;
453 GenerateData()
override;
467 GenerateInputRequestedRegion()
override;
507 for (
IdCellType i = 0; i < this->m_FunctionCount; ++i)
509 this->m_DifferenceFunctions[i]->InitializeIteration();
528 ResolveTimeStep(
const TimeStepVectorType & timeStepList,
const std::vector<uint8_t> & valid);
539 bool m_ManualReinitialization{};
542 bool m_InitializedState{};
546 #ifndef ITK_MANUAL_INSTANTIATION
547 # include "itkMultiphaseFiniteDifferenceImageFilter.hxx"