OctreeImplementation.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Octree Component, version 2.1
00004    Copyright (c) 2004-2007,  Harrison Ainsworth / HXA7241.
00005 
00006    http://www.hxa7241.org/
00007 
00008 ------------------------------------------------------------------------------*/
00009 
00010 /*------------------------------------------------------------------------------
00011 
00012 Copyright (c) 2004-2007, Harrison Ainsworth / HXA7241.
00013 
00014 Redistribution and use in source and binary forms, with or without modification,
00015 are permitted provided that the following conditions are met:
00016 
00017 * Redistributions of source code must retain the above copyright notice, this
00018   list of conditions and the following disclaimer.
00019 * Redistributions in binary form must reproduce the above copyright notice, this
00020   list of conditions and the following disclaimer in the documentation and/or
00021   other materials provided with the distribution.
00022 * The name of the author may not be used to endorse or promote products derived
00023   from this software without specific prior written permission.
00024 
00025 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
00026 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00027 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00028 SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00030 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00031 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00032 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00033 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00034 OF SUCH DAMAGE.
00035 
00036 ------------------------------------------------------------------------------*/
00037 
00038 
00039 #ifndef OctreeImplementation_h
00040 #define OctreeImplementation_h
00041 
00042 
00043 #include "OctreeAuxiliary.h"
00044 
00045 
00046 
00047 
00048 namespace hxa7241_graphics
00049 {
00050 
00051 
00064 class OctreeRoot
00065 {
00067 public:
00068             OctreeRoot( const Vector3r& position,
00069                         real            sizeOfCube,
00070                         dword           maxItemsPerCell,
00071                         dword           maxLevelCount,
00072                         real            minCellSize );
00073 
00074            ~OctreeRoot();
00075             OctreeRoot( const OctreeRoot& );
00076    OctreeRoot& operator=( const OctreeRoot& );
00077 
00078 
00080            bool  insert( const void*         pItem,
00081                          const OctreeAgentV& agent );
00082            bool  remove( const void*         pItem,
00083                          const OctreeAgentV& agent );
00084 
00085 
00087            void  visit( OctreeVisitorV& visitor )                         const;
00088 
00089            bool  isEmpty()                                                const;
00090            void  getInfo( dword  rootWrapperByteSize,
00091                           dword& byteSize,
00092                           dword& leafCount,
00093                           dword& itemCount,
00094                           dword& maxDepth )                               const;
00095 
00096            const Vector3r& getPosition()                                  const;
00097            real            getSize()                                      const;
00098            dword           getMaxItemCountPerCell()                       const;
00099            dword           getMaxLevelCount()                             const;
00100            real            getMinCellSize()                               const;
00101 
00102 
00104    static  void  continueVisit( const OctreeCell* pRootCell,
00105                                 const OctreeData& octreeData,
00106                                 OctreeVisitorV&   visitor );
00107 
00108 
00110 private:
00111    OctreeDimensions dimensions_m;
00112    OctreeCell*      pRootCell_m;
00113 };
00114 
00115 
00116 
00117 
00135 class OctreeCell
00136 {
00138 protected:
00139             OctreeCell() {}
00140 public:
00141    virtual ~OctreeCell() {}
00142 private:
00143             OctreeCell( const OctreeCell& );
00144    OctreeCell& operator=( const OctreeCell& );
00145 public:
00146 
00147 
00149    virtual void  insert( const OctreeData&   thisData,
00150                          OctreeCell*&        pThis,
00151                          const void*         pItem,
00152                          const OctreeAgentV& agent )                         =0;
00153    virtual bool  remove( OctreeCell*&        pThis,
00154                          const void*         pItem,
00155                          const dword         maxItemsPerCell,
00156                          dword&              itemCount )                     =0;
00157 
00158 
00160    virtual void  visit( const OctreeData& thisData,
00161                         OctreeVisitorV&   visitor )                    const =0;
00162 
00163    virtual OctreeCell* clone()                                         const =0;
00164 
00165    virtual void  getInfo( dword& byteSize,
00166                           dword& leafCount,
00167                           dword& itemCount,
00168                           dword& maxDepth )                            const =0;
00169 
00170 
00172    static  OctreeCell* cloneNonZero( const OctreeCell* );
00173 };
00174 
00175 
00176 
00177 
00186 class OctreeBranch
00187    : public OctreeCell
00188 {
00190 public:
00191             OctreeBranch();
00192             OctreeBranch( const OctreeData&         thisData,
00193                           const Array<const void*>& items,
00194                           const void* const         pItem,
00195                           const OctreeAgentV&       agent );
00196 
00197    virtual ~OctreeBranch();
00198             OctreeBranch( const OctreeBranch& );
00199    OctreeBranch& operator=( const OctreeBranch& );
00200 
00201 
00203    virtual void  insert( const OctreeData&   thisData,
00204                          OctreeCell*&        pThis,
00205                          const void*         pItem,
00206                          const OctreeAgentV& agent );
00207    virtual bool  remove( OctreeCell*&        pThis,
00208                          const void*         pItem,
00209                          const dword         maxItemsPerCell,
00210                          dword&              itemCount );
00211 
00212 
00214    virtual void  visit( const OctreeData& thisData,
00215                         OctreeVisitorV&   visitor )                       const;
00216 
00217    virtual OctreeCell* clone()                                            const;
00218 
00219    virtual void  getInfo( dword& byteSize,
00220                           dword& leafCount,
00221                           dword& itemCount,
00222                           dword& maxDepth )                               const;
00223 
00224 
00226    static  void  continueVisit( const OctreeCell* subCells[8],
00227                                 const OctreeData& octreeData,
00228                                 dword             subCellIndex,
00229                                 OctreeVisitorV&   visitor );
00230 
00231 
00233 protected:
00234    virtual void  zeroSubCells();
00235 
00236 
00238 private:
00239    OctreeCell* subCells_m[ 8 ];
00240 };
00241 
00242 
00243 
00244 
00250 class OctreeLeaf
00251    : public OctreeCell
00252 {
00254 public:
00255             OctreeLeaf();
00256             OctreeLeaf( const OctreeLeaf*const leafs[8] );
00257 private:
00258    explicit OctreeLeaf( const void* pItem );
00259 
00260 public:
00261    virtual ~OctreeLeaf();
00262             OctreeLeaf( const OctreeLeaf& );
00263    OctreeLeaf& operator=( const OctreeLeaf& );
00264 
00265 
00267    virtual void  insert( const OctreeData&   thisData,
00268                          OctreeCell*&        pThis,
00269                          const void*         pItem,
00270                          const OctreeAgentV& agent );
00271    virtual bool  remove( OctreeCell*&        pThis,
00272                          const void*         pItem,
00273                          const dword         maxItemsPerCell,
00274                          dword&              itemCount );
00275 
00276 
00278    virtual void  visit( const OctreeData& thisData,
00279                         OctreeVisitorV&   visitor )                       const;
00280 
00281    virtual OctreeCell* clone()                                            const;
00282 
00283    virtual void  getInfo( dword& byteSize,
00284                           dword& leafCount,
00285                           dword& itemCount,
00286                           dword& maxDepth )                               const;
00287 
00288 
00290    static  void  insertMaybeCreate( const OctreeData&   cellData,
00291                                     OctreeCell*&        pCell,
00292                                     const void*         pItem,
00293                                     const OctreeAgentV& agent );
00294 
00295 
00297 private:
00298    Array<const void*> items_m;
00299 };
00300 
00301 
00302 }//namespace
00303 
00304 
00305 
00306 
00307 #endif//OctreeImplementation_h

Generated on Fri Feb 13 13:58:10 2009 for meshmorph by  doxygen 1.5.1