QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
SpatialIndex.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) 2003, 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 "tools/Tools.h"
31
32#ifndef M_PI_2
33#define M_PI_2 1.57079632679489661922
34#endif
35
36namespace SpatialIndex
37{
38 class Point;
39 class LineSegment;
40 class Region;
41
42
43 typedef int64_t id_type;
44
51
53 {
54 public:
57 virtual std::string what();
58
59 private:
60 std::string m_error;
61 }; // InvalidPageException
62
63 //
64 // Interfaces
65 //
66
68 {
69 public:
70 virtual bool intersectsShape(const IShape& in) const = 0;
71 virtual bool containsShape(const IShape& in) const = 0;
72 virtual bool touchesShape(const IShape& in) const = 0;
73 virtual void getCenter(Point& out) const = 0;
74 virtual uint32_t getDimension() const = 0;
75 virtual void getMBR(Region& out) const = 0;
76 virtual double getArea() const = 0;
77 virtual double getMinimumDistance(const IShape& in) const = 0;
78 virtual ~IShape() {}
79 }; // IShape
80
82 {
83 public:
84 virtual bool intersectsShapeInTime(const ITimeShape& in) const = 0;
85 virtual bool intersectsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0;
86 virtual bool containsShapeInTime(const ITimeShape& in) const = 0;
87 virtual bool containsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0;
88 virtual bool touchesShapeInTime(const ITimeShape& in) const = 0;
89 virtual bool touchesShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0;
90 virtual double getAreaInTime() const = 0;
91 virtual double getAreaInTime(const Tools::IInterval& ivI) const = 0;
92 virtual double getIntersectingAreaInTime(const ITimeShape& r) const = 0;
93 virtual double getIntersectingAreaInTime(const Tools::IInterval& ivI, const ITimeShape& r) const = 0;
94 virtual ~ITimeShape() {}
95 }; // ITimeShape
96
98 {
99 public:
100 virtual void getVMBR(Region& out) const = 0;
101 virtual void getMBRAtTime(double t, Region& out) const = 0;
102 virtual ~IEvolvingShape() {}
103 }; // IEvolvingShape
104
106 {
107 public:
108 virtual id_type getIdentifier() const = 0;
109 virtual void getShape(IShape** out) const = 0;
110 virtual ~IEntry() {}
111 }; // IEntry
112
114 {
115 public:
116 virtual uint32_t getChildrenCount() const = 0;
117 virtual id_type getChildIdentifier(uint32_t index) const = 0;
118 virtual void getChildData(uint32_t index, uint32_t& len, byte** data) const = 0;
119 virtual void getChildShape(uint32_t index, IShape** out) const = 0;
120 virtual uint32_t getLevel() const = 0;
121 virtual bool isIndex() const = 0;
122 virtual bool isLeaf() const = 0;
123 virtual ~INode() {}
124 }; // INode
125
126 class SIDX_DLL IData : public IEntry
127 {
128 public:
129 virtual void getData(uint32_t& len, byte** data) const = 0;
130 virtual ~IData() {}
131 }; // IData
132
134 {
135 public:
136 virtual IData* getNext() = 0;
137 virtual ~IDataStream() {}
138 }; // IDataStream
139
141 {
142 public:
143 virtual void execute(const INode& in) = 0;
144 virtual ~ICommand() {}
145 }; // ICommand
146
148 {
149 public:
150 virtual double getMinimumDistance(const IShape& query, const IShape& entry) = 0;
151 virtual double getMinimumDistance(const IShape& query, const IData& data) = 0;
153 }; // INearestNeighborComparator
154
156 {
157 public:
158 virtual void loadByteArray(const id_type id, uint32_t& len, byte** data) = 0;
159 virtual void storeByteArray(id_type& id, const uint32_t len, const byte* const data) = 0;
160 virtual void deleteByteArray(const id_type id) = 0;
161 virtual void flush() = 0;
162 virtual ~IStorageManager() {}
163 }; // IStorageManager
164
166 {
167 public:
168 virtual void visitNode(const INode& in) = 0;
169 virtual void visitData(const IData& in) = 0;
170 virtual void visitData(std::vector<const IData*>& v) = 0;
171 virtual ~IVisitor() {}
172 }; // IVisitor
173
175 {
176 public:
177 virtual void getNextEntry(const IEntry& previouslyFetched, id_type& nextEntryToFetch, bool& bFetchNextEntry) = 0;
178 virtual ~IQueryStrategy() {}
179 }; // IQueryStrategy
180
182 {
183 public:
184 virtual uint64_t getReads() const = 0;
185 virtual uint64_t getWrites() const = 0;
186 virtual uint32_t getNumberOfNodes() const = 0;
187 virtual uint64_t getNumberOfData() const = 0;
188 virtual ~IStatistics() {}
189 }; // IStatistics
190
192 {
193 public:
194 virtual void insertData(uint32_t len, const byte* pData, const IShape& shape, id_type shapeIdentifier) = 0;
195 virtual bool deleteData(const IShape& shape, id_type shapeIdentifier) = 0;
196 virtual void containsWhatQuery(const IShape& query, IVisitor& v) = 0;
197 virtual void intersectsWithQuery(const IShape& query, IVisitor& v) = 0;
198 virtual void pointLocationQuery(const Point& query, IVisitor& v) = 0;
199 virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v, INearestNeighborComparator& nnc) = 0;
200 virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v) = 0;
201 virtual void selfJoinQuery(const IShape& s, IVisitor& v) = 0;
202 virtual void queryStrategy(IQueryStrategy& qs) = 0;
203 virtual void getIndexProperties(Tools::PropertySet& out) const = 0;
204 virtual void addCommand(ICommand* in, CommandType ct) = 0;
205 virtual bool isIndexValid() = 0;
206 virtual void getStatistics(IStatistics** out) const = 0;
207 virtual ~ISpatialIndex() {}
208
209 }; // ISpatialIndex
210
211 namespace StorageManager
212 {
218
220 {
221 public:
222 virtual uint64_t getHits() = 0;
223 virtual void clear() = 0;
224 virtual ~IBuffer() {}
225 }; // IBuffer
226
229
231 SIDX_DLL IStorageManager* createNewDiskStorageManager(std::string& baseName, uint32_t pageSize);
233
235 SIDX_DLL IBuffer* createNewRandomEvictionsBuffer(IStorageManager& in, uint32_t capacity, bool bWriteThrough);
236 }
237
238 //
239 // Global functions
240 //
241 SIDX_DLL std::ostream& operator<<(std::ostream&, const ISpatialIndex&);
242 SIDX_DLL std::ostream& operator<<(std::ostream&, const IStatistics&);
243}
244
245#include "Point.h"
246#include "Region.h"
247#include "LineSegment.h"
248#include "TimePoint.h"
249#include "TimeRegion.h"
250#include "MovingPoint.h"
251#include "MovingRegion.h"
252#include "RTree.h"
253//#include "MVRTree.h"
254//#include "TPRTree.h"
255#include "Version.h"
256
257
258// typedef SpatialIndex::Tools::PoolPointer<Region> RegionPtr;
259// typedef SpatialIndex::Tools::PoolPointer<Point> PointPtr;
260// typedef SpatialIndex::Tools::PoolPointer<TimeRegion> TimeRegionPtr;
261// typedef SpatialIndex::Tools::PoolPointer<MovingRegion> MovingRegionPtr;
@ Region
Definition RSMetaType.h:57
Base class for all point drawing tools.
Definition Point.js:18
Definition SpatialIndex.h:141
virtual ~ICommand()
Definition SpatialIndex.h:144
virtual void execute(const INode &in)=0
Definition SpatialIndex.h:127
virtual ~IData()
Definition SpatialIndex.h:130
virtual void getData(uint32_t &len, byte **data) const =0
Definition SpatialIndex.h:134
virtual ~IDataStream()
Definition SpatialIndex.h:137
virtual IData * getNext()=0
Definition SpatialIndex.h:106
virtual ~IEntry()
Definition SpatialIndex.h:110
virtual void getShape(IShape **out) const =0
virtual id_type getIdentifier() const =0
Definition SpatialIndex.h:98
virtual ~IEvolvingShape()
Definition SpatialIndex.h:102
virtual void getVMBR(Region &out) const =0
virtual void getMBRAtTime(double t, Region &out) const =0
Definition SpatialIndex.h:148
virtual double getMinimumDistance(const IShape &query, const IData &data)=0
virtual ~INearestNeighborComparator()
Definition SpatialIndex.h:152
virtual double getMinimumDistance(const IShape &query, const IShape &entry)=0
Definition SpatialIndex.h:114
virtual uint32_t getChildrenCount() const =0
virtual uint32_t getLevel() const =0
virtual void getChildShape(uint32_t index, IShape **out) const =0
virtual id_type getChildIdentifier(uint32_t index) const =0
virtual bool isIndex() const =0
virtual ~INode()
Definition SpatialIndex.h:123
virtual bool isLeaf() const =0
virtual void getChildData(uint32_t index, uint32_t &len, byte **data) const =0
Definition SpatialIndex.h:175
virtual void getNextEntry(const IEntry &previouslyFetched, id_type &nextEntryToFetch, bool &bFetchNextEntry)=0
virtual ~IQueryStrategy()
Definition SpatialIndex.h:178
Definition SpatialIndex.h:68
virtual bool containsShape(const IShape &in) const =0
virtual bool touchesShape(const IShape &in) const =0
virtual bool intersectsShape(const IShape &in) const =0
virtual double getMinimumDistance(const IShape &in) const =0
virtual void getCenter(Point &out) const =0
virtual ~IShape()
Definition SpatialIndex.h:78
virtual uint32_t getDimension() const =0
virtual double getArea() const =0
virtual void getMBR(Region &out) const =0
Definition SpatialIndex.h:192
virtual void addCommand(ICommand *in, CommandType ct)=0
virtual void selfJoinQuery(const IShape &s, IVisitor &v)=0
virtual void intersectsWithQuery(const IShape &query, IVisitor &v)=0
virtual void insertData(uint32_t len, const byte *pData, const IShape &shape, id_type shapeIdentifier)=0
virtual ~ISpatialIndex()
Definition SpatialIndex.h:207
virtual bool deleteData(const IShape &shape, id_type shapeIdentifier)=0
virtual void pointLocationQuery(const Point &query, IVisitor &v)=0
virtual void nearestNeighborQuery(uint32_t k, const IShape &query, IVisitor &v, INearestNeighborComparator &nnc)=0
virtual void nearestNeighborQuery(uint32_t k, const IShape &query, IVisitor &v)=0
virtual void getStatistics(IStatistics **out) const =0
virtual bool isIndexValid()=0
virtual void getIndexProperties(Tools::PropertySet &out) const =0
virtual void queryStrategy(IQueryStrategy &qs)=0
virtual void containsWhatQuery(const IShape &query, IVisitor &v)=0
Definition SpatialIndex.h:182
virtual uint64_t getNumberOfData() const =0
virtual ~IStatistics()
Definition SpatialIndex.h:188
virtual uint64_t getWrites() const =0
virtual uint32_t getNumberOfNodes() const =0
virtual uint64_t getReads() const =0
Definition SpatialIndex.h:156
virtual void storeByteArray(id_type &id, const uint32_t len, const byte *const data)=0
virtual ~IStorageManager()
Definition SpatialIndex.h:162
virtual void loadByteArray(const id_type id, uint32_t &len, byte **data)=0
virtual void deleteByteArray(const id_type id)=0
Definition SpatialIndex.h:82
virtual double getIntersectingAreaInTime(const Tools::IInterval &ivI, const ITimeShape &r) const =0
virtual bool touchesShapeInTime(const ITimeShape &in) const =0
virtual double getIntersectingAreaInTime(const ITimeShape &r) const =0
virtual bool containsShapeInTime(const ITimeShape &in) const =0
virtual double getAreaInTime(const Tools::IInterval &ivI) const =0
virtual bool intersectsShapeInTime(const Tools::IInterval &ivI, const ITimeShape &in) const =0
virtual double getAreaInTime() const =0
virtual bool containsShapeInTime(const Tools::IInterval &ivI, const ITimeShape &in) const =0
virtual bool touchesShapeInTime(const Tools::IInterval &ivI, const ITimeShape &in) const =0
virtual ~ITimeShape()
Definition SpatialIndex.h:94
virtual bool intersectsShapeInTime(const ITimeShape &in) const =0
Definition SpatialIndex.h:166
virtual void visitData(std::vector< const IData * > &v)=0
virtual ~IVisitor()
Definition SpatialIndex.h:171
virtual void visitNode(const INode &in)=0
virtual void visitData(const IData &in)=0
Definition SpatialIndex.h:53
std::string m_error
Definition SpatialIndex.h:60
virtual ~InvalidPageException()
Definition SpatialIndex.h:56
Definition Point.h:35
Definition Region.h:33
Definition SpatialIndex.h:220
virtual ~IBuffer()
Definition SpatialIndex.h:224
Definition Tools.h:125
Definition Tools.h:201
Definition Tools.h:215
Definition Tools.h:256
Definition Tools.h:225
Definition Tools.h:308
SIDX_DLL IBuffer * createNewRandomEvictionsBuffer(IStorageManager &in, uint32_t capacity, bool bWriteThrough)
SIDX_DLL IStorageManager * createNewDiskStorageManager(std::string &baseName, uint32_t pageSize)
SIDX_DLL IStorageManager * returnDiskStorageManager(Tools::PropertySet &in)
SIDX_DLL IStorageManager * returnMemoryStorageManager(Tools::PropertySet &in)
SIDX_DLL IStorageManager * createNewMemoryStorageManager()
SIDX_DLL IStorageManager * loadDiskStorageManager(std::string &baseName)
StorageManagerConstants
Definition SpatialIndex.h:214
@ NewPage
Definition SpatialIndex.h:216
@ EmptyPage
Definition SpatialIndex.h:215
SIDX_DLL IBuffer * returnRandomEvictionsBuffer(IStorageManager &ind, Tools::PropertySet &in)
Definition CustomStorage.h:34
CommandType
Definition SpatialIndex.h:46
@ CT_NODEDELETE
Definition SpatialIndex.h:48
@ CT_NODEREAD
Definition SpatialIndex.h:47
@ CT_NODEWRITE
Definition SpatialIndex.h:49
SIDX_DLL std::ostream & operator<<(std::ostream &os, const LineSegment &pt)
int64_t id_type
Definition SpatialIndex.h:43
char s
Definition opennurbs_string.cpp:32
#define SIDX_DLL
Definition sidx_export.h:41