Changeset 1623


Ignore:
Timestamp:
10/13/06 10:49:29 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis
Files:
4 edited

Legend:

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

    r1621 r1623  
    6666        } 
    6767         
     68        //------------------------------------------------------------------------- 
     69        inline static AxisAlignedBox ScaleBox(const AxisAlignedBox &box) 
     70        { 
     71                const float scale = 1.5f; 
     72        Vector3 max = box.getMaximum(); 
     73        Vector3 min = box.getMinimum(); 
     74                Vector3 size = max - min; 
     75                Vector3 newSize = size*(scale*0.5f); 
     76                Vector3 center = 0.5f * (min + max);  
     77 
     78                Vector3 min = center - newSize; 
     79                Vector3 max = center + newSize; 
     80 
     81                return AxisAlignedBox(min, max); 
     82        } 
    6883        /** find object which fits best to this bounding box 
    6984        */ 
     
    89104{ 
    90105        list<SceneNode *> sceneNodeList; 
     106        AxisAlignedBox3 enlargedBox =  
    91107        AxisAlignedBox mybox = EnlargeBox(box); 
    92108                 
     
    154170} 
    155171//----------------------------------------------------------------------- 
    156 template<typename T> 
     172/*template<typename T> 
    157173void PlatFormBoundingBoxConverter<T>::FindIntersectingObjects(const AxisAlignedBox &box, 
    158174                                                                                                                          EntityContainer &objects) const 
     
    161177                         
    162178        // get intersecting scene nodes (= candidates) 
    163         //AxisAlignedBox mybox = EnlargeBox(box); 
    164         //mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL); 
    165         mSceneMgr->findNodesIn(box, sceneNodeList, NULL); 
     179        AxisAlignedBox mybox = EnlargeBox(box); 
     180        mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL); 
     181        //mSceneMgr->findNodesIn(box, sceneNodeList, NULL); 
    166182 
    167183        list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 
    168184 
    169         //GtpVisibilityPreprocessor::AxisAlignedBox nodeBox = OgreTypeConverter::ConvertFromOgre(mybox); 
    170         GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(box); 
     185        GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(mybox); 
     186        //GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(box); 
    171187 
    172188        // find really intersecting objects 
     
    201217        } 
    202218} 
    203  
     219*/ 
     220template<typename T> 
     221void PlatFormBoundingBoxConverter<T>::FindIntersectingObjects(const AxisAlignedBox &box, 
     222                                                                                                                          EntityContainer &objects) const 
     223{//return; 
     224        list<SceneNode *> sceneNodeList; 
     225                         
     226        // get intersecting scene nodes (= candidates) 
     227        AxisAlignedBox mybox = EnlargeBox(box); 
     228        //mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL); 
     229        mSceneMgr->findNodesIn(box, sceneNodeList, NULL); 
     230 
     231        list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 
     232 
     233        //GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(mybox); 
     234        GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(box); 
     235 
     236        // find really intersecting objects 
     237        for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit) 
     238        { 
     239                SceneNode *sn = *sit; 
     240                SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator(); 
     241 
     242        while (oit.hasMoreElements()) 
     243                { 
     244                        MovableObject *mo = oit.getNext(); 
     245 
     246                        // we are only interested in scene entities 
     247                        if (mo->getMovableType() != "Entity") 
     248                        { 
     249                                continue; 
     250                        } 
     251                          
     252                        //const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox()); 
     253                        const AxisAlignedBox bbox = mo->getWorldBoundingBox(); 
     254 
     255                        const bool overlaps = Overlap(nodeBox, 
     256                                                                                  OgreTypeConverter::ConvertFromOgre(bbox) 
     257                                                                                  ); 
     258                                                                                  //,0.00001); 
     259         
     260                         if (overlaps) 
     261                         { 
     262                                 objects.push_back(static_cast<Entity *>(mo)); 
     263                         } 
     264                } 
     265        } 
     266} 
    204267#if USE_KD_PVS 
    205268//------------------------------------------------------------------------- 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp

    r1622 r1623  
    703703                        SetObjectsVisible(!mUseViewCells); 
    704704 
    705                         /*MovableObjectIterator movit = getMovableObjectIterator("Entity"); 
     705                        MovableObjectIterator movit = getMovableObjectIterator("Entity"); 
    706706                        while (movit.hasMoreElements()) 
    707707                        { 
    708708                                Entity *ent = static_cast<Entity *>(movit.getNext()); 
    709709                                ent->setVisible(!mUseViewCells); 
    710                         }*/ 
     710                        } 
    711711                } 
    712712 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1622 r1623  
    9494  , mBoundingBoxConverter(bconverter) 
    9595  , mHierarchyManager(NULL) 
     96  , nViewCells(0) 
    9697{ 
    9798        std::stable_sort(mObjects->begin(), mObjects->end(), ilt); 
     
    205206        // go one up in the tree 
    206207        if (mCurrentBspNode->GetParent()) 
    207         {       cout << "]"; 
     208        {       Debug << "]"; 
    208209                mCurrentBspNode = mCurrentBspNode->GetParent(); 
    209210        } 
     
    215216        // go one up in the tree 
    216217        if (mCurrentBvhNode->GetParent()) 
    217         {       cout << "]"; 
     218        {       Debug << "]"; 
    218219                mCurrentBvhNode = mCurrentBvhNode->GetParent(); 
    219220        } 
     
    225226        // go one up in the tree 
    226227        if (mCurrentOspNode->mParent) 
    227         {       cout << "]"; 
     228        {       Debug << "]"; 
    228229                mCurrentOspNode = mCurrentOspNode->mParent; 
    229230        } 
     
    235236        // go one up in the tree 
    236237        if (mCurrentVspNode->GetParent()) 
    237         {       cout << "]"; 
     238        {       Debug << "]"; 
    238239                mCurrentVspNode = mCurrentVspNode->GetParent(); 
    239240        } 
     
    245246        // go one up in the tree 
    246247        if (mCurrentViewCell->GetParent()) 
    247         {       cout << "]"; 
     248        {       Debug << "]"; 
    248249                mCurrentViewCell = mCurrentViewCell->GetParent(); 
    249250        } 
     
    260261{ 
    261262        // sort view cells to help associating view cells according to their id 
    262         //stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 
     263        stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 
    263264 
    264265        // not parsing view cells anymore 
     
    288289        if (element == "Interior")  
    289290        { 
    290                 cout << "["; 
     291                Debug << "["; 
    291292                StartBspInterior(attributes); 
    292293        } 
     
    294295        if (element == "Leaf")  
    295296        { 
    296                 cout << "l"; 
     297                Debug << "l"; 
    297298                StartBspLeaf(attributes); 
    298299        } 
     
    305306        if (element == "Interior")  
    306307        { 
    307                 cout << "["; 
     308                Debug << "["; 
    308309                StartVspInterior(attributes); 
    309310        } 
    310311        if (element == "Leaf")  
    311312        { 
    312                 cout << "l"; 
     313                Debug << "l"; 
    313314                StartVspLeaf(attributes); 
    314315        } 
     
    321322        if (element == "Interior")  
    322323        { 
    323                 cout << "["; 
     324                Debug << "["; 
    324325                StartOspInterior(attributes); 
    325326        } 
     
    327328        if (element == "Leaf")  
    328329        { 
    329                 cout << "l"; 
     330                Debug << "l"; 
    330331                StartOspLeaf(attributes); 
    331332        } 
     
    338339        if (element == "Interior")  
    339340        { 
    340                 cout << "["; 
     341                Debug << "["; 
    341342                StartBvhInterior(attributes); 
    342343        } 
     
    344345        if (element == "Leaf")  
    345346        { 
    346                 cout << "l"; 
     347                Debug << "l"; 
    347348                StartBvhLeaf(attributes); 
    348349        } 
     
    391392                                                                                                                   AttributeList& attributes) 
    392393{ 
     394        if (((nViewCells ++) % 1000) == 0) 
     395                Debug << "\n " << nViewCells << " view cells parsed" << endl; 
    393396        // interiors + leaves interpreted view cells else 
    394397        if (element == "Interior")  
    395398        { 
    396                 cout << "["; 
     399                Debug << "["; 
    397400                StartViewCell(attributes, false); 
    398401        } 
     
    400403        if (element == "Leaf")  
    401404        { 
    402                 cout << "l"; 
     405                Debug << "l"; 
    403406                StartViewCell(attributes, true); 
    404407        } 
     
    414417        if (element == "ViewCells") 
    415418        { 
    416                 cout << "\nparsing view cells" << endl; 
     419                Debug << "\nparsing view cells" << endl; 
    417420                 
    418421                mCurrentState = PARSE_VIEWCELLS; 
     
    425428        if (element == "ViewSpaceHierarchy") 
    426429        {                
    427                 cout << "\nparsing view space hierarchy" << endl; 
     430                Debug << "\nparsing view space hierarchy" << endl; 
    428431                mCurrentState = PARSE_VIEWSPACE_HIERARCHY; 
    429432                StartViewSpaceHierarchy(attributes); 
     
    433436        if (element == "ObjectSpaceHierarchy") 
    434437        { 
    435                 cout << "\nparsing object space hierarchy" << endl; 
     438                Debug << "\nparsing object space hierarchy" << endl; 
    436439                mCurrentState = PARSE_OBJECTSPACE_HIERARCHY; 
    437440                StartObjectSpaceHierarchy(attributes); 
     
    441444        if (element == "BoundingBox") 
    442445        { 
    443           //            cout << "b"; 
     446          //            Debug << "b"; 
    444447                StartBoundingBox(attributes); 
    445448        } 
     
    506509                else 
    507510                { 
    508                         cout << "error: object with id " << objId << " does not exist" << endl; 
     511                        Debug << "error: object with id " << objId << " does not exist" << endl; 
    509512                } 
    510513        } 
     
    529532                        if (strcmp(ptr, "bsp") == 0) 
    530533                        { 
    531                                 cout << "\nview space hierarchy: Bsp" << endl; 
     534                                Debug << "\nview space hierarchy: Bsp" << endl; 
    532535                                mViewSpaceHierarchyType = BSP; 
    533536                        } 
    534537                        else if (strcmp(ptr, "vsp") == 0) 
    535538                        { 
    536                                 cout << "\nview space hierarchy: Vsp" << endl; 
     539                                Debug << "\nview space hierarchy: Vsp" << endl; 
    537540                                mViewSpaceHierarchyType = VSP; 
    538541                        } 
     
    573576                        if (strcmp(ptr, "osp") == 0) 
    574577                        { 
    575                                 cout << "\nobject space hierarchy: Osp" << endl; 
     578                                Debug << "\nobject space hierarchy: Osp" << endl; 
    576579 
    577580                                mHierarchyManager =  
     
    597600                        else if (strcmp(ptr, "bvh") == 0) 
    598601                        { 
    599                                 cout << "\nobject space hierarchy: Bvh" << endl; 
     602                                Debug << "\nobject space hierarchy: Bvh" << endl; 
    600603                                mObjectSpaceHierarchyType = BVH; 
    601604                                mHierarchyManager =  
     
    639642        AxisAlignedBox3 box(bmin, bmax); 
    640643        mIBoundingBoxes.push_back(IndexedBoundingBox(id, box)); 
    641         //cout << "bbox: " << box << endl; 
     644        //Debug << "bbox: " << box << endl; 
    642645} 
    643646 
     
    683686        { 
    684687                // TODO: get view cell with specified id 
    685                 ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 
    686                 BspViewCell *viewCell = dynamic_cast<BspViewCell *>((*vit).second); 
    687          
     688                ViewCellInterior dummyVc; 
     689                dummyVc.SetId(viewCellId); 
     690 
     691                ViewCellContainer::iterator vit = 
     692                        lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 
     693                 
     694                //ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 
     695//              BspViewCell *viewCell = dynamic_cast<BspViewCell *>((*vit).second); 
     696                BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit); 
    688697                if (viewCell->GetId() == viewCellId) 
    689698                { 
     
    694703                else 
    695704                { 
    696                         cout << "error: view cell does not exist" << endl; 
     705                        Debug << "error: view cell does not exist" << endl; 
    697706                } 
    698707        } 
     
    744753 
    745754ViewCell *ViewCellsParseHandlers::GetOrCreateViewCell(const int id, const bool isLeaf) 
    746 { 
     755{/* 
    747756        ViewCellsMap::iterator vit = mViewCells.find(id); 
    748757 
     
    766775                mViewCells[id] = vc; 
    767776                return vc; 
    768         } 
     777        }*/ 
     778        return NULL; 
    769779} 
    770780 
     
    776786        const int len = attributes.getLength(); 
    777787        float mergeCost; 
    778         ObjectPvs pvs; 
     788        //ObjectPvs pvs; 
     789 
     790        //viewCell = GetOrCreateViewCell(id, isLeaf); 
     791         
     792                if (isLeaf) 
     793                { 
     794                        viewCell = new ViewCellLeaf(); 
     795                } 
     796                else 
     797                { 
     798                        viewCell = new ViewCellInterior(); 
     799                } 
    779800 
    780801        for (int i = 0; i < len; ++ i)  
     
    790811 
    791812                        // create new view cell, otherwise use reference. 
    792                         viewCell = GetOrCreateViewCell(id, isLeaf); 
    793                          
     813                        //viewCell = GetOrCreateViewCell(id, isLeaf); 
     814                        viewCell->SetId(id); 
     815 
    794816                        if (mCurrentViewCell) // replace front or (if not NULL) back child 
    795817                        {        
     
    815837                        // note: id must come before pvs!  
    816838                        // otherwise view cell is undefined 
    817                         StartViewCellPvs(pvs, ptr); 
     839 
     840                        StartViewCellPvs(viewCell->GetPvs(), ptr); // assume that view cell comes before pvs 
     841                        //StartViewCellPvs(pvs, ptr); 
    818842                } 
    819843                else if (attrName == "active") 
     
    840864 
    841865        viewCell->SetMergeCost(mergeCost); 
    842         viewCell->SetPvs(pvs); 
     866        //viewCell->SetPvs(pvs); 
     867        mViewCells.push_back(viewCell); 
    843868} 
    844869 
     
    848873        if (mViewSpaceHierarchyType == BSP) 
    849874        { 
    850                 cout << "hierarchy type: Bsp" << endl; 
     875                Debug << "hierarchy type: Bsp" << endl; 
    851876                mVspBspTree = new VspBspTree(); 
    852877 
     
    854879                mVspBspTree->mBoundingBox = mViewSpaceBox; 
    855880 
    856                 ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 
    857  
     881                //ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 
     882                ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 
     883 
     884                Debug << "exchanging boxes" << endl; 
     885int i = 0; 
    858886                // remove view cells and exchange them with the  
    859887                // view cells specialized for the current hierarchy node type 
    860                 for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
    861                 { 
    862                         ViewCell *vc = (*vit).second; 
     888                for (vit = mViewCells.begin(); vit != vit_end; ++ vit, ++ i) 
     889                { 
     890                        if ((i % 1000) == 0) 
     891                                Debug << "\n exchanged " << i << " boxes" << endl; 
     892                        ViewCell *vc = (*vit); 
    863893 
    864894                        if (!vc->IsLeaf()) // exchange only leaves 
     
    868898 
    869899                        bspVc->SetId(vc->GetId()); 
     900                        //bspVc->GetPvs().reserve(vc->GetPvs().size()); 
    870901                        bspVc->SetPvs(vc->GetPvs()); 
    871902 
     
    880911 
    881912                        DEL_PTR(vc); 
    882                         (*vit).second = bspVc; 
    883                 } 
     913//                      (*vit).second = bspVc; 
     914                        (*vit) = bspVc; 
     915                } 
     916                Debug << "finished" << endl; 
    884917        } 
    885918        else if (mViewSpaceHierarchyType == VSP)  
    886919        { 
    887                 cout << "hierarchy type: Vsp" << endl; 
     920                Debug << "hierarchy type: Vsp" << endl; 
    888921                mVspTree = new VspTree(); 
    889922 
     
    891924                mVspTree->mBoundingBox = mViewSpaceBox; 
    892925 
    893                 ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 
    894  
     926//              ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 
     927ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 
    895928                // reset view cells using the current node type 
    896929                for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
    897930                { 
    898                         ViewCell *vc = (*vit).second; 
    899  
     931                        //ViewCell *vc = (*vit).second; 
     932        ViewCell *vc = (*vit); 
    900933                        VspViewCell *vspVc = new VspViewCell(); 
    901934                        vspVc->SetPvs(vc->GetPvs()); 
     
    914947                        } 
    915948                         
    916                         DEL_PTR(vc); 
    917                         (*vit).second = vspVc; 
     949                        //DEL_PTR(vc); 
     950                        //(*vit).second = vspVc; 
     951                        (*vit) = vspVc; 
    918952                } 
    919953 
     
    10071041        { 
    10081042                // TODO: get view cell with specified id 
    1009                 /*ViewCellInterior dummyVc; 
     1043                ViewCellInterior dummyVc; 
    10101044                dummyVc.SetId(viewCellId); 
    10111045 
    10121046                ViewCellContainer::iterator vit = 
    10131047                        lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 
    1014                 */ 
    1015                 ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 
     1048                 
     1049                //ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 
    10161050                if (vit == mViewCells.end()) 
    1017                         cout << "error: view cell " << viewCellId << " not found" << endl; 
     1051                        Debug << "error: view cell " << viewCellId << " not found" << endl; 
    10181052         
    1019                 VspViewCell *viewCell = dynamic_cast<VspViewCell *>((*vit).second); 
     1053                //VspViewCell *viewCell = dynamic_cast<VspViewCell *>((*vit).second); 
     1054                VspViewCell *viewCell = dynamic_cast<VspViewCell *>(*vit); 
    10201055                 
    10211056                if (viewCell->GetId() == viewCellId) 
     
    10261061                else 
    10271062                { 
    1028                         cout << "error: view cell does not exist" << endl; 
     1063                        Debug << "error: view cell does not exist" << endl; 
    10291064                } 
    10301065        } 
     
    12371272                else 
    12381273                { 
    1239                         cout << "error: object with id " << objId << " does not exist" << endl; 
     1274                        Debug << "error: object with id " << objId << " does not exist" << endl; 
    12401275                } 
    12411276        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h

    r1551 r1623  
    9595  ViewCell *mViewCellRoot; 
    9696 
    97   typedef map<int, ViewCell *> ViewCellsMap; 
    98   ViewCellsMap mViewCells; 
     97 // typedef map<int, ViewCell *> ViewCellsMap; 
     98  //ViewCellsMap mViewCells; 
     99ViewCellContainer mViewCells; 
    99100 
    100101  ViewCellsManager *mViewCellsManager; 
     
    118119  int mViewSpaceHierarchyType; 
    119120  int mObjectSpaceHierarchyType; 
    120  
     121int nViewCells; 
    121122  //////////////////////////////// 
    122123 
Note: See TracChangeset for help on using the changeset viewer.