ITK  6.0.0
Insight Toolkit
itkWatershedSegmentTreeGenerator.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 itkWatershedSegmentTreeGenerator_h
19 #define itkWatershedSegmentTreeGenerator_h
20 
23 #include "itkEquivalencyTable.h"
24 
25 #include <algorithm>
26 #include <utility>
27 
28 namespace itk
29 {
30 namespace watershed
31 {
77 template <typename TScalar>
78 class ITK_TEMPLATE_EXPORT SegmentTreeGenerator : public ProcessObject
79 {
80 public:
81  ITK_DISALLOW_COPY_AND_MOVE(SegmentTreeGenerator);
82 
88 
90  itkNewMacro(Self);
91  itkOverrideGetNameOfClassMacro(SegmentTreeGenerator);
95  using ScalarType = TScalar;
101 
106 
110  {
111  return static_cast<SegmentTableType *>(this->ProcessObject::GetInput(0));
112  }
113 
114  void
116  {
117  // Reset the highest calculated flood level if we are given a
118  // different input image.
119  if (st != this->GetInput(0))
120  {
121  m_HighestCalculatedFloodLevel = 0.0;
122  }
123  this->ProcessObject::SetNthInput(0, st);
124  }
125 
129  void
131  {
132  this->ProcessObject::SetNthInput(1, eq);
133  }
134 
135  EquivalencyTableType *
137  {
138  return static_cast<EquivalencyTableType *>(this->ProcessObject::GetInput(1));
139  }
140 
142  SegmentTreeType *
144  {
145  return static_cast<SegmentTreeType *>(this->ProcessObject::GetOutput(0));
146  }
147 
149  void
150  GenerateData() override;
151 
156  itkSetMacro(Merge, bool);
157  itkGetConstMacro(Merge, bool);
165  void
166  SetFloodLevel(double);
167 
168  itkGetConstMacro(FloodLevel, double);
169 
173  itkSetMacro(HighestCalculatedFloodLevel, double);
174  itkGetConstMacro(HighestCalculatedFloodLevel, double);
182  itkSetMacro(ConsumeInput, bool);
183  itkGetConstMacro(ConsumeInput, bool);
188  static void
189  MergeSegments(SegmentTableTypePointer, OneWayEquivalencyTableTypePointer, const IdentifierType, const IdentifierType);
190 
193  static void
194  PruneMergeSegments(SegmentTableTypePointer,
195  OneWayEquivalencyTableTypePointer,
196  const IdentifierType,
197  const IdentifierType,
198  ScalarType);
199 
202  using Superclass::MakeOutput;
204  MakeOutput(DataObjectPointerArraySizeType idx) override;
205 
206 protected:
208  ~SegmentTreeGenerator() override = default;
209 
210  void
211  PrintSelf(std::ostream & os, Indent indent) const override;
212 
215  void CompileMergeList(SegmentTableTypePointer, SegmentTreeTypePointer);
216 
219  void ExtractMergeHierarchy(SegmentTableTypePointer, SegmentTreeTypePointer);
220 
221  void
222  MergeEquivalencies();
223 
225  void
226  GenerateOutputRequestedRegion(DataObject * output) override;
227 
228  void
229  GenerateInputRequestedRegion() override;
230 
231 private:
232  bool m_Merge{ false };
233  double m_FloodLevel{ 0.0 };
234  bool m_ConsumeInput{ false };
235 
236  using HashMapType = std::unordered_map<IdentifierType, bool>;
237 
238  OneWayEquivalencyTableType::Pointer m_MergedSegmentsTable{};
239 
244  double m_HighestCalculatedFloodLevel{ 0.0 };
245 };
246 } // end namespace watershed
247 } // end namespace itk
248 
249 #ifndef ITK_MANUAL_INSTANTIATION
250 # include "itkWatershedSegmentTreeGenerator.hxx"
251 #endif
252 
253 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::EquivalencyTable
Hash table to manage integral label equivalencies.
Definition: itkEquivalencyTable.h:44
itkWatershedSegmentTree.h
itk::OneWayEquivalencyTable
Hash table to manage integral label equivalencies that are order dependent.
Definition: itkOneWayEquivalencyTable.h:47
itkEquivalencyTable.h
itk::watershed::SegmentTreeGenerator::GetInputEquivalencyTable
EquivalencyTableType * GetInputEquivalencyTable()
Definition: itkWatershedSegmentTreeGenerator.h:136
itk::ProcessObject::GetOutput
DataObject * GetOutput(const DataObjectIdentifierType &key)
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ProcessObject::DataObjectPointerArraySizeType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Definition: itkProcessObject.h:194
itk::watershed::SegmentTreeGenerator< ScalarType >::HashMapType
std::unordered_map< IdentifierType, bool > HashMapType
Definition: itkWatershedSegmentTreeGenerator.h:236
itk::watershed::SegmentTreeGenerator< ScalarType >::SegmentTreeTypePointer
typename SegmentTreeType::Pointer SegmentTreeTypePointer
Definition: itkWatershedSegmentTreeGenerator.h:105
itk::watershed::SegmentTreeGenerator::SetInputSegmentTable
void SetInputSegmentTable(SegmentTableType *st)
Definition: itkWatershedSegmentTreeGenerator.h:115
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkWatershedSegmentTable.h
itk::watershed::SegmentTreeGenerator< ScalarType >::SegmentTableTypePointer
typename SegmentTableType::Pointer SegmentTableTypePointer
Definition: itkWatershedSegmentTreeGenerator.h:103
itk::watershed::SegmentTreeGenerator< ScalarType >::ScalarType
ScalarType ScalarType
Definition: itkWatershedSegmentTreeGenerator.h:95
itk::watershed::SegmentTreeGenerator
Definition: itkWatershedSegmentTreeGenerator.h:78
itk::watershed::SegmentTreeGenerator::SetInputEquivalencyTable
void SetInputEquivalencyTable(EquivalencyTableType *eq)
Definition: itkWatershedSegmentTreeGenerator.h:130
itk::watershed::SegmentTree
Definition: itkWatershedSegmentTree.h:48
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject::SetNthInput
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::watershed::SegmentTreeGenerator< ScalarType >::OneWayEquivalencyTableTypePointer
typename OneWayEquivalencyTableType::Pointer OneWayEquivalencyTableTypePointer
Definition: itkWatershedSegmentTreeGenerator.h:104
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
itk::watershed::SegmentTreeGenerator::GetOutputSegmentTree
SegmentTreeType * GetOutputSegmentTree()
Definition: itkWatershedSegmentTreeGenerator.h:143
itk::watershed::SegmentTreeGenerator::GetInputSegmentTable
SegmentTableType * GetInputSegmentTable()
Definition: itkWatershedSegmentTreeGenerator.h:109
itk::DataObject::Pointer
SmartPointer< Self > Pointer
Definition: itkDataObject.h:301
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
itk::ProcessObject::GetInput
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293
itk::watershed::SegmentTable
Definition: itkWatershedSegmentTable.h:48