GEOS  3.14.0dev
VertexSequencePackedRtree.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************/
14 
15 #pragma once
16 
17 #include <geos/export.h>
18 #include <vector>
19 
20 // Forward declarations
21 namespace geos {
22 namespace geom {
23 class Coordinate;
24 class CoordinateSequence;
25 class Envelope;
26 }
27 }
28 
29 namespace geos {
30 namespace index {
31 
32 
49 class GEOS_DLL VertexSequencePackedRtree {
53 
54 private:
55 
56 
61  static constexpr std::size_t NODE_CAPACITY = 16;
62 
63  // Members
64  const CoordinateSequence& items;
65  std::vector<bool> removedItems;
66  std::vector<std::size_t> levelOffset;
67  std::size_t nodeCapacity = NODE_CAPACITY;
68  std::vector<Envelope> bounds;
69 
70 
71  // Methods
72 
73  void build();
74 
85  std::vector<std::size_t> computeLevelOffsets();
86 
87  static std::size_t ceilDivisor(std::size_t num, std::size_t denom);
88  static std::size_t clampMax(std::size_t x, std::size_t max);
89 
90  std::size_t levelNodeCount(std::size_t numNodes);
91 
92  std::vector<Envelope> createBounds();
93 
94  void fillItemBounds(std::vector<Envelope>& bounds);
95  void fillLevelBounds(std::size_t lvl, std::vector<Envelope>& bounds);
96 
97  static Envelope computeNodeEnvelope(const std::vector<Envelope>& bounds,
98  std::size_t start, std::size_t end);
99  static Envelope computeItemEnvelope(const CoordinateSequence& items,
100  std::size_t start, std::size_t end);
101 
102  void queryNode(const Envelope& queryEnv,
103  std::size_t level, std::size_t nodeIndex,
104  std::vector<std::size_t>& result) const;
105  void queryNodeRange(const Envelope& queryEnv,
106  std::size_t level, std::size_t nodeStartIndex,
107  std::vector<std::size_t>& result) const;
108  void queryItemRange(const Envelope& queryEnv, std::size_t itemIndex,
109  std::vector<std::size_t>& result) const;
110 
111  std::size_t levelSize(std::size_t level) const;
112  bool isNodeEmpty(std::size_t level, std::size_t index);
113  bool isItemsNodeEmpty(std::size_t nodeIndex);
114 
115 
116 public:
117 
125 
126  std::vector<Envelope> getBounds();
127 
133  void remove(std::size_t index);
134 
143  void query(const Envelope& queryEnv, std::vector<std::size_t>& result) const;
144 
145 };
146 
147 
148 
149 } // namespace geos.index
150 } // namespace geos
151 
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:217
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
Definition: VertexSequencePackedRtree.h:49
void query(const Envelope &queryEnv, std::vector< std::size_t > &result) const
VertexSequencePackedRtree(const CoordinateSequence &pts)
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25