ITK  5.2.0
Insight Toolkit
itkSparseFieldLevelSetImageFilter.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  * 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 itkSparseFieldLevelSetImageFilter_h
19 #define itkSparseFieldLevelSetImageFilter_h
20 
22 #include "itkMultiThreaderBase.h"
23 #include "itkSparseFieldLayer.h"
24 #include "itkObjectStore.h"
25 #include <vector>
27 
28 namespace itk
29 {
35 template <typename TValue>
36 class ITK_TEMPLATE_EXPORT SparseFieldLevelSetNode
37 {
38 public:
39  TValue m_Value;
42 };
43 
72 template <typename TNeighborhoodType>
73 class ITK_TEMPLATE_EXPORT SparseFieldCityBlockNeighborList
74 {
75 public:
76  using NeighborhoodType = TNeighborhoodType;
79  static constexpr unsigned int Dimension = NeighborhoodType::Dimension;
80 
81  const RadiusType &
82  GetRadius() const
83  {
84  return m_Radius;
85  }
86 
87  const unsigned int &
88  GetArrayIndex(unsigned int i) const
89  {
90  return m_ArrayIndex[i];
91  }
92 
93  const OffsetType &
94  GetNeighborhoodOffset(unsigned int i) const
95  {
96  return m_NeighborhoodOffset[i];
97  }
98 
99  const unsigned int &
100  GetSize() const
101  {
102  return m_Size;
103  }
104 
105  int
106  GetStride(unsigned int i)
107  {
108  return m_StrideTable[i];
109  }
110 
113 
114  void
115  Print(std::ostream & os) const;
116 
117 private:
118  unsigned int m_Size;
120  std::vector<unsigned int> m_ArrayIndex;
121  std::vector<OffsetType> m_NeighborhoodOffset;
122 
125  unsigned m_StrideTable[Dimension];
126 };
127 
243 template <typename TInputImage, typename TOutputImage>
244 class ITK_TEMPLATE_EXPORT SparseFieldLevelSetImageFilter : public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
245 {
246 public:
247  ITK_DISALLOW_COPY_AND_MOVE(SparseFieldLevelSetImageFilter);
248 
254 
256  using TimeStepType = typename Superclass::TimeStepType;
257  using RadiusType = typename Superclass::RadiusType;
258  using NeighborhoodScalesType = typename Superclass::NeighborhoodScalesType;
259 
261  itkNewMacro(Self);
262 
265 
267  using InputImageType = TInputImage;
268  using OutputImageType = TOutputImage;
270  static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
271 
275 
278 
282 
284  using LayerListType = std::vector<LayerPointerType>;
285 
287  using StatusType = signed char;
288 
292 
296 
298  using UpdateBufferType = std::vector<ValueType>;
299 
303  itkSetMacro(NumberOfLayers, unsigned int);
304  itkGetConstMacro(NumberOfLayers, unsigned int);
306 
308  itkSetMacro(IsoSurfaceValue, ValueType);
309  itkGetConstMacro(IsoSurfaceValue, ValueType);
311 
315  // itkGetConstMacro(RMSChange, ValueType);
316 
322  itkSetMacro(InterpolateSurfaceLocation, bool);
323  itkGetConstMacro(InterpolateSurfaceLocation, bool);
325 
327  void
329  {
330  this->SetInterpolateSurfaceLocation(true);
331  }
332  void
334  {
335  this->SetInterpolateSurfaceLocation(false);
336  }
338 
339 #ifdef ITK_USE_CONCEPT_CHECKING
340  // Begin concept checking
344  // End concept checking
345 #endif
346 
347 protected:
349  ~SparseFieldLevelSetImageFilter() override = default;
350  void
351  PrintSelf(std::ostream & os, Indent indent) const override;
352 
357  inline virtual ValueType
358  CalculateUpdateValue(const IndexType & itkNotUsed(idx),
359  const TimeStepType & dt,
360  const ValueType & value,
361  const ValueType & change)
362  {
363  return (value + dt * change);
364  }
365 
369  void
370  PostProcessOutput() override;
371 
376  virtual void
377  InitializeBackgroundPixels();
378 
380  void
381  Initialize() override;
382 
387  void
388  CopyInputToOutput() override;
389 
391  void
392  AllocateUpdateBuffer() override;
393 
396  void
397  ApplyUpdate(const TimeStepType & dt) override;
398 
401  TimeStepType
402  CalculateChange() override;
403 
407  void
408  ConstructLayer(StatusType from, StatusType to);
409 
414  void
415  ConstructActiveLayer();
416 
418  void
419  InitializeActiveLayerValues();
420 
428  void
429  PropagateLayerValues(StatusType from, StatusType to, StatusType promote, int InOrOut);
430 
435  void
436  PropagateAllLayerValues();
437 
441  void
442  UpdateActiveLayerValues(TimeStepType dt, LayerType * UpList, LayerType * DownList);
443 
445  void
446  ProcessStatusList(LayerType * InputList,
447  LayerType * OutputList,
448  StatusType ChangeToStatus,
449  StatusType SearchForStatus);
450 
452  void
453  ProcessOutsideList(LayerType * OutsideList, StatusType ChangeToStatus);
454 
455  itkGetConstMacro(ValueZero, ValueType);
456  itkGetConstMacro(ValueOne, ValueType);
457 
460 
463  double m_ConstantGradientValue{ 1.0 };
464 
467 
470 
474 
478 
482 
486 
490 
495 
501 
506  unsigned int m_NumberOfLayers{ 2 };
507 
510 
513 
516 
520 
524  // ValueType m_RMSChange;
525 
530  bool m_InterpolateSurfaceLocation{ true };
531 
534 
535 private:
538  bool m_BoundsCheckingActive{ false };
539 };
540 } // end namespace itk
541 
542 #ifndef ITK_MANUAL_INSTANTIATION
543 # include "itkSparseFieldLevelSetImageFilter.hxx"
544 #endif
545 
546 #endif
itk::SparseFieldLevelSetImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::LayerListType
std::vector< LayerPointerType > LayerListType
Definition: itkSparseFieldLevelSetImageFilter.h:284
itkFiniteDifferenceImageFilter.h
itk::SparseFieldLevelSetImageFilter
This class implements a finite difference partial differential equation solver for evolving surfaces ...
Definition: itkSparseFieldLevelSetImageFilter.h:244
itk::SparseFieldLevelSetImageFilter::m_IsoSurfaceValue
ValueType m_IsoSurfaceValue
Definition: itkSparseFieldLevelSetImageFilter.h:515
itk::Concept::OStreamWritable
Definition: itkConceptChecking.h:636
itk::SparseFieldCityBlockNeighborList< NeighborhoodIterator< OutputImageType > >::RadiusType
typename NeighborhoodType::RadiusType RadiusType
Definition: itkSparseFieldLevelSetImageFilter.h:78
itkObjectStore.h
itk::SparseFieldLevelSetNode::Previous
SparseFieldLevelSetNode * Previous
Definition: itkSparseFieldLevelSetImageFilter.h:41
itkNeighborhoodIterator.h
itk::SparseFieldLevelSetImageFilter::m_ValueZero
static ValueType m_ValueZero
Definition: itkSparseFieldLevelSetImageFilter.h:469
itk::SparseFieldLevelSetImageFilter::m_Layers
LayerListType m_Layers
Definition: itkSparseFieldLevelSetImageFilter.h:500
itk::SparseFieldLevelSetImageFilter::m_StatusActiveChangingDown
static StatusType m_StatusActiveChangingDown
Definition: itkSparseFieldLevelSetImageFilter.h:481
itk::SparseFieldLevelSetImageFilter::m_ShiftedImage
OutputImageType::Pointer m_ShiftedImage
Definition: itkSparseFieldLevelSetImageFilter.h:494
itk::SparseFieldCityBlockNeighborList::m_Radius
RadiusType m_Radius
Definition: itkSparseFieldLevelSetImageFilter.h:119
itk::SparseFieldLevelSetImageFilter::m_OutputImage
OutputImageType * m_OutputImage
Definition: itkSparseFieldLevelSetImageFilter.h:533
itk::FiniteDifferenceImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::TimeStepType
typename FiniteDifferenceFunctionType::TimeStepType TimeStepType
Definition: itkFiniteDifferenceImageFilter.h:166
itk::SparseFieldLevelSetImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::StatusType
signed char StatusType
Definition: itkSparseFieldLevelSetImageFilter.h:287
itk::SparseFieldLevelSetImageFilter::InterpolateSurfaceLocationOff
void InterpolateSurfaceLocationOff()
Definition: itkSparseFieldLevelSetImageFilter.h:333
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SparseFieldLevelSetImageFilter::CalculateUpdateValue
virtual ValueType CalculateUpdateValue(const IndexType &, const TimeStepType &dt, const ValueType &value, const ValueType &change)
Definition: itkSparseFieldLevelSetImageFilter.h:358
itk::SparseFieldCityBlockNeighborList::GetArrayIndex
const unsigned int & GetArrayIndex(unsigned int i) const
Definition: itkSparseFieldLevelSetImageFilter.h:88
itk::SparseFieldCityBlockNeighborList< NeighborhoodIterator< OutputImageType > >::OffsetType
typename NeighborhoodType::OffsetType OffsetType
Definition: itkSparseFieldLevelSetImageFilter.h:77
itk::SparseFieldLevelSetNode
Definition: itkSparseFieldLevelSetImageFilter.h:36
itk::SparseFieldLevelSetImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::LayerPointerType
typename LayerType::Pointer LayerPointerType
Definition: itkSparseFieldLevelSetImageFilter.h:281
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:172
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::Image::ValueType
TPixel ValueType
Definition: itkImage.h:109
itk::SparseFieldCityBlockNeighborList
A convenience class for storing indices which reference neighbor pixels within a neighborhood.
Definition: itkSparseFieldLevelSetImageFilter.h:73
itk::FiniteDifferenceImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::NeighborhoodScalesType
typename FiniteDifferenceFunctionType::NeighborhoodScalesType NeighborhoodScalesType
Definition: itkFiniteDifferenceImageFilter.h:169
itk::FiniteDifferenceImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::RadiusType
typename FiniteDifferenceFunctionType::RadiusType RadiusType
Definition: itkFiniteDifferenceImageFilter.h:168
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::SparseFieldLevelSetImageFilter::m_NeighborList
SparseFieldCityBlockNeighborList< NeighborhoodIterator< OutputImageType > > m_NeighborList
Definition: itkSparseFieldLevelSetImageFilter.h:456
itk::ObjectStore
A specialized memory management object for allocating and destroying contiguous blocks of objects.
Definition: itkObjectStore.h:84
itk::SparseFieldCityBlockNeighborList::GetNeighborhoodOffset
const OffsetType & GetNeighborhoodOffset(unsigned int i) const
Definition: itkSparseFieldLevelSetImageFilter.h:94
itk::SparseFieldLevelSetImageFilter::m_StatusActiveChangingUp
static StatusType m_StatusActiveChangingUp
Definition: itkSparseFieldLevelSetImageFilter.h:477
itk::NeighborhoodIterator::RadiusType
typename Superclass::RadiusType RadiusType
Definition: itkNeighborhoodIterator.h:227
itk::SparseFieldCityBlockNeighborList::m_ArrayIndex
std::vector< unsigned int > m_ArrayIndex
Definition: itkSparseFieldLevelSetImageFilter.h:120
itk::ImageToImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk::FiniteDifferenceImageFilter
Definition: itkFiniteDifferenceImageFilter.h:132
itk::SparseFieldCityBlockNeighborList::GetStride
int GetStride(unsigned int i)
Definition: itkSparseFieldLevelSetImageFilter.h:106
itk::SparseFieldCityBlockNeighborList::m_Size
unsigned int m_Size
Definition: itkSparseFieldLevelSetImageFilter.h:118
itk::SparseFieldCityBlockNeighborList::m_NeighborhoodOffset
std::vector< OffsetType > m_NeighborhoodOffset
Definition: itkSparseFieldLevelSetImageFilter.h:121
itk::SparseFieldLevelSetImageFilter::m_StatusBoundaryPixel
static StatusType m_StatusBoundaryPixel
Definition: itkSparseFieldLevelSetImageFilter.h:485
itk::SparseFieldLevelSetImageFilter::m_InputImage
const InputImageType * m_InputImage
Definition: itkSparseFieldLevelSetImageFilter.h:532
itk::NeighborhoodIterator
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Definition: itkNeighborhoodIterator.h:212
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::SparseFieldLevelSetImageFilter::m_StatusImage
StatusImageType::Pointer m_StatusImage
Definition: itkSparseFieldLevelSetImageFilter.h:509
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::SparseFieldLevelSetImageFilter::m_StatusChanging
static StatusType m_StatusChanging
Definition: itkSparseFieldLevelSetImageFilter.h:473
itkMultiThreaderBase.h
itk::SparseFieldLevelSetImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::ValueType
typename OutputImageType::ValueType ValueType
Definition: itkSparseFieldLevelSetImageFilter.h:274
itk::SparseFieldCityBlockNeighborList::GetRadius
const RadiusType & GetRadius() const
Definition: itkSparseFieldLevelSetImageFilter.h:82
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itk::SparseFieldLevelSetImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::UpdateBufferType
std::vector< ValueType > UpdateBufferType
Definition: itkSparseFieldLevelSetImageFilter.h:298
itk::SparseFieldLevelSetImageFilter::m_LayerNodeStore
LayerNodeStorageType::Pointer m_LayerNodeStore
Definition: itkSparseFieldLevelSetImageFilter.h:512
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::SparseFieldLevelSetImageFilter::InterpolateSurfaceLocationOn
void InterpolateSurfaceLocationOn()
Definition: itkSparseFieldLevelSetImageFilter.h:328
itk::NeighborhoodIterator::OffsetType
typename Superclass::OffsetType OffsetType
Definition: itkNeighborhoodIterator.h:226
itk::SparseFieldLevelSetImageFilter::m_UpdateBuffer
UpdateBufferType m_UpdateBuffer
Definition: itkSparseFieldLevelSetImageFilter.h:519
itk::SparseFieldCityBlockNeighborList::GetSize
const unsigned int & GetSize() const
Definition: itkSparseFieldLevelSetImageFilter.h:100
itk::SparseFieldLevelSetNode::m_Value
TValue m_Value
Definition: itkSparseFieldLevelSetImageFilter.h:39
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::SparseFieldLevelSetNode::Next
SparseFieldLevelSetNode * Next
Definition: itkSparseFieldLevelSetImageFilter.h:40
itk::SparseFieldLevelSetImageFilter::m_StatusNull
static StatusType m_StatusNull
Definition: itkSparseFieldLevelSetImageFilter.h:489
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:306
itk::SparseFieldLevelSetImageFilter::m_ValueOne
static ValueType m_ValueOne
Definition: itkSparseFieldLevelSetImageFilter.h:466
itk::SparseFieldLevelSetImageFilter< TInputImage, Image< TOutputPixelType, TInputImage::ImageDimension > >::IndexType
typename OutputImageType::IndexType IndexType
Definition: itkSparseFieldLevelSetImageFilter.h:269
itkSparseFieldLayer.h