QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
Node.h
Go to the documentation of this file.
1/******************************************************************************
2 * Project: libspatialindex - A C++ library for spatial indexing
3 * Author: Marios Hadjieleftheriou, [email protected]
4 ******************************************************************************
5 * Copyright (c) 2002, Marios Hadjieleftheriou
6 *
7 * All rights reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26******************************************************************************/
27
28#pragma once
29
30namespace SpatialIndex
31{
32 namespace TPRTree
33 {
34 class TPRTree;
35 class Leaf;
36 class Index;
37 class Node;
38
40
42 {
43 public:
44 virtual ~Node();
45
46 //
47 // Tools::IObject interface
48 //
50
51 //
52 // Tools::ISerializable interface
53 //
54 virtual uint32_t getByteArraySize();
55 virtual void loadFromByteArray(const byte* data);
56 virtual void storeToByteArray(byte** data, uint32_t& len);
57
58 //
59 // SpatialIndex::IEntry interface
60 //
61 virtual id_type getIdentifier() const;
62 virtual void getShape(IShape** out) const;
63
64 //
65 // SpatialIndex::INode interface
66 //
67 virtual uint32_t getChildrenCount() const;
68 virtual id_type getChildIdentifier(uint32_t index) const;
69 virtual void getChildShape(uint32_t index, IShape** out) const;
70 virtual void getChildData(uint32_t index, uint32_t& length, byte** data) const;
71 virtual uint32_t getLevel() const;
72 virtual bool isIndex() const;
73 virtual bool isLeaf() const;
74
75 private:
77 Node(TPRTree* pTree, id_type id, uint32_t level, uint32_t capacity);
78
79 virtual Node& operator=(const Node&);
80
81 virtual bool insertEntry(uint32_t dataLength, byte* pData, MovingRegion& mbr, id_type id);
82 virtual void deleteEntry(uint32_t index);
83
84 virtual bool insertData(uint32_t dataLength, byte* pData, MovingRegion& mbr, id_type id, std::stack<id_type>& pathBuffer, byte* overflowTable);
85 virtual void reinsertData(uint32_t dataLength, byte* pData, MovingRegion& mbr, id_type id, std::vector<uint32_t>& reinsert, std::vector<uint32_t>& keep);
86
87 virtual void rstarSplit(uint32_t dataLength, byte* pData, MovingRegion& mbr, id_type id, std::vector<uint32_t>& group1, std::vector<uint32_t>& group2);
88
89 virtual void condenseTree(std::stack<NodePtr>& toReinsert, std::stack<id_type>& pathBuffer, NodePtr& ptrThis);
90
91 virtual NodePtr chooseSubtree(const MovingRegion& mbr, uint32_t level, std::stack<id_type>& pathBuffer) = 0;
92 virtual NodePtr findLeaf(const MovingRegion& mbr, id_type id, std::stack<id_type>& pathBuffer) = 0;
93
94 virtual void split(uint32_t dataLength, byte* pData, MovingRegion& mbr, id_type id, NodePtr& left, NodePtr& right) = 0;
95
97 // Parent of all nodes.
98
99 uint32_t m_level;
100 // The level of the node in the tree.
101 // Leaves are always at level 0.
102
104 // The unique ID of this node.
105
106 uint32_t m_children;
107 // The number of children pointed by this node.
108
109 uint32_t m_capacity;
110 // Specifies the node capacity.
111
113 // The minimum bounding region enclosing all data contained in the node.
114
115 byte** m_pData;
116 // The data stored in the node.
117
119 // The corresponding data MBRs.
120
122 // The corresponding data identifiers.
123
124 uint32_t* m_pDataLength;
125
127
129 {
130 public:
132 uint32_t m_index;
133 uint32_t m_sortDim;
134
135 RstarSplitEntry(MovingRegion* pr, uint32_t index, uint32_t dimension)
136 : m_pRegion(pr), m_index(index), m_sortDim(dimension) {}
137
138 static int compareLow(const void* pv1, const void* pv2)
139 {
140 RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
141 RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
142
143 if (pe1->m_pRegion->m_pLow[pe1->m_sortDim] < pe2->m_pRegion->m_pLow[pe1->m_sortDim]) return -1;
144 if (pe1->m_pRegion->m_pLow[pe1->m_sortDim] > pe2->m_pRegion->m_pLow[pe1->m_sortDim]) return 1;
145 return 0;
146 }
147
148 static int compareHigh(const void* pv1, const void* pv2)
149 {
150 RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
151 RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
152
153 if (pe1->m_pRegion->m_pHigh[pe1->m_sortDim] < pe2->m_pRegion->m_pHigh[pe1->m_sortDim]) return -1;
154 if (pe1->m_pRegion->m_pHigh[pe1->m_sortDim] > pe2->m_pRegion->m_pHigh[pe1->m_sortDim]) return 1;
155 return 0;
156 }
157
158 static int compareVLow(const void* pv1, const void* pv2)
159 {
160 RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
161 RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
162
163 if (pe1->m_pRegion->m_pVLow[pe1->m_sortDim] < pe2->m_pRegion->m_pVLow[pe1->m_sortDim]) return -1;
164 if (pe1->m_pRegion->m_pVLow[pe1->m_sortDim] > pe2->m_pRegion->m_pVLow[pe1->m_sortDim]) return 1;
165 return 0;
166 }
167
168 static int compareVHigh(const void* pv1, const void* pv2)
169 {
170 RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
171 RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
172
173 if (pe1->m_pRegion->m_pVHigh[pe1->m_sortDim] < pe2->m_pRegion->m_pVHigh[pe1->m_sortDim]) return -1;
174 if (pe1->m_pRegion->m_pVHigh[pe1->m_sortDim] > pe2->m_pRegion->m_pVHigh[pe1->m_sortDim]) return 1;
175 return 0;
176 }
177 }; // RstarSplitEntry
178
180 {
181 public:
182 uint32_t m_index;
183 double m_dist;
184
185 ReinsertEntry(uint32_t index, double dist) : m_index(index), m_dist(dist) {}
186
187 static int compareReinsertEntry(const void* pv1, const void* pv2)
188 {
189 ReinsertEntry* pe1 = * (ReinsertEntry**) pv1;
190 ReinsertEntry* pe2 = * (ReinsertEntry**) pv2;
191
192 if (pe1->m_dist < pe2->m_dist) return -1;
193 if (pe1->m_dist > pe2->m_dist) return 1;
194 return 0;
195 }
196 }; // ReinsertEntry
197
198 // Needed to access protected members without having to cast from Node.
199 // It is more efficient than using member functions to access protected members.
200 friend class TPRTree;
201 friend class Leaf;
202 friend class Index;
203 friend class Tools::PointerPool<Node>;
204 }; // Node
205 }
206}
Definition Index.h:34
Definition SpatialIndex.h:114
Definition SpatialIndex.h:68
Definition MovingRegion.h:33
double * m_pVLow
Definition MovingRegion.h:162
double * m_pVHigh
Definition MovingRegion.h:163
double * m_pHigh
Definition Region.h:99
double * m_pLow
Definition Region.h:98
Definition Index.h:35
Definition Leaf.h:35
Definition Node.h:180
ReinsertEntry(uint32_t index, double dist)
Definition Node.h:185
static int compareReinsertEntry(const void *pv1, const void *pv2)
Definition Node.h:187
uint32_t m_index
Definition Node.h:182
double m_dist
Definition Node.h:183
Definition Node.h:129
static int compareVHigh(const void *pv1, const void *pv2)
Definition Node.h:168
RstarSplitEntry(MovingRegion *pr, uint32_t index, uint32_t dimension)
Definition Node.h:135
MovingRegion * m_pRegion
Definition Node.h:131
uint32_t m_index
Definition Node.h:132
static int compareHigh(const void *pv1, const void *pv2)
Definition Node.h:148
static int compareLow(const void *pv1, const void *pv2)
Definition Node.h:138
uint32_t m_sortDim
Definition Node.h:133
static int compareVLow(const void *pv1, const void *pv2)
Definition Node.h:158
Definition Node.h:42
uint32_t * m_pDataLength
Definition Node.h:124
virtual bool isIndex() const
MovingRegionPtr * m_ptrMBR
Definition Node.h:118
virtual void storeToByteArray(byte **data, uint32_t &len)
uint32_t m_level
Definition Node.h:99
virtual NodePtr findLeaf(const MovingRegion &mbr, id_type id, std::stack< id_type > &pathBuffer)=0
virtual void getShape(IShape **out) const
id_type m_identifier
Definition Node.h:103
TPRTree * m_pTree
Definition Node.h:96
virtual uint32_t getLevel() const
virtual void rstarSplit(uint32_t dataLength, byte *pData, MovingRegion &mbr, id_type id, std::vector< uint32_t > &group1, std::vector< uint32_t > &group2)
virtual Tools::IObject * clone()
virtual void condenseTree(std::stack< NodePtr > &toReinsert, std::stack< id_type > &pathBuffer, NodePtr &ptrThis)
virtual void getChildData(uint32_t index, uint32_t &length, byte **data) const
MovingRegion m_nodeMBR
Definition Node.h:112
id_type * m_pIdentifier
Definition Node.h:121
virtual bool insertEntry(uint32_t dataLength, byte *pData, MovingRegion &mbr, id_type id)
uint32_t m_totalDataLength
Definition Node.h:126
virtual uint32_t getChildrenCount() const
virtual void loadFromByteArray(const byte *data)
virtual NodePtr chooseSubtree(const MovingRegion &mbr, uint32_t level, std::stack< id_type > &pathBuffer)=0
byte ** m_pData
Definition Node.h:115
virtual bool isLeaf() const
virtual void split(uint32_t dataLength, byte *pData, MovingRegion &mbr, id_type id, NodePtr &left, NodePtr &right)=0
uint32_t m_capacity
Definition Node.h:109
virtual Node & operator=(const Node &)
virtual void reinsertData(uint32_t dataLength, byte *pData, MovingRegion &mbr, id_type id, std::vector< uint32_t > &reinsert, std::vector< uint32_t > &keep)
uint32_t m_children
Definition Node.h:106
virtual id_type getChildIdentifier(uint32_t index) const
virtual id_type getIdentifier() const
virtual uint32_t getByteArraySize()
virtual bool insertData(uint32_t dataLength, byte *pData, MovingRegion &mbr, id_type id, std::stack< id_type > &pathBuffer, byte *overflowTable)
virtual void getChildShape(uint32_t index, IShape **out) const
virtual void deleteEntry(uint32_t index)
Node(TPRTree *pTree, id_type id, uint32_t level, uint32_t capacity)
Definition TPRTree.h:39
Definition Tools.h:215
Definition PointerPool.h:35
Definition PoolPointer.h:37
Tools::PoolPointer< Node > NodePtr
Definition Node.h:39
Definition CustomStorage.h:34
int64_t id_type
Definition SpatialIndex.h:43