00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GEOS_IDX_QUADTREE_NODEBASE_H
00020 #define GEOS_IDX_QUADTREE_NODEBASE_H
00021
00022 #include <geos/export.h>
00023 #include <vector>
00024 #include <string>
00025
00026 #ifdef _MSC_VER
00027 #pragma warning(push)
00028 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00029 #endif
00030
00031
00032 namespace geos {
00033 namespace geom {
00034 class Coordinate;
00035 class Envelope;
00036 }
00037 namespace index {
00038 class ItemVisitor;
00039 namespace quadtree {
00040 class Node;
00041 }
00042 }
00043 }
00044
00045 namespace geos {
00046 namespace index {
00047 namespace quadtree {
00048
00054 class GEOS_DLL NodeBase {
00055
00056 private:
00057
00058 void visitItems(const geom::Envelope* searchEnv,
00059 ItemVisitor& visitor);
00060
00061 public:
00062
00063 static int getSubnodeIndex(const geom::Envelope *env,
00064 const geom::Coordinate& centre);
00065
00066 NodeBase();
00067
00068 virtual ~NodeBase();
00069
00070 std::vector<void*>& getItems();
00071
00074 void add(void* item);
00075
00077 std::vector<void*>& addAllItems(std::vector<void*>& resultItems) const;
00078
00079 virtual void addAllItemsFromOverlapping(const geom::Envelope& searchEnv,
00080 std::vector<void*>& resultItems) const;
00081
00082 unsigned int depth() const;
00083
00084 unsigned int size() const;
00085
00086 unsigned int getNodeCount() const;
00087
00088 virtual std::string toString() const;
00089
00090 virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
00091
00099 bool remove(const geom::Envelope* itemEnv, void* item);
00100
00101 bool hasItems() const;
00102
00103 bool hasChildren() const;
00104
00105 bool isPrunable() const;
00106
00107 protected:
00108
00110 std::vector<void*> items;
00111
00122 Node* subnode[4];
00123
00124 virtual bool isSearchMatch(const geom::Envelope& searchEnv) const=0;
00125 };
00126
00127
00128
00129
00130 inline bool
00131 NodeBase::hasChildren() const
00132 {
00133 for (int i = 0; i < 4; i++)
00134 if (subnode[i]) return true;
00135 return false;
00136 }
00137
00138 inline bool
00139 NodeBase::isPrunable() const
00140 {
00141 return ! (hasChildren() || hasItems());
00142 }
00143
00144 inline bool
00145 NodeBase::hasItems() const
00146 {
00147 return ! items.empty();
00148 }
00149
00150 }
00151 }
00152 }
00153
00154 #ifdef _MSC_VER
00155 #pragma warning(pop)
00156 #endif
00157
00158 #endif // GEOS_IDX_QUADTREE_NODEBASE_H