Changeset 1595


Ignore:
Timestamp:
10/10/06 01:27:11 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h

    r1296 r1595  
    1 #ifndef _OgreBoundingBoxConverter_H__ 
    2 #define _OgreBoundingBoxConverter_H__ 
     1#ifndef _PlatFormBoundingBoxConverter_H__ 
     2#define _PlatFormBoundingBoxConverter_H__ 
    33  
    44#include "OgreAxisAlignedBox.h" 
     
    1313class OctreeSceneManager; 
    1414class KdTreeSceneManager; 
     15class BvHierarchySceneManager; 
     16 
    1517 
    1618/**     Class which converts preprocessor types to OGRE types 
    1719*/ 
    18 class __declspec(dllexport) OgreBoundingBoxConverter: public GtpVisibilityPreprocessor::BoundingBoxConverter 
     20template<typename T> 
     21class __declspec(dllexport) PlatFormBoundingBoxConverter: public GtpVisibilityPreprocessor::BoundingBoxConverter 
    1922{ 
    2023public: 
    21         OgreBoundingBoxConverter(OctreeSceneManager *sm); 
    22         OgreBoundingBoxConverter(KdTreeSceneManager *sm); 
    23  
     24        PlatFormBoundingBoxConverter(T *sm); 
     25         
    2426        bool IdentifyObjects(const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes, 
    2527                                                 GtpVisibilityPreprocessor::ObjectContainer &objects) const; 
     
    2830protected: 
    2931 
    30         Entity *FindCorrespondingObject(const AxisAlignedBox &box) const; 
     32        //------------------------------------------------------------------------- 
     33        inline static AxisAlignedBox EnlargeBox(const AxisAlignedBox &box) 
     34        { 
     35                const float eps = 1e-3f; 
     36                const Vector3 veps(eps, eps, eps); 
     37                 
     38                Vector3 max = box.getMaximum(); 
     39        Vector3 min = box.getMinimum(); 
    3140 
    32         OctreeSceneManager *mOctSceneMgr; 
    33         KdTreeSceneManager *mKdSceneMgr; 
     41                return AxisAlignedBox(min - veps, max + veps); 
     42        } 
     43         
     44        Entity *FindBestFittingObject(const AxisAlignedBox &box) const; 
     45 
     46        T *mSceneMgr; 
    3447}; 
     48 
     49//------------------------------------------------------------------------- 
     50template<typename T> 
     51PlatFormBoundingBoxConverter<T>::PlatFormBoundingBoxConverter(T *sm): 
     52mSceneMgr(sm) 
     53{ 
     54} 
     55//----------------------------------------------------------------------- 
     56template<typename T> 
     57Entity *PlatFormBoundingBoxConverter<T>::FindBestFittingObject(const AxisAlignedBox &box) const 
     58{ 
     59        list<SceneNode *> sceneNodeList; 
     60        AxisAlignedBox mybox = EnlargeBox(box); 
     61                 
     62        // get intersecting scene nodes 
     63        mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL); 
     64                 
     65        // minimal overlap 
     66        float overlap = 0;//1e-6; 
     67 
     68        Entity *bestFittingObj = NULL; 
     69        float bestFit = overlap; 
     70 
     71        // perfect fit threshold 
     72        const float thresh = 1.0 - GtpVisibilityPreprocessor::Limits::Small; 
     73 
     74        list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 
     75        // find the bbox which is closest to the current bbox 
     76        for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit) 
     77        { 
     78                SceneNode *sn = *sit; 
     79                SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator(); 
     80 
     81        while (oit.hasMoreElements()) 
     82                { 
     83                        MovableObject *mo = oit.getNext(); 
     84 
     85                        // we are only interested in scene entities 
     86                        if (mo->getMovableType() != "Entity") 
     87                        { 
     88                                continue; 
     89                        } 
     90                          
     91                        const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox()); 
     92                                         
     93                        // compute measure how much aabbs overlap 
     94                        overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox), 
     95                                                                         OgreTypeConverter::ConvertFromOgre(bbox)); 
     96         
     97                         if (overlap > bestFit) 
     98                         { 
     99                                 bestFit = overlap; 
     100                                 bestFittingObj = static_cast<Entity *>(mo); 
     101 
     102                                 // perfect fit => object found, early exit 
     103                                 if (overlap >= thresh) 
     104                                 { 
     105                                         return bestFittingObj;  
     106                                 } 
     107                         } 
     108                } 
     109        } 
     110 
     111        if (0) 
     112        { 
     113                std::stringstream d;  
     114                if (bestFittingObj) 
     115                        d << "best fit: " << bestFit;      
     116                else 
     117                        d << "warning, no best fitting object\n" << box; 
     118         
     119                Ogre::LogManager::getSingleton().logMessage(d.str()); 
     120        } 
     121 
     122        return bestFittingObj; 
     123} 
     124//------------------------------------------------------------------------- 
     125template<typename T> 
     126bool PlatFormBoundingBoxConverter<T>::IdentifyObjects( 
     127        const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes, 
     128        GtpVisibilityPreprocessor::ObjectContainer &objects) const 
     129{ 
     130        GtpVisibilityPreprocessor::IndexedBoundingBoxContainer:: 
     131                const_iterator iit, iit_end = iboxes.end(); 
     132   
     133        for (iit = iboxes.begin(); iit != iit_end; ++ iit) 
     134        { 
     135                const GtpVisibilityPreprocessor::AxisAlignedBox3 box = (*iit).second; 
     136                const AxisAlignedBox currentBox = OgreTypeConverter::ConvertToOgre(box); 
     137    
     138                Entity *ent = FindBestFittingObject(currentBox); 
     139 
     140                // create new mesh instance 
     141                if (ent) 
     142                { 
     143                        OgreMeshInstance *omi = new OgreMeshInstance(ent); 
     144                        omi->SetId((*iit).first); 
     145                        objects.push_back(omi); 
     146                } 
     147        } 
     148 
     149        return true; 
     150} 
     151 
     152 
     153typedef PlatFormBoundingBoxConverter<OctreeSceneManager> OctreeBoundingBoxConverter; 
     154typedef PlatFormBoundingBoxConverter<BvHierarchySceneManager> BvhBoundingBoxConverter; 
     155typedef PlatFormBoundingBoxConverter<KdTreeSceneManager> KdTreeBoundingBoxConverter; 
    35156 
    36157} // namespace Ogre 
    37158 
    38 #endif // OgreBoundingBoxConverter 
     159#endif // PlatFormBoundingBoxConverter 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchySceneManager.h

    r1320 r1595  
    271271        bool mDeleteQueueAfterRendering; 
    272272 
    273  
    274273        // remember visited scene nodes for viz 
    275274        BvHierarchy::NodeList mVisibleNodes; 
    276275 
    277         /************************************************************************/ 
    278         /* Kd-Tree specific options & members                                   */ 
    279         /************************************************************************/ 
     276 
     277        /************************************************************************/ 
     278        /* Bvh specific options & members                                   */ 
     279        /************************************************************************/ 
     280 
     281 
    280282        // maximum depth of the BvHierarchy 
    281283        int mMaxDepth; 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBoundingBoxConverter.cpp

    r1296 r1595  
    99namespace Ogre 
    1010{ 
    11 //------------------------------------------------------------------------- 
    12 OgreBoundingBoxConverter::OgreBoundingBoxConverter(OctreeSceneManager *sm): 
    13 mOctSceneMgr(sm), mKdSceneMgr(0) 
    14 { 
    15 } 
    16 //------------------------------------------------------------------------- 
    17 OgreBoundingBoxConverter::OgreBoundingBoxConverter(KdTreeSceneManager *sm): 
    18 mOctSceneMgr(0), mKdSceneMgr(sm) 
    19 { 
    20 } 
    21 //------------------------------------------------------------------------- 
    22 bool OgreBoundingBoxConverter::IdentifyObjects(const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes, 
    23                                                                                            GtpVisibilityPreprocessor::ObjectContainer &objects) const 
    24 { 
    25         GtpVisibilityPreprocessor::IndexedBoundingBoxContainer:: 
    26                 const_iterator iit, iit_end = iboxes.end(); 
    27    
    28         for (iit = iboxes.begin(); iit != iit_end; ++ iit) 
    29         { 
    30                 const GtpVisibilityPreprocessor::AxisAlignedBox3 box = (*iit).second; 
    31                 const AxisAlignedBox currentBox = OgreTypeConverter::ConvertToOgre(box); 
    32     
    33                 Entity *ent = FindCorrespondingObject(currentBox); 
    34  
    35                 // create new mesh instance 
    36                 OgreMeshInstance *omi = new OgreMeshInstance(ent); 
    37                 omi->SetId((*iit).first); 
    38                 objects.push_back(omi); 
    39         } 
    40  
    41         return true; 
    42 } 
    43 //------------------------------------------------------------------------- 
    44 inline static AxisAlignedBox EnlargeBox(const AxisAlignedBox &box) 
    45 { 
    46         const float eps = 1e-3f; 
    47         const Vector3 veps(eps, eps, eps); 
    48  
    49         Vector3 max = box.getMaximum(); 
    50         Vector3 min = box.getMinimum(); 
    51  
    52         return AxisAlignedBox(min - veps, max + veps); 
    53 } 
    54 //----------------------------------------------------------------------- 
    55 Entity *OgreBoundingBoxConverter::FindCorrespondingObject(const AxisAlignedBox &box) const 
    56 { 
    57         list<SceneNode *> sceneNodeList; 
    58         AxisAlignedBox mybox = EnlargeBox(box); 
    59         //AxisAlignedBox dummy(Vector3(-50000, -50000, -50000), Vector3(50000, 50000, 50000)); 
    60          
    61         // get intersecting scene nodes 
    62         if (mOctSceneMgr) 
    63                 mOctSceneMgr->findNodesIn(mybox, sceneNodeList, NULL); 
    64         else if (mKdSceneMgr) 
    65                 mKdSceneMgr->findNodesIn(mybox, sceneNodeList, NULL); 
    66         else 
    67                 OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Bounding Box Converter cannot " 
    68                 "find appropriate scene manager.", "OgreBoundingBoxConverter::FindCorrespondingObject"); 
    69          
    70  
    71         list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 
    72  
    73         // minimal overlap 
    74         float overlap = 0;//1e-6; 
    75  
    76         Entity *bestFittingObj = NULL; 
    77         float bestFit = overlap; 
    78  
    79         // perfect fit threshold 
    80         const float thresh = 1.0 - GtpVisibilityPreprocessor::Limits::Small; 
    8111 
    8212 
    83         // find the bbox which is closest to the current bbox 
    84         for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit) 
    85         { 
    86                 SceneNode *sn = *sit; 
    87                 SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator(); 
    88  
    89         while (oit.hasMoreElements()) 
    90                 { 
    91                         MovableObject *mo = oit.getNext(); 
    92  
    93                         // we are only interested in scene entities 
    94                         if (mo->getMovableType() != "Entity") 
    95                         { 
    96                                 continue; 
    97                         } 
    98                           
    99                         const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox()); 
    100                                          
    101  
    102                         // compute measure how much aabbs overlap 
    103                         overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox), 
    104                                                                          OgreTypeConverter::ConvertFromOgre(bbox)); 
    105          
    106                          if (overlap > bestFit) 
    107                          { 
    108                                  bestFit = overlap; 
    109                          
    110                                  bestFittingObj = static_cast<Entity *>(mo); 
    111  
    112                                  // perfect fit => object found, early exit 
    113                                  if (overlap >= thresh) 
    114                                          return bestFittingObj;                          
    115                          } 
    116                 } 
    117         } 
    118  
    119         if (0) 
    120         { 
    121                 std::stringstream d;  
    122                 if (bestFittingObj) 
    123                         d << "best fit: " << bestFit;      
    124                 else 
    125                         d << "warning, objects do not fit\n" << box; 
    126          
    127                 Ogre::LogManager::getSingleton().logMessage(d.str()); 
    128         } 
    129  
    130         return bestFittingObj; 
    131 } 
    13213 
    13314} 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp

    r1593 r1595  
    2727{ 
    2828 
    29 BvHierarchySceneManager::BvHierarchySceneManager(const String& name, GtpVisibility::VisibilityManager *vm): 
     29BvHierarchySceneManager::BvHierarchySceneManager(const String& name,  
     30                                                                                                 GtpVisibility::VisibilityManager *vm): 
    3031SceneManager(name),  
    3132mVisibilityManager(vm),  
     
    13231324        // converter between view cell ids and Ogre entites  
    13241325        GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes; 
    1325 #if 0 
    1326         OgreBoundingBoxConverter bconverter(this); 
    1327  
    1328         // load the view cells assigning the found objects to the pvss 
     1326        BvhBoundingBoxConverter bconverter(this); 
     1327 
     1328        // load the view cells and assigns the objects in the pvs to  
     1329        // the scene objects using the bounding boxes 
    13291330        mViewCellsManager =  
    13301331                GtpVisibilityPreprocessor::ViewCellsManager::LoadViewCells(filename, &mObjects, false, &bconverter); 
    13311332 
    13321333        return (mViewCellsManager != NULL); 
    1333 #endif 
    13341334} 
    13351335//------------------------------------------------------------------------- 
    13361336void BvHierarchySceneManager::applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc,  
    13371337                                                                                                        const bool load) 
    1338 {       // NOTE: should not happen, rather apply view cell representing unbounded space then 
     1338{       // NOTE: should not happen, rather apply view cell  
     1339        // representing unbounded space then 
    13391340        if (!vc)  
    1340         {        
    1341                 // set everything visible for savety 
     1341        {       // set everything visible for savety 
    13421342                SetObjectsVisible(true); 
    1343  
    13441343                return; 
    13451344        } 
     
    13481347                oit_end = vc->GetPvs().mEntries.end(); 
    13491348 
     1349        ////////////// 
    13501350        //-- PVS of view cell 
    13511351        for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp

    r1593 r1595  
    13221322        // converter between view cell ids and Ogre entites  
    13231323        GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes; 
    1324         OgreBoundingBoxConverter bconverter(this); 
     1324        KdTreeBoundingBoxConverter bconverter(this); 
    13251325 
    13261326        // load the view cells assigning the found objects to the pvss 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp

    r1593 r1595  
    593593                        // reset view cell 
    594594                        OGRE_DELETE(mCurrentViewCell); 
    595  
     595                         
    596596                        if (mUseViewCells) 
    597597                        { 
     
    601601                        mElementaryViewCell = NULL; 
    602602 
    603                         // if using view cells, all objects are set to false initially 
     603                        // if we use view cells, all objects are set to false initially 
    604604                        SetObjectsVisible(!mUseViewCells); 
    605605                } 
     
    10601060        // converter between view cell ids and Ogre entites  
    10611061        GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes; 
    1062         OgreBoundingBoxConverter bconverter(this); 
     1062        OctreeBoundingBoxConverter bconverter(this); 
    10631063 
    10641064        // load the view cells assigning the found objects to the pvss 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp

    r1495 r1595  
    125125{ 
    126126        // create new query if there is no query left 
    127         if (mCurrentTestIdx == mOcclusionQueries.size()) 
     127        if (mCurrentTestIdx == (int)mOcclusionQueries.size()) 
    128128        { 
    129129                mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem)); 
    130         } 
    131  
    132         std::stringstream d; 
    133         d << "resizing queries: " << (int)mOcclusionQueries.size() << std::endl; 
    134         LogManager::getSingleton().logMessage(d.str()); 
     130 
     131                std::stringstream d; 
     132                d << "resizing queries: " << (int)mOcclusionQueries.size() << std::endl; 
     133                LogManager::getSingleton().logMessage(d.str()); 
     134        } 
    135135         
    136136        return mOcclusionQueries[mCurrentTestIdx ++]; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r1580 r1595  
    270270        VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 
    271271        for (rit = vssRays.begin(); rit != rit_end; ++ rit) 
    272         {cout << "z"; 
     272        { 
    273273                (*rit)->mFlags |= VssRay::BorderSample; 
    274                 //(*rit)->mOriginObject = currentRay.mTerminationObject; 
    275         } 
     274        } 
     275 
    276276        // add to ray queue 
    277277        EnqueueRays(vssRays); 
     
    280280        int castRays = (int)vssRays.size(); 
    281281 
    282  
    283 #if 0 
    284282    // recursivly subdivide each edge 
    285         for (int i = 0; i < n; ++ i) 
     283        for (int i = 0; 1 && (i < n); ++ i) 
    286284        { 
    287285                castRays += SubdivideEdge( 
     
    293291                        currentRay); 
    294292        } 
    295 #endif 
    296293 
    297294        mBorderSamples += castRays; 
     
    348345{        
    349346        const long startTime = GetTime(); 
    350 //cout << "here8"<<endl; 
     347 
    351348        // generate simple rays 
    352349        SimpleRayContainer simpleRays; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1586 r1595  
    274274         
    275275        if (mBoundingBoxConverter) 
     276        { 
    276277                mBoundingBoxConverter->IdentifyObjects(mIBoundingBoxes, *mObjects); 
     278        } 
    277279 
    278280        Debug << "\nconverted bounding boxes to objects in " 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1581 r1595  
    129129        char internKdTree[100]; 
    130130        Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree); 
    131         //string internKdTree = ReplaceSuffic(filename, ".x3d", ".kd"); 
     131        //const string internKdTree = ReplaceSuffic(filename, ".x3d", ".kd"); 
    132132 
    133133        //-- initialize external ray casters 
Note: See TracChangeset for help on using the changeset viewer.