# Quadtree.h

    00001 /**********************************************************************
    00002  * $Id: Quadtree.h 1820 2006-09-06 16:54:23Z mloskot $
    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/quadtree/Quadtree.java rev. 1.14
    00017  *
    00018  **********************************************************************/
    00019
    00020 #ifndef GEOS_IDX_QUADTREE_QUADTREE_H
    00021 #define GEOS_IDX_QUADTREE_QUADTREE_H
    00022
    00023 #include <geos/index/SpatialIndex.h> // for inheritance
    00024 #include <geos/index/quadtree/Root.h> // for inline
    00025
    00026 #include <vector>
    00027 #include <string>
    00028
    00029 // Forward declarations
    00030 namespace geos {
    00031         namespace geom {
    00032                 class Envelope;
    00033         }
    00034         namespace index {
    00035                 namespace quadtree {
    00036                         // class Root;
    00037                 }
    00038         }
    00039 }
    00040
    00041 namespace geos {
    00042 namespace index { // geos::index
    00043 namespace quadtree { // geos::index::quadtree
    00044
    00067 class Quadtree: public SpatialIndex {
    00068
    00069 private:
    00070
    00071         std::vector<geom::Envelope *> newEnvelopes;
    00072
    00073         void collectStats(const geom::Envelope *itemEnv);
    00074
    00075         Root *root;
    00076
    00088         double minExtent;
    00089
    00090 public:
    00098         static geom::Envelope* ensureExtent(const geom::Envelope *itemEnv,
    00099                         double minExtent);
    00100
    00105         Quadtree()
    00106                 :
    00107                 root(new Root()),
    00108                 minExtent(1.0)
    00109         {}
    00110
    00111         ~Quadtree();
    00112
    00114         int depth();
    00115
    00117         int size();
    00118
    00119         void insert(const geom::Envelope *itemEnv, void *item);
    00120
    00121         void query(const geom::Envelope *searchEnv, std::vector<void*>& ret);
    00122
    00123         void query(const geom::Envelope *searchEnv, ItemVisitor& visitor) {
    00124                 /*
    00125                  * the items that are matched are the items in quads which
    00126                  * overlap the search envelope
    00127                  */
    00128                 root->visit(searchEnv, visitor);
    00129         }
    00130
    00138         bool remove(const geom::Envelope* itemEnv, void* item);
    00139
    00141         std::vector<void*>* queryAll();
    00142
    00143         std::string toString() const;
    00144
    00145 };
    00146
    00147
    00148 } // namespace geos::index::quadtree
    00149 } // namespace geos::index
    00150 } // namespace geos
    00151
    00152 #endif // GEOS_IDX_QUADTREE_QUADTREE_H
    00153
    00154 /**********************************************************************
    00155  * $Log$
    00156  * Revision 1.2  2006/04/03 08:29:30  strk
    00157  * Added port info, cleaned up log message, minor assertion checking.
    00158  *
    00159  * Revision 1.1  2006/03/22 12:22:50  strk
    00160  * indexQuadtree.h split
    00161  *
    00162  **********************************************************************/
    00163