Ignore:
Timestamp:
08/25/06 18:25:09 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1284 r1286  
    260260 
    261261 
    262 void HierarchyManager::Construct2(const VssRayContainer &sampleRays, 
    263                                                                   const ObjectContainer &objects, 
    264                                                                   AxisAlignedBox3 *forcedViewSpace) 
    265 { 
    266         // rays clipped in view space and in object space 
    267         RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
    268         RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
    269  
    270  
    271         ///////////////////////////////////////////////////////////// 
    272         // view space space partition 
    273         ///////////////////////////////////////////////////////////// 
    274  
    275 #if 0 
    276         // makes no sense otherwise because only one kd cell available 
    277         // during view space partition 
    278         const bool savedCountMethod = mVspTree.mUseKdPvsForHeuristics; 
    279         const bool savedStoreMethod = mVspTree.mStoreObjectPvs; 
    280          
    281         mVspTree.mUseKdPvsForHeuristics = false; 
    282         mVspTree.mStoreObjectPvs = false; 
    283 #endif 
    284         SubdivisionCandidate *vsc =  
    285                 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 
    286          
    287         // add to queue 
    288         mTQueue.Push(vsc); 
    289  
    290         long startTime = GetTime(); 
    291         cout << "starting vsp contruction ... " << endl; 
    292  
    293         mVspTree->mVspStats.Reset(); 
    294         mVspTree->mVspStats.Start(); 
    295  
    296         int i = 0; 
    297  
    298         // all objects can be seen from everywhere 
    299         mTotalCost = (float)dynamic_cast<VspTree::VspSubdivisionCandidate *>(vsc)->mParentData.mPvs; 
    300  
    301         const bool repairQueue = false; 
    302  
    303         // process view space candidates 
    304         RunConstruction(repairQueue); 
    305  
    306         cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    307         mVspTree->mVspStats.Stop(); 
    308  
    309  
    310         ///////////////////////////////////////////////////////////// 
    311         // object space partition 
    312         ///////////////////////////////////////////////////////////// 
    313  
    314  
    315         Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 
    316         cout << "starting osp contruction ... " << endl; 
    317  
    318         // start with one big kd cell - all objects can be seen from everywhere 
    319         // note: only true for view space = object space 
    320  
    321         // compute first candidate 
    322         SubdivisionCandidate *osc = 
    323                 mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 
    324  
    325         Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
    326         mTotalCost = mOspTree->mTotalCost; 
    327  
    328     mTQueue.Push(osc); 
    329  
    330         mOspTree->mOspStats.Reset(); 
    331         mOspTree->mOspStats.Start(); 
    332  
    333         startTime = GetTime(); 
    334          
    335         // process object space candidates 
    336         RunConstruction(repairQueue); 
    337          
    338         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    339  
    340         mOspTree->mOspStats.Stop(); 
    341  
    342         ////////////////////////// 
    343         // matt: only for debugging purpose 
    344  
    345         const float rc = mOspTree->EvalRenderCost(sampleRays); 
    346  
    347         Debug << "My render cost evalulation: " << rc << endl; 
    348  
    349 #if 0 
    350         // reset parameters 
    351         mVspTree->mUseKdPvsForHeuristics = savedCountMethod; 
    352         mVspTree->mStoreObjectPvs = savedStoreMethod; 
    353 #endif 
    354 } 
    355  
    356  
    357262void HierarchyManager::Construct3(const VssRayContainer &sampleRays, 
    358263                                                                  const ObjectContainer &objects, 
     
    372277        mTQueue.Push(sc); 
    373278 
    374         cout << "starting vsp contruction ... " << endl; 
     279        cout << "starting vsp construction ... " << endl; 
    375280 
    376281        long startTime = GetTime(); 
     
    552457void HierarchyManager::ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const 
    553458{ 
    554         if (mOspTree && mOspTree->GetRoot())  
    555         {        
    556                 //-- export final object partition 
    557                 Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 
     459        switch (mObjectSpaceSubdivisonType) 
     460        { 
     461        case KD_BASED_OBJ_SUBDIV: 
     462                { 
     463                        ExportOspTreeForViz(objects); 
     464                        break; 
     465                } 
     466        case BV_BASED_OBJ_SUBDIV: 
     467                { 
     468                        ExportBvhForViz(objects); 
     469                        break; 
     470                } 
     471        default: 
     472                break; 
     473        } 
     474} 
     475 
     476 
     477void HierarchyManager::ExportBvhForViz(const ObjectContainer &objects) const 
     478{ 
     479} 
     480 
     481 
     482void HierarchyManager::ExportOspTreeForViz(const ObjectContainer &objects) const 
     483{ 
     484        //-- export final object partition 
     485        Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 
    558486                 
    559                 if (exporter) 
    560                 { 
    561                         cout << "exporting object space partition ... "; 
    562  
    563                         if (1) 
    564                         { 
    565                                 exporter->ExportGeometry(objects); 
    566                         } 
     487        if (exporter) 
     488        { 
     489                cout << "exporting object space partition ... "; 
     490 
     491                if (1) exporter->ExportGeometry(objects); 
    567492                         
    568493#if 0            
    569                         // export rays 
    570                         exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
     494                // export rays 
     495                exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
    571496#endif 
    572  
    573                         exporter->SetWireframe(); 
    574          
    575                         const int colorCode = 0; 
    576                         const int maxPvs = 0;//mOspTree.GetStatistics().maxPvs; 
    577  
    578                         exporter->ExportOspTree(*mOspTree, 0); 
    579  
    580                         delete exporter; 
    581  
    582                         cout << "finished" << endl; 
    583                 } 
    584         } 
    585 } 
    586  
    587 } 
     497                exporter->SetWireframe(); 
     498         
     499                const int colorCode = 0; 
     500                const int maxPvs = 0;//mOspTree.GetStatistics().maxPvs; 
     501 
     502                exporter->ExportOspTree(*mOspTree, 0); 
     503                delete exporter; 
     504 
     505                cout << "finished" << endl; 
     506        } 
     507} 
     508 
     509 
     510void HierarchyManager::Construct2(const VssRayContainer &sampleRays, 
     511                                                                  const ObjectContainer &objects, 
     512                                                                  AxisAlignedBox3 *forcedViewSpace) 
     513{ 
     514        // rays clipped in view space and in object space 
     515        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
     516         
     517        ///////////////////////////////////////////////////////////// 
     518        // view space space partition 
     519        ///////////////////////////////////////////////////////////// 
     520 
     521        // use objects for evaluating vsp tree construction 
     522        const int savedobjectSpaceSubdivisionType = mObjectSpaceSubdivisonType; 
     523        mObjectSpaceSubdivisonType = NO_OBJ_SUBDIV; 
     524 
     525        SubdivisionCandidate *vsc =  
     526                mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 
     527         
     528        // add to queue 
     529        mTQueue.Push(vsc); 
     530 
     531        long startTime = GetTime(); 
     532        cout << "starting vsp construction ... " << endl; 
     533 
     534        mVspTree->mVspStats.Reset(); 
     535        mVspTree->mVspStats.Start(); 
     536 
     537        int i = 0; 
     538 
     539        // all objects can be seen from everywhere 
     540        mTotalCost = (float)dynamic_cast<VspTree::VspSubdivisionCandidate *>(vsc)->mParentData.mPvs; 
     541 
     542        const bool repairQueue = false; 
     543 
     544        // process view space candidates 
     545        RunConstruction(repairQueue); 
     546 
     547        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
     548        mVspTree->mVspStats.Stop(); 
     549 
     550        // reset subdivision type 
     551        mObjectSpaceSubdivisonType = savedobjectSpaceSubdivisionType; 
     552 
     553 
     554        ///////////////////////////////////////////////////////////// 
     555        // object space partition 
     556        ///////////////////////////////////////////////////////////// 
     557         
     558         
     559        switch (mObjectSpaceSubdivisonType) 
     560        { 
     561        case KD_BASED_OBJ_SUBDIV: 
     562                { 
     563                        ConstructOspTree(sampleRays, objects, forcedViewSpace); 
     564                        break; 
     565                } 
     566        case BV_BASED_OBJ_SUBDIV: 
     567                { 
     568                        ConstructBvHierarchy(sampleRays, objects, forcedViewSpace); 
     569                        break; 
     570                } 
     571        default: 
     572                break; 
     573        } 
     574} 
     575 
     576 
     577void HierarchyManager::ConstructBvHierarchy(const VssRayContainer &sampleRays, 
     578                                                                                        const ObjectContainer &objects, 
     579                                                                                        AxisAlignedBox3 *forcedViewSpace)  
     580 
     581{ 
     582        Debug << "\n$$$$$$$$$ bv hierarchy construction $$$$$$$$$$\n" << endl; 
     583        cout << "starting bv hierarchy construction ... " << endl; 
     584 
     585        // start with one big kd cell - all objects can be seen from everywhere 
     586        // note: only true for view space = object space 
     587 
     588        ObjectContainer obj = objects; 
     589 
     590        // compute first candidate 
     591        SubdivisionCandidate *sc = 
     592                mBvHierarchy->PrepareConstruction(sampleRays, obj, forcedViewSpace); 
     593 
     594        Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
     595        mTotalCost = mOspTree->mTotalCost; 
     596 
     597    mTQueue.Push(sc); 
     598 
     599        mOspTree->mOspStats.Reset(); 
     600        mOspTree->mOspStats.Start(); 
     601 
     602        const long startTime = GetTime(); 
     603        const bool repairQueue = false; 
     604 
     605        // process object space candidates 
     606        RunConstruction(repairQueue); 
     607         
     608        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     609 
     610        mOspTree->mOspStats.Stop(); 
     611 
     612        ////////////////////////// 
     613        // matt: only for debugging purpose 
     614 
     615        const float rc = mOspTree->EvalRenderCost(sampleRays); 
     616 
     617        Debug << "My render cost evalulation: " << rc << endl; 
     618} 
     619 
     620 
     621void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 
     622                                                                                const ObjectContainer &objects, 
     623                                                                                AxisAlignedBox3 *forcedViewSpace)  
     624 
     625{ 
     626        RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
     627 
     628        Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 
     629        cout << "starting osp tree construction ... " << endl; 
     630 
     631        // start with one big kd cell - all objects can be seen from everywhere 
     632        // note: only true for view space = object space 
     633 
     634        // compute first candidate 
     635        SubdivisionCandidate *osc = 
     636                mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 
     637 
     638        Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
     639        mTotalCost = mOspTree->mTotalCost; 
     640 
     641    mTQueue.Push(osc); 
     642 
     643        mOspTree->mOspStats.Reset(); 
     644        mOspTree->mOspStats.Start(); 
     645 
     646        const long startTime = GetTime(); 
     647        const bool repairQueue = false; 
     648         
     649        // process object space candidates 
     650        RunConstruction(repairQueue); 
     651         
     652        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     653 
     654        mOspTree->mOspStats.Stop(); 
     655 
     656        ////////////////////////// 
     657        // matt: only for debugging purpose 
     658 
     659        const float rc = mOspTree->EvalRenderCost(sampleRays); 
     660 
     661        Debug << "My render cost evalulation: " << rc << endl; 
     662} 
     663 
     664} 
Note: See TracChangeset for help on using the changeset viewer.