00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GEOS_IDX_QUADTREE_NODEBASE_H
00017 #define GEOS_IDX_QUADTREE_NODEBASE_H
00018
00019 #include <vector>
00020 #include <string>
00021
00022
00023 namespace geos {
00024 namespace geom {
00025 class Coordinate;
00026 class Envelope;
00027 }
00028 namespace index {
00029 class ItemVisitor;
00030 namespace quadtree {
00031 class Node;
00032 }
00033 }
00034 }
00035
00036 namespace geos {
00037 namespace index {
00038 namespace quadtree {
00039
00045 class NodeBase {
00046
00047 private:
00048
00049 void visitItems(const geom::Envelope* searchEnv,
00050 ItemVisitor& visitor);
00051
00052 public:
00053
00054 static int getSubnodeIndex(const geom::Envelope *env,
00055 const geom::Coordinate& centre);
00056
00057 NodeBase();
00058
00059 virtual ~NodeBase();
00060
00061 virtual std::vector<void*>* getItems();
00062
00063 virtual void add(void* item);
00064
00065 virtual std::vector<void*>* addAllItems(std::vector<void*> *resultItems);
00066
00067 virtual void addAllItemsFromOverlapping(const geom::Envelope *searchEnv,
00068 std::vector<void*> *resultItems);
00069
00070 virtual int depth();
00071
00072 virtual int size();
00073
00074 virtual int nodeCount();
00075
00076 virtual std::string toString() const;
00077
00078 virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
00079
00087 bool remove(const geom::Envelope* itemEnv, void* item);
00088
00089 bool hasItems() const;
00090
00091 bool hasChildren() const;
00092
00093 bool isPrunable() const;
00094
00095 protected:
00096
00097 std::vector<void*> *items;
00098
00107 Node* subnode[4];
00108
00109 virtual bool isSearchMatch(const geom::Envelope *searchEnv)=0;
00110 };
00111
00112
00113
00114
00115 inline bool
00116 NodeBase::hasChildren() const
00117 {
00118 for (int i = 0; i < 4; i++)
00119 if (subnode[i]) return true;
00120 return false;
00121 }
00122
00123 inline bool
00124 NodeBase::isPrunable() const
00125 {
00126 return ! (hasChildren() || hasItems());
00127 }
00128
00129 inline bool
00130 NodeBase::hasItems() const
00131 {
00132 return ! items->empty();
00133 }
00134
00135 }
00136 }
00137 }
00138
00139 #endif // GEOS_IDX_QUADTREE_NODEBASE_H
00140
00141
00142
00143
00144
00145
00146
00147