GEOS
3.3.9
|
00001 /********************************************************************** 00002 * $Id: NodeBase.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/NodeBase.java rev 1.9 (JTS-1.10) 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef GEOS_IDX_QUADTREE_NODEBASE_H 00021 #define GEOS_IDX_QUADTREE_NODEBASE_H 00022 00023 #include <geos/export.h> 00024 #include <vector> 00025 #include <string> 00026 00027 #ifdef _MSC_VER 00028 #pragma warning(push) 00029 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class 00030 #endif 00031 00032 // Forward declarations 00033 namespace geos { 00034 namespace geom { 00035 class Coordinate; 00036 class Envelope; 00037 } 00038 namespace index { 00039 class ItemVisitor; 00040 namespace quadtree { 00041 class Node; 00042 } 00043 } 00044 } 00045 00046 namespace geos { 00047 namespace index { // geos::index 00048 namespace quadtree { // geos::index::quadtree 00049 00055 class GEOS_DLL NodeBase { 00056 00057 private: 00058 00059 void visitItems(const geom::Envelope* searchEnv, 00060 ItemVisitor& visitor); 00061 00062 public: 00063 00064 static int getSubnodeIndex(const geom::Envelope *env, 00065 const geom::Coordinate& centre); 00066 00067 NodeBase(); 00068 00069 virtual ~NodeBase(); 00070 00071 std::vector<void*>& getItems(); 00072 00075 void add(void* item); 00076 00078 std::vector<void*>& addAllItems(std::vector<void*>& resultItems) const; 00079 00080 virtual void addAllItemsFromOverlapping(const geom::Envelope& searchEnv, 00081 std::vector<void*>& resultItems) const; 00082 00083 unsigned int depth() const; 00084 00085 unsigned int size() const; 00086 00087 unsigned int getNodeCount() const; 00088 00089 virtual std::string toString() const; 00090 00091 virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor); 00092 00100 bool remove(const geom::Envelope* itemEnv, void* item); 00101 00102 bool hasItems() const; 00103 00104 bool hasChildren() const; 00105 00106 bool isPrunable() const; 00107 00108 protected: 00109 00111 std::vector<void*> items; 00112 00123 Node* subnode[4]; 00124 00125 virtual bool isSearchMatch(const geom::Envelope& searchEnv) const=0; 00126 }; 00127 00128 00129 // INLINES, To be moved in NodeBase.inl 00130 00131 inline bool 00132 NodeBase::hasChildren() const 00133 { 00134 for (int i = 0; i < 4; i++) 00135 if (subnode[i]) return true; 00136 return false; 00137 } 00138 00139 inline bool 00140 NodeBase::isPrunable() const 00141 { 00142 return ! (hasChildren() || hasItems()); 00143 } 00144 00145 inline bool 00146 NodeBase::hasItems() const 00147 { 00148 return ! items.empty(); 00149 } 00150 00151 } // namespace geos::index::quadtree 00152 } // namespace geos::index 00153 } // namespace geos 00154 00155 #ifdef _MSC_VER 00156 #pragma warning(pop) 00157 #endif 00158 00159 #endif // GEOS_IDX_QUADTREE_NODEBASE_H 00160 00161 /********************************************************************** 00162 * $Log$ 00163 * Revision 1.1 2006/03/22 12:22:50 strk 00164 * indexQuadtree.h split 00165 * 00166 **********************************************************************/ 00167