ITK  4.2.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< class TScalarType >
78 class ITK_EXPORT SegmentTreeGenerator:public ProcessObject
79 {
80 public:
81 
87  itkNewMacro(Self);
88  itkTypeMacro(WatershedSegmentTreeGenerator, ProcessObject);
90 
92  typedef TScalarType ScalarType;
98 
103 
105  SegmentTableType * GetInputSegmentTable()
106  {
107  return static_cast< SegmentTableType * >( this->ProcessObject::GetInput(0) );
108  }
109 
110  void SetInputSegmentTable(SegmentTableType *st)
111  {
112  // Reset the highest calculated flood level if we are given a
113  // different input image.
114  if ( st != this->GetInput(0) )
115  {
116  m_HighestCalculatedFloodLevel = 0.0;
117  }
118  this->ProcessObject::SetNthInput(0, st);
119  }
120 
124  void SetInputEquivalencyTable(EquivalencyTableType *eq)
125  {
126  this->ProcessObject::SetNthInput(1, eq);
127  }
128 
129  EquivalencyTableType * GetInputEquivalencyTable()
130  {
131  return
132  static_cast< EquivalencyTableType * >( this->ProcessObject::GetInput(1) );
133  }
134 
136  SegmentTreeType * GetOutputSegmentTree()
137  {
138  return static_cast< SegmentTreeType * >
139  ( this->ProcessObject::GetOutput(0) );
140  }
141 
143  void GenerateData();
144 
149  itkSetMacro(Merge, bool);
150  itkGetConstMacro(Merge, bool);
152 
158  void SetFloodLevel(double);
159 
160  itkGetConstMacro(FloodLevel, double);
161 
165  itkSetMacro(HighestCalculatedFloodLevel, double);
166  itkGetConstMacro(HighestCalculatedFloodLevel, double);
168 
174  itkSetMacro(ConsumeInput, bool);
175  itkGetConstMacro(ConsumeInput, bool);
177 
180  static void MergeSegments(SegmentTableTypePointer,
181  OneWayEquivalencyTableTypePointer,
182  const IdentifierType,
183  const IdentifierType);
184 
187  static void PruneMergeSegments(SegmentTableTypePointer,
188  OneWayEquivalencyTableTypePointer,
189  const IdentifierType,
190  const IdentifierType,
191  ScalarType);
192 
195  using Superclass::MakeOutput;
196  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
197 
198 protected:
202  void operator=(const Self &) {}
203  void PrintSelf(std::ostream & os, Indent indent) const;
204 
207  void CompileMergeList(SegmentTableTypePointer, SegmentTreeTypePointer);
208 
211  void ExtractMergeHierarchy(SegmentTableTypePointer, SegmentTreeTypePointer);
212 
213  void MergeEquivalencies();
214 
216  void GenerateOutputRequestedRegion(DataObject *output);
217 
218  void GenerateInputRequestedRegion();
219 
220 private:
221  bool m_Merge;
222  double m_FloodLevel;
224 
225  typedef itksys::hash_map< IdentifierType, bool,
226  itksys::hash< IdentifierType > > HashMapType;
227 
229 
235 };
236 } // end namespace watershed
237 } // end namespace itk
238 
239 #ifndef ITK_MANUAL_INSTANTIATION
240 #include "itkWatershedSegmentTreeGenerator.hxx"
241 #endif
242 
243 #endif
244