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