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
84 return false;
85 }
86 };
87
90 using edge_list_t = std::list<edge_pair_t>;
91
93 struct segment_t
94 {
97 };
98
100 using HashMapType = std::unordered_map<IdentifierType, segment_t>;
101 using Iterator = typename HashMapType::iterator;
102 using ConstIterator = typename HashMapType::const_iterator;
103 using ValueType = typename HashMapType::value_type;
104 using DataType = typename HashMapType::mapped_type;
105
107 bool
109
114 void
115 PruneEdgeLists(ScalarType maximum_saliency);
116
119 segment_t *
121 {
122 auto result = m_HashMap.find(a);
123
124 if (result == m_HashMap.end())
125 {
126 return nullptr;
127 }
128
129 return &(result->second);
130 }
131
134 const segment_t *
135 Lookup(const IdentifierType a) const
136 {
137 ConstIterator result = m_HashMap.find(a);
138
139 if (result == m_HashMap.end())
140 {
141 return 0;
142 }
143
144 return &(result->second);
145 }
146
149 bool
150 IsEntry(const IdentifierType a) const
151 {
152 if (m_HashMap.find(a) == m_HashMap.end())
153 {
154 return false;
155 }
156
157 return true;
158 }
159
161 void
163 {
164 m_HashMap.erase(a);
165 }
166
168 void
170 {
171 m_HashMap.clear();
172 }
173
176 bool
177 Empty() const
178 {
179 return m_HashMap.empty();
180 }
181
184 void
186
188 typename HashMapType::size_type
189 Size() const
190 {
191 return m_HashMap.size();
192 }
193
195 // void Merge(const IdentifierType from, const IdentifierType to);
196
199 Iterator
201 {
202 return m_HashMap.begin();
203 }
204
207 Iterator
209 {
210 return m_HashMap.end();
211 }
212
215 ConstIterator
216 Begin() const
217 {
218 return m_HashMap.begin();
219 }
220
223 ConstIterator
224 End() const
225 {
226 return m_HashMap.end();
227 }
228
230 unsigned int
232 {
233 return sizeof(segment_t);
234 }
235
236 // void PrintHashTable() const;
237
240 void
242 {
243 m_MaximumDepth = s;
244 this->Modified();
245 }
248 ScalarType
250 {
251 return m_MaximumDepth;
252 }
253
257 void
258 Copy(const Self & o)
259 {
260 m_HashMap = o.m_HashMap;
261 m_MaximumDepth = o.m_MaximumDepth;
262 }
263
264protected:
266 : m_MaximumDepth(0)
267 {}
268 ~SegmentTable() override = default;
269
270 HashMapType m_HashMap{};
271
272 ScalarType m_MaximumDepth{};
273
274private:
275 void
277 {}
278};
279} // end namespace watershed
280} // end namespace itk
281
282#ifndef ITK_MANUAL_INSTANTIATION
283# include "itkWatershedSegmentTable.hxx"
284#endif
285
286#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:566