ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkWatershedSegmentTreeGenerator.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 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 
108  {
109  return static_cast< SegmentTableType * >( this->ProcessObject::GetInput(0) );
110  }
111 
113  {
114  // Reset the highest calculated flood level if we are given a
115  // different input image.
116  if ( st != this->GetInput(0) )
117  {
118  m_HighestCalculatedFloodLevel = 0.0;
119  }
120  this->ProcessObject::SetNthInput(0, st);
121  }
122 
127  {
128  this->ProcessObject::SetNthInput(1, eq);
129  }
130 
132  {
133  return
134  static_cast< EquivalencyTableType * >( this->ProcessObject::GetInput(1) );
135  }
136 
139  {
140  return static_cast< SegmentTreeType * >
141  ( this->ProcessObject::GetOutput(0) );
142  }
143 
145  void GenerateData() override;
146 
151  itkSetMacro(Merge, bool);
152  itkGetConstMacro(Merge, bool);
154 
160  void SetFloodLevel(double);
161 
162  itkGetConstMacro(FloodLevel, double);
163 
167  itkSetMacro(HighestCalculatedFloodLevel, double);
168  itkGetConstMacro(HighestCalculatedFloodLevel, double);
170 
176  itkSetMacro(ConsumeInput, bool);
177  itkGetConstMacro(ConsumeInput, bool);
179 
182  static void MergeSegments(SegmentTableTypePointer,
183  OneWayEquivalencyTableTypePointer,
184  const IdentifierType,
185  const IdentifierType);
186 
189  static void PruneMergeSegments(SegmentTableTypePointer,
190  OneWayEquivalencyTableTypePointer,
191  const IdentifierType,
192  const IdentifierType,
193  ScalarType);
194 
197  using Superclass::MakeOutput;
198  DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override;
199 
200 protected:
202  ~SegmentTreeGenerator() override = default;
204  void operator=(const Self &) {}
205  void PrintSelf(std::ostream & os, Indent indent) const override;
206 
209  void CompileMergeList(SegmentTableTypePointer, SegmentTreeTypePointer);
210 
213  void ExtractMergeHierarchy(SegmentTableTypePointer, SegmentTreeTypePointer);
214 
215  void MergeEquivalencies();
216 
218  void GenerateOutputRequestedRegion(DataObject *output) override;
219 
220  void GenerateInputRequestedRegion() override;
221 
222 private:
223  bool m_Merge{false};
224  double m_FloodLevel{0.0};
225  bool m_ConsumeInput{false};
226 
227  using HashMapType = itksys::hash_map< IdentifierType, bool,
228  itksys::hash< IdentifierType > >;
229 
231 
236  double m_HighestCalculatedFloodLevel{0.0};
237 };
238 } // end namespace watershed
239 } // end namespace itk
240 
241 #ifndef ITK_MANUAL_INSTANTIATION
242 #include "itkWatershedSegmentTreeGenerator.hxx"
243 #endif
244 
245 #endif
Light weight base class for most itk classes.
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:40
Hash table to manage integral label equivalencies that are order dependent.
Hash table to manage integral label equivalencies.
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
OneWayEquivalencyTableType::Pointer m_MergedSegmentsTable
void SetInputEquivalencyTable(EquivalencyTableType *eq)
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
SmartPointer< Self > Pointer
typename OneWayEquivalencyTableType::Pointer OneWayEquivalencyTableTypePointer
Base class for all data objects in ITK.
DataObject * GetOutput(const DataObjectIdentifierType &key)