libspatialindex API Reference  (git-trunk)
mvrtree/Node.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 #pragma GCC diagnostic push
31 #pragma GCC diagnostic ignored "-Wcast-qual"
32 
33 namespace SpatialIndex
34 {
35  namespace MVRTree
36  {
37  class MVRTree;
38  class Leaf;
39  class Index;
40  class Node;
41 
43 
44  class Node : public SpatialIndex::INode
45  {
46  public:
47  ~Node() override;
48 
49  //
50  // Tools::IObject interface
51  //
52  IObject* clone() override;
53 
54  //
55  // Tools::ISerializable interface
56  //
57  uint32_t getByteArraySize() override;
58  void loadFromByteArray(const uint8_t* data) override;
59  void storeToByteArray(uint8_t** data, uint32_t& len) override;
60 
61  //
62  // SpatialIndex::IEntry interface
63  //
64  id_type getIdentifier() const override;
65  void getShape(IShape** out) const override;
66 
67  //
68  // SpatialIndex::INode interface
69  //
70  uint32_t getChildrenCount() const override;
71  id_type getChildIdentifier(uint32_t index) const override;
72  void getChildShape(uint32_t index, IShape** out) const override;
73  void getChildData(uint32_t index, uint32_t& length, uint8_t** data) const override;
74  uint32_t getLevel() const override;
75  bool isIndex() const override;
76  bool isLeaf() const override;
77 
78  private:
79  Node();
80  Node(MVRTree* pTree, id_type id, uint32_t level, uint32_t capacity);
81 
82  virtual Node& operator=(const Node&);
83 
84  virtual void insertEntry(uint32_t dataLength, uint8_t* pData, TimeRegion& mbr, id_type id);
85  virtual bool deleteEntry(uint32_t index);
86 
87  virtual bool insertData(
88  uint32_t dataLength, uint8_t* pData, TimeRegion& mbr, id_type id, std::stack<id_type>& pathBuffer,
89  TimeRegion& mbr2, id_type id2, bool bInsertMbr2 = false, bool forceAdjust = false);
90  virtual void insertData(TimeRegion& mbr1, id_type id1, TimeRegion& mbr2, id_type id2, Node* oldVersion, std::stack<id_type>& pathBuffer);
91  virtual bool deleteData(id_type id, double delTime, std::stack<id_type>& pathBuffer, bool adjustMBR = false);
92 
93  virtual void rtreeSplit(
94  uint32_t dataLength, uint8_t* pData, TimeRegion& mbr, id_type id, std::vector<uint32_t>& group1, std::vector<uint32_t>& group2,
95  TimeRegion& mbr2, id_type id2, bool bInsertMbr2 = false);
96  virtual void rstarSplit(
97  uint32_t dataLength, uint8_t* pData, TimeRegion& mbr, id_type id, std::vector<uint32_t>& group1, std::vector<uint32_t>& group2,
98  TimeRegion& mbr2, id_type id2, bool bInsertMbr2 = false);
99 
100  virtual void pickSeeds(uint32_t& index1, uint32_t& index2, uint32_t total);
101 
102  virtual NodePtr chooseSubtree(const TimeRegion& mbr, uint32_t level, std::stack<id_type>& pathBuffer) = 0;
103  virtual NodePtr findLeaf(const TimeRegion& mbr, id_type id, std::stack<id_type>& pathBuffer) = 0;
104  virtual NodePtr findNode(const TimeRegion& mbr, id_type id, std::stack<id_type>& pathBuffer);
105 
106  virtual void split(
107  uint32_t dataLength, uint8_t* pData, TimeRegion& mbr, id_type id, NodePtr& left, NodePtr& right,
108  TimeRegion& mbr2, id_type id2, bool bInsertMbr2 = false) = 0;
109 
110  MVRTree* m_pTree{nullptr};
111  // Parent of all nodes.
112 
113  uint32_t m_level{0};
114  // The level of the node in the tree.
115  // Leaves are always at level 0.
116 
117  id_type m_identifier{-1};
118  // The unique ID of this node.
119 
120  uint32_t m_children{0};
121  // The number of children pointed by this node.
122 
123  uint32_t m_capacity{0};
124  // Specifies the node capacity.
125 
126  TimeRegion m_nodeMBR;
127  // The minimum bounding region enclosing all data contained in the node.
128 
129  uint8_t** m_pData{nullptr};
130  // The data stored in the node.
131 
132  TimeRegionPtr* m_ptrMBR{nullptr};
133  // The corresponding data MBRs.
134 
135  id_type* m_pIdentifier{nullptr};
136  // The corresponding data identifiers.
137 
138  uint32_t* m_pDataLength{nullptr};
139 
140  uint32_t m_totalDataLength{0};
141 
142  class RstarSplitEntry
143  {
144  public:
145  RstarSplitEntry(TimeRegion* pr, uint32_t index, uint32_t dimension) :
146  m_pRegion(pr), m_index(index), m_sortDim(dimension) {}
147 
148  static int compareLow(const void* pv1, const void* pv2)
149  {
150  RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
151  RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
152 
153  if (pe1->m_pRegion->m_pLow[pe1->m_sortDim] < pe2->m_pRegion->m_pLow[pe2->m_sortDim]) return -1;
154  if (pe1->m_pRegion->m_pLow[pe1->m_sortDim] > pe2->m_pRegion->m_pLow[pe2->m_sortDim]) return 1;
155  return 0;
156  }
157 
158  static int compareHigh(const void* pv1, const void* pv2)
159  {
160  RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
161  RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
162 
163  if (pe1->m_pRegion->m_pHigh[pe1->m_sortDim] < pe2->m_pRegion->m_pHigh[pe2->m_sortDim]) return -1;
164  if (pe1->m_pRegion->m_pHigh[pe1->m_sortDim] > pe2->m_pRegion->m_pHigh[pe2->m_sortDim]) return 1;
165  return 0;
166  }
167 
168  TimeRegion* m_pRegion;
169  uint32_t m_index;
170  uint32_t m_sortDim;
171  }; // RstarSplitEntry
172 
173  class DeleteDataEntry
174  {
175  public:
176  DeleteDataEntry(uint32_t index, double d) : m_index(index), m_increase(d) {}
177 
178  static bool compare(DeleteDataEntry e1, DeleteDataEntry e2) { return e1.m_increase < e2.m_increase; }
179 
180  uint32_t m_index;
181  double m_increase;
182  }; // DeleteDataEntry
183 
184  // Needed to access protected members without having to cast from Node.
185  // It is more efficient than using member functions to access protected members.
186  friend class MVRTree;
187  friend class Leaf;
188  friend class Index;
189  friend class Tools::PointerPool<Node>;
190  }; // Node
191  }
192 }
193 #pragma GCC diagnostic pop
uint32_t getLevel() const override
void getChildShape(uint32_t index, IShape **out) const override
void loadFromByteArray(const uint8_t *data) override
Definition: mvrtree/Node.cc:66
void storeToByteArray(uint8_t **data, uint32_t &len) override
void getChildData(uint32_t index, uint32_t &length, uint8_t **data) const override
bool isIndex() const override
IObject * clone() override
Definition: mvrtree/Node.cc:45
uint32_t getChildrenCount() const override
uint32_t getByteArraySize() override
Definition: mvrtree/Node.cc:53
void getShape(IShape **out) const override
id_type getChildIdentifier(uint32_t index) const override
bool isLeaf() const override
id_type getIdentifier() const override
Tools::PoolPointer< Node > NodePtr
Definition: mvrtree/Node.h:40
int64_t id_type
Definition: SpatialIndex.h:41