GEOS 3.14.0dev
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#pragma once
20
21#include <geos/export.h>
22#include <array>
23#include <vector>
24#include <string>
25
26#ifdef _MSC_VER
27#pragma warning(push)
28#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
29#endif
30
31// Forward declarations
32namespace geos {
33namespace geom {
34class Coordinate;
35class Envelope;
36}
37namespace index {
38class ItemVisitor;
39namespace quadtree {
40class Node;
41}
42}
43}
44
45namespace geos {
46namespace index { // geos::index
47namespace quadtree { // geos::index::quadtree
48
54class GEOS_DLL NodeBase {
55
56private:
57
58 void visitItems(const geom::Envelope* searchEnv,
59 ItemVisitor& visitor);
60
61public:
62
63 static int getSubnodeIndex(const geom::Envelope* env,
64 const geom::Coordinate& centre);
65
66 NodeBase();
67
68 virtual ~NodeBase();
69
70 std::vector<void*>& getItems();
71
74 void add(void* item);
75
77 std::vector<void*>& addAllItems(std::vector<void*>& resultItems) const;
78
79 virtual void addAllItemsFromOverlapping(const geom::Envelope& searchEnv,
80 std::vector<void*>& resultItems) const;
81
82 unsigned int depth() const;
83
84 std::size_t size() const;
85
86 std::size_t getNodeCount() const;
87
88 virtual std::string toString() const;
89
90 virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
91
99 bool remove(const geom::Envelope* itemEnv, void* item);
100
101 bool hasItems() const;
102
103 bool hasChildren() const;
104
105 bool isPrunable() const;
106
107protected:
108
110 std::vector<void*> items;
111
122 std::array<Node*, 4> subnodes;
123
124 virtual bool isSearchMatch(const geom::Envelope& searchEnv) const = 0;
125};
126
127
128// INLINES, To be moved in NodeBase.inl
129
130inline bool
131NodeBase::hasChildren() const
132{
133 for(const auto& subnode : subnodes) {
134 if(subnode != nullptr) {
135 return true;
136 }
137 }
138
139 return false;
140}
141
142inline bool
143NodeBase::isPrunable() const
144{
145 return !(hasChildren() || hasItems());
146}
147
148inline bool
149NodeBase::hasItems() const
150{
151 return ! items.empty();
152}
153
154} // namespace geos::index::quadtree
155} // namespace geos::index
156} // namespace geos
157
158#ifdef _MSC_VER
159#pragma warning(pop)
160#endif
161
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
A visitor for items in an index.
Definition ItemVisitor.h:28
The base class for nodes in a Quadtree.
Definition quadtree/NodeBase.h:54
std::array< Node *, 4 > subnodes
Definition quadtree/NodeBase.h:122
std::vector< void * > items
Actual items are NOT owned by this class.
Definition quadtree/NodeBase.h:110
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 geos.h:39