libsurf
Programmer's Documentation

dcfaceset.h (r6227/r5385)
1 
2 /* Copyright (C) 2015 David Eller <david@larosterna.com>
3  *
4  * Commercial License Usage
5  * Licensees holding valid commercial licenses may use this file in accordance
6  * with the terms contained in their respective non-exclusive license agreement.
7  * For further information contact david@larosterna.com .
8  *
9  * GNU General Public License Usage
10  * Alternatively, this file may be used under the terms of the GNU General
11  * Public License version 3.0 as published by the Free Software Foundation and
12  * appearing in the file gpl.txt included in the packaging of this file.
13  */
14 
15 #ifndef SURF_DCFACESET_H
16 #define SURF_DCFACESET_H
17 
18 #include "dcface.h"
19 #include <vector>
20 
21 #ifdef _MSC_VER
22 #undef near
23 #endif
24 
25 #ifdef HAVE_JUDY
26 
27 #include <genua/judymap.h>
28 
41 class DcIndexMap
42 {
43 public:
44 
45  typedef JudyArray<size_t> map_type;
46  typedef JudyArray<size_t>::iterator iterator;
47 
49  void insert(size_t zcode, uint idx) {
50  m_jmap.insert(zcode, size_t(idx));
51  }
52 
54  bool erase(size_t zcode) {
55  return m_jmap.erase(zcode);
56  }
57 
59  iterator begin() const {return m_jmap.begin();}
60 
62  iterator end() const {return m_jmap.end();}
63 
65  iterator find(size_t zcode) const {
66  return m_jmap.find(zcode);
67  }
68 
70  iterator lower(size_t zcode) const {
71  return m_jmap.lower_bound(zcode);
72  }
73 
75  iterator upper(size_t zcode) const {
76  return m_jmap.upper_bound(zcode);
77  }
78 
80  iterator near(size_t zcode) const {
81  iterator pos = lower(zcode);
82  if (pos != end())
83  return pos;
84  else if (pos != begin())
85  --pos;
86  return pos;
87  }
88 
90  uint triangle(iterator pos) const {
91  return *pos;
92  }
93 
95  void clear() {
96  m_jmap.clear();
97  }
98 
99 private:
100 
102  JudyArray<size_t> m_jmap;
103 };
104 
105 #else
106 
107 #include <map>
108 
110 {
111 public:
112 
113  typedef std::map<size_t, uint> map_type;
114  typedef map_type::const_iterator iterator;
115 
117  void insert(size_t zcode, uint idx) {
118  m_zmap[zcode] = idx;
119  }
120 
122  bool erase(size_t zcode) {
123  return (m_zmap.erase(zcode) == 1);
124  }
125 
127  iterator begin() const {return m_zmap.begin();}
128 
130  iterator end() const {return m_zmap.end();}
131 
133  iterator near(size_t zcode) const {
134  iterator pos = lower(zcode);
135  if (pos != end())
136  return pos;
137  else if (pos != begin())
138  --pos;
139  return pos;
140  }
141 
143  iterator lower(size_t zcode) const {
144  return m_zmap.lower_bound(zcode);
145  }
146 
148  iterator upper(size_t zcode) const {
149  return m_zmap.upper_bound(zcode);
150  }
151 
153  uint triangle(iterator pos) const {
154  return pos->second;
155  }
156 
158  void clear() {
159  m_zmap.clear();
160  }
161 
162 private:
163 
165  map_type m_zmap;
166 };
167 
168 #endif
169 
170 #endif // DCFACESET_H
iterator near(size_t zcode) const
find a valid iterator near zcode, unless map is empty
Definition: dcfaceset.h:133
map_type m_zmap
map Morton code to array index
Definition: dcfaceset.h:165
void clear()
clear all data
Definition: dcfaceset.h:158
uint triangle(iterator pos) const
return triangle index for a given iterator
Definition: dcfaceset.h:153
iterator upper(size_t zcode) const
return iterator to face with zcode equal or smaller than zcode
Definition: dcfaceset.h:148
iterator begin() const
iterator to first index
Definition: dcfaceset.h:127
void insert(size_t zcode, uint idx)
replace face at idx with new one with zcode
Definition: dcfaceset.h:117
iterator lower(size_t zcode) const
return iterator to face with zcode equal or larger than zcode
Definition: dcfaceset.h:143
Definition: dcfaceset.h:109
bool erase(size_t zcode)
erase a face from map
Definition: dcfaceset.h:122
iterator end() const
end/invalid iterator
Definition: dcfaceset.h:130
Generated on Mon Jan 24 2022 03:03:16 for libsurf by   doxygen 1.8.5