# STRtree.h

    00001 /**********************************************************************
    00002  * $Id: STRtree.h 1971 2007-02-07 00:34:26Z strk $
    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/strtree/STRtree.java rev. 1.11
    00017  *
    00018  **********************************************************************/
    00019
    00020 #ifndef GEOS_INDEX_STRTREE_STRTREE_H
    00021 #define GEOS_INDEX_STRTREE_STRTREE_H
    00022
    00023 #include <geos/index/strtree/AbstractSTRtree.h> // for inheritance
    00024 #include <geos/index/SpatialIndex.h> // for inheritance
    00025 #include <geos/geom/Envelope.h> // for inlines
    00026
    00027 #include <vector>
    00028
    00029 // Forward declarations
    00030 namespace geos {
    00031         namespace index {
    00032                 namespace strtree {
    00033                         class Boundable;
    00034                 }
    00035         }
    00036 }
    00037
    00038
    00039 namespace geos {
    00040 namespace index { // geos::index
    00041 namespace strtree { // geos::index::strtree
    00042
    00058 class STRtree: public AbstractSTRtree, public SpatialIndex
    00059 {
    00060 using AbstractSTRtree::insert;
    00061 using AbstractSTRtree::query;
    00062
    00063 private:
    00064         class STRIntersectsOp: public AbstractSTRtree::IntersectsOp {
    00065                 public:
    00066                         bool intersects(const void* aBounds, const void* bBounds);
    00067         };
    00068
    00076         std::auto_ptr<BoundableList> createParentBoundables(BoundableList* childBoundables, int newLevel);
    00077
    00078         std::auto_ptr<BoundableList> createParentBoundablesFromVerticalSlices(std::vector<BoundableList*>* verticalSlices, int newLevel);
    00079
    00080         STRIntersectsOp intersectsOp;
    00081
    00082         std::auto_ptr<BoundableList> sortBoundables(const BoundableList* input);
    00083
    00084         std::auto_ptr<BoundableList> createParentBoundablesFromVerticalSlice(
    00085                         BoundableList* childBoundables,
    00086                         int newLevel);
    00087
    00093         std::vector<BoundableList*>* verticalSlices(
    00094                         BoundableList* childBoundables,
    00095                         size_t sliceCount);
    00096
    00097
    00098 protected:
    00099
    00100         AbstractNode* createNode(int level);
    00101
    00102         IntersectsOp* getIntersectsOp() {
    00103                 return &intersectsOp;
    00104         };
    00105
    00106 public:
    00107
    00108         ~STRtree();
    00109
    00114         STRtree(size_t nodeCapacity=10);
    00115
    00116         void insert(const geom::Envelope *itemEnv,void* item);
    00117
    00118         //static double centreX(const geom::Envelope *e);
    00119
    00120         static double avg(double a, double b) {
    00121                 return (a + b) / 2.0;
    00122         }
    00123
    00124         static double centreY(const geom::Envelope *e) {
    00125                 return STRtree::avg(e->getMinY(), e->getMaxY());
    00126         }
    00127
    00128         void query(const geom::Envelope *searchEnv, std::vector<void*>& matches) {
    00129                 AbstractSTRtree::query(searchEnv, matches);
    00130         }
    00131
    00132         void query(const geom::Envelope *searchEnv, ItemVisitor& visitor) {
    00133                 return AbstractSTRtree::query(searchEnv, visitor);
    00134         }
    00135
    00136         bool remove(const geom::Envelope *itemEnv, void* item) {
    00137                 return AbstractSTRtree::remove(itemEnv, item);
    00138         }
    00139 };
    00140
    00141 } // namespace geos::index::strtree
    00142 } // namespace geos::index
    00143 } // namespace geos
    00144
    00145 #endif // GEOS_INDEX_STRTREE_STRTREE_H
    00146
    00147 /**********************************************************************
    00148  * $Log$
    00149  * Revision 1.3  2006/06/12 10:49:43  strk
    00150  * unsigned int => size_t
    00151  *
    00152  * Revision 1.2  2006/04/03 08:43:09  strk
    00153  * Added port info, minor cleanups
    00154  *
    00155  * Revision 1.1  2006/03/21 10:47:34  strk
    00156  * indexStrtree.h split
    00157  *
    00158  **********************************************************************/
    00159