ITK  6.0.0
Insight Toolkit
itkMultiphaseSparseFiniteDifferenceImageFilter.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 itkMultiphaseSparseFiniteDifferenceImageFilter_h
19 #define itkMultiphaseSparseFiniteDifferenceImageFilter_h
20 
27 
28 #include <vector>
29 
30 namespace itk
31 {
173 template <typename TInputImage,
174  typename TFeatureImage,
175  typename TOutputImage,
176  typename TFunction,
177  typename TIdCell = unsigned int>
179  : public MultiphaseFiniteDifferenceImageFilter<TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell>
180 {
181 public:
182  ITK_DISALLOW_COPY_AND_MOVE(MultiphaseSparseFiniteDifferenceImageFilter);
187  using Superclass =
191 
193  itkNewMacro(Self);
194 
196  itkOverrideGetNameOfClassMacro(MultiphaseSparseFiniteDifferenceImageFilter);
197 
198  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
199 
201  using typename Superclass::TimeStepType;
202 
204  using typename Superclass::InputImageType;
205  using typename Superclass::InputImagePointer;
206  using typename Superclass::InputRegionType;
207  using typename Superclass::InputSizeType;
208  using typename Superclass::InputSizeValueType;
209  using typename Superclass::InputIndexType;
210  using typename Superclass::InputIndexValueType;
211  using typename Superclass::InputPixelType;
212  using typename Superclass::InputPointType;
213  using typename Superclass::InputSpacingType;
214  using typename Superclass::InputOffsetValueType;
215 
216  using typename Superclass::FeatureImageType;
217  using typename Superclass::FeatureSizeType;
218  using typename Superclass::FeatureImagePointer;
219  using typename Superclass::FeatureRegionType;
220  using typename Superclass::FeatureSpacingType;
221  using typename Superclass::FeaturePointType;
222 
223  using typename Superclass::OutputImageType;
224  using typename Superclass::OutputImagePointer;
225  using typename Superclass::OutputRegionType;
226  using typename Superclass::OutputSizeType;
227  using typename Superclass::OutputIndexType;
228  using typename Superclass::OutputIndexValueType;
229  using typename Superclass::OutputPixelType;
230 
231  using ValueType = typename InputImageType::ValueType;
232  using typename Superclass::IdCellType;
233 
234  using typename Superclass::FiniteDifferenceFunctionType;
235  using typename Superclass::FiniteDifferenceFunctionPointer;
236  using FiniteDifferenceFunctionFloatOffsetType = typename FiniteDifferenceFunctionType::FloatOffsetType;
237 
240 
246 
248  using LayerListType = std::vector<LayerPointerType>;
249  using LayerListIterator = typename LayerListType::iterator;
250  using LayerListConstIterator = typename LayerListType::const_iterator;
251 
253  using StatusType = signed char;
254 
259 
262 
264 
269 
271  using UpdateBufferType = std::vector<ValueType>;
272  using UpdateBufferConstIterator = typename UpdateBufferType::const_iterator;
273 
276 
280  itkSetMacro(NumberOfLayers, unsigned int);
281  itkGetConstMacro(NumberOfLayers, unsigned int);
285  itkSetMacro(IsoSurfaceValue, ValueType);
286  itkGetConstMacro(IsoSurfaceValue, ValueType);
293  itkSetMacro(InterpolateSurfaceLocation, bool);
294  itkGetConstMacro(InterpolateSurfaceLocation, bool);
295  itkBooleanMacro(InterpolateSurfaceLocation);
298  void
300  {
301  this->Superclass::SetFunctionCount(n);
302 
303  m_SparseData.resize(this->m_FunctionCount, nullptr);
304 
305  for (IdCellType i = 0; i < this->m_FunctionCount; ++i)
306  {
307  m_SparseData[i] = new SparseDataStruct(i);
308  }
309  }
310 
311 #ifdef ITK_USE_CONCEPT_CHECKING
312  // Begin concept checking
316  // End concept checking
317 #endif
318 
319 protected:
322  {
323  while (!m_SparseData.empty())
324  {
325  delete m_SparseData.back();
326  m_SparseData.pop_back();
327  }
328  }
329 
330  void
331  PrintSelf(std::ostream & os, Indent indent) const override;
332 
333  // This data structure is created for each phase
335  {
337  {
338  m_LayerNodeStore = LayerNodeStorageType::New();
339  m_LayerNodeStore->SetGrowthStrategyToExponential();
340  m_Index = index;
341  }
342 
348 
351 
354 
358 
360  };
361 
363  NeighborListType m_NeighborList{};
364 
366  std::vector<ValueType> m_PixelDistance{};
367 
372  inline virtual ValueType
373  CalculateUpdateValue(const OutputIndexType & itkNotUsed(idx),
374  const TimeStepType & dt,
375  const ValueType & value,
376  const ValueType & change)
377  {
378  return (value + dt * change);
379  }
380 
384  void
385  PostProcessOutput() override;
386 
391  virtual void
392  InitializeBackgroundPixels();
393 
395  void
396  Initialize() override;
397 
402  void
403  CopyInputToOutput() override;
404 
406  void
408  {}
409 
412  void
413  ApplyUpdate(TimeStepType dt) override;
414 
417  TimeStepType
418  CalculateChange() override;
419 
423  void
424  ConstructLayer(SparseDataStruct * sparsePtr, StatusType from, StatusType to);
425 
430  void
431  ConstructActiveLayer();
432 
434  void
435  InitializeActiveLayerValues();
436 
439  void
440  InitializeBackgroundConstants();
441 
449  void
450  PropagateLayerValues(SparseDataStruct * sparsePtr, StatusType from, StatusType to, StatusType promote, int InOrOut);
451 
456  void
457  PropagateAllLayerValues();
458 
459  void
460  PropagateFunctionLayerValues(unsigned int functionIndex);
461 
465  void
466  UpdateActiveLayerValues(TimeStepType dt, LayerType * StatusUpList, LayerType * StatusDownList);
467 
469  void
470  ProcessStatusList(LayerType * InputList,
471  LayerType * OutputList,
472  StatusType ChangeToStatus,
473  StatusType SearchForStatus);
474 
476  void
477  ProcessOutsideList(LayerType * OutsideList, StatusType ChangeToStatus);
478 
479  void
480  InitializeIteration() override;
481 
482  virtual void
483  UpdatePixel(unsigned int itkNotUsed(functionIndex),
484  unsigned int itkNotUsed(idx),
485  NeighborhoodIterator<InputImageType> & itkNotUsed(iterator),
486  ValueType & itkNotUsed(newValue),
487  bool & itkNotUsed(status))
488  {}
489 
490  itkGetConstMacro(ValueZero, ValueType);
491  itkGetConstMacro(ValueOne, ValueType);
492 
495  static double m_ConstantGradientValue;
496 
498  static const ValueType m_ValueOne;
499 
501  static const ValueType m_ValueZero;
502 
506 
510 
514 
518 
521  static const StatusType m_StatusNull;
522 
523  std::vector<SparseDataStruct *> m_SparseData{};
524 
528  unsigned int m_NumberOfLayers{};
529 
531  ValueType m_IsoSurfaceValue{};
532 
534  ValueType m_BackgroundValue{};
535 
540  bool m_InterpolateSurfaceLocation{};
541 
542 private:
543  unsigned int m_CurrentFunctionIndex{};
544 
545  double m_RMSSum{ 0. };
546  unsigned int m_RMSCounter{ 0 };
547 
550  bool m_BoundsCheckingActive{};
551 };
552 } // end namespace itk
553 
554 #ifndef ITK_MANUAL_INSTANTIATION
555 # include "itkMultiphaseSparseFiniteDifferenceImageFilter.hxx"
556 #endif
557 
558 #endif
itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator
Splits an image into a main region and several "face" regions which are used to handle computations o...
Definition: itkNeighborhoodAlgorithm.h:63
itk::MultiphaseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >::OutputIndexType
typename OutputImageType::IndexType OutputIndexType
Definition: itkMultiphaseFiniteDifferenceImageFilter.h:207
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itkMultiphaseFiniteDifferenceImageFilter.h
itk::MultiphaseSparseFiniteDifferenceImageFilter::m_StatusActiveChangingDown
static const StatusType m_StatusActiveChangingDown
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:513
itk::Concept::OStreamWritable
Definition: itkConceptChecking.h:638
itk::ZeroCrossingImageFilter
This filter finds the closest pixel to the zero-crossings (sign changes) in a signed itk::Image.
Definition: itkZeroCrossingImageFilter.h:64
itkNeighborhoodAlgorithm.h
itk::MultiphaseSparseFiniteDifferenceImageFilter::~MultiphaseSparseFiniteDifferenceImageFilter
~MultiphaseSparseFiniteDifferenceImageFilter() override
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:321
itk::MultiphaseSparseFiniteDifferenceImageFilter::m_ConstantGradientValue
static double m_ConstantGradientValue
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:495
itk::MultiphaseSparseFiniteDifferenceImageFilter::SparseDataStruct::m_StatusImage
StatusImagePointer m_StatusImage
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:350
itk::MultiphaseSparseFiniteDifferenceImageFilter::LayerListConstIterator
typename LayerListType::const_iterator LayerListConstIterator
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:250
itk::MultiphaseSparseFiniteDifferenceImageFilter::m_ValueZero
static const ValueType m_ValueZero
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:501
itk::MultiphaseSparseFiniteDifferenceImageFilter::SetFunctionCount
void SetFunctionCount(const IdCellType &n)
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:299
itk::MultiphaseSparseFiniteDifferenceImageFilter::LayerConstIterator
typename LayerType::ConstIterator LayerConstIterator
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:245
itk::MultiphaseSparseFiniteDifferenceImageFilter::LayerListType
std::vector< LayerPointerType > LayerListType
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:248
itk::MultiphaseSparseFiniteDifferenceImageFilter::AllocateUpdateBuffer
void AllocateUpdateBuffer() override
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:407
itk::MultiphaseSparseFiniteDifferenceImageFilter::m_ValueOne
static const ValueType m_ValueOne
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:498
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ConstSparseFieldLayerIterator< NodeType >
itk::MultiphaseSparseFiniteDifferenceImageFilter::UpdateBufferType
std::vector< ValueType > UpdateBufferType
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:271
itk::SparseFieldCityBlockNeighborList< NeighborhoodIterator< OutputImageType > >::OffsetType
typename NeighborhoodType::OffsetType OffsetType
Definition: itkSparseFieldLevelSetImageFilter.h:77
itkImageRegionConstIterator.h
itk::SparseFieldLevelSetNode
Definition: itkSparseFieldLevelSetImageFilter.h:36
itkShiftScaleImageFilter.h
itk::MultiphaseSparseFiniteDifferenceImageFilter::SparseDataStruct::m_Layers
LayerListType m_Layers
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:347
itk::SparseFieldLayer
A very simple linked list that is used to manage nodes in a layer of a sparse field level-set solver.
Definition: itkSparseFieldLayer.h:162
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::SparseFieldCityBlockNeighborList< NeighborhoodIterator< OutputImageType > >
itk::ObjectStore
A specialized memory management object for allocating and destroying contiguous blocks of objects.
Definition: itkObjectStore.h:84
itk::MultiphaseSparseFiniteDifferenceImageFilter::ZeroCrossingFilterPointer
typename ZeroCrossingFilterType::Pointer ZeroCrossingFilterPointer
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:261
itk::MultiphaseSparseFiniteDifferenceImageFilter
This class implements a finite difference partial differential equation solver for evolving surfaces ...
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:178
itk::MultiphaseSparseFiniteDifferenceImageFilter::CalculateUpdateValue
virtual ValueType CalculateUpdateValue(const OutputIndexType &, const TimeStepType &dt, const ValueType &value, const ValueType &change)
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:373
itk::MultiphaseSparseFiniteDifferenceImageFilter::LayerListIterator
typename LayerListType::iterator LayerListIterator
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:249
itk::MultiphaseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >::TimeStepType
typename FiniteDifferenceFunctionType::TimeStepType TimeStepType
Definition: itkMultiphaseFiniteDifferenceImageFilter.h:218
itk::SparseFieldLayerIterator
The non-const version of the ConstSparseFieldLayerIterator.
Definition: itkSparseFieldLayer.h:94
itk::MultiphaseSparseFiniteDifferenceImageFilter::SparseDataStruct::SparseDataStruct
SparseDataStruct(const IdCellType &index)
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:336
itk::MultiphaseSparseFiniteDifferenceImageFilter::OffsetType
typename NeighborListType::OffsetType OffsetType
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:275
itk::MultiphaseSparseFiniteDifferenceImageFilter::LayerIterator
typename LayerType::Iterator LayerIterator
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:244
itk::MultiphaseSparseFiniteDifferenceImageFilter::m_StatusBoundaryPixel
static const StatusType m_StatusBoundaryPixel
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:517
itk::MultiphaseFiniteDifferenceImageFilter
Definition: itkMultiphaseFiniteDifferenceImageFilter.h:162
itk::MultiphaseSparseFiniteDifferenceImageFilter::SparseDataStruct
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:334
itk::MultiphaseSparseFiniteDifferenceImageFilter::SparseDataStruct::m_LayerNodeStore
LayerNodeStoragePointer m_LayerNodeStore
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:353
itk::MultiphaseSparseFiniteDifferenceImageFilter::StatusImagePointer
typename StatusImageType::Pointer StatusImagePointer
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:258
itk::NeighborhoodIterator
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Definition: itkNeighborhoodIterator.h:212
itk::MultiphaseSparseFiniteDifferenceImageFilter::LayerPointerType
typename LayerType::Pointer LayerPointerType
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:243
itk::MultiphaseSparseFiniteDifferenceImageFilter::m_StatusNull
static const StatusType m_StatusNull
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:521
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::MultiphaseSparseFiniteDifferenceImageFilter::StatusType
signed char StatusType
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:253
itk::MultiphaseSparseFiniteDifferenceImageFilter::SparseDataStruct::m_UpdateBuffer
UpdateBufferType m_UpdateBuffer
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:357
itk::MultiphaseSparseFiniteDifferenceImageFilter::SparseDataStruct::m_Index
IdCellType m_Index
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:359
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itkZeroCrossingImageFilter.h
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itk::MultiphaseSparseFiniteDifferenceImageFilter::LayerNodeStoragePointer
typename LayerNodeStorageType::Pointer LayerNodeStoragePointer
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:268
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::MultiphaseSparseFiniteDifferenceImageFilter::UpdatePixel
virtual void UpdatePixel(unsigned int, unsigned int, NeighborhoodIterator< InputImageType > &, ValueType &, bool &)
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:483
New
static Pointer New()
itk::MultiphaseSparseFiniteDifferenceImageFilter::m_StatusActiveChangingUp
static const StatusType m_StatusActiveChangingUp
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:509
itk::MultiphaseSparseFiniteDifferenceImageFilter::FiniteDifferenceFunctionFloatOffsetType
typename FiniteDifferenceFunctionType::FloatOffsetType FiniteDifferenceFunctionFloatOffsetType
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:236
itk::MultiphaseSparseFiniteDifferenceImageFilter::m_StatusChanging
static const StatusType m_StatusChanging
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:505
itkSparseFieldLevelSetImageFilter.h
itk::MultiphaseFiniteDifferenceImageFilter< TInputImage, TFeatureImage, TOutputImage, TFunction, TIdCell >::IdCellType
TIdCell IdCellType
Definition: itkMultiphaseFiniteDifferenceImageFilter.h:210
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:306
itk::MultiphaseSparseFiniteDifferenceImageFilter::ValueType
typename InputImageType::ValueType ValueType
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:231
itk::MultiphaseSparseFiniteDifferenceImageFilter::UpdateBufferConstIterator
typename UpdateBufferType::const_iterator UpdateBufferConstIterator
Definition: itkMultiphaseSparseFiniteDifferenceImageFilter.h:272