OctreeAuxiliary.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 OctreeAuxiliary_h
00040 #define OctreeAuxiliary_h
00041 
00042 
00043 #include "Array.h"
00044 #include "Vector3r.h"
00045 
00046 
00047 
00048 
00049 namespace hxa7241_graphics
00050 {
00051    using namespace hxa7241;
00052    using hxa7241_general::Array;
00053    class OctreeCell;
00054 
00055 
00067 class OctreeDimensions
00068 {
00070 public:
00071             OctreeDimensions( const Vector3r& positionOfLowerCorner,
00072                               real            size,
00073                               dword           maxItemCountPerCell,
00074                               dword           maxLevelCount,
00075                               real            minCellSize );
00076 
00077            ~OctreeDimensions();
00078             OctreeDimensions( const OctreeDimensions& );
00079    OctreeDimensions& operator=( const OctreeDimensions& );
00080 
00081 
00083            const Vector3r& getPosition()                                  const;
00084            real            getSize()                                      const;
00085            dword           getMaxItemCountPerCell()                       const;
00086            dword           getMaxLevelCount()                             const;
00087            real            getMinCellSize()                               const;
00088 
00089            bool            isSubdivide( dword itemCount,
00090                                         dword level,
00091                                         real  size )                      const;
00092 
00093 
00095 private:
00096    Vector3r positionOfLowerCorner_m;
00097    real     size_m;
00098    dword    maxItemsPerCell_m;
00099    dword    maxLevel_m;
00100    real     minSize_m;
00101 
00102    static const dword MAX_LEVEL;
00103    static const real  MIN_SIZE;
00104 };
00105 
00106 
00107 
00108 
00129 class OctreeBound
00130 {
00132 public:
00133             OctreeBound();
00134             OctreeBound( const Vector3r& positionOfLowerCorner,
00135                          real            size );
00136             OctreeBound( const OctreeBound& parentCellBound,
00137                          dword              subCellIndex );
00138 
00139            ~OctreeBound();
00140             OctreeBound( const OctreeBound& );
00141    OctreeBound& operator=( const OctreeBound& );
00142 
00143 
00145            const Vector3r& getLowerCorner()                               const;
00146            const Vector3r& getUpperCorner()                               const;
00147            const Vector3r& getCenter()                                    const;
00148            real            getRadius()                                    const;
00149            real            getSize()                                      const;
00150 
00151 
00153 private:
00154    Vector3r positionOfLowerCorner_m;
00155    Vector3r positionOfUpperCorner_m;
00156    Vector3r center_m;
00157    real     circumSphereRadius_m;
00158 };
00159 
00160 
00161 
00162 
00187 class OctreeData
00188 {
00190 public:
00191    explicit OctreeData( const OctreeDimensions& dimensions );
00192             OctreeData( const OctreeData& parentCellData,
00193                         dword             subCellIndex );
00194             OctreeData( const OctreeData&,
00195                         const OctreeDimensions& );
00196 
00197            ~OctreeData();
00198             OctreeData( const OctreeData& );
00199    OctreeData& operator=( const OctreeData& );
00200 
00201 
00203            const OctreeBound&      getBound()                             const;
00204            dword                   getLevel()                             const;
00205            const OctreeDimensions& getDimensions()                        const;
00206 
00207            bool  isSubdivide( dword itemCount )                           const;
00208 
00209 
00211 private:
00212    // local to cell
00213    OctreeBound bound_m;
00214    dword       level_m;
00215 
00216    // global for octree
00217    const OctreeDimensions* pDimensions_m;
00218 };
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00251 class OctreeAgentV
00252 {
00254 protected:
00255             OctreeAgentV() {}
00256 public:
00257    virtual ~OctreeAgentV() {}
00258 private:
00259             OctreeAgentV( const OctreeAgentV& );
00260    OctreeAgentV& operator=( const OctreeAgentV& );
00261 public:
00262 
00263 
00265    virtual bool  isOverlappingCellV ( const void*     pItem,
00266                                       const Vector3r& lowerCorner,
00267                                       const Vector3r& upperCorner )    const =0;
00268    virtual dword getSubcellOverlapsV( const void*     pItem,
00269                                       const Vector3r& lower,
00270                                       const Vector3r& middle,
00271                                       const Vector3r& upper )          const =0;
00272 
00273 
00275    static const dword ALL_INSIDE  = 0x0000FFFF;
00276    static const dword ALL_OUTSIDE = 0x00000000;
00277 };
00278 
00279 
00280 
00281 
00302 class OctreeVisitorV
00303 {
00305 protected:
00306             OctreeVisitorV() {}
00307 public:
00308    virtual ~OctreeVisitorV() {}
00309 private:
00310             OctreeVisitorV( const OctreeVisitorV& );
00311    OctreeVisitorV& operator=( const OctreeVisitorV& );
00312 public:
00313 
00314 
00316    virtual void  visitRootV  ( const OctreeCell* pRootCell,
00317                                const OctreeData& octreeData )                =0;
00318    virtual void  visitBranchV( const OctreeCell* subCells[8],
00319                                const OctreeData& octreeData )                =0;
00320    virtual void  visitLeafV  ( const Array<const void*>& items,
00321                                const OctreeData&         octreeData )        =0;
00322 };
00323 
00324 
00325 
00326 
00327 
00328 
00329 
00330 
00332 
00334 inline
00335 const Vector3r& OctreeDimensions::getPosition() const
00336 {
00337    return positionOfLowerCorner_m;
00338 }
00339 
00340 
00341 inline
00342 real OctreeDimensions::getSize() const
00343 {
00344    return size_m;
00345 }
00346 
00347 
00348 inline
00349 dword OctreeDimensions::getMaxItemCountPerCell() const
00350 {
00351    return maxItemsPerCell_m;
00352 }
00353 
00354 
00355 inline
00356 dword OctreeDimensions::getMaxLevelCount() const
00357 {
00358    return maxLevel_m + 1;
00359 }
00360 
00361 
00362 inline
00363 real OctreeDimensions::getMinCellSize() const
00364 {
00365    return minSize_m;
00366 }
00367 
00368 
00369 
00370 
00372 inline
00373 const Vector3r& OctreeBound::getLowerCorner() const
00374 {
00375    return positionOfLowerCorner_m;
00376 }
00377 
00378 
00379 inline
00380 const Vector3r& OctreeBound::getUpperCorner() const
00381 {
00382    return positionOfUpperCorner_m;
00383 }
00384 
00385 
00386 inline
00387 const Vector3r& OctreeBound::getCenter() const
00388 {
00389    return center_m;
00390 }
00391 
00392 
00393 inline
00394 real OctreeBound::getRadius() const
00395 {
00396    return circumSphereRadius_m;
00397 }
00398 
00399 
00400 inline
00401 real OctreeBound::getSize() const
00402 {
00403    return positionOfUpperCorner_m.getX() - positionOfLowerCorner_m.getX();
00404 }
00405 
00406 
00407 
00408 
00410 inline
00411 const OctreeBound& OctreeData::getBound() const
00412 {
00413    return bound_m;
00414 }
00415 
00416 
00417 inline
00418 dword OctreeData::getLevel() const
00419 {
00420    return level_m;
00421 }
00422 
00423 
00424 inline
00425 const OctreeDimensions& OctreeData::getDimensions() const
00426 {
00427    return *pDimensions_m;
00428 }
00429 
00430 
00431 inline
00432 bool OctreeData::isSubdivide
00433 (
00434    const dword itemCount
00435 ) const
00436 {
00437    return pDimensions_m->isSubdivide( itemCount, level_m, bound_m.getSize() );
00438 }
00439 
00440 
00441 }//namespace
00442 
00443 
00444 
00445 
00446 #endif//OctreeAuxiliary_h

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