GEOS
3.4.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2006 Refractions Research Inc. 00007 * 00008 * This is free software; you can redistribute and/or modify it under 00009 * the terms of the GNU Lesser General Public Licence as published 00010 * by the Free Software Foundation. 00011 * See the COPYING file for more information. 00012 * 00013 ********************************************************************** 00014 * 00015 * Last port: index/quadtree/Node.java rev 1.8 (JTS-1.10) 00016 * 00017 **********************************************************************/ 00018 00019 #ifndef GEOS_IDX_QUADTREE_NODE_H 00020 #define GEOS_IDX_QUADTREE_NODE_H 00021 00022 #include <geos/export.h> 00023 #include <geos/index/quadtree/NodeBase.h> // for inheritance 00024 #include <geos/geom/Coordinate.h> // for composition 00025 #include <geos/geom/Envelope.h> // for inline 00026 00027 #include <string> 00028 #include <memory> 00029 00030 #ifdef _MSC_VER 00031 #pragma warning(push) 00032 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class 00033 #endif 00034 00035 // Forward declarations 00036 namespace geos { 00037 namespace geom { 00038 //class Coordinate; 00039 class Envelope; 00040 } 00041 } 00042 00043 namespace geos { 00044 namespace index { // geos::index 00045 namespace quadtree { // geos::index::quadtree 00046 00055 class GEOS_DLL Node: public NodeBase { 00056 00057 private: 00058 00060 std::auto_ptr<geom::Envelope> env; 00061 00062 geom::Coordinate centre; 00063 00064 int level; 00065 00072 Node* getSubnode(int index); 00073 00074 std::auto_ptr<Node> createSubnode(int index); 00075 00076 protected: 00077 00078 bool isSearchMatch(const geom::Envelope& searchEnv) const { 00079 return env->intersects(searchEnv); 00080 } 00081 00082 public: 00083 00084 // Create a node computing level from given envelope 00085 static std::auto_ptr<Node> createNode(const geom::Envelope& env); 00086 00088 // 00092 static std::auto_ptr<Node> createExpanded(std::auto_ptr<Node> node, 00093 const geom::Envelope& addEnv); 00094 00095 Node(std::auto_ptr<geom::Envelope> nenv, int nlevel) 00096 : 00097 env(nenv), 00098 centre((env->getMinX()+env->getMaxX())/2, 00099 (env->getMinY()+env->getMaxY())/2), 00100 level(nlevel) 00101 { 00102 } 00103 00104 virtual ~Node() {} 00105 00108 geom::Envelope* getEnvelope() { return env.get(); } 00109 00115 Node* getNode(const geom::Envelope *searchEnv); 00116 00121 NodeBase* find(const geom::Envelope *searchEnv); 00122 00123 void insertNode(std::auto_ptr<Node> node); 00124 00125 std::string toString() const; 00126 00127 }; 00128 00129 } // namespace geos::index::quadtree 00130 } // namespace geos::index 00131 } // namespace geos 00132 00133 #ifdef _MSC_VER 00134 #pragma warning(pop) 00135 #endif 00136 00137 #endif // GEOS_IDX_QUADTREE_NODE_H