GEOS  3.13.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 
32 
33 
34 namespace geos {
35 namespace index {
36 
37 
54 class GEOS_DLL VertexSequencePackedRtree {
55 
56 private:
57 
58 
63  static constexpr std::size_t NODE_CAPACITY = 16;
64 
65  // Members
66  const CoordinateSequence& items;
67  std::vector<bool> removedItems;
68  std::vector<std::size_t> levelOffset;
69  std::size_t nodeCapacity = NODE_CAPACITY;
70  std::vector<Envelope> bounds;
71 
72 
73  // Methods
74 
75  void build();
76 
87  std::vector<std::size_t> computeLevelOffsets();
88 
89  static std::size_t ceilDivisor(std::size_t num, std::size_t denom);
90  static std::size_t clampMax(std::size_t x, std::size_t max);
91 
92  std::size_t levelNodeCount(std::size_t numNodes);
93 
94  std::vector<Envelope> createBounds();
95 
96  void fillItemBounds(std::vector<Envelope>& bounds);
97  void fillLevelBounds(std::size_t lvl, std::vector<Envelope>& bounds);
98 
99  static Envelope computeNodeEnvelope(const std::vector<Envelope>& bounds,
100  std::size_t start, std::size_t end);
101  static Envelope computeItemEnvelope(const CoordinateSequence& items,
102  std::size_t start, std::size_t end);
103 
104  void queryNode(const Envelope& queryEnv,
105  std::size_t level, std::size_t nodeIndex,
106  std::vector<std::size_t>& result) const;
107  void queryNodeRange(const Envelope& queryEnv,
108  std::size_t level, std::size_t nodeStartIndex,
109  std::vector<std::size_t>& result) const;
110  void queryItemRange(const Envelope& queryEnv, std::size_t itemIndex,
111  std::vector<std::size_t>& result) const;
112 
113  std::size_t levelSize(std::size_t level) const;
114  bool isNodeEmpty(std::size_t level, std::size_t index);
115  bool isItemsNodeEmpty(std::size_t nodeIndex);
116 
117 
118 public:
119 
127 
128  std::vector<Envelope> getBounds();
129 
135  void remove(std::size_t index);
136 
145  void query(const Envelope& queryEnv, std::vector<std::size_t>& result) const;
146 
147 };
148 
149 
150 
151 } // namespace geos.index
152 } // namespace geos
153 
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:216
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Definition: VertexSequencePackedRtree.h:54
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