ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkWatershedSegmentTable.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
26namespace itk::watershed
27{
45template <typename TScalar>
46class ITK_TEMPLATE_EXPORT SegmentTable : public DataObject
47{
48public:
54 using ScalarType = TScalar;
55
56 itkNewMacro(Self);
57 itkOverrideGetNameOfClassMacro(SegmentTable);
58
62 {
63 edge_pair_t() = default;
65 : label(l)
66 , height(s)
67 {}
68
71
73 bool
74 operator<(const edge_pair_t & o) const
75 {
76 if (this->height < o.height)
77 {
78 return true;
79 }
80
81 return false;
82 }
83 };
84
87 using edge_list_t = std::list<edge_pair_t>;
88
95
97 using HashMapType = std::unordered_map<IdentifierType, segment_t>;
98 using Iterator = typename HashMapType::iterator;
99 using ConstIterator = typename HashMapType::const_iterator;
100 using ValueType = typename HashMapType::value_type;
101 using DataType = typename HashMapType::mapped_type;
102
104 bool
105 Add(IdentifierType a, const segment_t & t);
106
111 void
112 PruneEdgeLists(ScalarType maximum_saliency);
113
116 segment_t *
118 {
119 auto result = m_HashMap.find(a);
120
121 if (result == m_HashMap.end())
122 {
123 return nullptr;
124 }
125
126 return &(result->second);
127 }
128
131 const segment_t *
132 Lookup(const IdentifierType a) const
133 {
134 ConstIterator result = m_HashMap.find(a);
135
136 if (result == m_HashMap.end())
137 {
138 return 0;
139 }
140
141 return &(result->second);
142 }
143
146 bool
147 IsEntry(const IdentifierType a) const
148 {
149 if (m_HashMap.find(a) == m_HashMap.end())
150 {
151 return false;
152 }
153
154 return true;
155 }
156
158 void
160 {
161 m_HashMap.erase(a);
162 }
163
165 void
167 {
168 m_HashMap.clear();
169 }
170
173 bool
174 Empty() const
175 {
176 return m_HashMap.empty();
177 }
178
181 void
183
185 typename HashMapType::size_type
186 Size() const
187 {
188 return m_HashMap.size();
189 }
190
192 // void Merge(const IdentifierType from, const IdentifierType to);
193
196 Iterator
198 {
199 return m_HashMap.begin();
200 }
201
204 Iterator
206 {
207 return m_HashMap.end();
208 }
209
212 ConstIterator
213 Begin() const
214 {
215 return m_HashMap.begin();
216 }
217
220 ConstIterator
221 End() const
222 {
223 return m_HashMap.end();
224 }
225
227 unsigned int
229 {
230 return sizeof(segment_t);
231 }
232
233 // void PrintHashTable() const;
234
238 void
240 {
241 m_MaximumDepth = s;
242 this->Modified();
243 }
244
245 ScalarType
247 {
248 return m_MaximumDepth;
249 }
250
251
255 void
256 Copy(const Self & o)
257 {
260 }
261
262protected:
264 : m_MaximumDepth(0)
265 {}
266 ~SegmentTable() override = default;
267
269
271
272private:
273 void
275 {}
276};
277} // namespace itk::watershed
278
279#ifndef ITK_MANUAL_INSTANTIATION
280# include "itkWatershedSegmentTable.hxx"
281#endif
282
283#endif
virtual void Modified() const
Implements transparent reference counting.
const segment_t * Lookup(const IdentifierType a) const
void PruneEdgeLists(ScalarType maximum_saliency)
~SegmentTable() override=default
segment_t * Lookup(const IdentifierType a)
void Erase(const IdentifierType a)
std::unordered_map< IdentifierType, segment_t > HashMapType
bool Add(IdentifierType a, const segment_t &t)
typename HashMapType::const_iterator ConstIterator
bool IsEntry(const IdentifierType a) const
HashMapType::size_type Size() const
SizeValueType IdentifierType
Definition itkIntTypes.h:90