libspatialindex API Reference  (git-trunk)
mvrtree/Leaf.cc
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 ******************************************************************************/
28 
29 #include "MVRTree.h"
30 #include "Node.h"
31 #include "Index.h"
32 #include "Leaf.h"
33 
34 using namespace SpatialIndex;
35 using namespace SpatialIndex::MVRTree;
36 
38 = default;
39 
40 Leaf::Leaf(SpatialIndex::MVRTree::MVRTree* pTree, id_type id): Node(pTree, id, 0, pTree->m_leafCapacity)
41 {
42 }
43 
44 NodePtr Leaf::chooseSubtree(const TimeRegion&, uint32_t, std::stack<id_type>&)
45 {
46  // should make sure to relinquish other PoolPointer lists that might be pointing to the
47  // same leaf.
48  return NodePtr(this, &(m_pTree->m_leafPool));
49 }
50 
51 NodePtr Leaf::findLeaf(const TimeRegion& mbr, id_type id, std::stack<id_type>&)
52 {
53  for (uint32_t cChild = 0; cChild < m_children; ++cChild)
54  {
55  // should make sure to relinquish other PoolPointer lists that might be pointing to the
56  // same leaf.
57  if (m_pIdentifier[cChild] == id && static_cast<Region>(mbr) == static_cast<Region>(*(m_ptrMBR[cChild])))
58  return NodePtr(this, &(m_pTree->m_leafPool));
59  }
60 
61  return NodePtr();
62 }
63 
64 void Leaf::split(
65  uint32_t dataLength, uint8_t* pData, TimeRegion& mbr, id_type id, NodePtr& pLeft, NodePtr& pRight,
66  TimeRegion& mbr2, id_type id2, bool bInsertMbr2)
67 {
68  ++(m_pTree->m_stats.m_u64Splits);
69 
70  std::vector<uint32_t> g1, g2;
71 
72  switch (m_pTree->m_treeVariant)
73  {
74  case RV_LINEAR:
75  case RV_QUADRATIC:
76  rtreeSplit(dataLength, pData, mbr, id, g1, g2, mbr2, id2, bInsertMbr2);
77  break;
78  case RV_RSTAR:
79  rstarSplit(dataLength, pData, mbr, id, g1, g2, mbr2, id2, bInsertMbr2);
80  break;
81  default:
82  throw Tools::NotSupportedException("Leaf::split: Tree variant not supported.");
83  }
84 
85  pLeft = m_pTree->m_leafPool.acquire();
86  pRight = m_pTree->m_leafPool.acquire();
87 
88  if (pLeft.get() == nullptr) pLeft = NodePtr(new Leaf(m_pTree, -1), &(m_pTree->m_leafPool));
89  if (pRight.get() == nullptr) pRight = NodePtr(new Leaf(m_pTree, -1), &(m_pTree->m_leafPool));
90 
91  pLeft->m_nodeMBR = m_pTree->m_infiniteRegion;
92  pRight->m_nodeMBR = m_pTree->m_infiniteRegion;
93 
94  uint32_t cIndex;
95 
96  for (cIndex = 0; cIndex < g1.size(); ++cIndex)
97  {
98  pLeft->insertEntry(m_pDataLength[g1[cIndex]], m_pData[g1[cIndex]], *(m_ptrMBR[g1[cIndex]]), m_pIdentifier[g1[cIndex]]);
99  // we don't want to delete the data array from this node's destructor!
100  m_pData[g1[cIndex]] = nullptr;
101  }
102 
103  for (cIndex = 0; cIndex < g2.size(); ++cIndex)
104  {
105  pRight->insertEntry(m_pDataLength[g2[cIndex]], m_pData[g2[cIndex]], *(m_ptrMBR[g2[cIndex]]), m_pIdentifier[g2[cIndex]]);
106  // we don't want to delete the data array from this node's destructor!
107  m_pData[g2[cIndex]] = nullptr;
108  }
109 }
X * get() const noexcept
Definition: PoolPointer.h:55
Tools::PoolPointer< Node > NodePtr
Definition: mvrtree/Node.h:40
int64_t id_type
Definition: SpatialIndex.h:41