ITK  6.0.0
Insight Toolkit
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
27{
28namespace watershed
29{
47template <typename TScalar>
48class ITK_TEMPLATE_EXPORT SegmentTable : public DataObject
49{
50public:
51
57 using ScalarType = TScalar;
58
59 itkNewMacro(Self);
60 itkOverrideGetNameOfClassMacro(SegmentTable);
61
65 {
66 edge_pair_t() = default;
68 : label(l)
69 , height(s)
70 {}
76 bool
77 operator<(const edge_pair_t & o) const
78 {
79 if (this->height < o.height)
80 {
81 return true;
82 }
83 else
84 {
85 return false;
86 }
87 }
88 };
93 using edge_list_t = std::list<edge_pair_t>;
94
96 struct segment_t
97 {
100 };
101
103 using HashMapType = std::unordered_map<IdentifierType, segment_t>;
104 using Iterator = typename HashMapType::iterator;
105 using ConstIterator = typename HashMapType::const_iterator;
106 using ValueType = typename HashMapType::value_type;
107 using DataType = typename HashMapType::mapped_type;
108
110 bool
112
117 void
118 PruneEdgeLists(ScalarType maximum_saliency);
119
122 segment_t *
124 {
125 auto result = m_HashMap.find(a);
126
127 if (result == m_HashMap.end())
128 {
129 return nullptr;
130 }
131 else
132 {
133 return &(result->second);
134 }
135 }
136
139 const segment_t *
140 Lookup(const IdentifierType a) const
141 {
142 ConstIterator result = m_HashMap.find(a);
143
144 if (result == m_HashMap.end())
145 {
146 return 0;
147 }
148 else
149 {
150 return &(result->second);
151 }
152 }
153
156 bool
157 IsEntry(const IdentifierType a) const
158 {
159 if (m_HashMap.find(a) == m_HashMap.end())
160 {
161 return false;
162 }
163 else
164 {
165 return true;
166 }
167 }
171 void
173 {
174 m_HashMap.erase(a);
175 }
176
178 void
180 {
181 m_HashMap.clear();
182 }
183
186 bool
187 Empty() const
188 {
189 return m_HashMap.empty();
190 }
191
194 void
196
198 typename HashMapType::size_type
199 Size() const
200 {
201 return m_HashMap.size();
202 }
203
205 // void Merge(const IdentifierType from, const IdentifierType to);
206
209 Iterator
211 {
212 return m_HashMap.begin();
213 }
214
217 Iterator
219 {
220 return m_HashMap.end();
221 }
222
225 ConstIterator
226 Begin() const
227 {
228 return m_HashMap.begin();
229 }
230
233 ConstIterator
234 End() const
235 {
236 return m_HashMap.end();
237 }
238
240 unsigned int
242 {
243 return sizeof(segment_t);
244 }
245
246 // void PrintHashTable() const;
247
250 void
252 {
253 m_MaximumDepth = s;
254 this->Modified();
255 }
258 ScalarType
260 {
261 return m_MaximumDepth;
262 }
263
267 void
268 Copy(const Self & o)
269 {
270 m_HashMap = o.m_HashMap;
271 m_MaximumDepth = o.m_MaximumDepth;
272 }
273
274protected:
276 : m_MaximumDepth(0)
277 {}
278 ~SegmentTable() override = default;
279
280 HashMapType m_HashMap{};
281
282 ScalarType m_MaximumDepth{};
283
284private:
285 void
287 {}
288};
289} // end namespace watershed
290} // end namespace itk
291
292#ifndef ITK_MANUAL_INSTANTIATION
293# include "itkWatershedSegmentTable.hxx"
294#endif
295
296#endif
Base class for all data objects in ITK.
Base class for most ITK classes.
Definition: itkObject.h:62
const segment_t * Lookup(const IdentifierType a) const
std::list< edge_pair_t > edge_list_t
void PruneEdgeLists(ScalarType maximum_saliency)
typename HashMapType::iterator Iterator
~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::mapped_type DataType
typename HashMapType::value_type ValueType
typename HashMapType::const_iterator ConstIterator
bool IsEntry(const IdentifierType a) const
HashMapType::size_type Size() const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:557