00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GEOS_INDEX_STRTREE_ABSTRACTSTRTREE_H
00017 #define GEOS_INDEX_STRTREE_ABSTRACTSTRTREE_H
00018
00019 #include <geos/index/strtree/AbstractNode.h>
00020
00021 #include <vector>
00022 #include <list>
00023 #include <memory>
00024 #include <cassert>
00025
00026
00027 namespace geos {
00028 namespace index {
00029 class ItemVisitor;
00030 namespace strtree {
00031 class Boundable;
00032 class AbstractNode;
00033 }
00034 }
00035 }
00036
00037 namespace geos {
00038 namespace index {
00039 namespace strtree {
00040
00042 typedef std::vector<Boundable*> BoundableList;
00043
00044
00057 class AbstractSTRtree {
00058
00059 private:
00060 bool built;
00061 BoundableList* itemBoundables;
00062
00073 virtual AbstractNode* createHigherLevels(
00074 BoundableList* boundablesOfALevel,
00075 int level);
00076
00077 virtual std::auto_ptr<BoundableList> sortBoundables(const BoundableList* input)=0;
00078
00079 bool remove(const void* searchBounds, AbstractNode& node, void* item);
00080 bool removeItem(AbstractNode& node, void* item);
00081
00082 protected:
00083
00089 class IntersectsOp {
00090 public:
00099 virtual bool intersects(const void* aBounds,
00100 const void* bBounds)=0;
00101
00102 virtual ~IntersectsOp() {}
00103 };
00104
00105 AbstractNode *root;
00106
00107 std::vector <AbstractNode *> *nodes;
00108
00109
00110 virtual AbstractNode* createNode(int level)=0;
00111
00116 virtual std::auto_ptr<BoundableList> createParentBoundables(
00117 BoundableList* childBoundables, int newLevel);
00118
00119 virtual AbstractNode* lastNode(BoundableList* nodes)
00120 {
00121 assert(!nodes->empty());
00122
00123 return static_cast<AbstractNode*>( nodes->back() );
00124 }
00125
00126 virtual AbstractNode* getRoot() {
00127 return root;
00128 }
00129
00131 virtual void insert(const void* bounds,void* item);
00132
00134 void query(const void* searchBounds, std::vector<void*>& foundItems);
00135
00136 #if 0
00138 std::vector<void*>* query(const void* searchBounds) {
00139 vector<void*>* matches = new vector<void*>();
00140 query(searchBounds, *matches);
00141 return matches;
00142 }
00143 #endif
00144
00145
00147 void query(const void* searchBounds, ItemVisitor& visitor);
00148
00149 void query(const void* searchBounds, const AbstractNode& node, ItemVisitor& visitor);
00150
00152 bool remove(const void* itemEnv, void* item);
00153
00154 std::auto_ptr<BoundableList> boundablesAtLevel(int level);
00155
00156
00157 size_t nodeCapacity;
00158
00165 virtual IntersectsOp *getIntersectsOp()=0;
00166
00167
00168 public:
00169
00174 AbstractSTRtree(size_t newNodeCapacity)
00175 :
00176 built(false),
00177 itemBoundables(new BoundableList()),
00178 nodes(new std::vector<AbstractNode *>()),
00179 nodeCapacity(newNodeCapacity)
00180 {
00181 assert(newNodeCapacity>1);
00182 }
00183
00184 static bool compareDoubles(double a, double b) {
00185 return a<b;
00186 }
00187
00188 virtual ~AbstractSTRtree();
00189
00196 virtual void build();
00197
00201 virtual size_t getNodeCapacity() { return nodeCapacity; }
00202
00203 virtual void query(const void* searchBounds, const AbstractNode* node, std::vector<void*>* matches);
00204
00208 virtual void boundablesAtLevel(int level, AbstractNode* top,
00209 BoundableList* boundables);
00210 };
00211
00212
00213 }
00214 }
00215 }
00216
00217 #endif // GEOS_INDEX_STRTREE_ABSTRACTSTRTREE_H
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231