libspatialindex API Reference  (git-trunk)
SpatialIndex.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Project: libspatialindex - A C++ library for spatial indexing
3  * Author: Marios Hadjieleftheriou, mhadji@gmail.com
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 
36 namespace SpatialIndex
37 {
38  class Point;
39  class Ball;
40  class LineSegment;
41  class Region;
42 
43 
44  typedef int64_t id_type;
45 
47  {
48  CT_NODEREAD = 0x0,
51  };
52 
54  {
55  public:
56  InvalidPageException(id_type id);
57  ~InvalidPageException() override = default;
58  std::string what() override;
59 
60  private:
61  std::string m_error;
62  }; // InvalidPageException
63 
64  //
65  // Interfaces
66  //
67 
69  {
70  public:
71  virtual bool intersectsShape(const IShape& in) const = 0;
72  virtual bool containsShape(const IShape& in) const = 0;
73  virtual bool touchesShape(const IShape& in) const = 0;
74  virtual void getCenter(Point& out) const = 0;
75  virtual uint32_t getDimension() const = 0;
76  virtual void getMBR(Region& out) const = 0;
77  virtual double getArea() const = 0;
78  virtual double getMinimumDistance(const IShape& in) const = 0;
79  ~IShape() override = default;
80  }; // IShape
81 
83  {
84  public:
85  virtual bool intersectsShapeInTime(const ITimeShape& in) const = 0;
86  virtual bool intersectsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0;
87  virtual bool containsShapeInTime(const ITimeShape& in) const = 0;
88  virtual bool containsShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0;
89  virtual bool touchesShapeInTime(const ITimeShape& in) const = 0;
90  virtual bool touchesShapeInTime(const Tools::IInterval& ivI, const ITimeShape& in) const = 0;
91  virtual double getAreaInTime() const = 0;
92  virtual double getAreaInTime(const Tools::IInterval& ivI) const = 0;
93  virtual double getIntersectingAreaInTime(const ITimeShape& r) const = 0;
94  virtual double getIntersectingAreaInTime(const Tools::IInterval& ivI, const ITimeShape& r) const = 0;
95  ~ITimeShape() override = default;
96  }; // ITimeShape
97 
99  {
100  public:
101  virtual void getVMBR(Region& out) const = 0;
102  virtual void getMBRAtTime(double t, Region& out) const = 0;
103  virtual ~IEvolvingShape() = default;
104  }; // IEvolvingShape
105 
107  {
108  public:
109  virtual id_type getIdentifier() const = 0;
110  virtual void getShape(IShape** out) const = 0;
111  ~IEntry() override = default;
112  }; // IEntry
113 
114  class SIDX_DLL INode : public IEntry, public Tools::ISerializable
115  {
116  public:
117  virtual uint32_t getChildrenCount() const = 0;
118  virtual id_type getChildIdentifier(uint32_t index) const = 0;
119  virtual void getChildData(uint32_t index, uint32_t& len, uint8_t** data) const = 0;
120  virtual void getChildShape(uint32_t index, IShape** out) const = 0;
121  virtual uint32_t getLevel() const = 0;
122  virtual bool isIndex() const = 0;
123  virtual bool isLeaf() const = 0;
124  ~INode() override = default;
125  }; // INode
126 
127  class SIDX_DLL IData : public IEntry
128  {
129  public:
130  virtual void getData(uint32_t& len, uint8_t** data) const = 0;
131  ~IData() override = default;
132  }; // IData
133 
135  {
136  public:
137  IData* getNext() override = 0;
138  ~IDataStream() override = default;
139  }; // IDataStream
140 
142  {
143  public:
144  virtual void execute(const INode& in) = 0;
145  virtual ~ICommand() = default;
146  }; // ICommand
147 
149  {
150  public:
151  virtual double getMinimumDistance(const IShape& query, const IShape& entry) = 0;
152  virtual double getMinimumDistance(const IShape& query, const IData& data) = 0;
153  virtual ~INearestNeighborComparator() = default;
154  }; // INearestNeighborComparator
155 
157  {
158  public:
159  virtual void loadByteArray(const id_type id, uint32_t& len, uint8_t** data) = 0;
160  virtual void storeByteArray(id_type& id, const uint32_t len, const uint8_t* const data) = 0;
161  virtual void deleteByteArray(const id_type id) = 0;
162  virtual void flush() = 0;
163  virtual ~IStorageManager() = default;
164  }; // IStorageManager
165 
167  {
168  public:
169  virtual void visitNode(const INode& in) = 0;
170  virtual void visitData(const IData& in) = 0;
171  virtual void visitData(std::vector<const IData*>& v) = 0;
172  virtual ~IVisitor() = default;
173  }; // IVisitor
174 
176  {
177  public:
178  virtual void getNextEntry(const IEntry& previouslyFetched, id_type& nextEntryToFetch, bool& bFetchNextEntry) = 0;
179  virtual ~IQueryStrategy() = default;
180  }; // IQueryStrategy
181 
183  {
184  public:
185  virtual uint64_t getReads() const = 0;
186  virtual uint64_t getWrites() const = 0;
187  virtual uint32_t getNumberOfNodes() const = 0;
188  virtual uint64_t getNumberOfData() const = 0;
189  virtual ~IStatistics() = default;
190  }; // IStatistics
191 
193  {
194  public:
195  virtual void insertData(uint32_t len, const uint8_t* pData, const IShape& shape, id_type shapeIdentifier) = 0;
196  virtual bool deleteData(const IShape& shape, id_type shapeIdentifier) = 0;
197  virtual void internalNodesQuery(const IShape& query, IVisitor& v) = 0;
198  virtual void containsWhatQuery(const IShape& query, IVisitor& v) = 0;
199  virtual void intersectsWithQuery(const IShape& query, IVisitor& v) = 0;
200  virtual void pointLocationQuery(const Point& query, IVisitor& v) = 0;
201  virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v, INearestNeighborComparator& nnc) = 0;
202  virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v) = 0;
203  virtual void selfJoinQuery(const IShape& s, IVisitor& v) = 0;
204  virtual void queryStrategy(IQueryStrategy& qs) = 0;
205  virtual void getIndexProperties(Tools::PropertySet& out) const = 0;
206  virtual void addCommand(ICommand* in, CommandType ct) = 0;
207  virtual bool isIndexValid() = 0;
208  virtual void getStatistics(IStatistics** out) const = 0;
209  virtual void flush() = 0;
210  virtual ~ISpatialIndex() = default;
211 
212  }; // ISpatialIndex
213 
214  namespace StorageManager
215  {
217  {
218  EmptyPage = -0x1,
219  NewPage = -0x1
220  };
221 
223  {
224  public:
225  virtual uint64_t getHits() = 0;
226  virtual void clear() = 0;
227  ~IBuffer() override = default;
228  }; // IBuffer
229 
232 
234  SIDX_DLL IStorageManager* createNewDiskStorageManager(std::string& baseName, uint32_t pageSize);
235  SIDX_DLL IStorageManager* loadDiskStorageManager(std::string& baseName);
236 
238  SIDX_DLL IBuffer* createNewRandomEvictionsBuffer(IStorageManager& in, uint32_t capacity, bool bWriteThrough);
239  }
240 
241  //
242  // Global functions
243  //
244  SIDX_DLL std::ostream& operator<<(std::ostream&, const ISpatialIndex&);
245  SIDX_DLL std::ostream& operator<<(std::ostream&, const IStatistics&);
246 }
247 
248 #include "Point.h"
249 #include "Region.h"
250 #include "Ball.h"
251 #include "LineSegment.h"
252 #include "TimePoint.h"
253 #include "TimeRegion.h"
254 #include "MovingPoint.h"
255 #include "MovingRegion.h"
256 #include "RTree.h"
257 #include "MVRTree.h"
258 #include "TPRTree.h"
259 #include "Version.h"
260 
261 
262 // typedef SpatialIndex::Tools::PoolPointer<Region> RegionPtr;
263 // typedef SpatialIndex::Tools::PoolPointer<Point> PointPtr;
264 // typedef SpatialIndex::Tools::PoolPointer<TimeRegion> TimeRegionPtr;
265 // typedef SpatialIndex::Tools::PoolPointer<MovingRegion> MovingRegionPtr;
SIDX_DLL IStorageManager * returnDiskStorageManager(Tools::PropertySet &in)
SIDX_DLL IStorageManager * returnMemoryStorageManager(Tools::PropertySet &in)
SIDX_DLL IStorageManager * loadDiskStorageManager(std::string &baseName)
SIDX_DLL IStorageManager * createNewMemoryStorageManager()
SIDX_DLL std::ostream & operator<<(std::ostream &os, const Ball &ball)
Definition: Ball.cc:215
SIDX_DLL IBuffer * createNewRandomEvictionsBuffer(IStorageManager &in, uint32_t capacity, bool bWriteThrough)
#define SIDX_DLL
Definition: sidx_export.h:41
int64_t id_type
Definition: SpatialIndex.h:41
SIDX_DLL IBuffer * returnRandomEvictionsBuffer(IStorageManager &ind, Tools::PropertySet &in)
SIDX_DLL IStorageManager * createNewDiskStorageManager(std::string &baseName, uint32_t pageSize)