00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkWatershedSegmentTreeGenerator_h
00018 #define __itkWatershedSegmentTreeGenerator_h
00019
00020 #include "itkWatershedSegmentTable.h"
00021 #include "itkWatershedSegmentTree.h"
00022 #include "itkEquivalencyTable.h"
00023 #include "itkOneWayEquivalencyTable.h"
00024
00025 #include <algorithm>
00026 #include <utility>
00027
00028 namespace itk
00029 {
00030 namespace watershed
00031 {
00032
00076 template <class TScalarType>
00077 class ITK_EXPORT SegmentTreeGenerator : public ProcessObject
00078 {
00079 public:
00080
00082 typedef SegmentTreeGenerator Self;
00083 typedef ProcessObject Superclass;
00084 typedef SmartPointer<Self> Pointer;
00085 typedef SmartPointer<const Self> ConstPointer;
00086 itkNewMacro(Self);
00087 itkTypeMacro(SegmentTreeGenerator, ProcessObject);
00089
00091 typedef TScalarType ScalarType;
00092 typedef SegmentTable<ScalarType> SegmentTableType;
00093 typedef SegmentTree<ScalarType> SegmentTreeType;
00094 typedef EquivalencyTable EquivalencyTableType;
00095 typedef OneWayEquivalencyTable OneWayEquivalencyTableType;
00096 typedef DataObject::Pointer DataObjectPointer;
00097
00099 typedef typename SegmentTableType::Pointer SegmentTableTypePointer;
00100 typedef typename OneWayEquivalencyTableType::Pointer
00101 OneWayEquivalencyTableTypePointer;
00102 typedef typename SegmentTreeType::Pointer SegmentTreeTypePointer;
00103
00104
00106 SegmentTableType* GetInputSegmentTable()
00107 {
00108 return static_cast<SegmentTableType *>(this->ProcessObject::GetInput(0));
00109 }
00110 void SetInputSegmentTable(SegmentTableType *st)
00111 {
00112
00113
00114 if (st != this->GetInput(0))
00115 {
00116 m_HighestCalculatedFloodLevel = 0.0;
00117 }
00118 this->ProcessObject::SetNthInput(0, st);
00119 }
00121
00125 void SetInputEquivalencyTable(EquivalencyTableType *eq)
00126 {
00127 this->ProcessObject::SetNthInput(1, eq);
00128 }
00129 EquivalencyTableType* GetInputEquivalencyTable()
00130 {
00131 return
00132 static_cast<EquivalencyTableType *>(this->ProcessObject::GetInput(1));
00133 }
00135
00137 SegmentTreeType * GetOutputSegmentTree()
00138 { return static_cast<SegmentTreeType *>
00139 (this->ProcessObject::GetOutput(0)); }
00140
00142 void GenerateData();
00143
00148 itkSetMacro(Merge, bool);
00149 itkGetMacro(Merge, bool);
00151
00157 void SetFloodLevel(double);
00158 itkGetMacro(FloodLevel, double);
00160
00164 itkSetMacro(HighestCalculatedFloodLevel, double);
00165 itkGetMacro(HighestCalculatedFloodLevel, double);
00167
00173 itkSetMacro(ConsumeInput, bool);
00174 itkGetMacro(ConsumeInput, bool);
00176
00179 static void MergeSegments(SegmentTableTypePointer,
00180 OneWayEquivalencyTableTypePointer,
00181 const unsigned long,
00182 const unsigned long);
00183
00186 static void PruneMergeSegments(SegmentTableTypePointer,
00187 OneWayEquivalencyTableTypePointer,
00188 const unsigned long,
00189 const unsigned long,
00190 ScalarType);
00191
00193 virtual DataObjectPointer MakeOutput(unsigned int idx);
00194
00195 protected:
00196 SegmentTreeGenerator();
00197 virtual ~SegmentTreeGenerator() {}
00198 SegmentTreeGenerator(const Self&) {}
00199 void operator=(const Self&) {}
00200 void PrintSelf(std::ostream& os, Indent indent) const;
00201
00204 void CompileMergeList(SegmentTableTypePointer, SegmentTreeTypePointer);
00205
00208 void ExtractMergeHierarchy(SegmentTableTypePointer, SegmentTreeTypePointer);
00209
00210 void MergeEquivalencies();
00211
00213 void GenerateOutputRequestedRegion(DataObject *output);
00214 void GenerateInputRequestedRegion();
00216
00217 private:
00218 bool m_Merge;
00219 double m_FloodLevel;
00220 bool m_ConsumeInput;
00221 OneWayEquivalencyTableType::Pointer m_MergedSegmentsTable;
00222
00227 double m_HighestCalculatedFloodLevel;
00228 };
00229
00230 }
00231 }
00232
00233 #ifndef ITK_MANUAL_INSTANTIATION
00234 #include "itkWatershedSegmentTreeGenerator.txx"
00235 #endif
00236
00237 #endif
00238
00239