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:
00081 typedef SegmentTreeGenerator Self;
00082 typedef ProcessObject Superclass;
00083 typedef SmartPointer<Self> Pointer;
00084 typedef SmartPointer<const Self> ConstPointer;
00085 itkNewMacro(Self);
00086 itkTypeMacro(SegmentTreeGenerator, ProcessObject);
00087
00089 typedef TScalarType ScalarType;
00090 typedef SegmentTable<ScalarType> SegmentTableType;
00091 typedef SegmentTree<ScalarType> SegmentTreeType;
00092 typedef EquivalencyTable EquivalencyTableType;
00093 typedef OneWayEquivalencyTable OneWayEquivalencyTableType;
00094 typedef DataObject::Pointer DataObjectPointer;
00095
00097 typedef typename SegmentTableType::Pointer SegmentTableTypePointer;
00098 typedef typename OneWayEquivalencyTableType::Pointer
00099 OneWayEquivalencyTableTypePointer;
00100 typedef typename SegmentTreeType::Pointer SegmentTreeTypePointer;
00101
00102
00104 SegmentTableType* GetInputSegmentTable()
00105 {
00106 return static_cast<SegmentTableType *>(this->ProcessObject::GetInput(0));
00107 }
00108 void SetInputSegmentTable(SegmentTableType *st)
00109 {
00110
00111
00112 if (st != this->GetInput(0))
00113 {
00114 m_HighestCalculatedFloodLevel = 0.0;
00115 }
00116 this->ProcessObject::SetNthInput(0, st);
00117 }
00118
00122 void SetInputEquivalencyTable(EquivalencyTableType *eq)
00123 {
00124 this->ProcessObject::SetNthInput(1, eq);
00125 }
00126 EquivalencyTableType* GetInputEquivalencyTable()
00127 {
00128 return
00129 static_cast<EquivalencyTableType *>(this->ProcessObject::GetInput(1));
00130 }
00131
00133 SegmentTreeType * GetOutputSegmentTree()
00134 { return static_cast<SegmentTreeType *>
00135 (this->ProcessObject::GetOutput(0)); }
00136
00138 void GenerateData();
00139
00144 itkSetMacro(Merge, bool);
00145 itkGetMacro(Merge, bool);
00146
00152 void SetFloodLevel(double);
00153 itkGetMacro(FloodLevel, double);
00154
00158 itkSetMacro(HighestCalculatedFloodLevel, double);
00159 itkGetMacro(HighestCalculatedFloodLevel, double);
00160
00166 itkSetMacro(ConsumeInput, bool);
00167 itkGetMacro(ConsumeInput, bool);
00168
00171 static void MergeSegments(SegmentTableTypePointer,
00172 OneWayEquivalencyTableTypePointer,
00173 const unsigned long,
00174 const unsigned long);
00175
00178 static void PruneMergeSegments(SegmentTableTypePointer,
00179 OneWayEquivalencyTableTypePointer,
00180 const unsigned long,
00181 const unsigned long,
00182 ScalarType);
00183
00185 virtual DataObjectPointer MakeOutput(unsigned int idx);
00186
00187 protected:
00188 SegmentTreeGenerator();
00189 virtual ~SegmentTreeGenerator() {}
00190 SegmentTreeGenerator(const Self&) {}
00191 void operator=(const Self&) {}
00192 void PrintSelf(std::ostream& os, Indent indent) const;
00193
00196 void CompileMergeList(SegmentTableTypePointer, SegmentTreeTypePointer);
00197
00200 void ExtractMergeHierarchy(SegmentTableTypePointer, SegmentTreeTypePointer);
00201
00202 void MergeEquivalencies();
00203
00205 void GenerateOutputRequestedRegion(DataObject *output);
00206 void GenerateInputRequestedRegion();
00207
00208 private:
00209 bool m_Merge;
00210 double m_FloodLevel;
00211 bool m_ConsumeInput;
00212 OneWayEquivalencyTableType::Pointer m_MergedSegmentsTable;
00213
00218 double m_HighestCalculatedFloodLevel;
00219 };
00220
00221 }
00222 }
00223
00224 #ifndef ITK_MANUAL_INSTANTIATION
00225 #include "itkWatershedSegmentTreeGenerator.txx"
00226 #endif
00227
00228 #endif
00229