NodeBase.h

00001 /**********************************************************************
00002  * $Id: NodeBase.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 #ifndef GEOS_IDX_QUADTREE_NODEBASE_H
00017 #define GEOS_IDX_QUADTREE_NODEBASE_H
00018 
00019 #include <vector>
00020 #include <string>
00021 
00022 // Forward declarations
00023 namespace geos {
00024         namespace geom {
00025                 class Coordinate;
00026                 class Envelope;
00027         }
00028         namespace index {
00029                 class ItemVisitor;
00030                 namespace quadtree {
00031                         class Node;
00032                 }
00033         }
00034 }
00035 
00036 namespace geos {
00037 namespace index { // geos::index
00038 namespace quadtree { // geos::index::quadtree
00039 
00045 class NodeBase {
00046 
00047 private:
00048 
00049         void visitItems(const geom::Envelope* searchEnv,
00050                         ItemVisitor& visitor);
00051         
00052 public:
00053 
00054         static int getSubnodeIndex(const geom::Envelope *env,
00055                         const geom::Coordinate& centre);
00056 
00057         NodeBase();
00058 
00059         virtual ~NodeBase();
00060 
00061         virtual std::vector<void*>* getItems();
00062 
00063         virtual void add(void* item);
00064 
00065         virtual std::vector<void*>* addAllItems(std::vector<void*> *resultItems);
00066 
00067         virtual void addAllItemsFromOverlapping(const geom::Envelope *searchEnv,
00068                         std::vector<void*> *resultItems);
00069 
00070         virtual int depth();
00071 
00072         virtual int size();
00073 
00074         virtual int nodeCount();
00075 
00076         virtual std::string toString() const;
00077 
00078         virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
00079 
00087         bool remove(const geom::Envelope* itemEnv, void* item);
00088  
00089         bool hasItems() const;
00090 
00091         bool hasChildren() const;
00092 
00093         bool isPrunable() const;
00094 
00095 protected:
00096 
00097         std::vector<void*> *items;
00098 
00107         Node* subnode[4];
00108 
00109         virtual bool isSearchMatch(const geom::Envelope *searchEnv)=0;
00110 };
00111 
00112 
00113 // INLINES, To be moved in NodeBase.inl
00114 
00115 inline bool
00116 NodeBase::hasChildren() const
00117 {
00118         for (int i = 0; i < 4; i++) 
00119                 if (subnode[i]) return true;
00120         return false;
00121 }
00122 
00123 inline bool
00124 NodeBase::isPrunable() const
00125 {
00126         return ! (hasChildren() || hasItems());
00127 }
00128 
00129 inline bool
00130 NodeBase::hasItems() const
00131 {
00132         return ! items->empty();
00133 }
00134 
00135 } // namespace geos::index::quadtree
00136 } // namespace geos::index
00137 } // namespace geos
00138 
00139 #endif // GEOS_IDX_QUADTREE_NODEBASE_H
00140 
00141 /**********************************************************************
00142  * $Log$
00143  * Revision 1.1  2006/03/22 12:22:50  strk
00144  * indexQuadtree.h split
00145  *
00146  **********************************************************************/
00147 

Generated on Fri Mar 27 04:52:53 2009 for GEOS by  doxygen 1.5.4