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 
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  itkOverrideGetNameOfClassMacro(SegmentTable);
61 
64  struct edge_pair_t
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
108  Add(IdentifierType a, const segment_t & t);
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
185  SortEdgeLists();
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
208  End()
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 
264 protected:
266  : m_MaximumDepth(0)
267  {}
268  ~SegmentTable() override = default;
269 
270  HashMapType m_HashMap{};
271 
272  ScalarType m_MaximumDepth{};
273 
274 private:
275  void
276  operator=(const Self &)
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
itk::watershed::SegmentTable::segment_t
Definition: itkWatershedSegmentTable.h:93
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:566
itk::watershed::SegmentTable::segment_t::edge_list
edge_list_t edge_list
Definition: itkWatershedSegmentTable.h:96
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:100
itk::watershed::SegmentTable::edge_list_t
std::list< edge_pair_t > edge_list_t
Definition: itkWatershedSegmentTable.h:90
itk::watershed::SegmentTable::GetMaximumDepth
ScalarType GetMaximumDepth() const
Definition: itkWatershedSegmentTable.h:249
itk::watershed::SegmentTable::SegmentTable
SegmentTable()
Definition: itkWatershedSegmentTable.h:265
itk::watershed::SegmentTable::operator=
void operator=(const Self &)
Definition: itkWatershedSegmentTable.h:276
itk::watershed::SegmentTable::segment_t::min
ScalarType min
Definition: itkWatershedSegmentTable.h:95
itk::SmartPointer< Self >
itk::watershed::SegmentTable::End
Iterator End()
Definition: itkWatershedSegmentTable.h:208
itkDataObject.h
itk::watershed::SegmentTable::Size
HashMapType::size_type Size() const
Definition: itkWatershedSegmentTable.h:189
itk::watershed::SegmentTable::Clear
void Clear()
Definition: itkWatershedSegmentTable.h:169
itk::watershed::SegmentTable::edge_pair_t
Definition: itkWatershedSegmentTable.h:64
itk::watershed::SegmentTable::End
ConstIterator End() const
Definition: itkWatershedSegmentTable.h:224
itk::watershed::SegmentTable::ConstIterator
typename HashMapType::const_iterator ConstIterator
Definition: itkWatershedSegmentTable.h:102
itk::watershed::SegmentTable::Lookup
const segment_t * Lookup(const IdentifierType a) const
Definition: itkWatershedSegmentTable.h:135
itk::watershed::SegmentTable::ValueType
typename HashMapType::value_type ValueType
Definition: itkWatershedSegmentTable.h:103
itk::watershed::SegmentTable::Lookup
segment_t * Lookup(const IdentifierType a)
Definition: itkWatershedSegmentTable.h:120
itk::watershed::SegmentTable::Erase
void Erase(const IdentifierType a)
Definition: itkWatershedSegmentTable.h:162
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:104
itk::watershed::SegmentTable::Empty
bool Empty() const
Definition: itkWatershedSegmentTable.h:177
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::watershed::SegmentTable::Iterator
typename HashMapType::iterator Iterator
Definition: itkWatershedSegmentTable.h:101
itk::watershed::SegmentTable::Copy
void Copy(const Self &o)
Definition: itkWatershedSegmentTable.h:258
itk::watershed::SegmentTable::IsEntry
bool IsEntry(const IdentifierType a) const
Definition: itkWatershedSegmentTable.h:150
itk::watershed::SegmentTable::GetSegmentMemorySize
unsigned int GetSegmentMemorySize() const
Definition: itkWatershedSegmentTable.h:231
itk::watershed::SegmentTable::edge_pair_t::height
ScalarType height
Definition: itkWatershedSegmentTable.h:72
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::watershed::SegmentTable::Begin
ConstIterator Begin() const
Definition: itkWatershedSegmentTable.h:216
itk::watershed::SegmentTable::SetMaximumDepth
void SetMaximumDepth(ScalarType s)
Definition: itkWatershedSegmentTable.h:241
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293
itk::watershed::SegmentTable::Begin
Iterator Begin()
Definition: itkWatershedSegmentTable.h:200
itk::watershed::SegmentTable
Definition: itkWatershedSegmentTable.h:48