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