QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
MVRTree.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 MVRTree
37 {
38 class MVRTree : public ISpatialIndex
39 {
40 class NNEntry;
41 class RootEntry;
42
43 public:
45 // String Value Description
46 // ----------------------------------------------
47 // IndexIndentifier VT_LONG If specified an existing index will be openened from the supplied
48 // storage manager with the given index id. Behaviour is unspecified
49 // if the index id or the storage manager are incorrect.
50 // Dimension VT_ULONG Dimensionality of the data that will be inserted.
51 // IndexCapacity VT_ULONG The index node capacity. Default is 100.
52 // LeafCapactiy VT_ULONG The leaf node capacity. Default is 100.
53 // FillFactor VT_DOUBLE The fill factor. Default is 70%
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 // StrongVersionOverflow VT_DOUBLE Default is 0.8
64 // VersionUnderflow VT_DOUBLE Default is 0.3
65
66 virtual ~MVRTree();
67
68 //
69 // ISpatialIndex interface
70 //
71 virtual void insertData(uint32_t len, const byte* pData, const IShape& shape, id_type id);
72 virtual bool deleteData(const IShape& shape, id_type id);
73 virtual void containsWhatQuery(const IShape& query, IVisitor& v);
74 virtual void intersectsWithQuery(const IShape& query, IVisitor& v);
75 virtual void pointLocationQuery(const Point& query, IVisitor& v);
76 virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v, INearestNeighborComparator&);
77 virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v);
78 virtual void selfJoinQuery(const IShape& s, IVisitor& v);
79 virtual void queryStrategy(IQueryStrategy& qs);
80 virtual void getIndexProperties(Tools::PropertySet& out) const;
81 virtual void addCommand(ICommand* pCommand, CommandType ct);
82 virtual bool isIndexValid();
83 virtual void getStatistics(IStatistics** out) const;
84
85 private:
89 void loadHeader();
90
91 void insertData_impl(uint32_t dataLength, byte* pData, TimeRegion& mbr, id_type id);
92 void insertData_impl(uint32_t dataLength, byte* pData, TimeRegion& mbr, id_type id, uint32_t level);
93 bool deleteData_impl(const TimeRegion& mbr, id_type id);
94
97 void deleteNode(Node* n);
98
99 void rangeQuery(RangeQueryType type, const IShape& query, IVisitor& v);
100
101 void findRootIdentifiers(const Tools::IInterval& ti, std::vector<id_type>& ids);
102 std::string printRootInfo() const;
103
105
106 std::vector<RootEntry> m_roots;
108
110
112
114
116
118 // The R*-Tree 'p' constant, for calculating nearly minimum overlap cost.
119 // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
120 // for Points and Rectangles, Section 4.1]
121
123 // The R*-Tree 'm' constant, for calculating spliting distributions.
124 // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
125 // for Points and Rectangles, Section 4.2]
126
128 // The R*-Tree 'p' constant, for removing entries at reinserts.
129 // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
130 // for Points and Rectangles, Section 4.3]
131
133 //double m_strongVersionUnderflow;
135
136 uint32_t m_dimension;
137
139
141
143
145
147
152
153 std::vector<Tools::SmartPointer<ICommand> > m_writeNodeCommands;
154 std::vector<Tools::SmartPointer<ICommand> > m_readNodeCommands;
155 std::vector<Tools::SmartPointer<ICommand> > m_deleteNodeCommands;
156
157#ifdef HAVE_PTHREAD_H
158 pthread_mutex_t m_lock;
159#endif
160
162 {
163 public:
165 RootEntry(id_type id, double s, double e) : m_id(id), m_startTime(s), m_endTime(e) {}
166
169 double m_endTime;
170 }; // RootEntry
171
173 {
174 public:
177 double m_minDist;
178
179 NNEntry(id_type id, IEntry* e, double f) : m_id(id), m_pEntry(e), m_minDist(f) {}
181
182 struct greater : public std::binary_function<NNEntry*, NNEntry*, bool>
183 {
184 bool operator()(const NNEntry* __x, const NNEntry* __y) const { return __x->m_minDist > __y->m_minDist; }
185 };
186 }; // NNEntry
187
189 {
190 public:
191 double getMinimumDistance(const IShape& query, const IShape& entry)
192 {
193 return query.getMinimumDistance(entry);
194 }
195 double getMinimumDistance(const IShape& query, const IData& data)
196 {
197 IShape* pR;
198 data.getShape(&pR);
199 double ret = query.getMinimumDistance(*pR);
200 delete pR;
201 return ret;
202 }
203 }; // NNComparator
204
206 {
207 public:
209
214 }; // ValidateEntry
215
216 friend class Node;
217 friend class Leaf;
218 friend class Index;
219
220 friend std::ostream& operator<<(std::ostream& os, const MVRTree& t);
221 }; // MVRTree
222
223 std::ostream& operator<<(std::ostream& os, const MVRTree& t);
224 }
225}
226
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 Index.h:35
Definition Leaf.h:35
double getMinimumDistance(const IShape &query, const IShape &entry)
Definition MVRTree.h:191
double getMinimumDistance(const IShape &query, const IData &data)
Definition MVRTree.h:195
Definition MVRTree.h:173
~NNEntry()
Definition MVRTree.h:180
double m_minDist
Definition MVRTree.h:177
IEntry * m_pEntry
Definition MVRTree.h:176
id_type m_id
Definition MVRTree.h:175
NNEntry(id_type id, IEntry *e, double f)
Definition MVRTree.h:179
Definition MVRTree.h:162
double m_startTime
Definition MVRTree.h:168
RootEntry()
Definition MVRTree.h:164
id_type m_id
Definition MVRTree.h:167
double m_endTime
Definition MVRTree.h:169
RootEntry(id_type id, double s, double e)
Definition MVRTree.h:165
Definition MVRTree.h:206
TimeRegion m_parentMBR
Definition MVRTree.h:211
bool m_bIsDead
Definition MVRTree.h:213
id_type m_parentID
Definition MVRTree.h:210
ValidateEntry(id_type pid, TimeRegion &r, NodePtr &pNode)
Definition MVRTree.h:208
NodePtr m_pNode
Definition MVRTree.h:212
Definition MVRTree.h:39
double m_splitDistributionFactor
Definition MVRTree.h:122
void initOld(Tools::PropertySet &ps)
uint32_t m_nearMinimumOverlapFactor
Definition MVRTree.h:117
double m_versionUnderflow
Definition MVRTree.h:134
Tools::PointerPool< Point > m_pointPool
Definition MVRTree.h:148
uint32_t m_indexCapacity
Definition MVRTree.h:113
virtual bool deleteData(const IShape &shape, id_type id)
virtual void pointLocationQuery(const Point &query, IVisitor &v)
std::string printRootInfo() const
virtual void getIndexProperties(Tools::PropertySet &out) const
virtual void nearestNeighborQuery(uint32_t k, const IShape &query, IVisitor &v, INearestNeighborComparator &)
void insertData_impl(uint32_t dataLength, byte *pData, TimeRegion &mbr, id_type id)
uint32_t m_leafCapacity
Definition MVRTree.h:115
virtual void queryStrategy(IQueryStrategy &qs)
void insertData_impl(uint32_t dataLength, byte *pData, TimeRegion &mbr, id_type id, uint32_t level)
MVRTreeVariant m_treeVariant
Definition MVRTree.h:109
bool deleteData_impl(const TimeRegion &mbr, id_type id)
std::vector< RootEntry > m_roots
Definition MVRTree.h:106
Tools::PointerPool< Node > m_indexPool
Definition MVRTree.h:150
bool m_bTightMBRs
Definition MVRTree.h:142
TimeRegion m_infiniteRegion
Definition MVRTree.h:138
Tools::PointerPool< TimeRegion > m_regionPool
Definition MVRTree.h:149
void initNew(Tools::PropertySet &)
virtual void intersectsWithQuery(const IShape &query, IVisitor &v)
virtual void selfJoinQuery(const IShape &s, IVisitor &v)
bool m_bHasVersionCopied
Definition MVRTree.h:144
double m_fillFactor
Definition MVRTree.h:111
virtual void addCommand(ICommand *pCommand, CommandType ct)
double m_strongVersionOverflow
Definition MVRTree.h:132
SpatialIndex::MVRTree::Statistics m_stats
Definition MVRTree.h:140
NodePtr readNode(id_type id)
virtual void insertData(uint32_t len, const byte *pData, const IShape &shape, id_type id)
virtual void getStatistics(IStatistics **out) const
Tools::PointerPool< Node > m_leafPool
Definition MVRTree.h:151
id_type m_headerID
Definition MVRTree.h:107
void findRootIdentifiers(const Tools::IInterval &ti, std::vector< id_type > &ids)
std::vector< Tools::SmartPointer< ICommand > > m_readNodeCommands
Definition MVRTree.h:154
uint32_t m_dimension
Definition MVRTree.h:136
std::vector< Tools::SmartPointer< ICommand > > m_writeNodeCommands
Definition MVRTree.h:153
IStorageManager * m_pStorageManager
Definition MVRTree.h:104
double m_reinsertFactor
Definition MVRTree.h:127
virtual void containsWhatQuery(const IShape &query, IVisitor &v)
MVRTree(IStorageManager &, Tools::PropertySet &)
void rangeQuery(RangeQueryType type, const IShape &query, IVisitor &v)
friend std::ostream & operator<<(std::ostream &os, const MVRTree &t)
virtual void nearestNeighborQuery(uint32_t k, const IShape &query, IVisitor &v)
double m_currentTime
Definition MVRTree.h:146
std::vector< Tools::SmartPointer< ICommand > > m_deleteNodeCommands
Definition MVRTree.h:155
Definition Node.h:42
Definition Statistics.h:40
Definition Point.h:35
Definition TimeRegion.h:33
Definition Tools.h:201
Definition PointerPool.h:35
Definition Tools.h:308
RangeQueryType
Definition MVRTree.h:48
MVRTreeVariant
Definition MVRTree.h:35
std::ostream & operator<<(std::ostream &os, const MVRTree &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
#define false
Definition opennurbs_system.h:252
Definition MVRTree.h:183
bool operator()(const NNEntry *__x, const NNEntry *__y) const
Definition MVRTree.h:184