GEOS  3.9.1dev
quadtree/NodeBase.h
Go to the documentation of this file.
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
33 namespace geos {
34 namespace geom {
35 class Coordinate;
36 class Envelope;
37 }
38 namespace index {
39 class ItemVisitor;
40 namespace quadtree {
41 class Node;
42 }
43 }
44 }
45 
46 namespace geos {
47 namespace index { // geos::index
48 namespace quadtree { // geos::index::quadtree
49 
56 
57 private:
58 
59  void visitItems(const geom::Envelope* searchEnv,
60  ItemVisitor& visitor);
61 
62 public:
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 
108 protected:
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 
131 inline bool
132 NodeBase::hasChildren() const
133 {
134  for(const auto& subnode : subnodes) {
135  if(subnode != nullptr) {
136  return true;
137  }
138  }
139 
140  return false;
141 }
142 
143 inline bool
144 NodeBase::isPrunable() const
145 {
146  return !(hasChildren() || hasItems());
147 }
148 
149 inline bool
150 NodeBase::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
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
#define GEOS_DLL
Definition: export.h:28
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
The base class for nodes in a Quadtree.
A visitor for items in an index.
Definition: ItemVisitor.h:29
Basic namespace for all GEOS functionalities.
std::array< Node *, 4 > subnodes
std::vector< void * > items
Actual items are NOT owned by this class.