qtree.h

Go to the documentation of this file.
00001 /**
00002  * \file qtree.h <mi32/qtree.h>
00003  * \brief Spatial searching functions
00004  *
00005  * \if NODOC
00006  * $Id: qtree.h_v 1.16 2004/02/19 22:01:38 scowan Exp $
00007  *
00008  * $Log: qtree.h_v $
00009  * Revision 1.16  2004/02/19 22:01:38  scowan
00010  * Added another method.
00011  *
00012  * Revision 1.15  2004/02/12 21:37:58  scowan
00013  * Replaced function version with class version.
00014  *
00015  * Revision 1.14  2003/09/15 13:49:56  fileserver!dwilliss
00016  * Doxygen
00017  *
00018  * Revision 1.13  2000/07/11 19:06:42  sparsons
00019  * Genitor documentation.
00020  *
00021  * Revision 1.12  2000/07/10 20:20:01  mju
00022  * Compile in isolation.
00023  *
00024  * Revision 1.11  1999/05/07 21:21:00  mju
00025  * Header restruct.
00026  *
00027  * Revision 1.10  1999/04/08  16:00:48  mju
00028  * Add inclusion guard.
00029  *
00030  * \endif
00031 **/
00032 
00033 #ifndef  INC_MI32_QTREE_H
00034 #define  INC_MI32_QTREE_H
00035 
00036 #ifndef  INC_MI32_SIMPLEAR_H
00037 #include <mi32/simplear.h>
00038 #endif
00039 
00040 #ifdef GEOMDLL
00041    #define GEOMLIBEXPORT MI_DLLEXPORT
00042    #define GEOMLIBCLASSEXPORT MI_DLLCLASSEXPORT
00043 #else
00044    #define GEOMLIBEXPORT MI_DLLIMPORT
00045    #define GEOMLIBCLASSEXPORT MI_DLLCLASSIMPORT
00046 #endif
00047 
00048 #ifndef GENERATING_DOXYGEN_OUTPUT
00049 //! Forward declarations
00050 struct DRECT2D;
00051 class BITSET_DEQUE;
00052 #endif // GENERATING_DOXYGEN_OUTPUT
00053 
00054 //! Quad search tree implementation
00055 class GEOMLIBCLASSEXPORT QUADTREE {
00056    public:
00057       enum INITFLAGS {
00058          INITFLAG_None =         0x0000,
00059          INITFLAG_StoreExtents = 0x0001,     //!< Ignored if INITFLAG_PointOnly is specified, stores DRECT2D passed to Add() according to ItemID
00060          INITFLAG_PointOnly =    0x0002,     //!< Creates optimized version for point only searches
00061          INITFLAG_FastAdd =      0x0004      //!< Performs no validation check for adding an ItemID multiple times
00062          };
00063 
00064       //! Default constructor 
00065       QUADTREE (
00066          );
00067    
00068       //! Copy constructor 
00069       QUADTREE (
00070          const QUADTREE& rhs
00071          );
00072    
00073       //! Destructor 
00074       ~QUADTREE (
00075          );
00076          
00077       //! Assignment operator
00078       QUADTREE& operator= (
00079          const QUADTREE& rhs
00080          );
00081    
00082       //! Add an element to the quad tree
00083       ERRVALUE Add (
00084          INT32 ItemID,
00085          const DRECT2D& Extents
00086          );
00087          
00088       //! Clear the quad tree of all elements, reverts back to the Initialize() state
00089       void Clear (
00090          );
00091    
00092       //! Delete an item from the quad tree
00093       //! Only valid if INITFLAG_StoreExtents is specified in Initialize()
00094       ERRVALUE Delete (
00095          INT32 ItemID
00096          );
00097          
00098       //! Delete an item from the quad tree
00099       ERRVALUE Delete (
00100          INT32 ItemID,
00101          const DRECT2D& Extents
00102          );
00103          
00104       //! Free the memory used by the quad tree
00105       void Free (
00106          );
00107    
00108       //! Get the extents of the item specified
00109       //! Only valid if INITFLAG_StoreExtents is specified in Initialize()
00110       ERRVALUE GetItemExtents (
00111          INT32 ItemID,
00112          DRECT2D& Extents
00113          ) const;
00114          
00115       //! Initialize the quad tree for a specific extents and number of elements
00116       ERRVALUE Initialize (
00117          const DRECT2D& Extents,
00118          INT32 NumItems,
00119          INITFLAGS InitFlags = INITFLAG_None
00120          );
00121 
00122       //! Determine if the quad tree is initialized
00123       bool IsInitialized (
00124          ) const;
00125          
00126       //! Search for the ItemID's that fall within the DRECT2D specified
00127       //! If INITFLAG_StoreExtents is not specified in Initialize(), some of the elements might fall outside the extents specified
00128       ERRVALUE Search (
00129          const DRECT2D& rect,
00130          SIMPLE_ARRAY<INT32>& ItemList
00131          ) const;
00132    
00133       //! Search for the ItemID's that fall within the DRECT2D specified
00134       //! If INITFLAG_StoreExtents is not specified in Initialize(), some of the elements might fall outside the extents specified
00135       ERRVALUE Search (
00136          const DRECT2D& rect,
00137          BITSET_DEQUE& Deque
00138          ) const;
00139 
00140       //! Sort the item list using the item extents stored in the quad tree
00141       //! The list is sorted from smallest extents to largest extents item
00142       //! Only valid if INITFLAG_StoreExtents is specified in Initialize()
00143       ERRVALUE SortItemListByExtents (
00144          SIMPLE_ARRAY<INT32>& ItemList
00145          ) const;
00146       
00147    private:
00148       #ifndef GENERATING_DOXYGEN_OUTPUT
00149       class PRIV;
00150       PRIV* m_Priv;
00151       #endif // GENERATING_DOXYGEN_OUTPUT
00152    };
00153 
00154 DEFINE_ENUM_OP_BITWISE(QUADTREE::INITFLAGS);
00155 
00156 #endif   //!<  INC_MI32_QTREE_H 

Generated on Tue Dec 14 13:18:32 2004 for TNTsdk by  doxygen 1.3.8-20040913