ITK  5.2.0
Insight Toolkit
itkFastMarchingImageFilter.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 itkFastMarchingImageFilter_h
19 #define itkFastMarchingImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
23 #include "itkLevelSet.h"
24 #include "itkMath.h"
25 #include "ITKFastMarchingExport.h"
26 
27 #include <functional>
28 #include <queue>
29 #include "itkMath.h"
30 
31 namespace itk
32 {
38 {
39 public:
47  enum class Label : uint8_t
48  {
49  FarPoint = 0,
50  AlivePoint,
51  TrialPoint,
54  };
55 };
56 // Define how to print enumeration
57 extern ITKFastMarching_EXPORT std::ostream &
58  operator<<(std::ostream & out, const FastMarchingImageFilterEnums::Label value);
59 
135 template <typename TLevelSet, typename TSpeedImage = Image<float, TLevelSet::ImageDimension>>
136 class ITK_TEMPLATE_EXPORT FastMarchingImageFilter : public ImageToImageFilter<TSpeedImage, TLevelSet>
137 {
138 public:
139  ITK_DISALLOW_COPY_AND_MOVE(FastMarchingImageFilter);
140 
146 
148  itkNewMacro(Self);
149 
152 
164  using OutputSpacingType = typename LevelSetImageType::SpacingType;
167 
168  class AxisNodeType : public NodeType
169  {
170  public:
171  AxisNodeType() = default;
172  int
173  GetAxis() const
174  {
175  return m_Axis;
176  }
177  void
178  SetAxis(int axis)
179  {
180  m_Axis = axis;
181  }
182  const AxisNodeType &
183  operator=(const NodeType & node)
184  {
185  this->NodeType::operator=(node);
186  return *this;
187  }
188 
189  private:
190  int m_Axis{ 0 };
191  };
192 
194  using SpeedImageType = TSpeedImage;
195 
197  using SpeedImagePointer = typename SpeedImageType::Pointer;
198  using SpeedImageConstPointer = typename SpeedImageType::ConstPointer;
199 
201  static constexpr unsigned int SetDimension = LevelSetType::SetDimension;
202  static constexpr unsigned int SpeedImageDimension = SpeedImageType::ImageDimension;
203 
206 
208 #if !defined(ITK_LEGACY_REMOVE)
209 
210  static constexpr LabelEnum FarPoint = LabelEnum::FarPoint;
211  static constexpr LabelEnum AlivePoint = LabelEnum::AlivePoint;
212  static constexpr LabelEnum TrialPoint = LabelEnum::TrialPoint;
213  static constexpr LabelEnum InitialTrialPoint = LabelEnum::InitialTrialPoint;
214  static constexpr LabelEnum OutsidePoint = LabelEnum::OutsidePoint;
215 #endif
216 
219 
222 
223  template <typename TPixel>
224  void
226  {
227  using InternalImageType = Image<TPixel, SetDimension>;
228  using InternalRegionIterator = ImageRegionConstIteratorWithIndex<InternalImageType>;
229  InternalRegionIterator b_it(iImage, iImage->GetLargestPossibleRegion());
230  b_it.GoToBegin();
231 
232  TPixel zero_value = NumericTraits<TPixel>::ZeroValue();
233  typename NodeContainer::ElementIdentifier NumberOfPoints = 0;
234 
235  NodeType node;
236  node.SetValue(0.);
237 
238  while (!b_it.IsAtEnd())
239  {
240  if (Math::ExactlyEquals(b_it.Get(), zero_value))
241  {
242  if (NumberOfPoints == 0)
243  {
244  m_OutsidePoints = NodeContainer::New();
245  }
246  node.SetIndex(b_it.GetIndex());
247  m_OutsidePoints->InsertElement(NumberOfPoints++, node);
248  }
249  ++b_it;
250  }
251  this->Modified();
252  }
253 
255  void
257  {
258  m_OutsidePoints = points;
259  this->Modified();
260  }
262 
265  void
267  {
268  m_AlivePoints = points;
269  this->Modified();
270  }
272 
274  NodeContainerPointer
276  {
277  return m_AlivePoints;
278  }
279 
282  void
284  {
285  m_TrialPoints = points;
286  this->Modified();
287  }
289 
291  NodeContainerPointer
293  {
294  return m_TrialPoints;
295  }
296 
298  LabelImagePointer
300  {
301  return m_LabelImage;
302  }
303 
307  void
308  SetSpeedConstant(double value)
309  {
310  m_SpeedConstant = value;
311  m_InverseSpeed = -1.0 * itk::Math::sqr(1.0 / m_SpeedConstant);
312  this->Modified();
313  }
315 
317  itkGetConstReferenceMacro(SpeedConstant, double);
318 
323  itkSetMacro(NormalizationFactor, double);
324  itkGetConstMacro(NormalizationFactor, double);
326 
330  itkSetMacro(StoppingValue, double);
331 
333  itkGetConstReferenceMacro(StoppingValue, double);
334 
339  itkSetMacro(CollectPoints, bool);
340 
342  itkGetConstReferenceMacro(CollectPoints, bool);
343  itkBooleanMacro(CollectPoints);
345 
350  NodeContainerPointer
352  {
353  return m_ProcessedPoints;
354  }
355 
362  virtual void
364  {
365  m_OutputRegion = size;
366  }
367  virtual OutputSizeType
369  {
370  return m_OutputRegion.GetSize();
371  }
372  itkSetMacro(OutputRegion, OutputRegionType);
373  itkGetConstReferenceMacro(OutputRegion, OutputRegionType);
374  itkSetMacro(OutputSpacing, OutputSpacingType);
375  itkGetConstReferenceMacro(OutputSpacing, OutputSpacingType);
376  itkSetMacro(OutputDirection, OutputDirectionType);
377  itkGetConstReferenceMacro(OutputDirection, OutputDirectionType);
378  itkSetMacro(OutputOrigin, OutputPointType);
379  itkGetConstReferenceMacro(OutputOrigin, OutputPointType);
380  itkSetMacro(OverrideOutputInformation, bool);
381  itkGetConstReferenceMacro(OverrideOutputInformation, bool);
382  itkBooleanMacro(OverrideOutputInformation);
384 
385 #ifdef ITK_USE_CONCEPT_CHECKING
386  // Begin concept checking
389  itkConceptMacro(DoubleConvertibleToLevelSetCheck, (Concept::Convertible<double, PixelType>));
390  itkConceptMacro(LevelSetOStreamWritableCheck, (Concept::OStreamWritable<PixelType>));
391  // End concept checking
392 #endif
393 
394 protected:
396  ~FastMarchingImageFilter() override = default;
397  void
398  PrintSelf(std::ostream & os, Indent indent) const override;
399 
400  virtual void
401  Initialize(LevelSetImageType *);
402 
403  virtual void
404  UpdateNeighbors(const IndexType & index, const SpeedImageType *, LevelSetImageType *);
405 
406  virtual double
407  UpdateValue(const IndexType & index, const SpeedImageType *, LevelSetImageType *);
408 
409  const AxisNodeType &
410  GetNodeUsedInCalculation(unsigned int idx) const
411  {
412  return m_NodesUsed[idx];
413  }
414 
415  void
416  GenerateData() override;
417 
419  void
420  GenerateOutputInformation() override;
421 
422  void
423  EnlargeOutputRequestedRegion(DataObject * output) override;
424 
429  itkGetConstReferenceMacro(LargeValue, PixelType);
430 
435 
436  itkGetConstReferenceMacro(StartIndex, LevelSetIndexType);
437  itkGetConstReferenceMacro(LastIndex, LevelSetIndexType);
438 
439 private:
443 
445 
449 
452 
458 
459  typename LevelSetImageType::PixelType m_LargeValue;
460  AxisNodeType m_NodesUsed[SetDimension];
461 
465  using HeapContainer = std::vector<AxisNodeType>;
466  using NodeComparer = std::greater<AxisNodeType>;
467  using HeapType = std::priority_queue<AxisNodeType, HeapContainer, NodeComparer>;
468 
470 
472 };
473 } // namespace itk
474 
475 #ifndef ITK_MANUAL_INSTANTIATION
476 # include "itkFastMarchingImageFilter.hxx"
477 #endif
478 
479 #endif
itk::FastMarchingImageFilter::PixelType
typename LevelSetType::PixelType PixelType
Definition: itkFastMarchingImageFilter.h:157
itk::FastMarchingImageFilter::HeapType
std::priority_queue< AxisNodeType, HeapContainer, NodeComparer > HeapType
Definition: itkFastMarchingImageFilter.h:467
itk::uint8_t
::uint8_t uint8_t
Definition: itkIntTypes.h:29
itk::FastMarchingImageFilter::m_AlivePoints
NodeContainerPointer m_AlivePoints
Definition: itkFastMarchingImageFilter.h:437
itk::LevelSetTypeDefault
Level set type information.
Definition: itkLevelSet.h:40
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itk::Concept::OStreamWritable
Definition: itkConceptChecking.h:636
itk::GTest::TypedefsAndConstructors::Dimension2::DirectionType
ImageBaseType::DirectionType DirectionType
Definition: itkGTestTypedefsAndConstructors.h:52
itk::FastMarchingImageFilter::LabelImagePointer
typename LabelImageType::Pointer LabelImagePointer
Definition: itkFastMarchingImageFilter.h:221
itkImageRegionConstIteratorWithIndex.h
itk::ImageRegionConstIteratorWithIndex
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
Definition: itkImageRegionConstIteratorWithIndex.h:130
itk::FastMarchingImageFilter::SetTrialPoints
void SetTrialPoints(NodeContainer *points)
Definition: itkFastMarchingImageFilter.h:283
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
itk::FastMarchingImageFilter::SetSpeedConstant
void SetSpeedConstant(double value)
Definition: itkFastMarchingImageFilter.h:308
itk::FastMarchingImageFilter::m_LabelImage
LabelImagePointer m_LabelImage
Definition: itkFastMarchingImageFilter.h:444
itk::FastMarchingImageFilter::LevelSetPointer
typename LevelSetType::LevelSetPointer LevelSetPointer
Definition: itkFastMarchingImageFilter.h:156
itk::FastMarchingImageFilter::SetOutsidePoints
void SetOutsidePoints(NodeContainer *points)
Definition: itkFastMarchingImageFilter.h:256
itk::FastMarchingImageFilterEnums::Label::FarPoint
itk::FastMarchingImageFilter::SpeedImagePointer
typename SpeedImageType::Pointer SpeedImagePointer
Definition: itkFastMarchingImageFilter.h:197
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::Math::ExactlyEquals
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:723
itk::FastMarchingImageFilter::OutputSpacingType
typename LevelSetImageType::SpacingType OutputSpacingType
Definition: itkFastMarchingImageFilter.h:164
itk::FastMarchingImageFilter::m_CollectPoints
bool m_CollectPoints
Definition: itkFastMarchingImageFilter.h:450
itk::FastMarchingImageFilter::GetTrialPoints
NodeContainerPointer GetTrialPoints()
Definition: itkFastMarchingImageFilter.h:292
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::FastMarchingImageFilter::m_OutputDirection
OutputDirectionType m_OutputDirection
Definition: itkFastMarchingImageFilter.h:456
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::FastMarchingImageFilter::NodeComparer
std::greater< AxisNodeType > NodeComparer
Definition: itkFastMarchingImageFilter.h:466
itk::LevelSetNode
Represent a node in a level set.
Definition: itkLevelSetNode.h:45
itk::FastMarchingImageFilter::GetAlivePoints
NodeContainerPointer GetAlivePoints()
Definition: itkFastMarchingImageFilter.h:275
itk::FastMarchingImageFilter::m_OutputOrigin
OutputPointType m_OutputOrigin
Definition: itkFastMarchingImageFilter.h:454
itk::FastMarchingImageFilter::m_StoppingValue
double m_StoppingValue
Definition: itkFastMarchingImageFilter.h:448
itk::FastMarchingImageFilter::m_OutputSpacing
OutputSpacingType m_OutputSpacing
Definition: itkFastMarchingImageFilter.h:455
itk::FastMarchingImageFilter::LevelSetIndexType
typename LevelSetImageType::IndexType LevelSetIndexType
Definition: itkFastMarchingImageFilter.h:432
itk::FastMarchingImageFilter::NodeIndexType
typename NodeType::IndexType NodeIndexType
Definition: itkFastMarchingImageFilter.h:159
itk::FastMarchingImageFilter::SetBinaryMask
void SetBinaryMask(Image< TPixel, SetDimension > *iImage)
Definition: itkFastMarchingImageFilter.h:225
itk::FastMarchingImageFilter::m_LastIndex
LevelSetIndexType m_LastIndex
Definition: itkFastMarchingImageFilter.h:434
itk::Concept::SameDimension
Definition: itkConceptChecking.h:694
itk::FastMarchingImageFilter::NodeType
typename LevelSetType::NodeType NodeType
Definition: itkFastMarchingImageFilter.h:158
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::FastMarchingImageFilterEnums::Label::InitialTrialPoint
itk::FastMarchingImageFilterEnums
Contains all enum classes used by the FastMarchingImageFilter class.
Definition: itkFastMarchingImageFilter.h:37
itk::LevelSetTypeDefault::LevelSetPointer
typename TLevelSet::Pointer LevelSetPointer
Definition: itkLevelSet.h:51
itk::FastMarchingImageFilter::m_InverseSpeed
double m_InverseSpeed
Definition: itkFastMarchingImageFilter.h:447
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::FastMarchingImageFilterEnums::Label
Label
Definition: itkFastMarchingImageFilter.h:47
itk::FastMarchingImageFilter::m_OutsidePoints
NodeContainerPointer m_OutsidePoints
Definition: itkFastMarchingImageFilter.h:442
itk::FastMarchingImageFilter::SetOutputSize
virtual void SetOutputSize(const OutputSizeType &size)
Definition: itkFastMarchingImageFilter.h:363
itk::FastMarchingImageFilter::m_NormalizationFactor
double m_NormalizationFactor
Definition: itkFastMarchingImageFilter.h:471
itk::FastMarchingImageFilter::m_TrialPoints
NodeContainerPointer m_TrialPoints
Definition: itkFastMarchingImageFilter.h:441
itk::FastMarchingImageFilter
Solve an Eikonal equation using Fast Marching.
Definition: itkFastMarchingImageFilter.h:136
itk::FastMarchingImageFilter::SpeedImageType
TSpeedImage SpeedImageType
Definition: itkFastMarchingImageFilter.h:194
itk::LevelSetTypeDefault::NodeContainerPointer
typename NodeContainer::Pointer NodeContainerPointer
Definition: itkLevelSet.h:64
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::FastMarchingImageFilter::m_OutputRegion
OutputRegionType m_OutputRegion
Definition: itkFastMarchingImageFilter.h:453
itk::FastMarchingImageFilter::OutputDirectionType
typename LevelSetImageType::DirectionType OutputDirectionType
Definition: itkFastMarchingImageFilter.h:165
itk::FastMarchingImageFilter::AxisNodeType
Definition: itkFastMarchingImageFilter.h:168
itk::FastMarchingImageFilter::AxisNodeType::SetAxis
void SetAxis(int axis)
Definition: itkFastMarchingImageFilter.h:178
itkImageToImageFilter.h
itk::FastMarchingImageFilterEnums::Label::AlivePoint
itk::FastMarchingImageFilter::OutputRegionType
typename LevelSetImageType::RegionType OutputRegionType
Definition: itkFastMarchingImageFilter.h:163
itk::FastMarchingImageFilter::GetOutputSize
virtual OutputSizeType GetOutputSize() const
Definition: itkFastMarchingImageFilter.h:368
itk::FastMarchingImageFilter::AxisNodeType::operator=
const AxisNodeType & operator=(const NodeType &node)
Definition: itkFastMarchingImageFilter.h:183
itk::ImageBase::GetLargestPossibleRegion
virtual const RegionType & GetLargestPossibleRegion() const
Definition: itkImageBase.h:262
itk::FastMarchingImageFilterEnums::Label::TrialPoint
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itk::ImageConstIteratorWithIndex::GoToBegin
void GoToBegin()
itk::LevelSetTypeDefault::LevelSetImageType
TLevelSet LevelSetImageType
Definition: itkLevelSet.h:45
itk::FastMarchingImageFilter::m_TrialHeap
HeapType m_TrialHeap
Definition: itkFastMarchingImageFilter.h:469
itk::FastMarchingImageFilter::HeapContainer
std::vector< AxisNodeType > HeapContainer
Definition: itkFastMarchingImageFilter.h:465
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::FastMarchingImageFilter::OutputPointType
typename LevelSetImageType::PointType OutputPointType
Definition: itkFastMarchingImageFilter.h:166
itk::FastMarchingImageFilter::m_ProcessedPoints
NodeContainerPointer m_ProcessedPoints
Definition: itkFastMarchingImageFilter.h:451
Label
itkLevelSet.h
itk::FastMarchingImageFilter::NodeContainer
typename LevelSetType::NodeContainer NodeContainer
Definition: itkFastMarchingImageFilter.h:160
itk::FastMarchingImageFilter::m_OverrideOutputInformation
bool m_OverrideOutputInformation
Definition: itkFastMarchingImageFilter.h:457
itk::FastMarchingImageFilter::m_BufferedRegion
OutputRegionType m_BufferedRegion
Definition: itkFastMarchingImageFilter.h:429
itk::FastMarchingImageFilter::m_LargeValue
LevelSetImageType::PixelType m_LargeValue
Definition: itkFastMarchingImageFilter.h:459
itk::FastMarchingImageFilter::OutputSizeType
typename LevelSetImageType::SizeType OutputSizeType
Definition: itkFastMarchingImageFilter.h:162
itk::FastMarchingImageFilter::NodeContainerPointer
typename LevelSetType::NodeContainerPointer NodeContainerPointer
Definition: itkFastMarchingImageFilter.h:161
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itk::FastMarchingImageFilter::GetLabelImage
LabelImagePointer GetLabelImage() const
Definition: itkFastMarchingImageFilter.h:299
itk::FastMarchingImageFilter::LevelSetImageType
typename LevelSetType::LevelSetImageType LevelSetImageType
Definition: itkFastMarchingImageFilter.h:155
itk::FastMarchingImageFilterEnums::Label::OutsidePoint
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::FastMarchingImageFilter::AxisNodeType::GetAxis
int GetAxis() const
Definition: itkFastMarchingImageFilter.h:173
itk::FastMarchingImageFilter::SpeedImageConstPointer
typename SpeedImageType::ConstPointer SpeedImageConstPointer
Definition: itkFastMarchingImageFilter.h:198
itk::LevelSetTypeDefault::PixelType
typename TLevelSet::PixelType PixelType
Definition: itkLevelSet.h:55
itk::FastMarchingImageFilter::m_StartIndex
LevelSetIndexType m_StartIndex
Definition: itkFastMarchingImageFilter.h:433
itk::FastMarchingImageFilter::GetNodeUsedInCalculation
const AxisNodeType & GetNodeUsedInCalculation(unsigned int idx) const
Definition: itkFastMarchingImageFilter.h:410
itk::FastMarchingImageFilter::SetAlivePoints
void SetAlivePoints(NodeContainer *points)
Definition: itkFastMarchingImageFilter.h:266
itk::FastMarchingImageFilter::m_SpeedConstant
double m_SpeedConstant
Definition: itkFastMarchingImageFilter.h:446
itkMath.h
itk::VectorContainer
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
Definition: itkVectorContainer.h:48
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293
itk::FastMarchingImageFilter::GetProcessedPoints
NodeContainerPointer GetProcessedPoints() const
Definition: itkFastMarchingImageFilter.h:351