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
32 namespace 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 
45 namespace geos {
46 namespace index { // geos::index
47 namespace quadtree { // geos::index::quadtree
48 
54 class GEOS_DLL NodeBase {
55 
56 private:
57 
58  void visitItems(const geom::Envelope* searchEnv,
59  ItemVisitor& visitor);
60 
61 public:
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 
107 protected:
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 
130 inline bool
131 NodeBase::hasChildren() const
132 {
133  for(const auto& subnode : subnodes) {
134  if(subnode != nullptr) {
135  return true;
136  }
137  }
138 
139  return false;
140 }
141 
142 inline bool
143 NodeBase::isPrunable() const
144 {
145  return !(hasChildren() || hasItems());
146 }
147 
148 inline bool
149 NodeBase::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::vector< void * > & addAllItems(std::vector< void * > &resultItems) const
Push all node items to the given vector, return the argument.
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)
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25