Changeset 1576 for GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
- Timestamp:
- 10/05/06 18:51:15 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1571 r1576 616 616 void VspTree::CreateViewCell(VspTraversalData &tData, const bool updatePvs) 617 617 { 618 /////////////// 618 619 //-- create new view cell 619 VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode);620 VspLeaf *leaf = tData.mNode; 620 621 621 622 VspViewCell *viewCell = new VspViewCell(); … … 627 628 if (updatePvs) 628 629 { 629 // --update pvs of view cell630 // update pvs of view cell 630 631 AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 631 632 … … 642 643 /////////// 643 644 //-- store sampling rays 644 645 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 645 646 646 647 for (it = tData.mRays->begin(); it != it_end; ++ it) 647 648 { 648 649 (*it).mRay->Ref(); 650 // note: should rather store rays with view cell 649 651 leaf->mVssRays.push_back((*it).mRay); 650 652 } … … 689 691 // create new interior node and two leaf node 690 692 const AxisAlignedPlane splitPlane = sc->mSplitPlane; 691 const int maxCostMisses = sc-> mMaxCostMisses;693 const int maxCostMisses = sc->GetMaxCostMisses(); 692 694 693 695 newNode = SubdivideNode(splitPlane, tData, tFrontData, tBackData); … … 788 790 789 791 // max cost threshold violated? 790 splitCandidate. mMaxCostMisses =maxCostRatioViolated ?792 splitCandidate.SetMaxCostMisses(maxCostRatioViolated ? 791 793 splitCandidate.mParentData.mMaxCostMisses + 1: 792 splitCandidate.mParentData.mMaxCostMisses ;794 splitCandidate.mParentData.mMaxCostMisses); 793 795 794 796 float oldRenderCost; … … 800 802 801 803 splitCandidate.SetRenderCostDecrease(renderCostDecr); 804 805 // the increase in pvs entries num induced by this split 806 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate); 807 splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 802 808 803 809 #if 0 … … 814 820 815 821 822 int VspTree::EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate) const 823 { 824 float oldPvsSize = 0; 825 float fPvsSize = 0; 826 float bPvsSize = 0; 827 828 AxisAlignedPlane candidatePlane = splitCandidate.mSplitPlane; 829 RayInfoContainer::const_iterator rit, 830 rit_end = splitCandidate.mParentData.mRays->end(); 831 832 // this is the main ray classification loop! 833 for(rit = splitCandidate.mParentData.mRays->begin(); rit != rit_end; ++ rit) 834 { 835 VssRay *ray = (*rit).mRay; 836 RayInfo rayInf = *rit; 837 838 float t; 839 // classify ray 840 const int cf = 841 rayInf.ComputeRayIntersection(candidatePlane.mAxis, 842 candidatePlane.mPosition, t); 843 844 UpdatePvsEntriesContribution(*ray, true, cf, fPvsSize, bPvsSize, oldPvsSize); 845 } 846 847 return (int)(fPvsSize + bPvsSize - oldPvsSize); 848 } 849 850 816 851 VspInterior *VspTree::SubdivideNode(const AxisAlignedPlane &splitPlane, 817 852 VspTraversalData &tData, … … 836 871 *backData.mRays); 837 872 838 /////////////839 873 //-- compute pvs 840 874 frontData.mPvs = EvalPvsSize(*frontData.mRays); 841 875 backData.mPvs = EvalPvsSize(*backData.mRays); 842 //Debug << "f pvs: " << frontData.mPvs << " b pvs: " << backData.mPvs << " pvs " << tData.mPvs << endl; 843 876 844 877 //-- split front and back node geometry and compute area 845 878 tData.mBoundingBox.Split(splitPlane.mAxis, … … 851 884 backData.mProbability = tData.mProbability - frontData.mProbability; 852 885 853 // update some stats 854 // store maximal depth 886 887 //////// 888 //-- update some stats 889 855 890 if (tData.mDepth > mVspStats.maxDepth) 856 { 857 //Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 891 { //Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 858 892 mVspStats.maxDepth = tData.mDepth; 859 893 } 860 894 861 // two more leaves 895 // two more leaves per split 862 896 mVspStats.nodes += 2; 863 897 /// and a new split … … 865 899 866 900 867 ///////////////////////901 //////////////// 868 902 //-- create front and back and subdivide further 869 903 … … 902 936 CreateViewCell(frontData, false); 903 937 CreateViewCell(backData, false); 904 905 938 906 939 #if WORK_WITH_VIEWCELL_PVS … … 1436 1469 // mark objects in the front / back / both using mailboxing 1437 1470 // then count pvs sizes 1471 1438 1472 Intersectable::NewMail(3); 1439 1473 KdLeaf::NewMail(3); … … 1497 1531 << "render cost decrease: " << renderCostDecrease << endl; 1498 1532 #endif 1533 1499 1534 return renderCostDecrease; 1500 1535 } … … 1519 1554 1520 1555 const int pvsSize = data.mPvs; 1521 1522 1556 RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); 1523 1557 … … 1535 1569 } 1536 1570 1537 1571 ////////////// 1538 1572 //-- evaluate cost heuristics 1539 1540 1573 float pOverall = data.mProbability; 1541 1574 … … 1555 1588 1556 1589 1557 void VspTree::UpdateContributionsToPvs(Intersectable *obj,1558 const int cf,1559 float &frontPvs,1560 float &backPvs,1561 float &totalPvs) const1562 {1563 if (!obj) return;1564 1565 //const float renderCost = mViewCellsManager->SimpleRay &raynderCost(obj);1566 const int renderCost = 1;1567 1568 // object in no pvs => new1569 if (!obj->Mailed() && !obj->Mailed(1) && !obj->Mailed(2))1570 {1571 totalPvs += renderCost;1572 }1573 1574 // QUESTION matt: is it safe to assume that1575 // the object belongs to no pvs in this case?1576 //if (cf == Ray::COINCIDENT) return;1577 1578 if (cf >= 0) // front pvs1579 {1580 if (!obj->Mailed() && !obj->Mailed(2))1581 {1582 frontPvs += renderCost;1583 1584 // already in back pvs => in both pvss1585 if (obj->Mailed(1))1586 obj->Mail(2);1587 else1588 obj->Mail();1589 }1590 }1591 1592 if (cf <= 0) // back pvs1593 {1594 if (!obj->Mailed(1) && !obj->Mailed(2))1595 {1596 backPvs += renderCost;1597 1598 // already in front pvs => in both pvss1599 if (obj->Mailed())1600 obj->Mail(2);1601 else1602 obj->Mail(1);1603 }1604 }1605 }1606 1607 1608 1590 void VspTree::UpdateContributionsToPvs(BvhLeaf *leaf, 1609 1591 const int cf, 1610 1592 float &frontPvs, 1611 1593 float &backPvs, 1612 float &totalPvs) const 1594 float &totalPvs, 1595 const bool countEntries) const 1613 1596 { 1614 1597 if (!leaf) return; 1615 1616 const int renderCost = (int)leaf->mObjects.size(); 1598 const int renderCost = countEntries ? 1 : (int)leaf->mObjects.size(); 1617 1599 1618 1600 // leaf in no pvs => new … … 1621 1603 totalPvs += renderCost; 1622 1604 } 1623 1624 // QUESTION matt: is it safe to assume that1625 // the leaf belongs to no pvs in this case?1626 //if (cf == Ray::COINCIDENT) return;1627 1605 1628 1606 if (cf >= 0) // front pvs … … 1684 1662 } 1685 1663 1686 // QUESTION matt: is it safe to assume that1687 // the object belongs to no pvs in this case?1688 //if (cf == Ray::COINCIDENT) return;1689 1690 1664 if (cf >= 0) // front pvs 1691 1665 { … … 2146 2120 2147 2121 2122 int VspTree::EvalPvsEntriesContribution(const VssRay &ray, 2123 const bool isTermination) const 2124 2125 { 2126 Intersectable *obj; 2127 Vector3 pt; 2128 KdNode *node; 2129 2130 ray.GetSampleData(isTermination, pt, &obj, &node); 2131 if (!obj) return 0; 2132 2133 switch(mHierarchyManager->GetObjectSpaceSubdivisionType()) 2134 { 2135 case HierarchyManager::NO_OBJ_SUBDIV: 2136 { 2137 if (!obj->Mailed()) 2138 { 2139 obj->Mail(); 2140 return 1; 2141 } 2142 2143 return 0; 2144 } 2145 2146 case HierarchyManager::KD_BASED_OBJ_SUBDIV: 2147 { 2148 KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 2149 if (!leaf->Mailed()) 2150 { 2151 leaf->Mail(); 2152 return 1; 2153 } 2154 2155 return 0; 2156 } 2157 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 2158 { 2159 BvhLeaf *bvhleaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 2160 2161 if (!bvhleaf->Mailed()) 2162 { 2163 bvhleaf->Mail(); 2164 return 1; 2165 } 2166 2167 return 0; 2168 } 2169 default: 2170 break; 2171 } 2172 2173 return 0; 2174 } 2175 2176 2177 int VspTree::EvalPvsEntriesSize(const RayInfoContainer &rays) const 2178 { 2179 int pvsSize = 0; 2180 2181 Intersectable::NewMail(); 2182 KdNode::NewMail(); 2183 BvhLeaf::NewMail(); 2184 2185 RayInfoContainer::const_iterator rit, rit_end = rays.end(); 2186 2187 for (rit = rays.begin(); rit != rays.end(); ++ rit) 2188 { 2189 VssRay *ray = (*rit).mRay; 2190 2191 pvsSize += EvalPvsEntriesContribution(*ray, true); 2192 pvsSize += EvalPvsEntriesContribution(*ray, false); 2193 } 2194 2195 return pvsSize; 2196 } 2197 2198 2148 2199 float VspTree::GetEpsilon() const 2149 2200 { … … 2991 3042 2992 3043 2993 int VspTree::EvalContributionToPvs(const VssRay &ray, 2994 const bool isTermination) const 3044 void VspTree::UpdatePvsEntriesContribution(const VssRay &ray, 3045 const bool isTermination, 3046 const int cf, 3047 float &frontPvs, 3048 float &backPvs, 3049 float &totalPvs) const 3050 { 3051 /*ray.GetSampleData(isTermination, pt, &obj, &node); 3052 if (!obj) return 0; 3053 3054 switch (mHierarchyManager->GetObjectSpaceSubdivisionType()) 3055 { 3056 case HierarchyManager::KD_BASED_OBJ_SUBDIV: 3057 // TODO 3058 break; 3059 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 3060 { 3061 BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 3062 UpdateContributionsToPvs(leaf, true, cf, pvsFront, pvsBack, totalPvs, true); 3063 break; 3064 } 3065 default: 3066 UpdateContributionsToPvs(obj, true, cf, pvsFront, pvsBack, totalPvs, true); 3067 break; 3068 }*/ 3069 } 3070 3071 3072 int VspTree::EvalContributionToPvs(const VssRay &ray, const bool isTermination) const 2995 3073 { 2996 3074 Intersectable *obj; … … 3018 3096 { 3019 3097 KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 3020 3021 3098 pvs += EvalContributionToPvs(leaf); 3022 3099 break; … … 3048 3125 leaf->Mail(); 3049 3126 3127 // this is the pvs which is uniquely part of this kd leaf 3050 3128 int pvs = (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 3051 3129
Note: See TracChangeset
for help on using the changeset viewer.