00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00028 namespace geos {
00029 namespace geom {
00030 class Coordinate;
00031 class Envelope;
00032 }
00033 namespace index {
00034 class ItemVisitor;
00035 namespace quadtree {
00036 class Node;
00037 }
00038 }
00039 }
00040
00041 namespace geos {
00042 namespace index {
00043 namespace quadtree {
00044
00050 class GEOS_DLL NodeBase {
00051
00052 private:
00053
00054 void visitItems(const geom::Envelope* searchEnv,
00055 ItemVisitor& visitor);
00056
00057 public:
00058
00059 static int getSubnodeIndex(const geom::Envelope *env,
00060 const geom::Coordinate& centre);
00061
00062 NodeBase();
00063
00064 virtual ~NodeBase();
00065
00066 std::vector<void*>& getItems();
00067
00070 void add(void* item);
00071
00073 std::vector<void*>& addAllItems(std::vector<void*>& resultItems) const;
00074
00075 virtual void addAllItemsFromOverlapping(const geom::Envelope& searchEnv,
00076 std::vector<void*>& resultItems) const;
00077
00078 unsigned int depth() const;
00079
00080 unsigned int size() const;
00081
00082 unsigned int getNodeCount() const;
00083
00084 virtual std::string toString() const;
00085
00086 virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
00087
00095 bool remove(const geom::Envelope* itemEnv, void* item);
00096
00097 bool hasItems() const;
00098
00099 bool hasChildren() const;
00100
00101 bool isPrunable() const;
00102
00103 protected:
00104
00106 std::vector<void*> items;
00107
00118 Node* subnode[4];
00119
00120 virtual bool isSearchMatch(const geom::Envelope& searchEnv) const=0;
00121 };
00122
00123
00124
00125
00126 inline bool
00127 NodeBase::hasChildren() const
00128 {
00129 for (int i = 0; i < 4; i++)
00130 if (subnode[i]) return true;
00131 return false;
00132 }
00133
00134 inline bool
00135 NodeBase::isPrunable() const
00136 {
00137 return ! (hasChildren() || hasItems());
00138 }
00139
00140 inline bool
00141 NodeBase::hasItems() const
00142 {
00143 return ! items.empty();
00144 }
00145
00146 }
00147 }
00148 }
00149
00150 #endif // GEOS_IDX_QUADTREE_NODEBASE_H
00151
00152
00153
00154
00155
00156
00157
00158