00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkWatershedSegmentTable_h
00018 #define __itkWatershedSegmentTable_h
00019
00020 #if defined(_MSC_VER)
00021 #pragma warning ( disable : 4786 )
00022 #endif
00023
00024 #include "itkObjectFactory.h"
00025 #include "itkDataObject.h"
00026 #include "itkProcessObject.h"
00027 #include "itk_hash_map.h"
00028 #include <list>
00029 #include "itkOneWayEquivalencyTable.h"
00030
00031 namespace itk
00032 {
00033 namespace watershed
00034 {
00049 template <class TScalarType>
00050 class ITK_EXPORT SegmentTable : public DataObject
00051 {
00052 public:
00054 typedef SegmentTable Self;
00055 typedef DataObject Superclass;
00056 typedef SmartPointer<Self> Pointer;
00057 typedef SmartPointer<const Self> ConstPointer;
00058 typedef TScalarType ScalarType;
00059 itkNewMacro(Self);
00060 itkTypeMacro(SegmentTable, DataObject);
00062
00065 struct edge_pair_t
00066 {
00067 edge_pair_t() {}
00068 edge_pair_t(unsigned long l, ScalarType s)
00069 : label(l), height(s) {}
00070 unsigned long label;
00071 ScalarType height;
00073
00075 bool operator<(edge_pair_t &o)
00076 {
00077 if ( this->height < o.height ) return true;
00078 else return false;
00079 }
00081
00082 };
00083
00086 typedef std::list<edge_pair_t> edge_list_t;
00087
00089 struct segment_t
00090 {
00091 ScalarType min;
00092 edge_list_t edge_list;
00093 };
00094
00096 typedef itk::hash_map<unsigned long, segment_t, itk::hash<unsigned long> >
00097 HashMapType;
00098 typedef typename HashMapType::iterator Iterator;
00099 typedef typename HashMapType::const_iterator ConstIterator;
00100 typedef typename HashMapType::value_type ValueType;
00101 typedef typename HashMapType::data_type DataType;
00102
00104 bool Add(unsigned long a, const segment_t &t);
00105
00110 void PruneEdgeLists(ScalarType maximum_saliency);
00111
00114 segment_t *Lookup(const unsigned long a)
00115 {
00116 Iterator result = m_HashMap.find(a);
00117 if ( result == m_HashMap.end() ) return 0;
00118 else return &((*result).second);
00119 }
00121
00124 const segment_t *Lookup(const unsigned long a) const
00125 {
00126 ConstIterator result = m_HashMap.find(a);
00127 if ( result == m_HashMap.end() ) return 0;
00128 else return &((*result).second);
00129 }
00131
00134 bool IsEntry(const unsigned long a) const
00135 {
00136 if ( m_HashMap.find(a) == m_HashMap.end() ) return false;
00137 else return true;
00138 }
00140
00142 void Erase(const unsigned long a)
00143 { m_HashMap.erase(a); }
00144
00146 void Clear()
00147 { m_HashMap.clear(); }
00148
00151 bool Empty() const
00152 { return m_HashMap.empty(); }
00153
00156 void SortEdgeLists();
00157
00159 typename HashMapType::size_type Size() const
00160 { return m_HashMap.size(); }
00161
00163
00164
00167 Iterator Begin() { return m_HashMap.begin(); }
00168
00171 Iterator End() { return m_HashMap.end(); }
00172
00175 ConstIterator Begin() const { return m_HashMap.begin(); }
00176
00179 ConstIterator End() const { return m_HashMap.end(); }
00180
00182 unsigned int GetSegmentMemorySize() const
00183 {
00184 return sizeof(segment_t);
00185 }
00186
00188
00191 void SetMaximumDepth(ScalarType s)
00192 {
00193 m_MaximumDepth = s;
00194 this->Modified();
00195 }
00196 ScalarType GetMaximumDepth() const
00197 { return m_MaximumDepth; }
00199
00203 void Copy(const Self& o)
00204 {
00205 m_HashMap = o.m_HashMap;
00206 m_MaximumDepth = o.m_MaximumDepth;
00207 }
00208
00209 protected:
00210 SegmentTable() {}
00211 virtual ~SegmentTable() {}
00212 void PrintSelf(std::ostream& os, Indent indent) const;
00213
00214 HashMapType m_HashMap;
00215 ScalarType m_MaximumDepth;
00216
00217 private:
00218 void operator=(const Self&) {}
00219
00220 };
00221
00222 }
00223 }
00224
00225 #ifndef ITK_MANUAL_INSTANTIATION
00226 #include "itkWatershedSegmentTable.txx"
00227 #endif
00228
00229 #endif
00230
00231