GEOS 3.6.2
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 <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 {
33 namespace geom {
34 class Coordinate;
35 class Envelope;
36 }
37 namespace index {
38 class ItemVisitor;
39 namespace quadtree {
40 class 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 unsigned int size() const;
85
86 unsigned int 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
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 (int i = 0; i < 4; i++)
134 if (subnode[i]) return true;
135 return false;
136}
137
138inline bool
139NodeBase::isPrunable() const
140{
141 return ! (hasChildren() || hasItems());
142}
143
144inline bool
145NodeBase::hasItems() const
146{
147 return ! items.empty();
148}
149
150} // namespace geos::index::quadtree
151} // namespace geos::index
152} // namespace geos
153
154#ifdef _MSC_VER
155#pragma warning(pop)
156#endif
157
158#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:53
A visitor for items in an index.
Definition ItemVisitor.h:29
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.
Node * subnode[4]
Definition quadtree/NodeBase.h:122
Represents a node of a Quadtree.
Definition index/quadtree/Node.h:55
Contains the Geometry interface hierarchy and supporting classes.
Definition IndexedNestedRingTester.h:26
Contains classes that implement a Quadtree spatial index.
Definition DoubleBits.h:29
Provides classes for various kinds of spatial indexes.
Definition IndexedNestedRingTester.h:31
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25