GEOS  3.14.0dev
SimpleSTRnode.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2020 Paul Ramsey
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 #pragma once
16 
17 #include <cassert>
18 #include <geos/export.h>
19 #include <geos/geom/Envelope.h>
20 #include <geos/index/strtree/ItemBoundable.h>
21 
22 #include <vector>
23 
24 #ifdef _MSC_VER
25 #pragma warning(push)
26 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
27 #endif
28 
29 namespace geos {
30 namespace index { // geos::index
31 namespace strtree { // geos::index::strtree
32 
37 class GEOS_DLL SimpleSTRnode : public ItemBoundable {
38 
39 private:
40 
41  std::vector<SimpleSTRnode*> childNodes;
42  void *item;
43  geom::Envelope bounds;
44  std::size_t level;
45 
46 public:
47 
48  /*
49  * Constructs an AbstractNode at the given level in the tree
50  */
51  SimpleSTRnode(std::size_t newLevel, const geom::Envelope *p_env, void* p_item, std::size_t capacity = 10)
52  : ItemBoundable(p_env, p_item)
53  , item(p_item)
54  , bounds()
55  , level(newLevel)
56  {
57  childNodes.reserve(capacity);
58  if (p_env) {
59  bounds = *p_env;
60  }
61 
62  }
63 
64  SimpleSTRnode(std::size_t newLevel)
65  : SimpleSTRnode(newLevel, nullptr, nullptr)
66  {}
67 
68  void toString(std::ostream& os, int indentLevel) const;
69 
70  std::size_t getNumNodes() const;
71  std::size_t getNumLeafNodes() const;
72 
73  const std::vector<SimpleSTRnode*>&
74  getChildNodes() const
75  {
76  return childNodes;
77  }
78 
79  void* getItem() const {
80  return item;
81  }
82 
83  bool removeItem(void *item);
84  bool removeChild(SimpleSTRnode *child);
85 
89  const inline geom::Envelope& getEnvelope() const {
90  return bounds;
91  }
92 
93  const void* getBounds() const override {
94  return &bounds;
95  }
96 
101  std::size_t getLevel() const {
102  return level;
103  }
104 
105  std::size_t size() const {
106  return childNodes.size();
107  }
108 
113  void addChildNode(SimpleSTRnode* childNode);
114 
115  bool isLeaf() const override
116  {
117  return level == 0;
118  }
119 
120  bool isComposite() const
121  {
122  return ! isLeaf();
123  }
124 
125  double area() const
126  {
127  return bounds.getArea();
128  }
129 
130 
131 };
132 
133 
134 } // namespace geos::index::strtree
135 } // namespace geos::index
136 } // namespace geos
137 
138 #ifdef _MSC_VER
139 #pragma warning(pop)
140 #endif
141 
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
double getArea() const
Gets the area of this envelope.
Definition: Envelope.h:290
Boundable wrapper for a non-Boundable spatial object. Used internally by AbstractSTRtree.
Definition: ItemBoundable.h:32
A node of the STR tree.
Definition: SimpleSTRnode.h:37
void addChildNode(SimpleSTRnode *childNode)
const geom::Envelope & getEnvelope() const
Definition: SimpleSTRnode.h:89
std::size_t getLevel() const
Definition: SimpleSTRnode.h:101
const void * getBounds() const override
Definition: SimpleSTRnode.h:93
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25