ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkWatershedSegmentTable.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 itkWatershedSegmentTable_h
19 #define itkWatershedSegmentTable_h
20 
21 
22 #include "itkDataObject.h"
23 #include <list>
25 
26 namespace itk
27 {
28 namespace watershed
29 {
46 template< typename TScalar >
48 {
49 public:
51  typedef SegmentTable Self;
55  typedef TScalar ScalarType;
56 
57  itkNewMacro(Self);
58  itkTypeMacro(WatershedSegmentTable, DataObject);
59 
62  struct edge_pair_t {
68 
70  bool operator<(const edge_pair_t & o) const
71  {
72  if ( this->height < o.height )
73  {
74  return true;
75  }
76  else
77  {
78  return false;
79  }
80  }
81  };
83 
86  typedef std::list< edge_pair_t > edge_list_t;
87 
89  struct segment_t {
92  };
93 
95  typedef itksys::hash_map< IdentifierType, segment_t,
96  itksys::hash< IdentifierType > > HashMapType;
97  typedef typename HashMapType::iterator Iterator;
98  typedef typename HashMapType::const_iterator ConstIterator;
99  typedef typename HashMapType::value_type ValueType;
100  typedef typename HashMapType::data_type DataType;
101 
103  bool Add(IdentifierType a, const segment_t & t);
104 
109  void PruneEdgeLists(ScalarType maximum_saliency);
110 
114  {
115  Iterator result = m_HashMap.find(a);
116 
117  if ( result == m_HashMap.end() ) { return ITK_NULLPTR; }
118  else { return &( ( *result ).second ); }
119  }
120 
123  const segment_t * Lookup(const IdentifierType a) const
124  {
125  ConstIterator result = m_HashMap.find(a);
126 
127  if ( result == m_HashMap.end() ) { return 0; }
128  else { return &( ( *result ).second ); }
129  }
130 
133  bool IsEntry(const IdentifierType a) const
134  {
135  if ( m_HashMap.find(a) == m_HashMap.end() ) { return false; }
136  else { return true; }
137  }
139 
141  void Erase(const IdentifierType a)
142  { m_HashMap.erase(a); }
143 
145  void Clear()
146  { m_HashMap.clear(); }
147 
150  bool Empty() const
151  { return m_HashMap.empty(); }
152 
155  void SortEdgeLists();
156 
158  typename HashMapType::size_type Size() const
159  { return m_HashMap.size(); }
160 
162  // void Merge(const IdentifierType from, const IdentifierType to);
163 
166  Iterator Begin() { return m_HashMap.begin(); }
167 
170  Iterator End() { return m_HashMap.end(); }
171 
174  ConstIterator Begin() const { return m_HashMap.begin(); }
175 
178  ConstIterator End() const { return m_HashMap.end(); }
179 
181  unsigned int GetSegmentMemorySize() const
182  {
183  return sizeof( segment_t );
184  }
185 
186  // void PrintHashTable() const;
187 
191  {
192  m_MaximumDepth = s;
193  this->Modified();
194  }
196 
198  { return m_MaximumDepth; }
199 
203  void Copy(const Self & o)
204  {
205  m_HashMap = o.m_HashMap;
206  m_MaximumDepth = o.m_MaximumDepth;
207  }
208 
209 protected:
211  m_MaximumDepth(0)
212  {}
213  virtual ~SegmentTable() {}
214 
216 
218 
219 private:
220  void operator=(const Self &) {}
221 };
222 } // end namespace watershed
223 } // end namespace itk
224 
225 #ifndef ITK_MANUAL_INSTANTIATION
226 #include "itkWatershedSegmentTable.hxx"
227 #endif
228 
229 #endif
segment_t * Lookup(const IdentifierType a)
HashMapType::size_type Size() const
bool IsEntry(const IdentifierType a) const
bool Add(IdentifierType a, const segment_t &t)
SmartPointer< const Self > ConstPointer
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
HashMapType::const_iterator ConstIterator
bool operator<(const edge_pair_t &o) const
const segment_t * Lookup(const IdentifierType a) const
unsigned int GetSegmentMemorySize() const
void PruneEdgeLists(ScalarType maximum_saliency)
virtual void Modified() const
itksys::hash_map< IdentifierType, segment_t, itksys::hash< IdentifierType > > HashMapType
void Erase(const IdentifierType a)
std::list< edge_pair_t > edge_list_t
Base class for all data objects in ITK.