QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RTree.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
30#include "Statistics.h"
31#include "Node.h"
32#include "PointerPoolNode.h"
33
34namespace SpatialIndex
35{
36 namespace RTree
37 {
38 class RTree : public ISpatialIndex
39 {
40 //class NNEntry;
41
42 public:
44 // String Value Description
45 // ----------------------------------------------
46 // IndexIndentifier VT_LONG If specified an existing index will be openened from the supplied
47 // storage manager with the given index id. Behaviour is unspecified
48 // if the index id or the storage manager are incorrect.
49 // Dimension VT_ULONG Dimensionality of the data that will be inserted.
50 // IndexCapacity VT_ULONG The index node capacity. Default is 100.
51 // LeafCapactiy VT_ULONG The leaf node capacity. Default is 100.
52 // FillFactor VT_DOUBLE The fill factor. Default is 70%
53 // TreeVariant VT_LONG Can be one of Linear, Quadratic or Rstar. Default is Rstar
54 // NearMinimumOverlapFactor VT_ULONG Default is 32.
55 // SplitDistributionFactor VT_DOUBLE Default is 0.4
56 // ReinsertFactor VT_DOUBLE Default is 0.3
57 // EnsureTightMBRs VT_BOOL Default is true
58 // IndexPoolCapacity VT_LONG Default is 100
59 // LeafPoolCapacity VT_LONG Default is 100
60 // RegionPoolCapacity VT_LONG Default is 1000
61 // PointPoolCapacity VT_LONG Default is 500
62
63 virtual ~RTree();
64
65
66
67 //
68 // ISpatialIndex interface
69 //
70 virtual void insertData(uint32_t len, const byte* pData, const IShape& shape, id_type shapeIdentifier);
71 virtual bool deleteData(const IShape& shape, id_type id);
72 virtual void containsWhatQuery(const IShape& query, IVisitor& v);
73 virtual void intersectsWithQuery(const IShape& query, IVisitor& v);
74 virtual void pointLocationQuery(const Point& query, IVisitor& v);
75 virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v, INearestNeighborComparator&);
76 virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v);
77 virtual void selfJoinQuery(const IShape& s, IVisitor& v);
78 virtual void queryStrategy(IQueryStrategy& qs);
79 virtual void getIndexProperties(Tools::PropertySet& out) const;
80 virtual void addCommand(ICommand* pCommand, CommandType ct);
81 virtual bool isIndexValid();
82 virtual void getStatistics(IStatistics** out) const;
83
84 private:
88 void loadHeader();
89
90 void insertData_impl(uint32_t dataLength, byte* pData, Region& mbr, id_type id);
91 void insertData_impl(uint32_t dataLength, byte* pData, Region& mbr, id_type id, uint32_t level, byte* overflowTable);
92 bool deleteData_impl(const Region& mbr, id_type id);
93
97
98 void rangeQuery(RangeQueryType type, const IShape& query, IVisitor& v);
99 void selfJoinQuery(id_type id1, id_type id2, const Region& r, IVisitor& vis);
100 void visitSubTree(NodePtr subTree, IVisitor& v);
101
103
105
107
109
111
113
115 // The R*-Tree 'p' constant, for calculating nearly minimum overlap cost.
116 // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
117 // for Points and Rectangles', Section 4.1]
118
120 // The R*-Tree 'm' constant, for calculating spliting distributions.
121 // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
122 // for Points and Rectangles', Section 4.2]
123
125 // The R*-Tree 'p' constant, for removing entries at reinserts.
126 // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
127 // for Points and Rectangles', Section 4.3]
128
129 uint32_t m_dimension;
130
132
134
136
141
142 std::vector<Tools::SmartPointer<ICommand> > m_writeNodeCommands;
143 std::vector<Tools::SmartPointer<ICommand> > m_readNodeCommands;
144 std::vector<Tools::SmartPointer<ICommand> > m_deleteNodeCommands;
145
146#ifdef HAVE_PTHREAD_H
147 pthread_mutex_t m_lock;
148#endif
149
151 {
152 public:
155 double m_minDist;
156
157 NNEntry(id_type id, IEntry* e, double f) : m_id(id), m_pEntry(e), m_minDist(f) {}
159
160 struct ascending : public std::binary_function<NNEntry*, NNEntry*, bool>
161 {
162 bool operator()(const NNEntry* __x, const NNEntry* __y) const { return __x->m_minDist > __y->m_minDist; }
163 };
164 }; // NNEntry
165
167 {
168 public:
169 double getMinimumDistance(const IShape& query, const IShape& entry)
170 {
171 return query.getMinimumDistance(entry);
172 }
173
174 double getMinimumDistance(const IShape& query, const IData& data)
175 {
176 IShape* pS;
177 data.getShape(&pS);
178 double ret = query.getMinimumDistance(*pS);
179 delete pS;
180 return ret;
181 }
182 }; // NNComparator
183
185 {
186 public:
187 ValidateEntry(Region& r, NodePtr& pNode) : m_parentMBR(r), m_pNode(pNode) {}
188
191 }; // ValidateEntry
192
193 friend class Node;
194 friend class Leaf;
195 friend class Index;
196 friend class BulkLoader;
197
198 friend std::ostream& operator<<(std::ostream& os, const RTree& t);
199 }; // RTree
200
201 std::ostream& operator<<(std::ostream& os, const RTree& t);
202 }
203}
Definition SpatialIndex.h:141
Definition SpatialIndex.h:127
Definition SpatialIndex.h:106
virtual void getShape(IShape **out) const =0
Definition SpatialIndex.h:148
Definition SpatialIndex.h:175
Definition SpatialIndex.h:68
virtual double getMinimumDistance(const IShape &in) const =0
Definition SpatialIndex.h:192
Definition SpatialIndex.h:182
Definition SpatialIndex.h:156
Definition SpatialIndex.h:166
Definition Point.h:35
Definition BulkLoader.h:106
Definition Index.h:35
Definition Leaf.h:35
Definition Node.h:42
double getMinimumDistance(const IShape &query, const IData &data)
Definition RTree.h:174
double getMinimumDistance(const IShape &query, const IShape &entry)
Definition RTree.h:169
Definition RTree.h:151
~NNEntry()
Definition RTree.h:158
NNEntry(id_type id, IEntry *e, double f)
Definition RTree.h:157
IEntry * m_pEntry
Definition RTree.h:154
id_type m_id
Definition RTree.h:153
double m_minDist
Definition RTree.h:155
Definition RTree.h:185
Region m_parentMBR
Definition RTree.h:189
ValidateEntry(Region &r, NodePtr &pNode)
Definition RTree.h:187
NodePtr m_pNode
Definition RTree.h:190
Definition RTree.h:39
NodePtr readNode(id_type page)
void visitSubTree(NodePtr subTree, IVisitor &v)
void rangeQuery(RangeQueryType type, const IShape &query, IVisitor &v)
uint32_t m_leafCapacity
Definition RTree.h:112
RTreeVariant m_treeVariant
Definition RTree.h:106
double m_fillFactor
Definition RTree.h:108
bool deleteData_impl(const Region &mbr, id_type id)
virtual bool isIndexValid()
id_type m_headerID
Definition RTree.h:104
virtual bool deleteData(const IShape &shape, id_type id)
uint32_t m_nearMinimumOverlapFactor
Definition RTree.h:114
virtual void nearestNeighborQuery(uint32_t k, const IShape &query, IVisitor &v)
void insertData_impl(uint32_t dataLength, byte *pData, Region &mbr, id_type id, uint32_t level, byte *overflowTable)
Tools::PointerPool< Region > m_regionPool
Definition RTree.h:138
Statistics m_stats
Definition RTree.h:133
Region m_infiniteRegion
Definition RTree.h:131
Tools::PointerPool< Point > m_pointPool
Definition RTree.h:137
RTree(IStorageManager &, Tools::PropertySet &)
bool m_bTightMBRs
Definition RTree.h:135
void initOld(Tools::PropertySet &ps)
virtual void pointLocationQuery(const Point &query, IVisitor &v)
Tools::PointerPool< Node > m_indexPool
Definition RTree.h:139
virtual void queryStrategy(IQueryStrategy &qs)
std::vector< Tools::SmartPointer< ICommand > > m_readNodeCommands
Definition RTree.h:143
virtual void selfJoinQuery(const IShape &s, IVisitor &v)
void selfJoinQuery(id_type id1, id_type id2, const Region &r, IVisitor &vis)
friend std::ostream & operator<<(std::ostream &os, const RTree &t)
std::vector< Tools::SmartPointer< ICommand > > m_deleteNodeCommands
Definition RTree.h:144
uint32_t m_dimension
Definition RTree.h:129
virtual void addCommand(ICommand *pCommand, CommandType ct)
Tools::PointerPool< Node > m_leafPool
Definition RTree.h:140
void insertData_impl(uint32_t dataLength, byte *pData, Region &mbr, id_type id)
uint32_t m_indexCapacity
Definition RTree.h:110
double m_reinsertFactor
Definition RTree.h:124
std::vector< Tools::SmartPointer< ICommand > > m_writeNodeCommands
Definition RTree.h:142
IStorageManager * m_pStorageManager
Definition RTree.h:102
virtual void nearestNeighborQuery(uint32_t k, const IShape &query, IVisitor &v, INearestNeighborComparator &)
virtual void insertData(uint32_t len, const byte *pData, const IShape &shape, id_type shapeIdentifier)
virtual void getStatistics(IStatistics **out) const
virtual void getIndexProperties(Tools::PropertySet &out) const
void initNew(Tools::PropertySet &)
id_type writeNode(Node *)
virtual void containsWhatQuery(const IShape &query, IVisitor &v)
double m_splitDistributionFactor
Definition RTree.h:119
id_type m_rootID
Definition RTree.h:104
virtual void intersectsWithQuery(const IShape &query, IVisitor &v)
Definition Statistics.h:40
Definition Region.h:33
Definition PointerPool.h:35
Definition Tools.h:308
RTreeVariant
Definition RTree.h:35
RangeQueryType
Definition RTree.h:53
std::ostream & operator<<(std::ostream &os, const RTree &t)
Definition CustomStorage.h:34
CommandType
Definition SpatialIndex.h:46
int64_t id_type
Definition SpatialIndex.h:43
char s
Definition opennurbs_string.cpp:32
Definition RTree.h:161
bool operator()(const NNEntry *__x, const NNEntry *__y) const
Definition RTree.h:162