GEOS  3.4.2
Quadtree.h
00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.osgeo.org
00005  *
00006  * Copyright (C) 2006 Refractions Research Inc.
00007  *
00008  * This is free software; you can redistribute and/or modify it under
00009  * the terms of the GNU Lesser General Public Licence as published
00010  * by the Free Software Foundation. 
00011  * See the COPYING file for more information.
00012  *
00013  **********************************************************************
00014  *
00015  * Last port: index/quadtree/Quadtree.java rev. 1.16 (JTS-1.10)
00016  *
00017  **********************************************************************/
00018 
00019 #ifndef GEOS_IDX_QUADTREE_QUADTREE_H
00020 #define GEOS_IDX_QUADTREE_QUADTREE_H
00021 
00022 #include <geos/export.h>
00023 #include <geos/index/SpatialIndex.h> // for inheritance
00024 #include <geos/index/quadtree/Root.h> // for composition
00025 
00026 #include <vector>
00027 #include <string>
00028 
00029 #ifdef _MSC_VER
00030 #pragma warning(push)
00031 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00032 #endif
00033 
00034 // Forward declarations
00035 namespace geos {
00036         namespace geom {
00037                 class Envelope;
00038         }
00039         namespace index {
00040                 namespace quadtree {
00041                         // class Root; 
00042                 }
00043         }
00044 }
00045 
00046 namespace geos {
00047 namespace index { // geos::index
00048 namespace quadtree { // geos::index::quadtree
00049 
00072 class GEOS_DLL Quadtree: public SpatialIndex {
00073 
00074 private:
00075 
00076         std::vector<geom::Envelope *> newEnvelopes;
00077 
00078         void collectStats(const geom::Envelope& itemEnv);
00079 
00080         Root root;
00081 
00093         double minExtent;
00094 
00095 public:
00103         static geom::Envelope* ensureExtent(const geom::Envelope *itemEnv,
00104                         double minExtent);
00105 
00110         Quadtree()
00111                 :
00112                 root(),
00113                 minExtent(1.0)
00114         {}
00115 
00116         ~Quadtree();
00117 
00119         int depth();
00120 
00122         int size();
00123         
00124         void insert(const geom::Envelope *itemEnv, void *item);
00125 
00143         void query(const geom::Envelope *searchEnv, std::vector<void*>& ret);
00144 
00145 
00162         void query(const geom::Envelope *searchEnv, ItemVisitor& visitor)
00163         {
00164                 /*
00165                  * the items that are matched are the items in quads which
00166                  * overlap the search envelope
00167                  */
00168                 root.visit(searchEnv, visitor);
00169         }
00170 
00178         bool remove(const geom::Envelope* itemEnv, void* item);
00179 
00181         std::vector<void*>* queryAll();
00182 
00183         std::string toString() const;
00184 
00185 };
00186 
00187 } // namespace geos::index::quadtree
00188 } // namespace geos::index
00189 } // namespace geos
00190 
00191 #ifdef _MSC_VER
00192 #pragma warning(pop)
00193 #endif
00194 
00195 #endif // GEOS_IDX_QUADTREE_QUADTREE_H