Changeset 1016


Ignore:
Timestamp:
06/14/06 11:02:34 (18 years ago)
Author:
mattausch
Message:

worked on view space / object space partition

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

Legend:

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

    r1004 r1016  
    17091709inline void BspTree::GenerateUniqueIdsForPvs() 
    17101710{ 
    1711         ViewCell::NewMail(); sBackId = ViewCell::sMailId; 
    1712         ViewCell::NewMail(); sFrontId = ViewCell::sMailId; 
    1713         ViewCell::NewMail(); sFrontAndBackId = ViewCell::sMailId; 
     1711        Intersectable::NewMail(); sBackId = Intersectable::sMailId; 
     1712        Intersectable::NewMail(); sFrontId = Intersectable::sMailId; 
     1713        Intersectable::NewMail(); sFrontAndBackId = Intersectable::sMailId; 
    17141714} 
    17151715 
     
    17361736        const bool pvsUseLen = false; 
    17371737 
     1738         
    17381739        if (mSplitPlaneStrategy & PVS) 
    17391740        { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1012 r1016  
    482482 
    483483 
    484  
    485484void VspBspTree::Construct(const PolygonContainer &polys, RayInfoContainer *rays) 
    486485{ 
    487486        VspBspTraversalQueue tQueue; 
    488487 
     488        /// create new vsp tree 
    489489        mRoot = new BspLeaf(); 
    490490 
     
    493493        ConstructGeometry(mRoot, *geom); 
    494494 
     495        /// we use the overall probability as normalizer 
     496        /// either the overall area or the volume 
    495497        const float prop = mUseAreaForPvs ? geom->GetArea() : geom->GetVolume(); 
    496498 
     
    518520        mTotalPvsSize = tData.mPvs; 
    519521         
     522        // first stats 
    520523        mSubdivisionStats  
    521524                        << "#ViewCells\n1" <<  endl 
     
    525528 
    526529        Debug << "total cost: " << mTotalCost << endl; 
    527          
    528          
     530 
     531 
    529532        mBspStats.Start(); 
    530533        cout << "Constructing vsp bsp tree ... \n"; 
    531534 
    532         long startTime = GetTime();      
     535        const long startTime = GetTime();        
     536        // used for intermediate time measurements and progress 
     537        long interTime = GetTime(); 
     538 
    533539        int nLeaves = 500; 
    534540        int nViewCells = 500; 
    535541 
    536         // used for intermediate time measurements and progress 
    537         long interTime = GetTime();      
    538  
    539542        mOutOfMemory = false; 
    540  
    541543        mCreatedViewCells = 0; 
    542544         
     
    558560 
    559561                // subdivide leaf node 
    560                 BspNode *r = Subdivide(tQueue, tData); 
     562                const BspNode *r = Subdivide(tQueue, tData); 
    561563 
    562564                if (r == mRoot) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h

    r1006 r1016  
    130130                {} 
    131131 
    132                 /** Returns cost of the traversal data. 
     132                /** Returns priority of the traversal data. 
    133133                */ 
    134134                float GetCost() const 
     
    167167                // parent data 
    168168                VspBspTraversalData mParentData; 
    169                 // cost of applying this split 
     169                // prioriry of this split 
    170170                float mRenderCost; 
    171171 
     
    183183#if 1 
    184184                        return mRenderCost; 
    185 #endif 
    186 #if 0 
     185#else 
    187186                        return (float) (-mDepth); // for kd tree 
    188187#endif 
     
    221220                a certain threshold. 
    222221                @param onlyUnmailed if only the unmailed leaves should be considered 
    223                 @param maxPvs the maximal pvs (-1 means unlimited) 
     222                @param maxPvs the maximal pvs of a leaf to be added (-1 means unlimited) 
    224223        */ 
    225224        void CollectLeaves(vector<BspLeaf *> &leaves,  
     
    359358        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 
    360359 
    361         // pointer to the hierarchy of view cells 
     360        /// pointer to the hierarchy of view cells 
    362361        ViewCellsTree *mViewCellsTree; 
    363362 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1015 r1016  
    2424//-- static members 
    2525 
    26 int VspOspTree::sFrontId = 0; 
    27 int VspOspTree::sBackId = 0; 
    28 int VspOspTree::sFrontAndBackId = 0; 
     26int VspTree::sFrontId = 0; 
     27int VspTree::sBackId = 0; 
     28int VspTree::sFrontAndBackId = 0; 
    2929 
    3030 
     
    184184 
    185185 
    186 AxisAlignedBox3 VspInterior::GetBox() const 
    187 { 
    188         return mBox; 
    189 } 
    190  
    191  
    192 void VspInterior::SetBox(const AxisAlignedBox3 &box) 
    193 { 
    194         mBox = box; 
     186AxisAlignedBox3 VspInterior::GetBoundingBox() const 
     187{ 
     188        return mBoundingBox; 
     189} 
     190 
     191 
     192void VspInterior::SetBoundingBox(const AxisAlignedBox3 &box) 
     193{ 
     194        mBoundingBox = box; 
    195195} 
    196196 
     
    258258 
    259259/******************************************************************************/ 
    260 /*                       class VspOspTree implementation                      */ 
     260/*                       class VspTree implementation                      */ 
    261261/******************************************************************************/ 
    262262 
    263263 
    264 VspOspTree::VspOspTree(): 
     264VspTree::VspTree(): 
    265265mRoot(NULL), 
    266266mOutOfBoundsCell(NULL), 
     
    270270{ 
    271271        bool randomize = false; 
    272         Environment::GetSingleton()->GetBoolValue("VspOspTree.Construction.randomize", randomize); 
     272        Environment::GetSingleton()->GetBoolValue("VspTree.Construction.randomize", randomize); 
    273273        if (randomize) 
    274274                Randomize(); // initialise random generator for heuristics 
    275275 
    276276        //-- termination criteria for autopartition 
    277         Environment::GetSingleton()->GetIntValue("VspOspTree.Termination.maxDepth", mTermMaxDepth); 
    278         Environment::GetSingleton()->GetIntValue("VspOspTree.Termination.minPvs", mTermMinPvs); 
    279         Environment::GetSingleton()->GetIntValue("VspOspTree.Termination.minRays", mTermMinRays); 
    280         Environment::GetSingleton()->GetFloatValue("VspOspTree.Termination.minProbability", mTermMinProbability); 
    281         Environment::GetSingleton()->GetFloatValue("VspOspTree.Termination.maxRayContribution", mTermMaxRayContribution); 
    282         Environment::GetSingleton()->GetFloatValue("VspOspTree.Termination.maxCostRatio", mTermMaxCostRatio); 
    283         Environment::GetSingleton()->GetIntValue("VspOspTree.Termination.missTolerance", mTermMissTolerance); 
    284         Environment::GetSingleton()->GetIntValue("VspOspTree.Termination.maxViewCells", mMaxViewCells); 
     277        Environment::GetSingleton()->GetIntValue("VspTree.Termination.maxDepth", mTermMaxDepth); 
     278        Environment::GetSingleton()->GetIntValue("VspTree.Termination.minPvs", mTermMinPvs); 
     279        Environment::GetSingleton()->GetIntValue("VspTree.Termination.minRays", mTermMinRays); 
     280        Environment::GetSingleton()->GetFloatValue("VspTree.Termination.minProbability", mTermMinProbability); 
     281        Environment::GetSingleton()->GetFloatValue("VspTree.Termination.maxRayContribution", mTermMaxRayContribution); 
     282        Environment::GetSingleton()->GetFloatValue("VspTree.Termination.maxCostRatio", mTermMaxCostRatio); 
     283        Environment::GetSingleton()->GetIntValue("VspTree.Termination.missTolerance", mTermMissTolerance); 
     284        Environment::GetSingleton()->GetIntValue("VspTree.Termination.maxViewCells", mMaxViewCells); 
    285285 
    286286        //-- max cost ratio for early tree termination 
    287         Environment::GetSingleton()->GetFloatValue("VspOspTree.Termination.maxCostRatio", mTermMaxCostRatio); 
    288  
    289         Environment::GetSingleton()->GetFloatValue("VspOspTree.Termination.minGlobalCostRatio", mTermMinGlobalCostRatio); 
    290         Environment::GetSingleton()->GetIntValue("VspOspTree.Termination.globalCostMissTolerance", mTermGlobalCostMissTolerance); 
     287        Environment::GetSingleton()->GetFloatValue("VspTree.Termination.maxCostRatio", mTermMaxCostRatio); 
     288 
     289        Environment::GetSingleton()->GetFloatValue("VspTree.Termination.minGlobalCostRatio", mTermMinGlobalCostRatio); 
     290        Environment::GetSingleton()->GetIntValue("VspTree.Termination.globalCostMissTolerance", mTermGlobalCostMissTolerance); 
    291291 
    292292        // HACK//mTermMinPolygons = 25; 
    293293 
    294294        //-- factors for bsp tree split plane heuristics 
    295         Environment::GetSingleton()->GetFloatValue("VspOspTree.Termination.ct_div_ci", mCtDivCi); 
     295        Environment::GetSingleton()->GetFloatValue("VspTree.Termination.ct_div_ci", mCtDivCi); 
    296296 
    297297        //-- partition criteria 
    298         Environment::GetSingleton()->GetFloatValue("VspOspTree.Construction.epsilon", mEpsilon); 
     298        Environment::GetSingleton()->GetFloatValue("VspTree.Construction.epsilon", mEpsilon); 
    299299 
    300300        // if only the driving axis is used for axis aligned split 
    301         Environment::GetSingleton()->GetBoolValue("VspOspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 
    302          
    303         //Environment::GetSingleton()->GetFloatValue("VspOspTree.maxTotalMemory", mMaxTotalMemory); 
    304         Environment::GetSingleton()->GetFloatValue("VspOspTree.maxStaticMemory", mMaxMemory); 
    305  
    306         Environment::GetSingleton()->GetBoolValue("VspOspTree.useCostHeuristics", mUseCostHeuristics); 
    307         Environment::GetSingleton()->GetBoolValue("VspOspTree.simulateOctree", mCirculatingAxis); 
    308         Environment::GetSingleton()->GetBoolValue("VspOspTree.useRandomAxis", mUseRandomAxis); 
    309         Environment::GetSingleton()->GetIntValue("VspOspTree.nodePriorityQueueType", mNodePriorityQueueType); 
     301        Environment::GetSingleton()->GetBoolValue("VspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 
     302         
     303        //Environment::GetSingleton()->GetFloatValue("VspTree.maxTotalMemory", mMaxTotalMemory); 
     304        Environment::GetSingleton()->GetFloatValue("VspTree.maxStaticMemory", mMaxMemory); 
     305 
     306        Environment::GetSingleton()->GetBoolValue("VspTree.useCostHeuristics", mUseCostHeuristics); 
     307        Environment::GetSingleton()->GetBoolValue("VspTree.simulateOctree", mCirculatingAxis); 
     308        Environment::GetSingleton()->GetBoolValue("VspTree.useRandomAxis", mUseRandomAxis); 
     309        Environment::GetSingleton()->GetIntValue("VspTree.nodePriorityQueueType", mNodePriorityQueueType); 
    310310         
    311311        char subdivisionStatsLog[100]; 
    312         Environment::GetSingleton()->GetStringValue("VspOspTree.subdivisionStats", subdivisionStatsLog); 
     312        Environment::GetSingleton()->GetStringValue("VspTree.subdivisionStats", subdivisionStatsLog); 
    313313        mSubdivisionStats.open(subdivisionStatsLog); 
    314314 
    315         Environment::GetSingleton()->GetFloatValue("VspOspTree.Construction.minBand", mMinBand); 
    316         Environment::GetSingleton()->GetFloatValue("VspOspTree.Construction.maxBand", mMaxBand); 
     315        Environment::GetSingleton()->GetFloatValue("VspTree.Construction.minBand", mMinBand); 
     316        Environment::GetSingleton()->GetFloatValue("VspTree.Construction.maxBand", mMaxBand); 
    317317         
    318318 
     
    349349 
    350350 
    351 VspViewCell *VspOspTree::GetOutOfBoundsCell() 
     351VspViewCell *VspTree::GetOutOfBoundsCell() 
    352352{ 
    353353        return mOutOfBoundsCell; 
     
    355355 
    356356 
    357 VspViewCell *VspOspTree::GetOrCreateOutOfBoundsCell() 
     357VspViewCell *VspTree::GetOrCreateOutOfBoundsCell() 
    358358{ 
    359359        if (!mOutOfBoundsCell) 
     
    368368 
    369369 
    370 const VspTreeStatistics &VspOspTree::GetStatistics() const 
     370const VspTreeStatistics &VspTree::GetStatistics() const 
    371371{ 
    372372        return mVspStats; 
     
    374374 
    375375 
    376 VspOspTree::~VspOspTree() 
     376VspTree::~VspTree() 
    377377{ 
    378378        DEL_PTR(mRoot); 
     
    381381 
    382382 
    383 void VspOspTree::Construct(const VssRayContainer &sampleRays, 
     383void VspTree::Construct(const VssRayContainer &sampleRays, 
    384384                                                   AxisAlignedBox3 *forcedBoundingBox) 
    385385{ 
     
    437437 
    438438// TODO: return memory usage in MB 
    439 float VspOspTree::GetMemUsage() const 
     439float VspTree::GetMemUsage() const 
    440440{ 
    441441        return (float) 
    442                  (sizeof(VspOspTree) +  
     442                 (sizeof(VspTree) +  
    443443                  mVspStats.Leaves() * sizeof(VspLeaf) +  
    444444                  mCreatedViewCells * sizeof(VspViewCell) + 
     
    449449 
    450450 
    451 void VspOspTree::Construct(RayInfoContainer *rays) 
    452 { 
    453         VspOspSplitQueue tQueue; 
    454  
     451void VspTree::Construct(RayInfoContainer *rays) 
     452{ 
     453#if TODO 
     454        VspSplitQueue tQueue; 
     455        /// create new vsp tree 
    455456        mRoot = new VspLeaf(); 
    456  
     457        /// we use the overall probability as normalizer 
    457458        const float prop = mBox.GetVolume(); 
    458459 
    459         VspOspTraversalData tData(mRoot, 
    460                                                           0, 
    461                                                           rays, 
    462                               ComputePvsSize(*rays), 
    463                                                           prop, 
    464                                                           mBox); 
     460        VspTraversalData tData(mRoot, 
     461                                                  0, 
     462                                                  rays, 
     463                          ComputePvsSize(*rays), 
     464                                                  prop, 
     465                                                  mBox); 
    465466 
    466467 
    467468        // compute first split candidate 
    468         VspOspSplitCandidate splitCandidate; 
     469        VspSplitCandidate splitCandidate; 
    469470        EvalSplitCandidate(tData, splitCandidate); 
    470471 
     
    552553 
    553554        mVspStats.Stop(); 
    554 } 
    555  
    556  
    557 bool VspOspTree::LocalTerminationCriteriaMet(const VspOspTraversalData &data) const 
     555#endif 
     556} 
     557 
     558 
     559bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const 
    558560{ 
    559561        return 
     
    566568 
    567569 
    568 bool VspOspTree::GlobalTerminationCriteriaMet(const VspOspTraversalData &data) const 
     570bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const 
    569571{ 
    570572        return 
     
    576578 
    577579// subdivide using a split plane queue 
    578 VspNode *VspOspTree::Subdivide(VspOspSplitQueue &tQueue, 
    579                                                            VspOspSplitCandidate &splitCandidate) 
    580 { 
    581         VspOspTraversalData &tData = splitCandidate.mParentData; 
     580VspNode *VspTree::Subdivide(SplitQueue &tQueue, 
     581                                                        VspSplitCandidate &splitCandidate) 
     582{ 
     583        VspTraversalData &tData = splitCandidate.mParentData; 
    582584 
    583585        VspNode *newNode = tData.mNode; 
     
    585587        if (!LocalTerminationCriteriaMet(tData) && !GlobalTerminationCriteriaMet(tData)) 
    586588        {        
    587                 VspOspTraversalData tFrontData; 
    588                 VspOspTraversalData tBackData; 
     589                VspTraversalData tFrontData; 
     590                VspTraversalData tBackData; 
    589591 
    590592                //-- continue subdivision 
     
    619621                                        << "#ViewCells\n" << mVspStats.Leaves() << endl 
    620622                                        << "#RenderCostDecrease\n" << -costDecr << endl 
    621                                         << "#SplitCandidateCost\n" << splitCandidate.GetCost() << endl 
     623                                        << "#SplitCandidateCost\n" << splitCandidate.GetPriority() << endl 
    622624                                        << "#TotalRenderCost\n" << mTotalCost << endl 
    623625                                        << "#AvgRenderCost\n" << (float)mTotalPvsSize / (float)mVspStats.Leaves() << endl; 
     
    626628         
    627629                //-- push the new split candidates on the stack 
    628                 VspOspSplitCandidate frontCandidate; 
    629                 VspOspSplitCandidate backCandidate; 
     630                VspSplitCandidate frontCandidate; 
     631                VspSplitCandidate backCandidate; 
    630632 
    631633                EvalSplitCandidate(tFrontData, frontCandidate); 
    632634                EvalSplitCandidate(tBackData, backCandidate); 
    633          
     635#if TODO 
    634636                tQueue.push(frontCandidate); 
    635637                tQueue.push(backCandidate); 
    636          
     638#endif 
    637639                // delete old leaf node 
    638640                DEL_PTR(tData.mNode); 
     
    686688 
    687689 
    688 void VspOspTree::EvalSplitCandidate(VspOspTraversalData &tData, 
    689                                                                         VspOspSplitCandidate &splitData) 
    690 { 
    691         VspOspTraversalData frontData; 
    692         VspOspTraversalData backData; 
     690void VspTree::EvalSplitCandidate(VspTraversalData &tData, 
     691                                                                 VspSplitCandidate &splitData) 
     692{ 
     693        VspTraversalData frontData; 
     694        VspTraversalData backData; 
    693695 
    694696        VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); 
     
    701703        //TODO 
    702704        // compute global decrease in render cost 
    703         splitData.mRenderCost = EvalRenderCostDecrease(splitData.mSplitPlane, tData); 
     705        splitData.mPriority = EvalRenderCostDecrease(splitData.mSplitPlane, tData); 
    704706        splitData.mParentData = tData; 
    705707        splitData.mMaxCostMisses = success ? tData.mMaxCostMisses : tData.mMaxCostMisses + 1; 
     
    707709 
    708710 
    709 VspInterior *VspOspTree::SubdivideNode(const AxisAlignedPlane &splitPlane, 
    710                                                                            VspOspTraversalData &tData, 
    711                                                                            VspOspTraversalData &frontData, 
    712                                                                            VspOspTraversalData &backData) 
     711VspInterior *VspTree::SubdivideNode(const AxisAlignedPlane &splitPlane, 
     712                                                                        VspTraversalData &tData, 
     713                                                                        VspTraversalData &frontData, 
     714                                                                        VspTraversalData &backData) 
    713715{ 
    714716        VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); 
     
    777779        // and setup child links 
    778780        interior->SetupChildLinks(new VspLeaf(interior), new VspLeaf(interior)); 
     781        // add bounding box 
     782        interior->SetBoundingBox(tData.mBoundingBox); 
    779783 
    780784        frontData.mNode = interior->GetFront(); 
     
    786790} 
    787791 
    788  
    789 void VspOspTree::AddToPvs(VspLeaf *leaf, 
     792/* 
     793KdNode *VspOpsTree::SubdivideSpatialNode(KdLeaf *leaf, 
     794                                                                                 const AxisAlignedPlane &splitPlane, 
     795                                                                                 const AxisAlignedBox3 &box, 
     796                                                                                 AxisAlignedBox3 &backBBox, 
     797                                                                                 AxisAlignedBox3 &frontBBox) 
     798{ 
     799        float position; 
     800 
     801#if TODO 
     802    mSpatialStat.nodes += 2; 
     803        mSpatialStat.splits[axis]; 
     804#endif 
     805 
     806        // add the new nodes to the tree 
     807        KdInterior *node = new KdInterior(leaf->mParent); 
     808 
     809        node->mAxis = splitPlane.mAxis; 
     810        node->mPosition = splitPlane.mPosition; 
     811        node->mBox = box; 
     812 
     813    backBBox = box; 
     814        frontBBox = box; 
     815   
     816        // first count ray sides 
     817        int objectsBack = 0; 
     818        int objectsFront = 0; 
     819   
     820        backBBox.SetMax(axis, position); 
     821        frontBBox.SetMin(axis, position); 
     822 
     823        SplitObjects(leaf->m 
     824        ObjectContainer::const_iterator mi, mi_end = leaf->mObjects.end(); 
     825 
     826        for ( mi = leaf->mObjects.begin(); mi != mi_end; ++ mi)  
     827        { 
     828                // determine the side of this ray with respect to the plane 
     829                AxisAlignedBox3 box = (*mi)->GetBox(); 
     830                 
     831                if (box.Max(axis) > position )  
     832                        ++ objectsFront; 
     833     
     834                if (box.Min(axis) < position ) 
     835      objectsBack++; 
     836  } 
     837 
     838   
     839  KdLeaf *back = new KdLeaf(node, objectsBack); 
     840  KdLeaf *front = new KdLeaf(node, objectsFront); 
     841 
     842  // replace a link from node's parent 
     843  if (  leaf->mParent ) 
     844    leaf->mParent->ReplaceChildLink(leaf, node); 
     845 
     846  // and setup child links 
     847  node->SetupChildLinks(back, front); 
     848   
     849  for (mi = leaf->mObjects.begin(); 
     850       mi != leaf->mObjects.end(); 
     851       mi++) { 
     852    // determine the side of this ray with respect to the plane 
     853    AxisAlignedBox3 box = (*mi)->GetBox(); 
     854 
     855    if (box.Max(axis) >= position ) 
     856      front->mObjects.push_back(*mi); 
     857     
     858    if (box.Min(axis) < position ) 
     859      back->mObjects.push_back(*mi); 
     860     
     861    mStat.objectRefs -= (int)leaf->mObjects.size(); 
     862    mStat.objectRefs += objectsBack + objectsFront; 
     863  } 
     864   
     865  delete leaf; 
     866  return node; 
     867} 
     868*/ 
     869 
     870 
     871 
     872void VspTree::AddToPvs(VspLeaf *leaf, 
    790873                                                  const RayInfoContainer &rays, 
    791874                                                  float &sampleContributions, 
     
    832915 
    833916 
    834 void VspOspTree::SortSplitCandidates(const RayInfoContainer &rays,  
     917void VspTree::SortSplitCandidates(const RayInfoContainer &rays,  
    835918                                                                         const int axis,  
    836919                                                                         float minBand,  
     
    883966 
    884967 
    885 float VspOspTree::BestCostRatioHeuristics(const RayInfoContainer &rays, 
     968float VspTree::BestCostRatioHeuristics(const RayInfoContainer &rays, 
    886969                                                                                  const AxisAlignedBox3 &box, 
    887970                                                                                  const int pvsSize, 
     
    10551138 
    10561139 
    1057 float VspOspTree::SelectPlane(const VspOspTraversalData &tData, 
    1058                                                           AxisAlignedPlane &plane, 
    1059                                                           float &pFront, 
    1060                                                           float &pBack) 
     1140float VspTree::SelectPlane(const VspTraversalData &tData, 
     1141                                                   AxisAlignedPlane &plane, 
     1142                                                   float &pFront, 
     1143                                                   float &pBack) 
    10611144{ 
    10621145        float nPosition[3]; 
     
    11341217 
    11351218 
    1136 inline void VspOspTree::GenerateUniqueIdsForPvs() 
     1219inline void VspTree::GenerateUniqueIdsForPvs() 
    11371220{ 
    11381221        Intersectable::NewMail(); sBackId = Intersectable::sMailId; 
     
    11421225 
    11431226 
    1144 float VspOspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
    1145                                                                                  const VspOspTraversalData &data) const 
     1227float VspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
     1228                                                                          const VspTraversalData &data) const 
    11461229{ 
    11471230        float pvsFront = 0; 
     
    11581241        GenerateUniqueIdsForPvs(); 
    11591242         
    1160         RayInfoContainer::const_iterator rit, rit_end = data.mRays.end(); 
    1161  
    1162         for (rit = data.mRays.begin(); rit != rit_end; ++ rit) 
     1243        RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); 
     1244 
     1245        for (rit = data.mRays->begin(); rit != rit_end; ++ rit) 
    11631246        { 
    11641247                RayInfo rayInf = *rit; 
     
    12101293 
    12111294 
    1212  
    1213 float VspOspTree::EvalSplitCost(const VspOspTraversalData &data, 
    1214                                                                 const AxisAlignedBox3 &box, 
    1215                                                                 const int axis, 
    1216                                                                 const float &position,                                                                             
    1217                                                                 float &pFront, 
    1218                                                                 float &pBack) const 
     1295float VspTree::EvalSplitCost(const VspTraversalData &data, 
     1296                                                         const AxisAlignedBox3 &box, 
     1297                                                         const int axis, 
     1298                                                         const float &position,                                                                            
     1299                                                         float &pFront, 
     1300                                                         float &pBack) const 
    12191301{ 
    12201302        float pvsTotal = 0; 
     
    12631345 
    12641346 
    1265 void VspOspTree::AddObjToPvs(Intersectable *obj, 
     1347void VspTree::AddObjToPvs(Intersectable *obj, 
    12661348                                                         const int cf, 
    12671349                                                         float &frontPvs, 
     
    13161398 
    13171399 
    1318 void VspOspTree::CollectLeaves(vector<VspLeaf *> &leaves,  
     1400void VspTree::CollectLeaves(vector<VspLeaf *> &leaves,  
    13191401                                                           const bool onlyUnmailed, 
    13201402                                                           const int maxPvsSize) const 
     
    13501432 
    13511433 
    1352 AxisAlignedBox3 VspOspTree::GetBoundingBox() const 
     1434AxisAlignedBox3 VspTree::GetBoundingBox() const 
    13531435{ 
    13541436        return mBox; 
     
    13561438 
    13571439 
    1358 VspNode *VspOspTree::GetRoot() const 
     1440VspNode *VspTree::GetRoot() const 
    13591441{ 
    13601442        return mRoot; 
     
    13621444 
    13631445 
    1364 void VspOspTree::EvaluateLeafStats(const VspOspTraversalData &data) 
     1446void VspTree::EvaluateLeafStats(const VspTraversalData &data) 
    13651447{ 
    13661448        // the node became a leaf -> evaluate stats for leafs 
     
    14181500 
    14191501 
    1420 void VspOspTree::CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const 
     1502void VspTree::CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const 
    14211503{ 
    14221504        ViewCell::NewMail(); 
     
    14251507 
    14261508 
    1427 void VspOspTree::CollapseViewCells() 
     1509void VspTree::CollapseViewCells() 
    14281510{ 
    14291511// TODO 
     
    14801562 
    14811563 
    1482 void VspOspTree::CollectRays(VssRayContainer &rays) 
     1564void VspTree::CollectRays(VssRayContainer &rays) 
    14831565{ 
    14841566        vector<VspLeaf *> leaves; 
     
    14971579 
    14981580 
    1499 void VspOspTree::ValidateTree() 
     1581void VspTree::ValidateTree() 
    15001582{ 
    15011583        stack<VspNode *> nodeStack; 
     
    15401622 
    15411623 
    1542 void VspOspTree::CollectViewCells(VspNode *root, 
     1624void VspTree::CollectViewCells(VspNode *root, 
    15431625                                                                  bool onlyValid, 
    15441626                                                                  ViewCellContainer &viewCells, 
     
    15841666 
    15851667 
    1586 int VspOspTree::FindNeighbors(VspLeaf *n, 
     1668int VspTree::FindNeighbors(VspLeaf *n, 
    15871669                                                          vector<VspLeaf *> &neighbors, 
    15881670                                                          const bool onlyUnmailed) const 
     
    16311713 
    16321714// Find random neighbor which was not mailed 
    1633 VspLeaf *VspOspTree::GetRandomLeaf(const Plane3 &plane) 
     1715VspLeaf *VspTree::GetRandomLeaf(const Plane3 &plane) 
    16341716{ 
    16351717        stack<VspNode *> nodeStack; 
     
    16761758 
    16771759 
    1678 VspLeaf *VspOspTree::GetRandomLeaf(const bool onlyUnmailed) 
     1760VspLeaf *VspTree::GetRandomLeaf(const bool onlyUnmailed) 
    16791761{ 
    16801762        stack<VspNode *> nodeStack; 
     
    17121794 
    17131795 
    1714 int VspOspTree::ComputePvsSize(const RayInfoContainer &rays) const 
     1796int VspTree::ComputePvsSize(const RayInfoContainer &rays) const 
    17151797{ 
    17161798        int pvsSize = 0; 
     
    17461828 
    17471829 
    1748 float VspOspTree::GetEpsilon() const 
     1830float VspTree::GetEpsilon() const 
    17491831{ 
    17501832        return mEpsilon; 
     
    17521834 
    17531835 
    1754 int VspOspTree::CastLineSegment(const Vector3 &origin, 
     1836int VspTree::CastLineSegment(const Vector3 &origin, 
    17551837                                                                const Vector3 &termination, 
    17561838                                                                ViewCellContainer &viewcells) 
     
    18551937 
    18561938 
    1857 int VspOspTree::CastRay(Ray &ray) 
     1939int VspTree::CastRay(Ray &ray) 
    18581940{ 
    18591941        int hits = 0; 
     
    19612043 
    19622044 
    1963 VspNode *VspOspTree::CollapseTree(VspNode *node, int &collapsed) 
     2045VspNode *VspTree::CollapseTree(VspNode *node, int &collapsed) 
    19642046{ 
    19652047// TODO 
     
    20032085 
    20042086 
    2005 int VspOspTree::CollapseTree() 
     2087int VspTree::CollapseTree() 
    20062088{ 
    20072089        int collapsed = 0; 
     
    20172099 
    20182100 
    2019 void VspOspTree::RepairViewCellsLeafLists() 
     2101void VspTree::RepairViewCellsLeafLists() 
    20202102{ 
    20212103// TODO 
     
    20612143 
    20622144 
    2063 ViewCell *VspOspTree::GetViewCell(const Vector3 &point, const bool active) 
     2145ViewCell *VspTree::GetViewCell(const Vector3 &point, const bool active) 
    20642146{ 
    20652147        if (mRoot == NULL) 
     
    21002182 
    21012183 
    2102 bool VspOspTree::ViewPointValid(const Vector3 &viewPoint) const 
     2184bool VspTree::ViewPointValid(const Vector3 &viewPoint) const 
    21032185{ 
    21042186        VspNode *node = mRoot; 
     
    21302212 
    21312213 
    2132 void VspOspTree::PropagateUpValidity(VspNode *node) 
     2214void VspTree::PropagateUpValidity(VspNode *node) 
    21332215{ 
    21342216        const bool isValid = node->TreeValid(); 
     
    21592241 
    21602242#if ZIPPED_VIEWCELLS 
    2161 bool VspOspTree::Export(ogzstream &stream) 
     2243bool VspTree::Export(ogzstream &stream) 
    21622244#else 
    2163 bool VspOspTree::Export(ofstream &stream) 
     2245bool VspTree::Export(ofstream &stream) 
    21642246#endif 
    21652247{ 
     
    21712253 
    21722254#if ZIPPED_VIEWCELLS 
    2173 void VspOspTree::ExportNode(VspNode *node, ogzstream &stream) 
     2255void VspTree::ExportNode(VspNode *node, ogzstream &stream) 
    21742256#else 
    2175 void VspOspTree::ExportNode(VspNode *node, ofstream &stream) 
     2257void VspTree::ExportNode(VspNode *node, ofstream &stream) 
    21762258#endif 
    21772259{ 
     
    22032285 
    22042286 
    2205 int VspOspTree::SplitRays(const AxisAlignedPlane &plane, 
     2287int VspTree::SplitRays(const AxisAlignedPlane &plane, 
    22062288                                                  RayInfoContainer &rays, 
    22072289                                                  RayInfoContainer &frontRays, 
     
    22532335 
    22542336 
    2255 AxisAlignedBox3 VspOspTree::GetBBox(VspNode *node) const 
     2337AxisAlignedBox3 VspTree::GetBBox(VspNode *node) const 
    22562338{ 
    22572339        if (!node->GetParent()) 
     
    22602342        if (!node->IsLeaf()) 
    22612343        { 
    2262                 return (dynamic_cast<VspInterior *>(node))->GetBox();            
     2344                return (dynamic_cast<VspInterior *>(node))->GetBoundingBox();            
    22632345        } 
    22642346 
    22652347        VspInterior *parent = dynamic_cast<VspInterior *>(node->GetParent()); 
    22662348 
    2267         AxisAlignedBox3 box(parent->GetBox()); 
     2349        AxisAlignedBox3 box(parent->GetBoundingBox()); 
    22682350 
    22692351        if (parent->GetFront() == node) 
     
    22762358 
    22772359 
    2278 } 
     2360/*****************************************************************/ 
     2361/*              class HierarchyManager implementation            */ 
     2362/*****************************************************************/ 
     2363 
     2364HierarchyManager::HierarchyManager() 
     2365{ 
     2366} 
     2367 
     2368 
     2369SplitCandidate *HierarchyManager::NextSplitCandidate() 
     2370{ 
     2371        SplitCandidate *splitCandidate = mTQueue.top(); 
     2372        mTQueue.pop(); 
     2373 
     2374        return splitCandidate; 
     2375} 
     2376 
     2377 
     2378void HierarchyManager::PrepareTraversal() 
     2379{ 
     2380 
     2381#if TODO 
     2382        /// create new vsp tree 
     2383        mRoot = new VspLeaf(); 
     2384        /// we use the overall probability as normalizer 
     2385        const float prop = mBoundingBox.GetVolume(); 
     2386 
     2387        VspTraversalData tData(mRoot, 
     2388                                                   0, 
     2389                                                   rays, 
     2390                           ComputePvsSize(*rays), 
     2391                                                   prop, 
     2392                                                   mBoundingBox); 
     2393 
     2394 
     2395        // compute first split candidates 
     2396        VspTree::VspSplitCandidate vspSplitCandidate = new VspTree::VspSplitCandidate(); 
     2397        EvalSplitCandidate(tData, *vspSplitCandidate); 
     2398        mTQueue.push(splitCandidate); 
     2399 
     2400    OspSplitCandidate ospSplitCandidate = new OspSplitCandidate(); 
     2401        EvalSplitCandidate(tData, *ospSplitCandidate); 
     2402        mTQueue.push(ospSplitCandidate); 
     2403 
     2404        mTotalCost = tData.mPvs * tData.mProbability / mBox.GetVolume(); 
     2405        mTotalPvsSize = tData.mPvs; 
     2406         
     2407        mSubdivisionStats  
     2408                        << "#ViewCells\n1\n" <<  endl 
     2409                        << "#RenderCostDecrease\n0\n" << endl  
     2410                        << "#SplitCandidateCost\n0\n" << endl 
     2411                        << "#TotalRenderCost\n" << mTotalCost << endl 
     2412                        << "#AvgRenderCost\n" << mTotalPvsSize << endl; 
     2413 
     2414        Debug << "total cost: " << mTotalCost << endl; 
     2415 
     2416#endif 
     2417} 
     2418 
     2419 
     2420void HierarchyManager::Construct(const VssRayContainer &sampleRays, 
     2421                                                                 const ObjectContainer &objects, 
     2422                                                                 AxisAlignedBox3 *forcedBoundingBox) 
     2423{ 
     2424#if TODO 
     2425        //-- store rays 
     2426        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
     2427        { 
     2428                VssRay *ray = *rit; 
     2429 
     2430                float minT, maxT; 
     2431 
     2432                static Ray hray; 
     2433                hray.Init(*ray); 
     2434 
     2435                // TODO: not very efficient to implictly cast between rays types 
     2436                if (mBoundingBox.GetRaySegment(hray, minT, maxT)) 
     2437                { 
     2438                        float len = ray->Length(); 
     2439 
     2440                        if (!len) 
     2441                                len = Limits::Small; 
     2442 
     2443                        rays->push_back(RayInfo(ray, minT / len, maxT / len)); 
     2444                } 
     2445        } 
     2446#endif 
     2447} 
     2448 
     2449 
     2450bool HierarchyManager::FinishedConstruction() 
     2451{ 
     2452        return mTQueue.empty(); 
     2453} 
     2454 
     2455 
     2456void HierarchyManager::Construct(RayInfoContainer *rays) 
     2457{ 
     2458        PrepareTraversal(); 
     2459 
     2460        mVspTree->mVspStats.Start(); 
     2461        cout << "Constructing vsp bsp tree ... \n"; 
     2462 
     2463        const long startTime = GetTime();        
     2464 
     2465        while (!FinishedConstruction()) 
     2466        { 
     2467                SplitCandidate *splitCandidate = NextSplitCandidate(); 
     2468             
     2469                // cost ratio of cost decrease / totalCost 
     2470                const float costRatio = splitCandidate->GetPriority() / mTotalCost; 
     2471                 
     2472                //Debug << "cost ratio: " << costRatio << endl; 
     2473 
     2474                if (costRatio < mTermMinGlobalCostRatio) 
     2475                        ++ mGlobalCostMisses; 
     2476         
     2477                // subdivide leaf node 
     2478                // either object space or view space 
     2479                if (splitCandidate->Type() == SplitCandidate::VIEW_SPACE) 
     2480                { 
     2481                        VspTree::VspSplitCandidate *sc =  
     2482                                dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate); 
     2483 
     2484                        VspNode *r = mVspTree->Subdivide(mTQueue, *sc); 
     2485                } 
     2486                else // object space 
     2487                { 
     2488#if TODO 
     2489                        KdNode *r = mKdtree->Subdivide(tOspQueue, dynamic_cast<OspSplitCandidate<(splitCandidate)); 
     2490#endif 
     2491                } 
     2492        } 
     2493 
     2494        cout << "finished\n"; 
     2495 
     2496        mVspTree->mVspStats.Stop(); 
     2497} 
     2498 
     2499} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1013 r1016  
    4545}; 
    4646 
    47  
     47/** Candidate for a view space / object space split. 
     48*/ 
     49class SplitCandidate 
     50 
     51public: 
     52 
     53        enum {OBJECT_SPACE, VIEW_SPACE}; 
     54 
     55        /// the current split plane 
     56        AxisAlignedPlane mSplitPlane; 
     57        /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned) 
     58        int mSplitAxis; 
     59        /// the number of misses of max cost ratio until this split 
     60        int mMaxCostMisses; 
     61 
     62        /// priority of this split 
     63        float mPriority; 
     64         
     65        SplitCandidate(): mPriority(0)  
     66        {}; 
     67 
     68        SplitCandidate(const AxisAlignedPlane &plane): mSplitPlane(plane) 
     69        {} 
     70 
     71        virtual int Type() const = 0; 
     72 
     73        /** Returns cost of the traversal data. 
     74        */ 
     75        float GetPriority() const 
     76        { 
     77#if 1 
     78                return mPriority; 
     79#else 
     80                return (float) (-mDepth); // for kd tree 
     81#endif 
     82        } 
     83 
     84        friend bool operator<(const SplitCandidate &a, const SplitCandidate &b) 
     85        { 
     86                return a.GetPriority() < b.GetPriority(); 
     87        } 
     88}; 
     89 
     90 
     91/** View space partition statistics. 
     92*/ 
    4893class VspTreeStatistics: public StatisticsBase 
    4994{ 
     
    154199 
    155200        /** Determines whether this node is a leaf or not 
    156         @return true if leaf 
     201                @return true if leaf 
    157202        */ 
    158203        virtual bool IsLeaf() const = 0; 
     
    161206 
    162207        /** Determines whether this node is a root 
    163         @return true if root 
     208                @return true if root 
    164209        */ 
    165210        virtual bool IsRoot() const; 
     
    250295        } 
    251296 
    252         AxisAlignedBox3 GetBox() const; 
    253         void SetBox(const AxisAlignedBox3 &box); 
     297        AxisAlignedBox3 GetBoundingBox() const; 
     298        void SetBoundingBox(const AxisAlignedBox3 &box); 
    254299 
    255300protected: 
    256301 
    257         AxisAlignedBox3 mBox; 
     302        AxisAlignedBox3 mBoundingBox; 
    258303 
    259304        /// Splitting plane corresponding to this node 
     
    310355 
    311356 
    312 /** 
    313         This class implements a structure holding two different hierarchies, 
    314         one for object space partitioning and one for view space partitioning. 
    315  
    316         The object space and the view space are subdivided using a cost heuristics. 
    317         If an object space split or a view space split is chosen is also evaluated 
    318         based on the heuristics.  
    319          
    320         The view space heuristics is evaluated by weighting and adding the pvss of the back and 
    321         front node of each specific split. unlike for the standalone method vspbsp tree, 
    322         the pvs of an object would not be the pvs of single object but that of all objects 
    323         which are contained in the same leaf of the object subdivision. This could be done 
    324         by storing the pointer to the object space partition parent, which would allow access to all children. 
    325         Another possibility is to include traced kd-cells in the ray casing process. 
    326  
    327         Accordingly, the object space heuristics is evaluated by storing a pvs of view cells with each object. 
    328         the contribution to an object to the pvs is the number of view cells it can be seen from. 
    329  
    330  
    331         There is a potential efficiency problem involved in a sense that once a certain type 
    332         of split is chosen for view space / object space, the candidates for the next split of  
    333         object space / view space must be reevaluated. 
    334          
     357typedef std::priority_queue<SplitCandidate *> SplitQueue; 
     358 
     359 
     360#if TODO 
     361/** candidate for a view space split 
    335362*/ 
    336 class VspOspTree  
     363class OspSplitCandidate: public SplitCandidate 
     364 
     365        /// parent data 
     366        OspTraversalData mParentData; 
     367                 
     368        VspOspSplitCandidate(): mRenderCost(0)  
     369        {}; 
     370 
     371        int Type() const { return OSP_CANDIDATE; }  
     372 
     373        VspOspSplitCandidate(const AxisAlignedPlane &plane, const VspOspTraversalData &tData):  
     374        mSplitPlane(plane), mParentData(tData), mRenderCost(0) 
     375        {} 
     376}; 
     377#endif 
     378 
     379/** View Space Partitioning tree. 
     380*/ 
     381class VspTree  
    337382{ 
    338383        friend class ViewCellsParseHandlers; 
    339         friend class VspVspViewCellsManager; 
     384        friend class HierarchyManager; 
    340385 
    341386public: 
     
    343388        /** Additional data which is passed down the BSP tree during traversal. 
    344389        */ 
    345         class VspOspTraversalData 
     390        class VspTraversalData 
    346391        {   
    347392        public: 
     
    374419 
    375420 
    376                 VspOspTraversalData(): 
     421                VspTraversalData(): 
    377422                mNode(NULL), 
    378423                mDepth(0), 
     
    385430                {} 
    386431                 
    387                 VspOspTraversalData(VspNode *node,  
    388                                                         const int depth,  
    389                                                         RayInfoContainer *rays, 
    390                                                         const int pvs, 
    391                                                         const float p, 
    392                                                         const AxisAlignedBox3 &box):  
     432                VspTraversalData(VspNode *node,  
     433                                                 const int depth,  
     434                                                 RayInfoContainer *rays, 
     435                                                 const int pvs, 
     436                                                 const float p, 
     437                                                 const AxisAlignedBox3 &box): 
    393438                mNode(node),  
    394439                mDepth(depth),  
     
    402447                {} 
    403448 
    404                 VspOspTraversalData(PolygonContainer *polys,  
    405                                                         const int depth,  
    406                                                         RayInfoContainer *rays, 
    407                                                         const AxisAlignedBox3 &box):  
     449                VspTraversalData(const int depth,  
     450                                                 RayInfoContainer *rays, 
     451                                                 const AxisAlignedBox3 &box):  
    408452                mNode(NULL),  
    409453                mDepth(depth),  
     
    430474                } 
    431475 
    432                 friend bool operator<(const VspOspTraversalData &a, const VspOspTraversalData &b) 
     476                friend bool operator<(const VspTraversalData &a, const VspTraversalData &b) 
    433477                { 
    434478                        return a.GetCost() < b.GetCost(); 
    435479                } 
    436480    }; 
    437          
     481 
     482        /** Candidate for a view space split. 
     483        */ 
     484        class VspSplitCandidate: public SplitCandidate 
     485        {   
     486        public: 
     487                /// parent data 
     488                VspTraversalData mParentData; 
     489                 
     490                VspSplitCandidate() 
     491                {}; 
     492 
     493                int Type() const { return VIEW_SPACE; } 
     494 
     495                VspSplitCandidate(const AxisAlignedPlane &plane, const VspTraversalData &tData):  
     496                SplitCandidate(plane), mParentData(tData) 
     497                {} 
     498        }; 
    438499 
    439500        /** Struct for traversing line segment. 
     
    451512        }; 
    452513 
    453         typedef std::priority_queue<VspOspTraversalData> VspOspTraversalQueue; 
    454          
    455         /** candidate for a view space split 
    456         */ 
    457         struct VspOspSplitCandidate 
    458         {   
    459                 /// the current plane 
    460                 AxisAlignedPlane mSplitPlane; 
    461                 /// the number of misses of max cost ratio until this split 
    462                 int mMaxCostMisses; 
    463                 /// parent data 
    464                 VspOspTraversalData mParentData; 
    465                 /// cost of applying this split 
    466                 float mRenderCost; 
    467  
    468                 VspOspSplitCandidate(): mRenderCost(0)  
    469                 {}; 
    470  
    471                 VspOspSplitCandidate(const AxisAlignedPlane &plane, const VspOspTraversalData &tData):  
    472                 mSplitPlane(plane), mParentData(tData), mRenderCost(0) 
    473                 {} 
    474  
    475                 /** Returns cost of the traversal data. 
    476                 */ 
    477                 float GetCost() const 
    478                 { 
    479 #if 1 
    480                         return mRenderCost; 
    481 #else 
    482                         return (float) (-mDepth); // for kd tree 
    483 #endif 
    484                 } 
    485  
    486                 friend bool operator<(const VspOspSplitCandidate &a, const VspOspSplitCandidate &b) 
    487                 { 
    488                         return a.GetCost() < b.GetCost(); 
    489                 } 
    490     }; 
    491  
    492         typedef std::priority_queue<VspOspSplitCandidate> VspOspSplitQueue; 
     514        //typedef std::priority_queue<VspTraversalData> VspOspTraversalQueue; 
    493515 
    494516        /** Default constructor creating an empty tree. 
    495517        */  
    496         VspOspTree(); 
     518        VspTree(); 
    497519 
    498520        /** Default destructor. 
    499521        */ 
    500         ~VspOspTree(); 
     522        ~VspTree(); 
    501523 
    502524        /** Returns BSP Tree statistics. 
     
    510532        /** Constructs the tree from a given set of rays. 
    511533                @param sampleRays the set of sample rays the construction is based on 
    512                 @param viewCells if not NULL, new view cells are  
    513                 created in the leafs and stored in the container 
     534                @param forcedBoundingBox a given bounding box is taken as view space 
    514535        */ 
    515536        void Construct(const VssRayContainer &sampleRays, 
     
    519540                a certain threshold. 
    520541                @param onlyUnmailed if only the unmailed leaves should be considered 
    521                 @param maxPvs the maximal pvs (-1 means unlimited) 
     542                @param maxPvs the maximal pvs of a leaf to be added (-1 means unlimited) 
    522543        */ 
    523544        void CollectLeaves(vector<VspLeaf *> &leaves,  
     
    638659                                                                ViewCellContainer &viewCells) const; 
    639660 
    640         // pointer to the hierarchy of view cells 
     661        /// pointer to the hierarchy of view cells 
    641662        ViewCellsTree *mViewCellsTree; 
    642663 
     
    673694        /** faster evaluation of split plane cost for kd axis aligned cells. 
    674695        */ 
    675         float EvalSplitCost(const VspOspTraversalData &data, 
     696        float EvalSplitCost(const VspTraversalData &data, 
    676697                                                const AxisAlignedBox3 &box, 
    677698                                                const int axis, 
     
    682703        /** Evaluates candidate for splitting. 
    683704        */ 
    684         void EvalSplitCandidate(VspOspTraversalData &tData, VspOspSplitCandidate &splitData); 
     705        void EvalSplitCandidate(VspTraversalData &tData, VspSplitCandidate &splitData); 
    685706 
    686707        /** Computes priority of the traversal data and stores it in tData. 
    687708        */ 
    688         void EvalPriority(VspOspTraversalData &tData) const; 
     709        void EvalPriority(VspTraversalData &tData) const; 
    689710 
    690711        /** Evaluates render cost decrease of next split. 
    691712        */ 
    692713        float EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
    693                                                                  const VspOspTraversalData &data) const; 
     714                                                                 const VspTraversalData &data) const; 
    694715 
    695716        /** Constructs tree using the split priority queue. 
     
    724745        /** Evaluates tree stats in the BSP tree leafs. 
    725746        */ 
    726         void EvaluateLeafStats(const VspOspTraversalData &data); 
     747        void EvaluateLeafStats(const VspTraversalData &data); 
    727748 
    728749        /** Subdivides node with respect to the traversal data. 
     
    731752                @returns new root of the subtree 
    732753        */ 
    733         VspNode *Subdivide(VspOspSplitQueue &tQueue, 
    734                                            VspOspSplitCandidate &splitCandidate); 
     754        VspNode *Subdivide(SplitQueue &tQueue, 
     755                                           VspSplitCandidate &splitCandidate); 
    735756 
    736757         
     
    750771 
    751772        VspInterior *SubdivideNode(const AxisAlignedPlane &splitPlane, 
    752                                                            VspOspTraversalData &tData, 
    753                                                            VspOspTraversalData &frontData, 
    754                                VspOspTraversalData &backData); 
     773                                                           VspTraversalData &tData, 
     774                                                           VspTraversalData &frontData, 
     775                               VspTraversalData &backData); 
    755776 
    756777        /** Selects an axis aligned for the next split. 
    757778                @returns cost for this split 
    758779        */ 
    759         float SelectPlane(const VspOspTraversalData &tData, 
     780        float SelectPlane(const VspTraversalData &tData, 
    760781                                          AxisAlignedPlane &plane, 
    761782                                          float &pFront, 
     
    815836        /** Returns true if tree can be terminated. 
    816837        */ 
    817         inline bool LocalTerminationCriteriaMet(const VspOspTraversalData &data) const; 
     838        inline bool LocalTerminationCriteriaMet(const VspTraversalData &data) const; 
    818839 
    819840        /** Returns true if global tree can be terminated. 
    820841        */ 
    821         inline bool GlobalTerminationCriteriaMet(const VspOspTraversalData &data) const; 
     842        inline bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const; 
    822843 
    823844        /** Adds ray sample contributions to the PVS. 
     
    951972}; 
    952973 
     974 
     975class KdTree; 
     976 
     977/** This class implements a structure holding two different hierarchies, 
     978        one for object space partitioning and one for view space partitioning. 
     979 
     980        The object space and the view space are subdivided using a cost heuristics. 
     981        If an object space split or a view space split is chosen is also evaluated 
     982        based on the heuristics.  
     983         
     984        The view space heuristics is evaluated by weighting and adding the pvss of the back and 
     985        front node of each specific split. unlike for the standalone method vspbsp tree, 
     986        the pvs of an object would not be the pvs of single object but that of all objects 
     987        which are contained in the same leaf of the object subdivision. This could be done 
     988        by storing the pointer to the object space partition parent, which would allow access to all children. 
     989        Another possibility is to include traced kd-cells in the ray casing process. 
     990 
     991        Accordingly, the object space heuristics is evaluated by storing a pvs of view cells with each object. 
     992        the contribution to an object to the pvs is the number of view cells it can be seen from. 
     993 
     994        @note 
     995        There is a potential efficiency problem involved in a sense that once a certain type 
     996        of split is chosen for view space / object space, the candidates for the next split of  
     997        object space / view space must be reevaluated. 
     998         
     999*/ 
     1000class HierarchyManager 
     1001{ 
     1002        /** Default constructor. 
     1003        */ 
     1004        HierarchyManager(); 
     1005 
     1006        /** Constructs the view space and object space subdivision from a given set of rays 
     1007                and a set of objects. 
     1008                @param sampleRays the set of sample rays the construction is based on 
     1009                @param objects the set of objects 
     1010        */ 
     1011        void Construct(const VssRayContainer &sampleRays, 
     1012                                   const ObjectContainer &objects, 
     1013                                   AxisAlignedBox3 *forcedBoundingBox); 
     1014 
     1015public: 
     1016        VspTree *mVspTree; 
     1017        KdTree *mKdTree; 
     1018 
     1019protected: 
     1020 
     1021        void Construct(RayInfoContainer *rays); 
     1022        void PrepareTraversal(); 
     1023        bool FinishedConstruction(); 
     1024        SplitCandidate *NextSplitCandidate(); 
     1025 
     1026 
     1027 
     1028        AxisAlignedBox3 mBoundingBox; 
     1029 
     1030        SplitQueue mTQueue; 
     1031 
     1032        //-- global criteria 
     1033        float mTermMinGlobalCostRatio; 
     1034        int mTermGlobalCostMissTolerance; 
     1035        int mGlobalCostMisses; 
     1036 
     1037        /// keeps track of cost during subdivision 
     1038        float mTotalCost; 
     1039}; 
     1040 
    9531041} 
    9541042 
Note: See TracChangeset for help on using the changeset viewer.