ITK  5.3.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  * 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 {
47 template <typename TScalar>
48 class ITK_TEMPLATE_EXPORT SegmentTable : public DataObject
49 {
50 public:
51 
53  using Self = SegmentTable;
57  using ScalarType = TScalar;
58 
59  itkNewMacro(Self);
60  itkTypeMacro(WatershedSegmentTable, DataObject);
61 
64  struct edge_pair_t
65  {
66  edge_pair_t() = default;
68  : label(l)
69  , height(s)
70  {}
74 
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  };
90 
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
111  Add(IdentifierType a, const segment_t & t);
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  }
169 
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
195  SortEdgeLists();
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
218  End()
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  }
257 
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 
274 protected:
276  : m_MaximumDepth(0)
277  {}
278  ~SegmentTable() override = default;
279 
281 
283 
284 private:
285  void
286  operator=(const Self &)
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
itk::watershed::SegmentTable::m_MaximumDepth
ScalarType m_MaximumDepth
Definition: itkWatershedSegmentTable.h:282
itk::watershed::SegmentTable::segment_t
Definition: itkWatershedSegmentTable.h:96
itk::watershed::SegmentTable::edge_pair_t::label
IdentifierType label
Definition: itkWatershedSegmentTable.h:71
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:550
itk::watershed::SegmentTable::m_HashMap
HashMapType m_HashMap
Definition: itkWatershedSegmentTable.h:280
itk::watershed::SegmentTable::segment_t::edge_list
edge_list_t edge_list
Definition: itkWatershedSegmentTable.h:99
itk::watershed::SegmentTable::edge_pair_t::edge_pair_t
edge_pair_t(IdentifierType l, ScalarType s)
Definition: itkWatershedSegmentTable.h:67
itk::watershed::SegmentTable::HashMapType
std::unordered_map< IdentifierType, segment_t > HashMapType
Definition: itkWatershedSegmentTable.h:103
itk::watershed::SegmentTable::edge_list_t
std::list< edge_pair_t > edge_list_t
Definition: itkWatershedSegmentTable.h:93
itk::watershed::SegmentTable::GetMaximumDepth
ScalarType GetMaximumDepth() const
Definition: itkWatershedSegmentTable.h:259
itk::watershed::SegmentTable::SegmentTable
SegmentTable()
Definition: itkWatershedSegmentTable.h:275
itk::watershed::SegmentTable::operator=
void operator=(const Self &)
Definition: itkWatershedSegmentTable.h:286
itk::watershed::SegmentTable::segment_t::min
ScalarType min
Definition: itkWatershedSegmentTable.h:98
itk::SmartPointer< Self >
itk::watershed::SegmentTable::End
Iterator End()
Definition: itkWatershedSegmentTable.h:218
itkDataObject.h
itk::watershed::SegmentTable::Size
HashMapType::size_type Size() const
Definition: itkWatershedSegmentTable.h:199
itk::watershed::SegmentTable::Clear
void Clear()
Definition: itkWatershedSegmentTable.h:179
itk::watershed::SegmentTable::edge_pair_t
Definition: itkWatershedSegmentTable.h:64
itk::watershed::SegmentTable::End
ConstIterator End() const
Definition: itkWatershedSegmentTable.h:234
itk::watershed::SegmentTable::ConstIterator
typename HashMapType::const_iterator ConstIterator
Definition: itkWatershedSegmentTable.h:105
itk::watershed::SegmentTable::Lookup
const segment_t * Lookup(const IdentifierType a) const
Definition: itkWatershedSegmentTable.h:140
itk::watershed::SegmentTable::ValueType
typename HashMapType::value_type ValueType
Definition: itkWatershedSegmentTable.h:106
itk::watershed::SegmentTable::Lookup
segment_t * Lookup(const IdentifierType a)
Definition: itkWatershedSegmentTable.h:123
itk::watershed::SegmentTable::Erase
void Erase(const IdentifierType a)
Definition: itkWatershedSegmentTable.h:172
itkOneWayEquivalencyTable.h
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::watershed::SegmentTable::ScalarType
TScalar ScalarType
Definition: itkWatershedSegmentTable.h:57
itk::watershed::SegmentTable::DataType
typename HashMapType::mapped_type DataType
Definition: itkWatershedSegmentTable.h:107
itk::watershed::SegmentTable::Empty
bool Empty() const
Definition: itkWatershedSegmentTable.h:187
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::watershed::SegmentTable::Iterator
typename HashMapType::iterator Iterator
Definition: itkWatershedSegmentTable.h:104
itk::watershed::SegmentTable::Copy
void Copy(const Self &o)
Definition: itkWatershedSegmentTable.h:268
itk::watershed::SegmentTable::IsEntry
bool IsEntry(const IdentifierType a) const
Definition: itkWatershedSegmentTable.h:157
itk::watershed::SegmentTable::GetSegmentMemorySize
unsigned int GetSegmentMemorySize() const
Definition: itkWatershedSegmentTable.h:241
itk::watershed::SegmentTable::edge_pair_t::height
ScalarType height
Definition: itkWatershedSegmentTable.h:72
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::watershed::SegmentTable::Begin
ConstIterator Begin() const
Definition: itkWatershedSegmentTable.h:226
itk::watershed::SegmentTable::SetMaximumDepth
void SetMaximumDepth(ScalarType s)
Definition: itkWatershedSegmentTable.h:251
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293
itk::watershed::SegmentTable::Begin
Iterator Begin()
Definition: itkWatershedSegmentTable.h:210
itk::watershed::SegmentTable
Definition: itkWatershedSegmentTable.h:48