Changeset 1143


Ignore:
Timestamp:
07/19/06 18:31:33 (18 years ago)
Author:
mattausch
Message:

worked on vsp osp tree

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
10 edited

Legend:

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

    r1142 r1143  
    14461446        RegisterOption("ViewCells.PostProcess.avgCostMaxDeviation", 
    14471447                        optFloat, 
    1448                         "vsp_bsp_avgcost_max_deviations", 
     1448                        "view_cells_avgcost_max_deviations", 
    14491449                        "0.5"); 
    14501450 
     
    22172217                                        "true"); 
    22182218         
     2219 
     2220 
    22192221/***************************************************************************/ 
    22202222/*               Object space partition tree related options               */ 
    22212223/***************************************************************************/ 
     2224 
    22222225 
    22232226        RegisterOption("OspTree.Construction.randomize", 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1135 r1143  
    3434 
    3535  /// # of object references 
    36   int mObjectRefs; 
     36  int mReferences; 
    3737 
    3838  enum { MESH_INSTANCE,  
     
    4444                }; 
    4545   
    46   Intersectable():mMailbox(0), mObjectRefs(0) {} 
     46  Intersectable():mMailbox(0), mReferences(0) {} 
    4747 
    4848        void SetId(const int id) { mId = id; } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1122 r1143  
    295295    // determine the side of this ray with respect to the plane 
    296296    AxisAlignedBox3 box = (*mi)->GetBox(); 
    297  
    298     if (box.Max(axis) >= position ) 
     297                 
     298        // for handling multiple objects: keep track of references 
     299        if (leaf->IsRoot())  
     300                (*mi)->mReferences = 1; // initialise references at root 
     301         
     302        -- (*mi)->mReferences; // remove parent ref 
     303 
     304 
     305        if (box.Max(axis) >= position ) 
     306        { 
    299307      front->mObjects.push_back(*mi); 
    300      
     308          ++ (*mi)->mReferences; 
     309        } 
     310         
    301311    if (box.Min(axis) < position ) 
     312        { 
    302313      back->mObjects.push_back(*mi); 
    303      
     314          ++ (*mi)->mReferences; 
     315        } 
     316 
     317        // store objects referenced in more than one leaf 
     318        // for easy access 
     319        ProcessMultipleRefs(back); 
     320        ProcessMultipleRefs(front); 
     321 
    304322    mStat.objectRefs -= (int)leaf->mObjects.size(); 
    305323    mStat.objectRefs += objectsBack + objectsFront; 
     
    308326  delete leaf; 
    309327  return node; 
     328} 
     329 
     330 
     331void KdTree::ProcessMultipleRefs(KdLeaf *leaf) const 
     332{ 
     333        // find objects from multiple kd-leaves 
     334        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     335 
     336        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     337        { 
     338                Intersectable *object = *oit; 
     339                 
     340                if (object->mReferences > 1) 
     341                { 
     342                        leaf->mMultipleObjects.push_back(object); 
     343                } 
     344        } 
    310345} 
    311346 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1122 r1143  
    540540              ); 
    541541 
     542        /** does some post processing on the objects in the new child leaves. 
     543        */ 
     544        void ProcessMultipleRefs(KdLeaf *leaf) const; 
    542545 
    543546  int mTermMaxNodes; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1135 r1143  
    440440        { 
    441441                mVspTree = new VspTree(); 
    442                 mOspTree = new OspTree(); 
     442                //mOspTree = new OspTree(); 
     443                // HACK 
     444                mOspTree = new OspTree(*mKdTree); 
    443445 
    444446                mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree); 
     
    446448        else if (strcmp(name, "sceneDependent") == 0) 
    447449        { 
     450                Debug << "view cell type: Bsp" << endl; 
     451 
    448452                //TODO 
    449453                mBspTree = new BspTree(); 
    450  
    451                 Debug << "view cell type: Bsp" << endl; 
    452                  
    453454                mViewCellsManager = new BspViewCellsManager(mBspTree); 
    454455        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r1141 r1143  
    3030                Intersectable *obj = (*it).first; 
    3131 
     32                // found kd node 
     33                // the pvs is the sum of the objects in the leaves in the subtree 
     34                // We eliminate already accounted kd nodes and objects 
     35                // using mailboxing.  
    3236                if (obj->Type() == Intersectable::KD_INTERSECTABLE) 
    3337                { 
     
    5155                                if (node->IsLeaf()) 
    5256                                { 
    53                                          
    5457                                        KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 
    5558 
    5659                                        pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
    5760 
    58                                         ObjectContainer::const_iterator it, it_end = leaf->mMultipleObjects.end(); 
     61                                        // Objects already accounted for can only be found among those 
     62                                        // which are referenced in more than one leaf 
     63                                        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     64                                        for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
    5965                                        { 
    60                                                 Intersectable *object = *it;                                             
     66                                                Intersectable *object = *oit;                                            
    6167                                                 
    6268                                                if (!object->Mailed()) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1142 r1143  
    22172217 
    22182218 
    2219  
    2220  
    22212219void 
    22222220ViewCellsManager::ApplyFilter(ViewCell *viewCell, 
     
    42574255                        } 
    42584256 
    4259                         const int maxDepth = mVspBspTree->mBspStats.maxDepth; 
     4257                        const int maxDepth = mVspBspTree->GetStatistics().maxDepth; 
    42604258 
    42614259                        ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 
     
    49044902        long startTime; 
    49054903 
    4906         //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 
    4907         //mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); 
    4908         mHierarchyManager->Construct3(constructionRays, objects, &mViewSpaceBox); 
    4909  
    4910         //-- stats 
     4904        if (!mOspTree->GetRoot()) 
     4905        { 
     4906                cout << "constructing vsp and osp tree" << endl; 
     4907                //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 
     4908                mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); 
     4909        } 
     4910        else // just build view space partition tree 
     4911        { 
     4912                cout << "constructing only vsp tree" << endl; 
     4913                mHierarchyManager->Construct3(constructionRays, objects, &mViewSpaceBox); 
     4914        } 
     4915 
     4916        // print subdivision statistics 
    49114917        Debug << mVspTree->GetStatistics() << endl; 
    49124918 
     4919        // print view cell statistics 
    49134920        ResetViewCells(); 
    49144921        Debug << "\nView cells after construction:\n" << mCurrentViewCellsStats << endl; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1022 r1143  
    640640                mOspTree = new OspTree(); 
    641641 
    642                 //mCurrentBspNode = mVspBspTree->GetRoot(); 
     642                // hack 
    643643                mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree); 
    644644 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1142 r1143  
    401401 
    402402        if (!mUseKdPvsForHeuristics) 
    403                 Debug << "pvs count method: per object" << endl; 
     403                Debug << "pvs heuristics: per object" << endl; 
    404404        else 
    405                 Debug << "pvs count method: per kd node" << endl; 
     405                Debug << "pvs heuristics: per kd node" << endl; 
    406406 
    407407        mSplitCandidates = new vector<SortableEntry>; 
     
    443443 
    444444 
    445 void VspTree::ComputeBoundingBox(const RayInfoContainer &rays, 
     445void VspTree::ComputeBoundingBox(const VssRayContainer &rays, 
    446446                                                                 AxisAlignedBox3 *forcedBoundingBox)  
    447447{        
     
    454454                mBoundingBox.Initialize(); 
    455455 
    456                 RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     456                VssRayContainer::const_iterator rit, rit_end = rays.end(); 
    457457 
    458458                //-- compute bounding box 
    459459        for (rit = rays.begin(); rit != rit_end; ++ rit) 
    460460                { 
    461                         VssRay *ray = (*rit).mRay; 
     461                        VssRay *ray = *rit; 
    462462 
    463463                        // compute bounding box of view space 
     
    499499bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const 
    500500{ 
    501         return( 
     501        const bool localTerminationCriteriaMet = ( 
    502502                ((int)data.mRays->size() <= mTermMinRays) || 
    503503                (data.mPvs <= mTermMinPvs)   || 
     
    506506                (data.mDepth >= mTermMaxDepth) 
    507507                ); 
     508 
     509        if (0 && localTerminationCriteriaMet) 
     510        { 
     511                Debug << "********local termination *********" << endl; 
     512                Debug << "rays: " << (int)data.mRays->size() << "  " << mTermMinRays << endl; 
     513                Debug << "pvs: " << data.mPvs << " " << mTermMinPvs << endl; 
     514                Debug << "p: " <<  data.mProbability << " " << mTermMinProbability << endl; 
     515                Debug << "avg contri: " << data.GetAvgRayContribution() << " " << mTermMaxRayContribution << endl; 
     516                Debug << "depth " << data.mDepth << " " << mTermMaxDepth << endl; 
     517        } 
     518 
     519        return localTerminationCriteriaMet; 
    508520                 
    509521} 
     
    512524bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const 
    513525{ 
    514         Debug << "cost misses " << mGlobalCostMisses << " " << mTermGlobalCostMissTolerance << endl; 
    515         Debug << "leaves " << mVspStats.Leaves() << " " <<  mMaxViewCells << endl; 
    516  
    517         return ( 
    518 //              mOutOfMemory ||  
     526        const bool terminationCriteriaMet = ( 
     527                // mOutOfMemory ||  
    519528                (mVspStats.Leaves() >= mMaxViewCells) ||  
    520529        (mGlobalCostMisses >= mTermGlobalCostMissTolerance)  
    521                 );               
     530                ); 
     531 
     532        if (0 && terminationCriteriaMet) 
     533        { 
     534                Debug << "********* terminationCriteriaMet *********" << endl; 
     535                Debug << "cost misses: " << mGlobalCostMisses << " " << mTermGlobalCostMissTolerance << endl; 
     536                Debug << "leaves: " << mVspStats.Leaves() << " " <<  mMaxViewCells << endl; 
     537        } 
     538        return terminationCriteriaMet; 
    522539} 
    523540 
     
    559576        } 
    560577                 
     578        // 
    561579        viewCell->mLeaf = leaf; 
    562580 
    563581        viewCell->SetVolume(tData.mProbability); 
    564582    leaf->mProbability = tData.mProbability; 
    565  
    566         mVspStats.contributingSamples += conSamp; 
    567         mVspStats.sampleContributions += (int)sampCon; 
    568  
    569         // finally evaluate statistics for this leaf 
    570         EvaluateLeafStats(tData); 
    571583} 
    572584 
     
    632644                 
    633645                // delete old view cell 
    634                 delete tData.mNode->GetViewCell(); 
     646                delete tData.mNode->mViewCell; 
    635647                // delete old leaf node 
    636648                DEL_PTR(tData.mNode); 
    637649        } 
    638650 
    639         // subdivision terminated 
    640         if (newNode->IsLeaf()) 
    641         { 
    642                 //-- create new view cell 
    643                 //CreateViewCell(tData); 
    644          
     651        if (newNode->IsLeaf()) // subdivision terminated 
     652        { 
     653                //CreateViewCell(tData); // create new view cell 
     654 
     655                VspLeaf *leaf = dynamic_cast<VspLeaf *>(newNode); 
     656                ViewCell *viewCell = leaf->GetViewCell(); 
     657 
     658                int conSamp = 0; 
     659                float sampCon = 0.0f; 
     660 
     661 
     662                //-- store pvs optained from rays 
     663                AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 
     664 
     665                // update scalar pvs size value 
     666                mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs()); 
     667 
     668                mVspStats.contributingSamples += conSamp; 
     669                mVspStats.sampleContributions += (int)sampCon; 
     670 
    645671                //-- store additional info 
    646672                if (mStoreRays) 
     
    771797 
    772798        // explicitely create front and back view cell 
    773         CreateViewCell(frontData, true); 
    774         CreateViewCell(backData, true); 
     799        CreateViewCell(frontData, false); 
     800        CreateViewCell(backData, false); 
    775801 
    776802         
     
    907933   
    908934        ViewCellLeaf *vc = leaf->GetViewCell(); 
    909    
    910          
     935  
    911936        // add contributions from samples to the PVS 
    912937        for (it = rays.begin(); it != it_end; ++ it) 
     
    922947                if (obj)  
    923948                { 
    924                         Intersectable *entry; 
    925  
    926949                        // potentially visible kd cells 
    927950                        if (mStoreKdPvs) 
     
    945968                if (obj)  
    946969                { 
    947                         Intersectable *entry; 
    948  
    949970                        // potentially visible kd cells 
    950971                        if (mUseKdPvsForHeuristics) 
     
    26842705OspTree::OspTree(): 
    26852706mRoot(NULL), 
    2686 mTimeStamp(1) 
     2707mTimeStamp(1), 
     2708mCopyFromKdTree(false) 
     2709{ 
     2710        ReadEnvironment(); 
     2711 
     2712        mSplitCandidates = new vector<SortableEntry>; 
     2713} 
     2714 
     2715 
     2716OspTree::OspTree(const KdTree &kdTree) 
     2717{ 
     2718        ReadEnvironment(); 
     2719 
     2720        // copy values from kd tree 
     2721        mCopyFromKdTree = true; 
     2722        mBoundingBox = kdTree.GetBox(); 
     2723        mRoot = kdTree.GetRoot(); 
     2724} 
     2725 
     2726 
     2727OspTree::~OspTree() 
     2728{ 
     2729        KdIntersectableMap::iterator it, it_end = mKdIntersectables.end(); 
     2730 
     2731        for (it = mKdIntersectables.begin(); it != mKdIntersectables.end(); ++ it) 
     2732        { 
     2733                DEL_PTR((*it).second); 
     2734        } 
     2735 
     2736        // if not using kd tree root 
     2737        if (!mCopyFromKdTree) 
     2738                DEL_PTR(mRoot); 
     2739} 
     2740 
     2741 
     2742void OspTree::ReadEnvironment() 
    26872743{ 
    26882744        bool randomize = false; 
     
    27482804        Debug << "split borders: " << mSplitBorder << endl; 
    27492805        Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl; 
    2750  
    2751  
    2752         mSplitCandidates = new vector<SortableEntry>; 
    2753  
    27542806        Debug << endl; 
    27552807} 
    27562808 
    27572809 
    2758 OspTree::~OspTree() 
    2759 { 
    2760         KdIntersectableMap::iterator it, it_end = mKdIntersectables.end(); 
    2761  
    2762         for (it = mKdIntersectables.begin(); it != mKdIntersectables.end(); ++ it) 
    2763         { 
    2764                 DEL_PTR((*it).second); 
    2765         } 
    2766 } 
    2767  
    2768  
    2769 void OspTree::SplitObjects(const AxisAlignedPlane & splitPlane, 
     2810void OspTree::SplitObjects(KdLeaf *parent, 
     2811                                                   const AxisAlignedPlane& splitPlane, 
    27702812                                                   const ObjectContainer &objects, 
    27712813                                                   ObjectContainer &front, 
     
    27772819        { 
    27782820                Intersectable *object = *oit; 
     2821                 
     2822                // initialise 
     2823                if (parent->IsRoot()) 
     2824                        object->mReferences = 1; 
     2825 
     2826                // remove parent ref 
     2827                -- object->mReferences; 
    27792828 
    27802829                // determine the side of this ray with respect to the plane 
     
    27842833                { 
    27852834            front.push_back(object); 
    2786                         ++ object->mObjectRefs; 
     2835                        ++ object->mReferences; 
    27872836                } 
    27882837 
     
    27902839                { 
    27912840                        back.push_back(object); 
    2792                         ++ object->mObjectRefs; 
    2793                 } 
    2794  
    2795                 // remove parent reference 
    2796                 -- object->mObjectRefs; 
     2841                        ++ object->mReferences; 
     2842                } 
    27972843        } 
    27982844 
     
    28902936        node->SetupChildLinks(back, front); 
    28912937 
    2892         SplitObjects(splitPlane, leaf->mObjects, front->mObjects, back->mObjects); 
    2893         //ProcessLeafObjects(leaf, front, back); 
    2894      
     2938        SplitObjects(leaf, splitPlane, leaf->mObjects, front->mObjects, back->mObjects); 
     2939 
     2940        ProcessMultipleRefs(front); 
     2941    ProcessMultipleRefs(back); 
     2942 
    28952943        backData.mNode = back; 
    28962944        frontData.mNode = front; 
     
    36043652 
    36053653 
    3606 #if DEPRECATED 
    3607 void OspTree::ProcessLeafObjects(KdLeaf *parent, KdLeaf *front, KdLeaf *back) const 
    3608 { 
    3609         if (parent) 
    3610         { 
    3611                 // remove the parents from the set 
    3612                 ObjectContainer::const_iterator oit, oit_end = parent->mObjects.end(); 
    3613  
    3614                 for (oit = parent->mObjects.begin(); oit != oit_end; ++ oit) 
    3615                 { 
    3616                         Intersectable *object = *oit; 
    3617  
    3618                         set<KdLeaf *>::iterator kdit = object->mKdLeaves.find(parent); 
    3619  
    3620                         // remove parent leaf 
    3621                         if (kdit != object->mKdLeaves.end()) 
    3622                                 object->mKdLeaves.erase(kdit); 
    3623                 } 
    3624         } 
    3625  
    3626         //Intersectable::NewMail(); 
    3627  
    3628         if (front) 
    3629         { 
    3630                 // Add front to leaf kd cells 
    3631                 ObjectContainer::const_iterator oit, oit_end = front->mObjects.end(); 
    3632  
    3633                 for (oit = front->mObjects.begin(); oit != oit_end; ++ oit) 
    3634                 { 
    3635                         Intersectable *object = *oit; 
    3636                         object->mKdLeaves.insert(front); 
    3637                 } 
    3638         } 
    3639  
    3640         if (back) 
    3641         { 
    3642                 // Add back to leaf kd cells 
    3643                 ObjectContainer::const_iterator oit, oit_end = back->mObjects.end(); 
    3644  
    3645                 for (oit = back->mObjects.begin(); oit != oit_end; ++ oit) 
    3646                 { 
    3647                         Intersectable *object = *oit; 
    3648                         object->mKdLeaves.insert(back);  
    3649                 } 
    3650         } 
    3651  
    3652         // note: can find out about multiple objects only now after adding and deleting 
    3653         // finished  
    3654         if (front) 
    3655         { 
    3656                 // find objects from multiple kd-leaves 
    3657                 ObjectContainer::const_iterator oit, oit_end = front->mObjects.end(); 
    3658  
    3659                 for (oit = front->mObjects.begin(); oit != oit_end; ++ oit) 
    3660                 { 
    3661                         Intersectable *object = *oit; 
    3662  
    3663                         if (object->mKdLeaves.size() > 1) 
    3664                                 front->mMultipleObjects.push_back(object); 
    3665                 } 
    3666         } 
    3667  
    3668         if (back)  
    3669         { 
    3670                 // find objects from multiple kd-leaves 
    3671                 ObjectContainer::const_iterator oit, oit_end = back->mObjects.end(); 
    3672  
    3673                 for (oit = back->mObjects.begin(); oit != oit_end; ++ oit) 
    3674                 { 
    3675                         Intersectable *object = *oit; 
    3676  
    3677                         if (object->mKdLeaves.size() > 1) 
    3678                                 back->mMultipleObjects.push_back(object); 
    3679                 } 
    3680         } 
    3681          
    3682 } 
    3683 #endif 
     3654void OspTree::ProcessMultipleRefs(KdLeaf *leaf) const 
     3655{ 
     3656        // find objects from multiple kd-leaves 
     3657        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     3658 
     3659        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     3660        { 
     3661                Intersectable *object = *oit; 
     3662                 
     3663                if (object->mReferences > 1) 
     3664                { 
     3665                        leaf->mMultipleObjects.push_back(object); 
     3666                } 
     3667        } 
     3668} 
     3669 
    36843670 
    36853671void OspTree::CollectLeaves(vector<KdLeaf *> &leaves) const 
     
    39723958 
    39733959 
     3960 
    39743961/********************************************************************/ 
    39753962/*               class HierarchyManager implementation              */ 
     
    40033990                                                                                         RayInfoContainer &rays) 
    40043991{ 
    4005         // get clipped rays 
    4006         mVspTree.ProcessRays(sampleRays, rays); 
    4007  
    40083992        // store pointer to this tree 
    40093993        VspTree::VspSplitCandidate::sVspTree = &mVspTree; 
     
    40113995 
    40123996        // compute view space bounding box 
    4013         mVspTree.ComputeBoundingBox(rays, forcedViewSpace); 
    4014  
     3997        mVspTree.ComputeBoundingBox(sampleRays, forcedViewSpace); 
     3998 
     3999        // initialise termination criteria 
    40154000        mVspTree.mTermMinProbability *= mBoundingBox.GetVolume(); 
    40164001        mVspTree.mGlobalCostMisses = 0; 
    40174002 
     4003        // get clipped rays 
     4004        mVspTree.ProcessRays(sampleRays, rays); 
    40184005 
    40194006        const int pvsSize = mVspTree.ComputePvsSize(rays); 
    40204007         
    4021         cout <<  "here450 pvs size: " << pvsSize << endl; 
    4022         // -- prepare view space partition 
     4008        Debug <<  "pvs size: " << pvsSize << endl; 
     4009        Debug <<  "rays size: " << rays.size() << endl; 
     4010 
     4011        //-- prepare view space partition 
    40234012 
    40244013        // add first candidate for view space partition 
     
    40384027 
    40394028        // create first view cell 
    4040         mVspTree.CreateViewCell(vData, true); 
     4029        mVspTree.CreateViewCell(vData, false); 
    40414030                 
    40424031        // add first view cell to all the objects view cell pvs 
     
    40884077        const float prop = mOspTree.mBoundingBox.GetVolume(); 
    40894078 
    4090         cout <<  "here40 pvs size: " << pvsSize << endl; 
    40914079        // first osp traversal data 
    40924080        OspTree::OspTraversalData oData(kdleaf, 
     
    40984086 
    40994087                 
    4100         //mOspTree.ProcessLeafObjects(NULL, kdleaf, NULL); 
     4088        //mOspTree.ProcessMultipleRefs(NULL, kdleaf, NULL); 
    41014089 
    41024090        // compute first split candidate 
     
    41334121 
    41344122 
     4123void HierarchyManager::Construct(const VssRayContainer &sampleRays, 
     4124                                                                 const ObjectContainer &objects, 
     4125                                                                 AxisAlignedBox3 *forcedViewSpace) 
     4126{ 
     4127        RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
     4128        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
     4129 
     4130        // prepare vsp and osp trees for traversal 
     4131        PrepareConstruction(sampleRays, objects, forcedViewSpace, *viewSpaceRays, *objectSpaceRays); 
     4132 
     4133        mVspTree.mVspStats.Reset(); 
     4134        mVspTree.mVspStats.Start(); 
     4135 
     4136        cout << "Constructing view space / object space tree ... \n"; 
     4137        const long startTime = GetTime();        
     4138         
     4139        int i = 0; 
     4140        while (!FinishedConstruction()) 
     4141        { 
     4142                mCurrentCandidate = NextSplitCandidate(); 
     4143            
     4144                const bool globalTerminationCriteriaMet =  
     4145                        GlobalTerminationCriteriaMet(mCurrentCandidate); 
     4146 
     4147                cout << "view cells: " << i ++ << endl; 
     4148 
     4149                // cost ratio of cost decrease / totalCost 
     4150                const float costRatio = mCurrentCandidate->GetPriority() / mTotalCost; 
     4151                //Debug << "cost ratio: " << costRatio << endl; 
     4152 
     4153                if (costRatio < mTermMinGlobalCostRatio) 
     4154                        ++ mGlobalCostMisses; 
     4155 
     4156                //-- subdivide leaf node 
     4157 
     4158                // we have either a object space or view space split 
     4159                if (mCurrentCandidate->Type() == SplitCandidate::VIEW_SPACE) 
     4160                { 
     4161                        VspTree::VspSplitCandidate *sc =  
     4162                                dynamic_cast<VspTree::VspSplitCandidate *>(mCurrentCandidate); 
     4163 
     4164                        VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
     4165                } 
     4166                else // object space split 
     4167                {                        
     4168                        OspTree::OspSplitCandidate *sc =  
     4169                                dynamic_cast<OspTree::OspSplitCandidate *>(mCurrentCandidate); 
     4170 
     4171                        KdNode *r = mOspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
     4172                } 
     4173 
     4174                // reevaluate candidates affected by the split 
     4175                // for view space splits, this would be object space splits 
     4176                // and other way round 
     4177                RepairQueue(); 
     4178 
     4179                DEL_PTR(mCurrentCandidate); 
     4180        } 
     4181 
     4182        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
     4183 
     4184        mVspTree.mVspStats.Stop(); 
     4185} 
     4186 
     4187 
    41354188void HierarchyManager::Construct2(const VssRayContainer &sampleRays, 
    41364189                                                                  const ObjectContainer &objects, 
     
    41394192        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
    41404193        RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
     4194 
     4195        ///////////////////////////////////////////////////////////// 
     4196        // view space space partition 
     4197        ///////////////////////////////////////////////////////////// 
    41414198 
    41424199        // makes no sense otherwise because only one kd cell available 
     
    41484205        mVspTree.mStoreKdPvs = false; 
    41494206 
    4150         mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays)); 
     4207        SplitCandidate *sc = PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays); 
     4208        mTQueue.Push(sc); 
    41514209 
    41524210        long startTime = GetTime(); 
    41534211        cout << "starting vsp contruction ... " << endl; 
     4212 
     4213        mVspTree.mVspStats.Reset(); 
     4214        mVspTree.mVspStats.Start(); 
     4215 
    41544216        int i = 0; 
    41554217 
     
    41864248         
    41874249         
    4188         /////////////////////////////////////////////////////////////// 
    4189         //-- object space partition 
     4250        ///////////////////////////////////////////////////////////// 
     4251        // object space partition 
    41904252        ///////////////////////////////////////////////////////////// 
    41914253 
     
    42394301                                                                  AxisAlignedBox3 *forcedViewSpace) 
    42404302{ 
     4303        mVspTree.mVspStats.Reset(); 
     4304        mVspTree.mVspStats.Start(); 
     4305 
    42414306        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
    4242  
     4307         
    42434308        SplitCandidate *sc = PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays); 
    42444309        mTQueue.Push(sc); 
     
    42574322 
    42584323                cout << "vsp nodes: " << i ++ << endl; 
    4259  
     4324                 
    42604325                // cost ratio of cost decrease / totalCost 
    42614326                const float costRatio = splitCandidate->GetPriority() / mTotalCost; 
     
    42664331 
    42674332                //-- subdivide leaf node 
    4268  
     4333         
    42694334                // we have either a object space or view space split 
    42704335                VspTree::VspSplitCandidate *sc =  
     
    42784343 
    42794344        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    4280         mVspTree.mVspStats.Stop(); 
    4281 } 
    4282  
    4283  
    4284  
    4285 void HierarchyManager::Construct(const VssRayContainer &sampleRays, 
    4286                                                                  const ObjectContainer &objects, 
    4287                                                                  AxisAlignedBox3 *forcedViewSpace) 
    4288 { 
    4289         RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
    4290         RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
    4291  
    4292         // prepare vsp and osp trees for traversal 
    4293         PrepareConstruction(sampleRays, objects, forcedViewSpace, *viewSpaceRays, *objectSpaceRays); 
    4294  
    4295         mVspTree.mVspStats.Reset(); 
    4296         mVspTree.mVspStats.Start(); 
    4297  
    4298         cout << "Constructing view space / object space tree ... \n"; 
    4299         const long startTime = GetTime();        
    4300          
    4301         int i = 0; 
    4302         while (!FinishedConstruction()) 
    4303         { 
    4304                 mCurrentCandidate = NextSplitCandidate(); 
    4305             
    4306                 const bool globalTerminationCriteriaMet =  
    4307                         GlobalTerminationCriteriaMet(mCurrentCandidate); 
    4308  
    4309                 cout << "view cells: " << i ++ << endl; 
    4310  
    4311                 // cost ratio of cost decrease / totalCost 
    4312                 const float costRatio = mCurrentCandidate->GetPriority() / mTotalCost; 
    4313                 //Debug << "cost ratio: " << costRatio << endl; 
    4314  
    4315                 if (costRatio < mTermMinGlobalCostRatio) 
    4316                         ++ mGlobalCostMisses; 
    4317  
    4318                 //-- subdivide leaf node 
    4319  
    4320                 // we have either a object space or view space split 
    4321                 if (mCurrentCandidate->Type() == SplitCandidate::VIEW_SPACE) 
    4322                 { 
    4323                         VspTree::VspSplitCandidate *sc =  
    4324                                 dynamic_cast<VspTree::VspSplitCandidate *>(mCurrentCandidate); 
    4325  
    4326                         VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
    4327                 } 
    4328                 else // object space split 
    4329                 {                        
    4330                         OspTree::OspSplitCandidate *sc =  
    4331                                 dynamic_cast<OspTree::OspSplitCandidate *>(mCurrentCandidate); 
    4332  
    4333                         KdNode *r = mOspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
    4334                 } 
    4335  
    4336                 // reevaluate candidates affected by the split 
    4337                 // for view space splits, this would be object space splits 
    4338                 // and other way round 
    4339                 RepairQueue(); 
    4340  
    4341                 DEL_PTR(mCurrentCandidate); 
    4342         } 
    4343  
    4344         cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    4345  
    43464345        mVspTree.mVspStats.Stop(); 
    43474346} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1142 r1143  
    3434class OspTree; 
    3535class KdIntersectable; 
    36  
    37  
    38  
     36class KdTree; 
     37class VspTree; 
    3938class KdTreeStatistics; 
     39 
     40 
    4041 
    4142template <typename T> class GtPriority 
     
    410411class VspLeaf: public VspNode  
    411412{ 
     413        friend VspTree; 
    412414 
    413415public: 
     
    802804                                                         float &pBack) const; 
    803805 
    804         void ComputeBoundingBox(const RayInfoContainer &rays, 
    805                 AxisAlignedBox3 *forcedBoundingBox); 
     806        void ComputeBoundingBox(const VssRayContainer &rays, 
     807                                                        AxisAlignedBox3 *forcedBoundingBox); 
    806808 
    807809        /** Evaluates candidate for splitting. 
     
    12621264        OspTree(); 
    12631265 
     1266        OspTree(const KdTree &kdTree); 
     1267 
    12641268        /** Default destructor. 
    12651269        */ 
     
    14811485                OspTraversalData &backData); 
    14821486 
    1483         void SplitObjects(const AxisAlignedPlane & splitPlane, 
     1487        void SplitObjects(KdLeaf *leaf, 
     1488                                          const AxisAlignedPlane & splitPlane, 
    14841489                                          const ObjectContainer &objects, 
    14851490                                          ObjectContainer &front, 
    14861491                                          ObjectContainer &back); 
    14871492 
    1488 #if DEPRECATED 
    1489          /** does some post processing on the objects in the new child leaves. 
    1490          */ 
    1491         void ProcessLeafObjects(KdLeaf *parent, KdLeaf *front, KdLeaf *back) const; 
    1492 #endif 
     1493        /** does some post processing on the objects in the new child leaves. 
     1494        */ 
     1495        void ProcessMultipleRefs(KdLeaf *leaf) const; 
     1496 
    14931497        /** Selects an axis aligned for the next split. 
    14941498                @returns cost for this split 
     
    16031607        */ 
    16041608        void ComputeBoundingBox(const ObjectContainer &objects, 
    1605                 AxisAlignedBox3 *forcedBoundingBox); 
     1609                                                        AxisAlignedBox3 *forcedBoundingBox); 
    16061610 
    16071611        void CollectDirtyCandidates(OspSplitCandidate *sc, 
     
    16161620                RayInfoContainer &rays); 
    16171621 
     1622 
     1623        void ReadEnvironment(); 
    16181624 
    16191625protected: 
     
    17001706        /// stores the kd node intersectables used for pvs 
    17011707        KdIntersectableMap mKdIntersectables; 
     1708 
     1709 
     1710private: 
     1711 
     1712        bool mCopyFromKdTree; 
    17021713}; 
    17031714 
Note: See TracChangeset for help on using the changeset viewer.