GEOS 3.9.1
quadtree/NodeBase.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2006 Refractions Research Inc.
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 * Last port: index/quadtree/NodeBase.java rev 1.9 (JTS-1.10)
16 *
17 **********************************************************************/
18
19#ifndef GEOS_IDX_QUADTREE_NODEBASE_H
20#define GEOS_IDX_QUADTREE_NODEBASE_H
21
22#include <geos/export.h>
23#include <array>
24#include <vector>
25#include <string>
26
27#ifdef _MSC_VER
28#pragma warning(push)
29#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
30#endif
31
32// Forward declarations
33namespace geos {
34namespace geom {
35class Coordinate;
36class Envelope;
37}
38namespace index {
39class ItemVisitor;
40namespace quadtree {
41class Node;
42}
43}
44}
45
46namespace geos {
47namespace index { // geos::index
48namespace quadtree { // geos::index::quadtree
49
55class GEOS_DLL NodeBase {
56
57private:
58
59 void visitItems(const geom::Envelope* searchEnv,
60 ItemVisitor& visitor);
61
62public:
63
64 static int getSubnodeIndex(const geom::Envelope* env,
65 const geom::Coordinate& centre);
66
67 NodeBase();
68
69 virtual ~NodeBase();
70
71 std::vector<void*>& getItems();
72
75 void add(void* item);
76
78 std::vector<void*>& addAllItems(std::vector<void*>& resultItems) const;
79
80 virtual void addAllItemsFromOverlapping(const geom::Envelope& searchEnv,
81 std::vector<void*>& resultItems) const;
82
83 unsigned int depth() const;
84
85 size_t size() const;
86
87 size_t getNodeCount() const;
88
89 virtual std::string toString() const;
90
91 virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
92
100 bool remove(const geom::Envelope* itemEnv, void* item);
101
102 bool hasItems() const;
103
104 bool hasChildren() const;
105
106 bool isPrunable() const;
107
108protected:
109
111 std::vector<void*> items;
112
123 std::array<Node*, 4> subnodes;
124
125 virtual bool isSearchMatch(const geom::Envelope& searchEnv) const = 0;
126};
127
128
129// INLINES, To be moved in NodeBase.inl
130
131inline bool
132NodeBase::hasChildren() const
133{
134 for(const auto& subnode : subnodes) {
135 if(subnode != nullptr) {
136 return true;
137 }
138 }
139
140 return false;
141}
142
143inline bool
144NodeBase::isPrunable() const
145{
146 return !(hasChildren() || hasItems());
147}
148
149inline bool
150NodeBase::hasItems() const
151{
152 return ! items.empty();
153}
154
155} // namespace geos::index::quadtree
156} // namespace geos::index
157} // namespace geos
158
159#ifdef _MSC_VER
160#pragma warning(pop)
161#endif
162
163#endif // GEOS_IDX_QUADTREE_NODEBASE_H
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
A visitor for items in an index.
Definition: ItemVisitor.h:29
The base class for nodes in a Quadtree.
Definition: quadtree/NodeBase.h:55
std::array< Node *, 4 > subnodes
Definition: quadtree/NodeBase.h:123
std::vector< void * > items
Actual items are NOT owned by this class.
Definition: quadtree/NodeBase.h:111
bool remove(const geom::Envelope *itemEnv, void *item)
std::vector< void * > & addAllItems(std::vector< void * > &resultItems) const
Push all node items to the given vector, return the argument.
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26