ITK  5.2.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  * 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 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 
87 
89  itkNewMacro(Self);
90  itkTypeMacro(WatershedSegmentTreeGenerator, ProcessObject);
92 
94  using ScalarType = TScalar;
100 
105 
109  {
110  return static_cast<SegmentTableType *>(this->ProcessObject::GetInput(0));
111  }
112 
113  void
115  {
116  // Reset the highest calculated flood level if we are given a
117  // different input image.
118  if (st != this->GetInput(0))
119  {
120  m_HighestCalculatedFloodLevel = 0.0;
121  }
122  this->ProcessObject::SetNthInput(0, st);
123  }
124 
128  void
130  {
131  this->ProcessObject::SetNthInput(1, eq);
132  }
133 
134  EquivalencyTableType *
136  {
137  return static_cast<EquivalencyTableType *>(this->ProcessObject::GetInput(1));
138  }
139 
141  SegmentTreeType *
143  {
144  return static_cast<SegmentTreeType *>(this->ProcessObject::GetOutput(0));
145  }
146 
148  void
149  GenerateData() override;
150 
155  itkSetMacro(Merge, bool);
156  itkGetConstMacro(Merge, bool);
158 
164  void
165  SetFloodLevel(double);
166 
167  itkGetConstMacro(FloodLevel, double);
168 
172  itkSetMacro(HighestCalculatedFloodLevel, double);
173  itkGetConstMacro(HighestCalculatedFloodLevel, double);
175 
181  itkSetMacro(ConsumeInput, bool);
182  itkGetConstMacro(ConsumeInput, bool);
184 
187  static void
188  MergeSegments(SegmentTableTypePointer, OneWayEquivalencyTableTypePointer, const IdentifierType, const IdentifierType);
189 
192  static void
193  PruneMergeSegments(SegmentTableTypePointer,
194  OneWayEquivalencyTableTypePointer,
195  const IdentifierType,
196  const IdentifierType,
197  ScalarType);
198 
201  using Superclass::MakeOutput;
203  MakeOutput(DataObjectPointerArraySizeType idx) override;
204 
205 protected:
207  ~SegmentTreeGenerator() override = default;
209  void
210  operator=(const Self &)
211  {}
212  void
213  PrintSelf(std::ostream & os, Indent indent) const override;
214 
217  void CompileMergeList(SegmentTableTypePointer, SegmentTreeTypePointer);
218 
221  void ExtractMergeHierarchy(SegmentTableTypePointer, SegmentTreeTypePointer);
222 
223  void
224  MergeEquivalencies();
225 
227  void
228  GenerateOutputRequestedRegion(DataObject * output) override;
229 
230  void
231  GenerateInputRequestedRegion() override;
232 
233 private:
234  bool m_Merge{ false };
235  double m_FloodLevel{ 0.0 };
236  bool m_ConsumeInput{ false };
237 
238  using HashMapType = std::unordered_map<IdentifierType, bool>;
239 
241 
246  double m_HighestCalculatedFloodLevel{ 0.0 };
247 };
248 } // end namespace watershed
249 } // end namespace itk
250 
251 #ifndef ITK_MANUAL_INSTANTIATION
252 # include "itkWatershedSegmentTreeGenerator.hxx"
253 #endif
254 
255 #endif
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:135
itk::ProcessObject::GetOutput
DataObject * GetOutput(const DataObjectIdentifierType &key)
itk::SmartPointer< Self >
itk::watershed::SegmentTreeGenerator::operator=
void operator=(const Self &)
Definition: itkWatershedSegmentTreeGenerator.h:210
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ProcessObject::DataObjectPointerArraySizeType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Definition: itkProcessObject.h:193
itk::watershed::SegmentTreeGenerator< ScalarType >::HashMapType
std::unordered_map< IdentifierType, bool > HashMapType
Definition: itkWatershedSegmentTreeGenerator.h:238
itk::watershed::SegmentTreeGenerator< ScalarType >::SegmentTreeTypePointer
typename SegmentTreeType::Pointer SegmentTreeTypePointer
Definition: itkWatershedSegmentTreeGenerator.h:104
itk::watershed::SegmentTreeGenerator::SetInputSegmentTable
void SetInputSegmentTable(SegmentTableType *st)
Definition: itkWatershedSegmentTreeGenerator.h:114
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itkWatershedSegmentTable.h
itk::watershed::SegmentTreeGenerator< ScalarType >::SegmentTableTypePointer
typename SegmentTableType::Pointer SegmentTableTypePointer
Definition: itkWatershedSegmentTreeGenerator.h:102
itk::watershed::SegmentTreeGenerator< ScalarType >::ScalarType
ScalarType ScalarType
Definition: itkWatershedSegmentTreeGenerator.h:94
itk::watershed::SegmentTreeGenerator
Definition: itkWatershedSegmentTreeGenerator.h:78
itk::watershed::SegmentTreeGenerator::SegmentTreeGenerator
SegmentTreeGenerator(const Self &)
Definition: itkWatershedSegmentTreeGenerator.h:208
itk::watershed::SegmentTreeGenerator::SetInputEquivalencyTable
void SetInputEquivalencyTable(EquivalencyTableType *eq)
Definition: itkWatershedSegmentTreeGenerator.h:129
itk::watershed::SegmentTreeGenerator::m_MergedSegmentsTable
OneWayEquivalencyTableType::Pointer m_MergedSegmentsTable
Definition: itkWatershedSegmentTreeGenerator.h:240
itk::watershed::SegmentTree
Definition: itkWatershedSegmentTree.h:48
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::watershed::SegmentTreeGenerator< ScalarType >::OneWayEquivalencyTableTypePointer
typename OneWayEquivalencyTableType::Pointer OneWayEquivalencyTableTypePointer
Definition: itkWatershedSegmentTreeGenerator.h:103
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
itk::ProcessObject::SetNthInput
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
itk::watershed::SegmentTreeGenerator::GetOutputSegmentTree
SegmentTreeType * GetOutputSegmentTree()
Definition: itkWatershedSegmentTreeGenerator.h:142
itk::watershed::SegmentTreeGenerator::GetInputSegmentTable
SegmentTableType * GetInputSegmentTable()
Definition: itkWatershedSegmentTreeGenerator.h:108
itk::DataObject::Pointer
SmartPointer< Self > Pointer
Definition: itkDataObject.h:301
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
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