GEOS  3.4.2
index/quadtree/Node.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/Node.java rev 1.8 (JTS-1.10)
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_IDX_QUADTREE_NODE_H
20 #define GEOS_IDX_QUADTREE_NODE_H
21 
22 #include <geos/export.h>
23 #include <geos/index/quadtree/NodeBase.h> // for inheritance
24 #include <geos/geom/Coordinate.h> // for composition
25 #include <geos/geom/Envelope.h> // for inline
26 
27 #include <string>
28 #include <memory>
29 
30 #ifdef _MSC_VER
31 #pragma warning(push)
32 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
33 #endif
34 
35 // Forward declarations
36 namespace geos {
37  namespace geom {
38  //class Coordinate;
39  class Envelope;
40  }
41 }
42 
43 namespace geos {
44 namespace index { // geos::index
45 namespace quadtree { // geos::index::quadtree
46 
55 class GEOS_DLL Node: public NodeBase {
56 
57 private:
58 
60  std::auto_ptr<geom::Envelope> env;
61 
62  geom::Coordinate centre;
63 
64  int level;
65 
72  Node* getSubnode(int index);
73 
74  std::auto_ptr<Node> createSubnode(int index);
75 
76 protected:
77 
78  bool isSearchMatch(const geom::Envelope& searchEnv) const {
79  return env->intersects(searchEnv);
80  }
81 
82 public:
83 
84  // Create a node computing level from given envelope
85  static std::auto_ptr<Node> createNode(const geom::Envelope& env);
86 
88  //
92  static std::auto_ptr<Node> createExpanded(std::auto_ptr<Node> node,
93  const geom::Envelope& addEnv);
94 
95  Node(std::auto_ptr<geom::Envelope> nenv, int nlevel)
96  :
97  env(nenv),
98  centre((env->getMinX()+env->getMaxX())/2,
99  (env->getMinY()+env->getMaxY())/2),
100  level(nlevel)
101  {
102  }
103 
104  virtual ~Node() {}
105 
108  geom::Envelope* getEnvelope() { return env.get(); }
109 
115  Node* getNode(const geom::Envelope *searchEnv);
116 
121  NodeBase* find(const geom::Envelope *searchEnv);
122 
123  void insertNode(std::auto_ptr<Node> node);
124 
125  std::string toString() const;
126 
127 };
128 
129 } // namespace geos::index::quadtree
130 } // namespace geos::index
131 } // namespace geos
132 
133 #ifdef _MSC_VER
134 #pragma warning(pop)
135 #endif
136 
137 #endif // GEOS_IDX_QUADTREE_NODE_H
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:53
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
The base class for nodes in a Quadtree.
Definition: quadtree/NodeBase.h:54
double getMinY() const
double getMaxY() const
double getMaxX() const
geom::Envelope * getEnvelope()
Definition: index/quadtree/Node.h:108
double getMinX() const
Represents a node of a Quadtree.
Definition: index/quadtree/Node.h:55