ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkSparseFieldLevelSetImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 & GetRadius() const
82  { return m_Radius; }
83 
84  const unsigned int & GetArrayIndex(unsigned int i) const
85  { return m_ArrayIndex[i]; }
86 
87  const OffsetType & GetNeighborhoodOffset(unsigned int i) const
88  { return m_NeighborhoodOffset[i]; }
89 
90  const unsigned int & GetSize() const
91  { return m_Size; }
92 
93  int GetStride(unsigned int i)
94  { return m_StrideTable[i]; }
95 
98 
99  void Print(std::ostream & os) const;
100 
101 private:
102  unsigned int m_Size;
104  std::vector< unsigned int > m_ArrayIndex;
105  std::vector< OffsetType > m_NeighborhoodOffset;
106 
109  unsigned m_StrideTable[Dimension];
110 };
111 
227 template< typename TInputImage, typename TOutputImage >
228 class ITK_TEMPLATE_EXPORT SparseFieldLevelSetImageFilter:
229  public FiniteDifferenceImageFilter< TInputImage, TOutputImage >
230 {
231 public:
232  ITK_DISALLOW_COPY_AND_ASSIGN(SparseFieldLevelSetImageFilter);
233 
239 
241  using TimeStepType = typename Superclass::TimeStepType;
242  using RadiusType = typename Superclass::RadiusType;
243  using NeighborhoodScalesType = typename Superclass::NeighborhoodScalesType;
244 
246  itkNewMacro(Self);
247 
250 
252  using InputImageType = TInputImage;
253  using OutputImageType = TOutputImage;
255  static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
256 
260 
263 
267 
269  using LayerListType = std::vector< LayerPointerType >;
270 
272  using StatusType = signed char;
273 
276  using StatusImageType =
278 
282 
284  using UpdateBufferType = std::vector< ValueType >;
285 
289  itkSetMacro(NumberOfLayers, unsigned int);
290  itkGetConstMacro(NumberOfLayers, unsigned int);
292 
294  itkSetMacro(IsoSurfaceValue, ValueType);
295  itkGetConstMacro(IsoSurfaceValue, ValueType);
297 
301  // itkGetConstMacro(RMSChange, ValueType);
302 
308  itkSetMacro(InterpolateSurfaceLocation, bool);
309  itkGetConstMacro(InterpolateSurfaceLocation, bool);
311 
314  { this->SetInterpolateSurfaceLocation(true); }
316  { this->SetInterpolateSurfaceLocation(false); }
318 
319 #ifdef ITK_USE_CONCEPT_CHECKING
320  // Begin concept checking
321  itkConceptMacro( OutputEqualityComparableCheck,
323  itkConceptMacro( DoubleConvertibleToOutputCheck,
325  itkConceptMacro( OutputOStreamWritableCheck,
327  // End concept checking
328 #endif
329 
330 protected:
332  ~SparseFieldLevelSetImageFilter() override = default;
333  void PrintSelf(std::ostream & os, Indent indent) const override;
334 
340  const IndexType & itkNotUsed(idx),
341  const TimeStepType & dt,
342  const ValueType & value,
343  const ValueType & change)
344  { return ( value + dt * change ); }
345 
349  void PostProcessOutput() override;
350 
355  virtual void InitializeBackgroundPixels();
356 
358  void Initialize() override;
359 
364  void CopyInputToOutput() override;
365 
367  void AllocateUpdateBuffer() override;
368 
371  void ApplyUpdate(const TimeStepType& dt) override;
372 
375  TimeStepType CalculateChange() override;
376 
380  void ConstructLayer(StatusType from, StatusType to);
381 
386  void ConstructActiveLayer();
387 
389  void InitializeActiveLayerValues();
390 
398  void PropagateLayerValues(StatusType from, StatusType to,
399  StatusType promote, int InOrOut);
400 
405  void PropagateAllLayerValues();
406 
410  void UpdateActiveLayerValues(TimeStepType dt, LayerType *StatusUpList,
411  LayerType *StatusDownList);
412 
414  void ProcessStatusList(LayerType *InputList, LayerType *OutputList,
415  StatusType ChangeToStatus, StatusType SearchForStatus);
416 
418  void ProcessOutsideList(LayerType *OutsideList, StatusType ChangeToStatus);
419 
420  itkGetConstMacro(ValueZero, ValueType);
421  itkGetConstMacro(ValueOne, ValueType);
422 
426 
429  double m_ConstantGradientValue{1.0};
430 
433 
436 
440 
444 
448 
452 
456 
461 
467 
472  unsigned int m_NumberOfLayers{2};
473 
476 
479 
482 
486 
490  // ValueType m_RMSChange;
491 
496  bool m_InterpolateSurfaceLocation{true};
497 
500 
501 private:
504  bool m_BoundsCheckingActive{false};
505 };
506 } // end namespace itk
507 
508 #ifndef ITK_MANUAL_INSTANTIATION
509 #include "itkSparseFieldLevelSetImageFilter.hxx"
510 #endif
511 
512 #endif
SparseFieldCityBlockNeighborList< NeighborhoodIterator< OutputImageType > > m_NeighborList
Light weight base class for most itk classes.
A convenience class for storing indices which reference neighbor pixels within a neighborhood.
virtual ValueType CalculateUpdateValue(const IndexType &, const TimeStepType &dt, const ValueType &value, const ValueType &change)
This class implements a finite difference partial differential equation solver for evolving surfaces ...
TPixel ValueType
Definition: itkImage.h:98
typename Superclass::RadiusType RadiusType
typename Superclass::OffsetType OffsetType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
const unsigned int & GetArrayIndex(unsigned int i) const
A very simple linked list that is used to manage nodes in a layer of a sparse field level-set solver...
#define itkConceptMacro(name, concept)
A specialized memory management object for allocating and destroying contiguous blocks of objects...
const OffsetType & GetNeighborhoodOffset(unsigned int i) const
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Templated n-dimensional image class.
Definition: itkImage.h:75