libspatialindex API Reference  (git-trunk)
src/mvrtree/MVRTree.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) 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 #include <memory>
34 
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wcast-qual"
37 
38 namespace SpatialIndex
39 {
40  namespace MVRTree
41  {
42  class MVRTree : public ISpatialIndex
43  {
44  class NNEntry;
45  class RootEntry;
46 
47  public:
49  // String Value Description
50  // ----------------------------------------------
51  // IndexIndentifier VT_LONG If specified an existing index will be openened from the supplied
52  // storage manager with the given index id. Behaviour is unspecified
53  // if the index id or the storage manager are incorrect.
54  // Dimension VT_ULONG Dimensionality of the data that will be inserted.
55  // IndexCapacity VT_ULONG The index node capacity. Default is 100.
56  // LeafCapactiy VT_ULONG The leaf node capacity. Default is 100.
57  // FillFactor VT_DOUBLE The fill factor. Default is 70%
58  // TreeVariant VT_LONG Can be one of Linear, Quadratic or Rstar. Default is Rstar
59  // NearMinimumOverlapFactor VT_ULONG Default is 32.
60  // SplitDistributionFactor VT_DOUBLE Default is 0.4
61  // ReinsertFactor VT_DOUBLE Default is 0.3
62  // EnsureTightMBRs VT_BOOL Default is true
63  // IndexPoolCapacity VT_LONG Default is 100
64  // LeafPoolCapacity VT_LONG Default is 100
65  // RegionPoolCapacity VT_LONG Default is 1000
66  // PointPoolCapacity VT_LONG Default is 500
67  // StrongVersionOverflow VT_DOUBLE Default is 0.8
68  // VersionUnderflow VT_DOUBLE Default is 0.3
69 
70  ~MVRTree() ;
71 
72  //
73  // ISpatialIndex interface
74  //
75  virtual void insertData(uint32_t len, const uint8_t* pData, const IShape& shape, id_type id) ;
76  virtual bool deleteData(const IShape& shape, id_type id) ;
77  virtual void internalNodesQuery(const IShape& query, IVisitor& v) ;
78  virtual void containsWhatQuery(const IShape& query, IVisitor& v) ;
79  virtual void intersectsWithQuery(const IShape& query, IVisitor& v) ;
80  virtual void pointLocationQuery(const Point& query, IVisitor& v) ;
81  virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v, INearestNeighborComparator&) ;
82  virtual void nearestNeighborQuery(uint32_t k, const IShape& query, IVisitor& v) ;
83  virtual void selfJoinQuery(const IShape& s, IVisitor& v) ;
84  virtual void queryStrategy(IQueryStrategy& qs) ;
85  virtual void getIndexProperties(Tools::PropertySet& out) const ;
86  virtual void addCommand(ICommand* pCommand, CommandType ct) ;
87  virtual bool isIndexValid() ;
88  virtual void getStatistics(IStatistics** out) const ;
89  virtual void flush() ;
90 
91  private:
92  void initNew(Tools::PropertySet&);
93  void initOld(Tools::PropertySet& ps);
94  void storeHeader();
95  void loadHeader();
96 
97  void insertData_impl(uint32_t dataLength, uint8_t* pData, TimeRegion& mbr, id_type id);
98  void insertData_impl(uint32_t dataLength, uint8_t* pData, TimeRegion& mbr, id_type id, uint32_t level);
99  bool deleteData_impl(const TimeRegion& mbr, id_type id);
100 
101  id_type writeNode(Node*);
102  NodePtr readNode(id_type id);
103  void deleteNode(Node* n);
104 
105  void rangeQuery(RangeQueryType type, const IShape& query, IVisitor& v);
106 
107  void findRootIdentifiers(const Tools::IInterval& ti, std::vector<id_type>& ids);
108  std::string printRootInfo() const;
109 
110  IStorageManager* m_pStorageManager;
111 
112  std::vector<RootEntry> m_roots;
113  id_type m_headerID;
114 
115  MVRTreeVariant m_treeVariant;
116 
117  double m_fillFactor;
118 
119  uint32_t m_indexCapacity;
120 
121  uint32_t m_leafCapacity;
122 
123  uint32_t m_nearMinimumOverlapFactor;
124  // The R*-Tree 'p' constant, for calculating nearly minimum overlap cost.
125  // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
126  // for Points and Rectangles, Section 4.1]
127 
128  double m_splitDistributionFactor;
129  // The R*-Tree 'm' constant, for calculating spliting distributions.
130  // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
131  // for Points and Rectangles, Section 4.2]
132 
133  double m_reinsertFactor;
134  // The R*-Tree 'p' constant, for removing entries at reinserts.
135  // [Beckmann, Kriegel, Schneider, Seeger 'The R*-tree: An efficient and Robust Access Method
136  // for Points and Rectangles, Section 4.3]
137 
138  double m_strongVersionOverflow;
139  //double m_strongVersionUnderflow;
140  double m_versionUnderflow;
141 
142  uint32_t m_dimension;
143 
144  TimeRegion m_infiniteRegion;
145 
147 
148  bool m_bTightMBRs;
149 
150  bool m_bHasVersionCopied;
151 
152  double m_currentTime;
153 
154  Tools::PointerPool<Point> m_pointPool;
155  Tools::PointerPool<TimeRegion> m_regionPool;
156  Tools::PointerPool<Node> m_indexPool;
157  Tools::PointerPool<Node> m_leafPool;
158 
159  std::vector<std::shared_ptr<ICommand> > m_writeNodeCommands;
160  std::vector<std::shared_ptr<ICommand> > m_readNodeCommands;
161  std::vector<std::shared_ptr<ICommand> > m_deleteNodeCommands;
162 
163  class RootEntry
164  {
165  public:
166  RootEntry() = default;
167  RootEntry(id_type id, double s, double e) : m_id(id), m_startTime(s), m_endTime(e) {}
168 
169  id_type m_id;
170  double m_startTime;
171  double m_endTime;
172  }; // RootEntry
173 
174  class NNEntry
175  {
176  public:
177  id_type m_id;
178  IEntry* m_pEntry;
179  double m_minDist;
180 
181  NNEntry(id_type id, IEntry* e, double f) : m_id(id), m_pEntry(e), m_minDist(f) {}
182  ~NNEntry() = default;
183 
184  }; // NNEntry
185 
186  class NNComparator : public INearestNeighborComparator
187  {
188  public:
189  double getMinimumDistance(const IShape& query, const IShape& entry)
190  {
191  return query.getMinimumDistance(entry);
192  }
193  double getMinimumDistance(const IShape& query, const IData& data)
194  {
195  IShape* pR;
196  data.getShape(&pR);
197  double ret = query.getMinimumDistance(*pR);
198  delete pR;
199  return ret;
200  }
201  }; // NNComparator
202 
203  class ValidateEntry
204  {
205  public:
206  ValidateEntry(id_type pid, TimeRegion& r, NodePtr& pNode) : m_parentID(pid), m_parentMBR(r), m_pNode(pNode), m_bIsDead(false) {}
207 
208  id_type m_parentID;
209  TimeRegion m_parentMBR;
210  NodePtr m_pNode;
211  bool m_bIsDead;
212  }; // ValidateEntry
213 
214  friend class Node;
215  friend class Leaf;
216  friend class Index;
217 
218  friend std::ostream& operator<<(std::ostream& os, const MVRTree& t);
219  }; // MVRTree
220 
221  std::ostream& operator<<(std::ostream& os, const MVRTree& t);
222  }
223 }
224 #pragma GCC diagnostic pop
virtual void getShape(IShape **out) const =0
virtual double getMinimumDistance(const IShape &in) const =0
virtual void pointLocationQuery(const Point &query, IVisitor &v)
Definition: MVRTree.cc:322
virtual void addCommand(ICommand *pCommand, CommandType ct)
Definition: MVRTree.cc:449
virtual void getIndexProperties(Tools::PropertySet &out) const
Definition: MVRTree.cc:360
virtual void queryStrategy(IQueryStrategy &qs)
Definition: MVRTree.cc:348
virtual void nearestNeighborQuery(uint32_t k, const IShape &query, IVisitor &v, INearestNeighborComparator &)
Definition: MVRTree.cc:331
virtual void internalNodesQuery(const IShape &query, IVisitor &v)
Definition: MVRTree.cc:305
virtual void getStatistics(IStatistics **out) const
Definition: MVRTree.cc:555
friend std::ostream & operator<<(std::ostream &os, const MVRTree &t)
virtual void containsWhatQuery(const IShape &query, IVisitor &v)
Definition: MVRTree.cc:310
virtual void selfJoinQuery(const IShape &s, IVisitor &v)
Definition: MVRTree.cc:343
virtual bool deleteData(const IShape &shape, id_type id)
Definition: MVRTree.cc:282
MVRTree(IStorageManager &, Tools::PropertySet &)
Definition: MVRTree.cc:200
virtual void insertData(uint32_t len, const uint8_t *pData, const IShape &shape, id_type id)
Definition: MVRTree.cc:251
virtual void intersectsWithQuery(const IShape &query, IVisitor &v)
Definition: MVRTree.cc:316
virtual bool isIndexValid()
Definition: MVRTree.cc:465
std::ostream & operator<<(std::ostream &os, const MVRTree &t)
Definition: MVRTree.cc:1316
int64_t id_type
Definition: SpatialIndex.h:41