ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkEquivalencyTable.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 itkEquivalencyTable_h
19 #define itkEquivalencyTable_h
20 
21 
22 #include "itkProcessObject.h"
23 #include "itksys/hash_map.hxx"
24 
25 namespace itk
26 {
44 class ITKCommon_EXPORT EquivalencyTable:public DataObject
45 {
46 public:
47  ITK_DISALLOW_COPY_AND_ASSIGN(EquivalencyTable);
48 
54  itkNewMacro(Self);
55  itkTypeMacro(EquivalencyTable, DataObject);
57 
59  using HashTableType = itksys::hash_map< unsigned long, unsigned long,
60  itksys::hash< unsigned long > >;
61 
62  using Iterator = HashTableType::iterator;
63  using ConstIterator = HashTableType::const_iterator;
64  using ValueType = HashTableType::value_type;
65 
69  void Flatten();
70 
77  bool Add(unsigned long a, unsigned long b);
78 
86  bool AddAndFlatten(unsigned long a, unsigned long b);
87 
91  unsigned long Lookup(const unsigned long a) const
92  {
93  ConstIterator result = m_HashMap.find(a);
94 
95  if ( result == m_HashMap.end() ) { return a; }
96  else { return ( *result ).second; }
97  }
98 
103  unsigned long RecursiveLookup(const unsigned long a) const;
104 
107  bool IsEntry(const unsigned long a) const
108  {
109  if ( m_HashMap.find(a) == m_HashMap.end() ) { return false; }
110  else { return true; }
111  }
113 
115  void Erase(const unsigned long a)
116  { m_HashMap.erase(a); }
117 
119  void Clear()
120  { m_HashMap.clear(); }
121 
123  bool Empty() const
124  { return m_HashMap.empty(); }
125 
127  HashTableType::size_type Size() const
128  { return m_HashMap.size(); }
129 
132  Iterator Begin() { return m_HashMap.begin(); }
133 
136  Iterator End() { return m_HashMap.end(); }
137 
139  // void PrintHashTable();
140 
141 protected:
142  EquivalencyTable() = default;
143  ~EquivalencyTable() override = default;
144  void PrintSelf(std::ostream & os, Indent indent) const override;
145 
147 };
148 } // end namespace itk
149 
150 #endif
unsigned long Lookup(const unsigned long a) const
itksys::hash_map< unsigned long, unsigned long, itksys::hash< unsigned long > > HashTableType
void Erase(const unsigned long a)
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:41
HashTableType::size_type Size() const
Hash table to manage integral label equivalencies.
HashTableType::value_type ValueType
HashTableType::iterator Iterator
bool IsEntry(const unsigned long a) const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
HashTableType::const_iterator ConstIterator
Base class for most ITK classes.
Definition: itkObject.h:60
Base class for all data objects in ITK.