114 |
cycrow |
1 |
#ifndef NEW_POINT_MAP_INCLUDED
|
|
|
2 |
#define NEW_POINT_MAP_INCLUDED
|
|
|
3 |
|
|
|
4 |
#include "../common/ext_array.h"
|
|
|
5 |
#include "../common/ext_simple_list.h"
|
|
|
6 |
|
|
|
7 |
#include "../common/ext_patricia_trie.h"
|
|
|
8 |
|
|
|
9 |
class point_traits
|
|
|
10 |
{
|
|
|
11 |
public:
|
|
|
12 |
static const size_t element_bits=32;
|
|
|
13 |
|
|
|
14 |
static size_t size(const int *key) { return 3; }
|
|
|
15 |
static bool compare(const int *k1, const int *k2)
|
|
|
16 |
{
|
|
|
17 |
if(k1==0 || k2==0)
|
|
|
18 |
return false;
|
|
|
19 |
else
|
|
|
20 |
return
|
|
|
21 |
k1[0]==k2[0] &&
|
|
|
22 |
k1[1]==k2[1] &&
|
|
|
23 |
k1[2]==k2[2];
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
static int * copy(const int *key) { return (int*)key; }
|
|
|
27 |
static void free(int *key) { }
|
|
|
28 |
};
|
|
|
29 |
|
|
|
30 |
class bob_point_map
|
|
|
31 |
{
|
|
|
32 |
private:
|
|
|
33 |
class vertex_bucket;
|
|
|
34 |
class bucket_allocator;
|
|
|
35 |
typedef ext::array<bob_vertex*> vertex_array;
|
|
|
36 |
typedef ext::array<int> int_array;
|
|
|
37 |
typedef ext::simple_list<int> int_list;
|
|
|
38 |
typedef ext::patricia_trie<int, vertex_bucket, point_traits, bucket_allocator> vertex_trie;
|
|
|
39 |
|
|
|
40 |
vertex_trie m_trie;
|
|
|
41 |
vertex_array m_points; // all points
|
|
|
42 |
int_array m_indexes; // converted indexes
|
|
|
43 |
int m_pointSize; // size of points
|
|
|
44 |
|
|
|
45 |
int_list m_uniqueIndexes; // list of indexes to unique points in points array
|
|
|
46 |
int_list::iterator m_unique_it;
|
|
|
47 |
|
|
|
48 |
private:
|
|
|
49 |
class vertex_bucket
|
|
|
50 |
{
|
|
|
51 |
private:
|
|
|
52 |
int m_index;
|
|
|
53 |
public:
|
|
|
54 |
int index() const { return m_index; }
|
|
|
55 |
void index(int i) { m_index=i; }
|
|
|
56 |
|
|
|
57 |
vertex_bucket() { m_index=0; }
|
|
|
58 |
};
|
|
|
59 |
|
|
|
60 |
class bucket_allocator
|
|
|
61 |
{
|
|
|
62 |
public:
|
|
|
63 |
static void deallocate(vertex_bucket pb) { }
|
|
|
64 |
};
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
public:
|
|
|
68 |
typedef vertex_array::iterator iterator;
|
|
|
69 |
typedef vertex_array::const_iterator const_iterator;
|
|
|
70 |
typedef int_list::const_iterator const_index_iterator;
|
|
|
71 |
|
|
|
72 |
iterator begin() { return m_points.begin(); }
|
|
|
73 |
iterator end() { return m_points.end(); }
|
|
|
74 |
|
|
|
75 |
const_iterator begin() const { return m_points.begin(); }
|
|
|
76 |
const_iterator end() const { return m_points.end(); }
|
|
|
77 |
|
|
|
78 |
const_index_iterator indexBegin() const { return m_uniqueIndexes.begin(); }
|
|
|
79 |
const_index_iterator indexEnd() const { return m_uniqueIndexes.end(); }
|
|
|
80 |
|
|
|
81 |
size_t m_compCount;
|
|
|
82 |
|
|
|
83 |
void create(size_t size)
|
|
|
84 |
{
|
|
|
85 |
m_points.resize(size, 0);
|
|
|
86 |
m_indexes.resize(size);
|
|
|
87 |
m_pointSize=0;
|
|
|
88 |
m_compCount=0;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
void addPoint(bob_vertex * pnt)
|
|
|
92 |
{
|
|
|
93 |
vertex_bucket pb;
|
|
|
94 |
|
|
|
95 |
const int *coords=pnt->getCoordArray();
|
|
|
96 |
|
|
|
97 |
vertex_trie::iterator where=m_trie.find(coords);
|
|
|
98 |
if(where==m_trie.end()) {
|
|
|
99 |
pb.index((int)m_uniqueIndexes.size());
|
|
|
100 |
m_uniqueIndexes.push_back(m_pointSize);
|
|
|
101 |
|
|
|
102 |
m_trie.insert(vertex_trie::value_type(coords, pb));
|
|
|
103 |
}
|
|
|
104 |
else
|
|
|
105 |
pb=(*where).second;
|
|
|
106 |
|
|
|
107 |
m_points[m_pointSize]=pnt;
|
|
|
108 |
m_indexes[m_pointSize]=pb.index();
|
|
|
109 |
m_pointSize++;
|
|
|
110 |
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
bob_point_map() { m_pointSize=0; m_unique_it=m_uniqueIndexes.end(); }
|
|
|
114 |
~bob_point_map() { clear(); }
|
|
|
115 |
|
|
|
116 |
void clear()
|
|
|
117 |
{
|
|
|
118 |
m_trie.clear();
|
|
|
119 |
|
|
|
120 |
for(vertex_array::iterator &it=m_points.begin(); it!=m_points.end(); ++it){
|
|
|
121 |
delete *it;
|
|
|
122 |
}
|
|
|
123 |
m_points.clear();
|
|
|
124 |
m_indexes.clear();
|
|
|
125 |
m_pointSize=0;
|
|
|
126 |
|
|
|
127 |
m_unique_it=m_uniqueIndexes.end();
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
bob_vertex * operator[](int idx) { return m_points[idx]; }
|
|
|
131 |
const bob_vertex * operator[](int idx) const { return m_points[idx]; }
|
|
|
132 |
|
|
|
133 |
int uniqueIndex(int idx) const { return (size_t)idx < m_points.size() ? m_indexes[idx] : -1; }
|
|
|
134 |
|
|
|
135 |
size_t pointsSize() const { return m_points.size(); }
|
|
|
136 |
size_t uniquePointsSize() const { return m_uniqueIndexes.size(); }
|
|
|
137 |
|
|
|
138 |
bob_vertex * nextUniquePoint()
|
|
|
139 |
{
|
|
|
140 |
++m_unique_it;
|
|
|
141 |
bob_vertex *p=(m_unique_it!=m_uniqueIndexes.end() ? m_points[*m_unique_it] : 0);
|
|
|
142 |
return p;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
void test_trie_clear() { m_trie.test_clear(); }
|
|
|
146 |
|
|
|
147 |
};
|
|
|
148 |
|
|
|
149 |
#endif // !defined(NEW_POINT_MAP_INCLUDED)
|