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 RTree
33 {
34 class RTree;
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(RTree* pTree, id_type id, uint32_t level, uint32_t capacity);
78
79 virtual Node& operator=(const Node&);
80
81 virtual void insertEntry(uint32_t dataLength, byte* pData, Region& mbr, id_type id);
82 virtual void deleteEntry(uint32_t index);
83
84 virtual bool insertData(uint32_t dataLength, byte* pData, Region& mbr, id_type id, std::stack<id_type>& pathBuffer, byte* overflowTable);
85 virtual void reinsertData(uint32_t dataLength, byte* pData, Region& mbr, id_type id, std::vector<uint32_t>& reinsert, std::vector<uint32_t>& keep);
86
87 virtual void rtreeSplit(uint32_t dataLength, byte* pData, Region& mbr, id_type id, std::vector<uint32_t>& group1, std::vector<uint32_t>& group2);
88 virtual void rstarSplit(uint32_t dataLength, byte* pData, Region& mbr, id_type id, std::vector<uint32_t>& group1, std::vector<uint32_t>& group2);
89
90 virtual void pickSeeds(uint32_t& index1, uint32_t& index2);
91
92 virtual void condenseTree(std::stack<NodePtr>& toReinsert, std::stack<id_type>& pathBuffer, NodePtr& ptrThis);
93
94 virtual NodePtr chooseSubtree(const Region& mbr, uint32_t level, std::stack<id_type>& pathBuffer) = 0;
95 virtual NodePtr findLeaf(const Region& mbr, id_type id, std::stack<id_type>& pathBuffer) = 0;
96
97 virtual void split(uint32_t dataLength, byte* pData, Region& mbr, id_type id, NodePtr& left, NodePtr& right) = 0;
98
100 // Parent of all nodes.
101
102 uint32_t m_level;
103 // The level of the node in the tree.
104 // Leaves are always at level 0.
105
107 // The unique ID of this node.
108
109 uint32_t m_children;
110 // The number of children pointed by this node.
111
112 uint32_t m_capacity;
113 // Specifies the node capacity.
114
116 // The minimum bounding region enclosing all data contained in the node.
117
118 byte** m_pData;
119 // The data stored in the node.
120
122 // The corresponding data MBRs.
123
125 // The corresponding data identifiers.
126
127 uint32_t* m_pDataLength;
128
130
132 {
133 public:
135 uint32_t m_index;
136 uint32_t m_sortDim;
137
138 RstarSplitEntry(Region* pr, uint32_t index, uint32_t dimension) :
139 m_pRegion(pr), m_index(index), m_sortDim(dimension) {}
140
141 static int compareLow(const void* pv1, const void* pv2)
142 {
143 RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
144 RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
145
146 assert(pe1->m_sortDim == pe2->m_sortDim);
147
148 if (pe1->m_pRegion->m_pLow[pe1->m_sortDim] < pe2->m_pRegion->m_pLow[pe2->m_sortDim]) return -1;
149 if (pe1->m_pRegion->m_pLow[pe1->m_sortDim] > pe2->m_pRegion->m_pLow[pe2->m_sortDim]) return 1;
150 return 0;
151 }
152
153 static int compareHigh(const void* pv1, const void* pv2)
154 {
155 RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
156 RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
157
158 assert(pe1->m_sortDim == pe2->m_sortDim);
159
160 if (pe1->m_pRegion->m_pHigh[pe1->m_sortDim] < pe2->m_pRegion->m_pHigh[pe2->m_sortDim]) return -1;
161 if (pe1->m_pRegion->m_pHigh[pe1->m_sortDim] > pe2->m_pRegion->m_pHigh[pe2->m_sortDim]) return 1;
162 return 0;
163 }
164 }; // RstarSplitEntry
165
167 {
168 public:
169 uint32_t m_index;
170 double m_dist;
171
172 ReinsertEntry(uint32_t index, double dist) : m_index(index), m_dist(dist) {}
173
174 static int compareReinsertEntry(const void* pv1, const void* pv2)
175 {
176 ReinsertEntry* pe1 = * (ReinsertEntry**) pv1;
177 ReinsertEntry* pe2 = * (ReinsertEntry**) pv2;
178
179 if (pe1->m_dist < pe2->m_dist) return -1;
180 if (pe1->m_dist > pe2->m_dist) return 1;
181 return 0;
182 }
183 }; // ReinsertEntry
184
185 // Needed to access protected members without having to cast from Node.
186 // It is more efficient than using member functions to access protected members.
187 friend class RTree;
188 friend class Leaf;
189 friend class Index;
190 friend class Tools::PointerPool<Node>;
191 friend class BulkLoader;
192 }; // Node
193 }
194}
Definition Index.h:34
Definition SpatialIndex.h:114
Definition SpatialIndex.h:68
Definition BulkLoader.h:106
Definition Index.h:35
Definition Leaf.h:35
Definition Node.h:167
ReinsertEntry(uint32_t index, double dist)
Definition Node.h:172
uint32_t m_index
Definition Node.h:169
static int compareReinsertEntry(const void *pv1, const void *pv2)
Definition Node.h:174
double m_dist
Definition Node.h:170
Definition Node.h:132
static int compareLow(const void *pv1, const void *pv2)
Definition Node.h:141
static int compareHigh(const void *pv1, const void *pv2)
Definition Node.h:153
Region * m_pRegion
Definition Node.h:134
RstarSplitEntry(Region *pr, uint32_t index, uint32_t dimension)
Definition Node.h:138
uint32_t m_index
Definition Node.h:135
uint32_t m_sortDim
Definition Node.h:136
Definition Node.h:42
virtual void loadFromByteArray(const byte *data)
id_type * m_pIdentifier
Definition Node.h:124
virtual NodePtr findLeaf(const Region &mbr, id_type id, std::stack< id_type > &pathBuffer)=0
virtual void deleteEntry(uint32_t index)
RTree * m_pTree
Definition Node.h:99
uint32_t m_level
Definition Node.h:102
uint32_t m_totalDataLength
Definition Node.h:129
virtual NodePtr chooseSubtree(const Region &mbr, uint32_t level, std::stack< id_type > &pathBuffer)=0
virtual void getChildShape(uint32_t index, IShape **out) const
virtual bool isIndex() const
uint32_t m_capacity
Definition Node.h:112
uint32_t * m_pDataLength
Definition Node.h:127
virtual Node & operator=(const Node &)
virtual void storeToByteArray(byte **data, uint32_t &len)
virtual id_type getChildIdentifier(uint32_t index) const
virtual void getShape(IShape **out) const
virtual bool insertData(uint32_t dataLength, byte *pData, Region &mbr, id_type id, std::stack< id_type > &pathBuffer, byte *overflowTable)
id_type m_identifier
Definition Node.h:106
virtual uint32_t getChildrenCount() const
virtual void getChildData(uint32_t index, uint32_t &length, byte **data) const
virtual void condenseTree(std::stack< NodePtr > &toReinsert, std::stack< id_type > &pathBuffer, NodePtr &ptrThis)
virtual bool isLeaf() const
virtual Tools::IObject * clone()
virtual void insertEntry(uint32_t dataLength, byte *pData, Region &mbr, id_type id)
virtual id_type getIdentifier() const
virtual uint32_t getLevel() const
RegionPtr * m_ptrMBR
Definition Node.h:121
virtual void pickSeeds(uint32_t &index1, uint32_t &index2)
virtual void split(uint32_t dataLength, byte *pData, Region &mbr, id_type id, NodePtr &left, NodePtr &right)=0
virtual void rstarSplit(uint32_t dataLength, byte *pData, Region &mbr, id_type id, std::vector< uint32_t > &group1, std::vector< uint32_t > &group2)
byte ** m_pData
Definition Node.h:118
virtual uint32_t getByteArraySize()
uint32_t m_children
Definition Node.h:109
Node(RTree *pTree, id_type id, uint32_t level, uint32_t capacity)
virtual void reinsertData(uint32_t dataLength, byte *pData, Region &mbr, id_type id, std::vector< uint32_t > &reinsert, std::vector< uint32_t > &keep)
virtual void rtreeSplit(uint32_t dataLength, byte *pData, Region &mbr, id_type id, std::vector< uint32_t > &group1, std::vector< uint32_t > &group2)
Region m_nodeMBR
Definition Node.h:115
Definition RTree.h:39
Definition Region.h:33
double * m_pHigh
Definition Region.h:99
double * m_pLow
Definition Region.h:98
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