Ignore:
Timestamp:
02/12/07 19:00:37 (17 years ago)
Author:
mattausch
Message:

changed pvs loading: loading objects in a first pass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r2114 r2115  
    103103  , nObjects(0) 
    104104{ 
    105         // pvs objects empty => have to create new ones 
    106         mCreatePvsObjects = mPvsObjects.empty(); 
    107  
     105        // q: can we assume that the objects are sorted? 
     106         
    108107        // sort objects so we can search in them 
    109108        //if (!is_sorted(mPvsObjects.begin(), mPvsObjects.end(), ilt)) 
     
    111110 
    112111        //if (!is_sorted(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt)) 
    113                 sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt); 
     112        //      sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt); 
    114113} 
    115114 
     
    407406 
    408407 
    409 void ViewCellsParseHandlers::ReplaceBvhPvs(ViewCell *vc) 
    410 { 
    411         //cout << "exchanging pvs" << endl; 
    412         ObjectPvs newPvs; 
    413  
    414         ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 
    415  
    416         BvhLeaf *dummyInst = new BvhLeaf(AxisAlignedBox3()); 
    417  
    418         ObjectContainer oldIntersectables; 
    419  
    420         // output PVS of view cell 
    421         while (pit.HasMoreEntries()) 
    422         {                
    423                 ObjectPvsEntry entry = pit.Next(); 
    424  
    425                 Intersectable *intersect = entry.mObject; 
    426                 oldIntersectables.push_back(intersect); 
    427  
    428                 DummyIntersectable *dummyIntersect = static_cast<DummyIntersectable *>(intersect); 
    429  
    430                 const int objId = dummyIntersect->GetItem();     
    431                 dummyInst->SetId(objId); 
    432  
    433                 vector<BvhLeaf *>::iterator oit = 
    434                         lower_bound(mBvhLeaves.begin(),  
    435                                                 mBvhLeaves.end(),  
    436                                                 dummyInst, ilt);         
    437  
    438                 if ((oit != mBvhLeaves.end()) && ((*oit)->GetId() == objId)) 
    439                 { 
    440                         // $$JB we should store a float a per object which corresponds 
    441                         // to sumof pdfs, i.e. its relative visibility 
    442                         // temporarily set to 1.0f 
    443                         //cout << (*oit)->GetId() << " "; 
    444                          
    445                         newPvs.AddSample(*oit, 1.0f); 
    446                 } 
    447                 else 
    448                 { 
    449                         Debug << "exchangePvs error: object with id " << objId << " does not exist" << endl; 
    450                 } 
    451         } 
    452  
    453         //newPvs.SimpleSort(); 
    454         delete dummyInst; 
    455         vc->SetPvs(newPvs); 
    456  
    457         CLEAR_CONTAINER(oldIntersectables); 
    458 } 
    459  
    460  
    461 void ViewCellsParseHandlers::ReplacePvs() 
    462 { 
    463         // sort the pvs entries 
    464         sort(mPvsObjects.begin(), mPvsObjects.end(), ilt); 
    465  
    466         ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 
    467          
    468         //cout << "viewcells : " << mViewCells.size() << endl; 
    469         for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
    470         { 
    471                 ReplaceBvhPvs(*vit); 
    472         } 
    473 } 
    474  
    475  
    476408void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element, 
    477409                                                                                                                   AttributeList& attributes) 
     
    513445        {                
    514446                Debug << "\nparsing view space hierarchy" << endl; 
    515                 cout << "\nparsing view space hierarchy" << endl; 
     447                cout  << "\nparsing view space hierarchy" << endl; 
     448 
    516449                mCurrentState = PARSE_VIEWSPACE_HIERARCHY; 
    517450                StartViewSpaceHierarchy(attributes); 
     
    521454        if (element == "ObjectSpaceHierarchy") 
    522455        { 
    523                 cout << "\nparsing object space hierarchy" << endl; 
     456                cout  << "\nparsing object space hierarchy" << endl; 
    524457                Debug << "\nparsing object space hierarchy" << endl; 
    525458 
     
    540473        case PARSE_VIEWSPACE_HIERARCHY: 
    541474                if ((++ nViewCells % 1000) == 0) 
    542                         cout<<"\r"<<nViewCells<<" view cells parsed\r"; 
     475                        cout << "\r" << nViewCells << " view cells parsed\r"; 
    543476                 
    544477                StartViewSpaceHierarchyElement(element, attributes); 
     
    546479        case PARSE_OBJECTSPACE_HIERARCHY: 
    547480                if ((++ nObjects % 1000) == 0) 
    548                  cout<<"\r"<< nObjects <<" objects parsed\r"; 
     481                        cout <<"\r" << nObjects << " objects parsed\r"; 
    549482                 
    550483                StartObjectSpaceHierarchyElement(element, attributes); 
     
    577510        } 
    578511 
     512#if 1 
    579513        // TODO:  
    580514        // 1) find objects and add them to pvs 
     
    583517 
    584518        vector<int>::const_iterator it, it_end = objIndices.end(); 
     519         
     520        pair<ObjectContainer::const_iterator, ObjectContainer::const_iterator> result; 
     521 
    585522        for (it = objIndices.begin(); it != it_end; ++ it) 
    586523        { 
    587                 if (mCreatePvsObjects) 
    588                 { 
    589                         // pvs entries will be created => just use dummy proxy 
    590                         pvs.AddSample(new DummyIntersectable(*it), 1); 
     524                const int objId = *it;   
     525                dummyInst.SetId(objId); 
     526 
     527                // equal indeces possible! 
     528                result = equal_range(mPvsObjects.begin(),  
     529                                                         mPvsObjects.end(),  
     530                                                         (Intersectable *)&dummyInst,  
     531                                                         ilt);   
     532 
     533                ObjectContainer::const_iterator eit = result.first; 
     534 
     535                for (; eit != result.second; ++ eit) 
     536                { 
     537                        pvs.AddSample(*eit, 1.0f); 
     538                } 
     539        } 
     540 
     541#else 
     542 
     543        // TODO:  
     544        // 1) find objects and add them to pvs 
     545        // 2) get view cell with specified id 
     546        MeshInstance dummyInst(NULL); 
     547 
     548        vector<int>::const_iterator it, it_end = objIndices.end(); 
     549        for (it = objIndices.begin(); it != it_end; ++ it) 
     550        { 
     551                const int objId = *it;   
     552                dummyInst.SetId(objId); 
     553 
     554                ObjectContainer::iterator oit =  
     555                                                        lower_bound(mPvsObjects.begin(),  
     556                                                                                mPvsObjects.end(),  
     557                                                                                (Intersectable *)&dummyInst, ilt);       
     558 
     559                if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId)) 
     560                { 
     561                        // $$JB we should store a float a per object which corresponds 
     562                        // to sumof pdfs, i.e. its relative visibility 
     563                        // temporarily set to 1.0f 
     564                        pvs.AddSample(*oit, 1.0f); 
    591565                } 
    592566                else 
    593567                { 
    594                         const int objId = *it;   
    595                         dummyInst.SetId(objId); 
    596  
    597                         ObjectContainer::iterator oit =  
    598                                                                 lower_bound(mPvsObjects.begin(),  
    599                                                                                         mPvsObjects.end(),  
    600                                                                                         (Intersectable *)&dummyInst, ilt);       
    601  
    602                         if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId)) 
    603                         { 
    604                                 // $$JB we should store a float a per object which corresponds 
    605                                 // to sumof pdfs, i.e. its relative visibility 
    606                                 // temporarily set to 1.0f 
    607                                 pvs.AddSample(*oit, 1.0f); 
    608                         } 
    609                         else 
    610                         { 
    611                                 //Debug << "x"; 
    612                                 //Debug << "StartViewCellPvs error: object with id " << objId << " does not exist" << endl; 
    613                         } 
    614                 } 
    615         } 
     568                        Debug << "x"; 
     569                        //Debug << "StartViewCellPvs error: object with id " << objId << " does not exist" << endl; 
     570                } 
     571        } 
     572#endif 
    616573} 
    617574 
     
    12871244                if (attrName == "objects") 
    12881245                { 
    1289                         StartBvhLeafObjects(objects, ptr); 
     1246                        if (!mPreprocessorObjects.empty()) 
     1247                                StartBvhLeafObjects(objects, ptr); 
    12901248                } 
    12911249        } 
     
    12981256        { 
    12991257                BvhInterior *interior = static_cast<BvhInterior *>(mCurrentBvhNode); 
     1258 
    13001259                leaf = new BvhLeaf(box, interior, (int)objects.size()); 
    13011260                interior->ReplaceChildLink(NULL, leaf); 
     
    13091268        leaf->mObjects = objects; 
    13101269        BvHierarchy::AssociateObjectsWithLeaf(leaf); 
    1311          
    1312         if (mCreatePvsObjects) 
    1313         { 
    1314                 // Temp matt: leaves should already have right id 
    1315                 if (0) leaf->SetId((int)mBvhLeaves.size()); 
    1316                  
    1317                 mPvsObjects.push_back(leaf);     
    1318         } 
    13191270} 
    13201271 
     
    13361287 
    13371288        MeshInstance dummyInst(NULL); 
    1338  
    13391289        vector<int>::const_iterator it, it_end = objIndices.end(); 
    13401290 
     
    13441294                dummyInst.SetId(objId); 
    13451295 
    1346                 ObjectContainer::iterator oit = 
    1347                         lower_bound(mPvsObjects.begin(),  
    1348                                                 mPvsObjects.end(),  
     1296                ObjectContainer::const_iterator oit = 
     1297                        lower_bound(mPreprocessorObjects.begin(),  
     1298                                                mPreprocessorObjects.end(),  
    13491299                                                (Intersectable *)&dummyInst,  
    13501300                                                ilt);    
    13511301                                                         
    1352                 if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId)) 
     1302                if ((oit != mPreprocessorObjects.end()) && ((*oit)->GetId() == objId)) 
    13531303                { 
    13541304                        objects.push_back(*oit); 
Note: See TracChangeset for help on using the changeset viewer.