Changeset 1176 for GTP/trunk/Lib/Vis
- Timestamp:
- 08/02/06 09:09:03 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1174 r1176 45 45 }; 46 46 47 Intersectable(): mMailbox(0), mReferences(0) {}47 Intersectable(): mMailbox(0), mReferences(0) {} 48 48 49 49 void SetId(const int id) { mId = id; } … … 62 62 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 63 63 64 int IncMail() { return ++ mMailbox - sMailId; }64 int IncMail() { return ++ mMailbox - sMailId; } 65 65 66 66 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1144 r1176 12 12 namespace GtpVisibilityPreprocessor { 13 13 14 int KdNode::mailID = 1; 15 16 KdNode::KdNode(KdInterior *parent):mParent(parent), mailbox(0) 14 int KdNode::sMailId = 1; 15 int KdNode::sReservedMailboxes = 1; 16 17 KdNode::KdNode(KdInterior *parent):mParent(parent), mMailbox(0) 17 18 { 18 19 if (parent) -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1144 r1176 64 64 65 65 int Nodes() const {return nodes;} 66 int Interior() const { return nodes /2; }67 int Leaves() const { return (nodes /2) + 1; }66 int Interior() const { return nodes / 2; } 67 int Leaves() const { return (nodes / 2) + 1; } 68 68 69 69 void Reset() { … … 95 95 class KdNode { 96 96 public: 97 static int mailID; 98 int mailbox; 99 100 void Mail() { mailbox = mailID; } 101 static void NewMail() { mailID++; } 102 bool Mailed() const { return mailbox == mailID; } 97 98 static int sMailId; 99 static int sReservedMailboxes; 100 int mMailbox; 101 102 void Mail() { mMailbox = sMailId; } 103 //static void NewMail() { sMailId ++; } 104 bool Mailed() const { return mMailbox == sMailId; } 105 106 static void NewMail(const int reserve = 1) { 107 sMailId += sReservedMailboxes; 108 sReservedMailboxes = reserve; 109 } 110 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 111 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 103 112 104 113 virtual ~KdNode(){}; -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
r1168 r1176 22 22 23 23 Intersectable::NewMail(); 24 Kd Node::NewMail();24 KdLeaf::NewMail(); 25 25 26 26 ObjectPvsMap::const_iterator it, it_end = mEntries.end(); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1174 r1176 3547 3547 while (node->mParent && node->mDepth > mKdPvsDepth) 3548 3548 node = node->mParent; 3549 3549 3550 return node; 3550 3551 } … … 3810 3811 } 3811 3812 3812 if (0) // export merged view cells using pvs coding 3813 { 3814 mColorCode = 1; 3815 3813 if (0) 3814 { 3815 mColorCode = 1; // export merged view cells using pvs coding 3816 3816 Exporter *exporter = Exporter::GetExporter("merged_view_cells_pvs.wrl"); 3817 3817 3818 3818 cout << "exporting view cells after merge (pvs size) ... "; 3819 3819 … … 4886 4886 long startTime; 4887 4887 4888 if (!mOspTree->GetRoot()) 4889 { 4890 Debug << "constructing vsp and osp tree" << endl; 4891 //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 4892 mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); 4893 } 4894 else // just build view space partition tree 4895 { 4896 Debug << "constructing only vsp tree" << endl; 4897 mHierarchyManager->Construct3(constructionRays, objects, &mViewSpaceBox); 4898 } 4888 //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 4889 mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); 4890 4899 4891 4900 4892 // print subdivision statistics … … 5689 5681 if (!mStoreKdPvs) 5690 5682 { 5691 viewcell->AddPvsSample(ray.mTerminationObject, ray.mPdf, ray.mRelativePvsContribution); 5683 viewcell->AddPvsSample(ray.mTerminationObject, 5684 ray.mPdf, ray.mRelativePvsContribution); 5692 5685 } 5693 5686 else -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1174 r1176 370 370 371 371 372 /************************************************************************* *****/373 /* class VspTree implementation 374 /************************************************************************* *****/372 /*************************************************************************/ 373 /* class VspTree implementation */ 374 /*************************************************************************/ 375 375 376 376 … … 642 642 643 643 AddSubdivisionStats(mVspStats.Leaves(), 644 -costDecr,644 costDecr, 645 645 mTotalCost, 646 646 (float)mTotalPvsSize / (float)mVspStats.Leaves()); … … 887 887 888 888 return interior; 889 }890 891 892 KdNode *VspTree::GetKdNode(VssRay &ray, const bool termination) const893 {894 if (termination)895 {896 if (!ray.mTerminationNode)897 {898 ray.mTerminationNode = mOspTree->GetRoot();899 }900 901 ray.mTerminationNode =902 mOspTree->GetLeaf(ray.mTermination, ray.mTerminationNode);903 904 return ray.mTerminationNode;905 }906 else907 {908 if (!ray.mOriginNode)909 {910 ray.mOriginNode = mOspTree->GetRoot();911 }912 913 ray.mOriginNode =914 mOspTree->GetLeaf(ray.mOrigin, ray.mOriginNode);915 916 return ray.mOriginNode;917 }918 889 } 919 890 … … 1045 1016 { 1046 1017 // potentially visible kd cells 1047 if (mUseKdPvsForHeuristics) 1048 { 1049 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 1050 AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 1051 } 1052 else 1018 if (!mUseKdPvsForHeuristics) // matt TODo: remove storekdpvs!! 1053 1019 { 1054 1020 if (vc->AddPvsSample(obj, ray->mPdf, contribution)) … … 1057 1023 } 1058 1024 } 1025 else 1026 { 1027 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 1028 AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 1029 } 1030 1031 1059 1032 1060 1033 sc += contribution; … … 1208 1181 oObject->Mail(); 1209 1182 oObject->mCounter = 1; 1183 1210 1184 ++ pvsSize; 1211 1185 } … … 1342 1316 } 1343 1317 } 1344 1345 1346 1318 } 1347 1319 … … 1615 1587 // create unique ids for pvs heuristics 1616 1588 Intersectable::NewMail(3); 1617 1589 KdLeaf::NewMail(3); 1590 1618 1591 RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); 1619 1592 … … 1629 1602 candidatePlane.mPosition, t); 1630 1603 1631 // find front and back pvs for origing and termination object 1632 AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 1633 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 1604 if (!mUseKdPvsForHeuristics) 1605 { 1606 // find front and back pvs for origing and termination object 1607 UpdateObjPvsContri(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 1608 UpdateObjPvsContri(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 1609 } 1610 else 1611 { 1612 if (ray->mTerminationObject) 1613 { 1614 KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 1615 UpdateKdLeafPvsContri(leaf, cf, pvsFront, pvsBack, totalPvs); 1616 } 1617 1618 if (ray->mOriginObject) 1619 { 1620 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 1621 UpdateKdLeafPvsContri(leaf, cf, pvsFront, pvsBack, totalPvs); 1622 } 1623 } 1634 1624 } 1635 1625 … … 1661 1651 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 1662 1652 1663 1664 1653 Debug << "\n==== eval render cost decrease ===" << endl 1665 1654 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl … … 1697 1686 const int side = (*rit).ComputeRayIntersection(axis, position, t); 1698 1687 1699 AddObjToPvs((*rit).mRay->mTerminationObject, side, pvsFront, pvsBack, pvsTotal);1700 AddObjToPvs((*rit).mRay->mOriginObject, side, pvsFront, pvsBack, pvsTotal);1688 UpdateObjPvsContri((*rit).mRay->mTerminationObject, side, pvsFront, pvsBack, pvsTotal); 1689 UpdateObjPvsContri((*rit).mRay->mOriginObject, side, pvsFront, pvsBack, pvsTotal); 1701 1690 } 1702 1691 … … 1721 1710 1722 1711 1723 void VspTree:: AddObjToPvs(Intersectable *obj,1712 void VspTree::UpdateObjPvsContri(Intersectable *obj, 1724 1713 const int cf, 1725 1714 float &frontPvs, … … 1727 1716 float &totalPvs) const 1728 1717 { 1729 if (!obj) 1730 return; 1718 if (!obj) return; 1731 1719 1732 1720 //const float renderCost = mViewCellsManager->SimpleRay &raynderCost(obj); … … 1773 1761 1774 1762 1763 void VspTree::UpdateKdLeafPvsContri(KdLeaf *leaf, 1764 const int cf, 1765 float &frontPvs, 1766 float &backPvs, 1767 float &totalPvs) const 1768 { 1769 if (!leaf) return; 1770 1771 // the objects which are referenced in this and only this leaf 1772 const int contri = (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 1773 1774 // newly found leaf 1775 if (!leaf->Mailed() && !leaf->Mailed(1) && !leaf->Mailed(2)) 1776 { 1777 totalPvs += contri; 1778 } 1779 1780 // compute contribution of yet unclassified objects 1781 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 1782 1783 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 1784 { 1785 UpdateObjPvsContri(*oit, cf, frontPvs, backPvs, totalPvs); 1786 } 1787 1788 // QUESTION matt: is it safe to assume that 1789 // the object belongs to no pvs in this case? 1790 //if (cf == Ray::COINCIDENT) return; 1791 1792 if (cf >= 0) // front pvs 1793 { 1794 if (!leaf->Mailed() && !leaf->Mailed(2)) 1795 { 1796 frontPvs += contri; 1797 1798 // already in back pvs => in both pvss 1799 if (leaf->Mailed(1)) 1800 leaf->Mail(2); 1801 else 1802 leaf->Mail(); 1803 } 1804 } 1805 1806 if (cf <= 0) // back pvs 1807 { 1808 if (!leaf->Mailed(1) && !leaf->Mailed(2)) 1809 { 1810 backPvs += contri; 1811 1812 // already in front pvs => in both pvss 1813 if (leaf->Mailed()) 1814 leaf->Mail(2); 1815 else 1816 leaf->Mail(1); 1817 } 1818 } 1819 } 1820 1821 1775 1822 void VspTree::CollectLeaves(vector<VspLeaf *> &leaves, 1776 1777 1823 const bool onlyUnmailed, 1824 const int maxPvsSize) const 1778 1825 { 1779 1826 stack<VspNode *> nodeStack; … … 2219 2266 { 2220 2267 int pvsSize = 0; 2268 Intersectable::NewMail(); 2221 2269 2222 2270 RayInfoContainer::const_iterator rit, rit_end = rays.end(); 2223 2271 2224 Intersectable::NewMail(); 2225 2226 for (rit = rays.begin(); rit != rays.end(); ++ rit) 2227 { 2228 VssRay *ray = (*rit).mRay; 2229 2230 if (ray->mOriginObject) 2231 { 2232 if (!ray->mOriginObject->Mailed()) 2233 { 2234 ray->mOriginObject->Mail(); 2235 ++ pvsSize; 2236 } 2237 } 2238 if (ray->mTerminationObject) 2239 { 2240 if (!ray->mTerminationObject->Mailed()) 2241 { 2242 ray->mTerminationObject->Mail(); 2243 ++ pvsSize; 2272 if (!mUseKdPvsForHeuristics) 2273 { 2274 for (rit = rays.begin(); rit != rays.end(); ++ rit) 2275 { 2276 VssRay *ray = (*rit).mRay; 2277 2278 if (ray->mOriginObject) 2279 { 2280 if (!ray->mOriginObject->Mailed()) 2281 { 2282 ray->mOriginObject->Mail(); 2283 ++ pvsSize; 2284 } 2285 } 2286 if (ray->mTerminationObject) 2287 { 2288 if (!ray->mTerminationObject->Mailed()) 2289 { 2290 ray->mTerminationObject->Mail(); 2291 ++ pvsSize; 2292 } 2293 } 2294 } 2295 } 2296 else 2297 { 2298 KdNode::NewMail(); 2299 2300 for (rit = rays.begin(); rit != rays.end(); ++ rit) 2301 { 2302 VssRay *ray = (*rit).mRay; 2303 2304 if (ray->mTerminationObject) 2305 { 2306 KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 2307 2308 if (!leaf->Mailed()) 2309 { 2310 leaf->Mail(); 2311 pvsSize += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 2312 2313 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 2314 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 2315 { 2316 Intersectable *obj = *oit; 2317 2318 if (!obj->Mailed()) 2319 { 2320 obj->Mail(); 2321 ++ pvsSize; 2322 } 2323 } 2324 } 2325 } 2326 2327 if (ray->mOriginObject) 2328 { 2329 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 2330 2331 if (!leaf->Mailed()) 2332 { 2333 leaf->Mail(); 2334 pvsSize += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 2335 2336 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 2337 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 2338 { 2339 Intersectable *obj = *oit; 2340 2341 if (!obj->Mailed()) 2342 { 2343 obj->Mail(); 2344 ++ pvsSize; 2345 } 2346 } 2347 } 2244 2348 } 2245 2349 } … … 2763 2867 2764 2868 2765 void VspTree::Pr ocessRays(const VssRayContainer &sampleRays,2766 2869 void VspTree::PreprocessRays(const VssRayContainer &sampleRays, 2870 RayInfoContainer &rays) 2767 2871 { 2768 2872 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); … … 2841 2945 } 2842 2946 2843 // if not using kd tree root 2947 // if not using kd tree root, delete tree (otherwise mKdTree has to do the job) 2844 2948 if (!mCopyFromKdTree) 2845 2949 DEL_PTR(mRoot); 2950 2951 mSubdivisionStats.close(); 2846 2952 } 2847 2953 … … 2927 3033 Intersectable *object = *oit; 2928 3034 2929 // initialise 3035 // initialise leaf references of objects 2930 3036 if (parent->IsRoot()) 2931 3037 object->mReferences = 1; … … 3296 3402 3297 3403 //-- traverse through events and find best split plane 3298 3299 3404 vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 3300 3405 … … 3306 3411 *ci, 3307 3412 voll, volr, 3308 pvsl, pvsr ,3309 vcl, vcr);3413 pvsl, pvsr 3414 ); 3310 3415 3311 3416 // Note: sufficient to compare size of bounding boxes of front and back side? … … 3313 3418 if (((*ci).mPos >= minBand) && ((*ci).mPos <= maxBand)) 3314 3419 { 3315 sum = voll * pvsl + volr * pvsr; 3420 // voll = view cells that see only left node (i.e., left pvs) 3421 // volr = view cells that see only right node (i.e., right pvs) 3422 // rest = view cells that see both nodes (i.e., total pvs) 3423 sum = voll * pvsl + volr * pvsr + (totalVol - voll - volr) * totalPvs; 3316 3424 3317 3425 float currentPos; 3318 3426 3319 3427 // HACK: current positition is BETWEEN visibility events 3320 if ( 0&& ((ci + 1) != ci_end))3428 if (1 && ((ci + 1) != ci_end)) 3321 3429 currentPos = ((*ci).mPos + (*(ci + 1)).mPos) * 0.5f; 3322 3430 else … … 3349 3457 } 3350 3458 3351 3352 3459 //-- compute cost 3353 3354 const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 3355 const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 3356 3357 const float pOverall = totalVol; 3358 const float pBack = volBack; 3359 const float pFront = volFront; 3360 3361 const float penaltyOld = (float)totalPvs; 3362 const float penaltyFront = (float)pvsFront; 3363 const float penaltyBack = (float)pvsBack; 3364 3365 const float oldRenderCost = penaltyOld * pOverall + Limits::Small; 3366 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 3460 const float frontAndBackVol = totalVol - volFront - volBack; 3461 3462 const float oldRenderCost = (float)totalPvs * totalVol + Limits::Small; 3463 const float newRenderCost = 3464 (float)pvsFront * volFront + 3465 (float)pvsBack * volBack + 3466 (float)totalPvs * frontAndBackVol; 3367 3467 3368 3468 … … 3380 3480 Debug << "\n§§§§ eval local cost §§§§" << endl 3381 3481 << "back pvs: " << pvsBack << " front pvs: " << pvsFront << " total pvs: " << totalPvs << endl 3382 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl3482 << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl 3383 3483 << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 3384 3484 << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; … … 3443 3543 ); 3444 3544 } 3545 3546 3547 3445 3548 3446 3549 if (ray->mTerminationObject && (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf)) … … 3572 3675 float &volRight, 3573 3676 int &pvsLeft, 3574 int &pvsRight, 3575 int &viewCellsLeft, 3576 int &viewCellsRight) 3677 int &pvsRight 3678 ) 3577 3679 { 3578 3680 Intersectable *obj = ci.mObject; 3579 3681 VssRay *ray = ci.mRay; 3580 3682 3683 // switch between different types of events 3581 3684 switch (ci.mType) 3582 3685 { … … 3592 3695 // compute volume contribution from view cells 3593 3696 case SortableEntry::BOX_INTERSECT: 3697 // process ray if the hit point with termination / origin object 3698 // is inside this kd leaf 3594 3699 if ((ray->mOriginObject && (GetLeaf(ray->mOrigin, ray->mOriginNode) == leaf)) || 3595 3700 (ray->mTerminationObject && (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf))) 3596 3701 { 3597 EvalVolumeContribution(*ray, volLeft, volRight , viewCellsLeft, viewCellsRight);3702 EvalVolumeContribution(*ray, volLeft, volRight); 3598 3703 } 3599 3704 break; … … 3609 3714 void OspTree::EvalVolumeContribution(const VssRay &ray, 3610 3715 float &volLeft, 3611 float &volRight, 3612 int &viewCellsLeft, 3613 int &viewCellsRight) 3716 float &volRight) 3614 3717 { 3615 3718 ViewCellContainer viewCells; … … 3617 3720 mVspTree->GetViewCells(ray, viewCells); 3618 3721 3722 /// classify view cells and compute volume contri accordingly 3723 /// possible view cell classifications: 3724 /// view cell mailed => view cell can be seen from left child node 3725 /// view cell counter > 0 view cell can be seen from right child node 3726 /// combined: view cell volume belongs to both nodes 3619 3727 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 3620 3728 3621 3729 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 3622 3730 { 3623 // add view cells volume toleft child node3731 // view cells can also be seen from left child node 3624 3732 ViewCell *viewCell = *vit; 3625 3733 3734 const float vol = viewCell->GetVolume(); 3735 3626 3736 if (!viewCell->Mailed()) 3627 3737 { 3628 3738 viewCell->Mail(); 3629 3630 volLeft += viewCell->GetVolume();3631 3632 ++ viewCellsLeft;3633 } 3634 3635 // remove from right childnode3739 3740 // we now see view cell from both nodes 3741 // => remove ref to right child node 3742 volRight -= vol; 3743 } 3744 3745 // last reference into the right node 3636 3746 if (-- viewCell->mCounter == 0) 3637 3747 { 3638 volRight -= viewCell->GetVolume(); 3639 3640 -- viewCellsRight; 3748 #if 0 3749 // view cell was previousy seen from right node only 3750 // => remove from right node (matt: need this?) 3751 if (!viewCell->Mailed()) 3752 volRight -= vol; 3753 else 3754 #endif 3755 // view cell was previously seen from both nodes => 3756 // contributes only to left node now 3757 volLeft += vol; 3641 3758 } 3642 3759 } … … 3753 3870 { 3754 3871 const float costDecr = sc.GetRenderCostDecrease(); 3755 Debug << "**********************$$$$$$$$$$$$$$"<< endl; 3756 Debug << "here78 " << mOspStats.Leaves() << " " << mTotalCost << endl; 3872 3757 3873 AddSubdivisionStats(mOspStats.Leaves(), 3758 3874 costDecr, … … 3766 3882 const float renderCostDecr, 3767 3883 const float totalRenderCost) 3768 //const float avgRenderCost) 3769 {Debug << "here64 " << totalRenderCost << " " << renderCostDecr << endl; 3884 { 3770 3885 mSubdivisionStats 3771 3886 << "#Leaves\n" << leaves << endl … … 3818 3933 float pFront = 0; 3819 3934 float pBack = 0; 3935 float pFrontAndBack = 0; 3936 3820 3937 3821 3938 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); … … 3856 3973 // => the volume is the weight for the render cost equation 3857 3974 ViewCell::NewMail(3); 3858 3975 3859 3976 RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 3977 3978 ViewCellContainer collectedViewCells; 3860 3979 3861 3980 for (rit = tData.mRays->begin(); rit < rit_end; ++ rit) … … 3873 3992 const int classification = ClassifyRay(ray, leaf, candidatePlane); 3874 3993 3875 ViewCellContainer viewCells; 3994 ViewCellContainer viewCells; 3876 3995 mVspTree->GetViewCells(*ray, viewCells); 3877 3996 3878 3997 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 3879 3998 3880 // evaluate view cells volume contribution3999 // mail view cell 3881 4000 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 3882 4001 { 3883 AddViewCellVolume(*vit, classification, pFront, pBack, pOverall); 3884 } 3885 } 4002 ViewCell *vc = *vit; 4003 4004 // if not previously mailed 4005 if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 4006 collectedViewCells.push_back(vc); 4007 4008 MailViewCell(*vit, classification); 4009 } 4010 } 4011 } 4012 4013 // these are non-overlapping sets 4014 pOverall = pFront + pBack + pFrontAndBack; 4015 4016 ViewCellContainer::const_iterator vit, vit_end = collectedViewCells.end(); 4017 4018 // evaluate view cells volume contribution with respect to mail box 4019 for (vit = collectedViewCells.begin(); vit != vit_end; ++ vit) 4020 { 4021 AddViewCellVolumeContri(*vit, pFront, pBack, pFrontAndBack); 3886 4022 } 3887 4023 … … 3889 4025 //-- pvs rendering heuristics 3890 4026 const float oldRenderCost = pOverall * totalPvs; 3891 const float newRenderCost = pvsFront * pFront + pvsBack * pBack ;4027 const float newRenderCost = pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack; 3892 4028 3893 4029 // normalize volume with view space volume 3894 4030 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 3895 4031 3896 Debug << "\n ==== eval render cost decrease ====" << endl4032 Debug << "\n(((( eval render cost decrease ))))" << endl 3897 4033 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 3898 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl 4034 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol 4035 << " front and back p " << pFrontAndBack / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl 3899 4036 << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 3900 4037 << "render cost decrease: " << renderCostDecrease << endl; … … 3902 4039 normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 3903 4040 3904 if (oldRenderCost < newRenderCost )4041 if (oldRenderCost < newRenderCost * 0.99) 3905 4042 Debug << "\nwarning2!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 3906 else 3907 Debug << "here4" << endl; 3908 3909 if (pBack + pFront < pOverall * 0.9) 3910 Debug << "\nwarning3!!:\n" << "p new: " << pBack + pFront << " p old: " << pOverall << endl; 3911 else 3912 Debug << "here55" << endl; 3913 3914 if (pvsBack + pvsFront < totalPvs) 3915 Debug << "\nwarning4!!:\n" << "pvs new: " << pvsBack + pvsFront << " pvs old: " << totalPvs << endl; 3916 else 3917 Debug << "here25" << endl; 3918 4043 3919 4044 return renderCostDecrease; 3920 4045 } … … 4148 4273 4149 4274 4150 void OspTree::Pr ocessRays(const VssRayContainer &sampleRays,4151 4275 void OspTree::PreprocessRays(const VssRayContainer &sampleRays, 4276 RayInfoContainer &rays) 4152 4277 { 4153 4278 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); … … 4177 4302 4178 4303 rays.push_back(RayInfo(ray, minT / len, maxT / len)); 4304 4305 // HACK: reset nodes for the case we have used object kd tree for 4306 // tree building. 4307 ray->mOrigin = NULL; 4308 ray->mTerminationNode = NULL; 4179 4309 } 4180 4310 } … … 4254 4384 4255 4385 4386 /* 4256 4387 void OspTree::AddViewCellVolume(ViewCell *vc, 4257 4388 const int cf, … … 4297 4428 } 4298 4429 } 4430 */ 4431 void OspTree::MailViewCell(ViewCell *vc, const int cf) const 4432 { 4433 if (vc->Mailed(2)) // already classified 4434 return; 4435 4436 if (cf >= 0) // front volume 4437 { 4438 // already in back volume => in both volumes 4439 if (vc->Mailed(1)) 4440 { 4441 vc->Mail(2); 4442 } 4443 else 4444 { 4445 vc->Mail(); 4446 } 4447 } 4448 4449 if (cf <= 0) // back volume 4450 { 4451 // already in front volume => in both volume 4452 if (vc->Mailed()) 4453 { 4454 vc->Mail(2); 4455 } 4456 else 4457 { 4458 vc->Mail(1); 4459 } 4460 } 4461 } 4462 4463 4464 void OspTree::AddViewCellVolumeContri(ViewCell *vc, 4465 float &frontVol, 4466 float &backVol, 4467 float &frontAndBackVol) const 4468 { 4469 if (vc->Mailed()) 4470 frontVol += vc->GetVolume(); 4471 else if (vc->Mailed(1)) 4472 backVol += vc->GetVolume(); 4473 else if (vc->Mailed(2)) 4474 frontAndBackVol += vc->GetVolume(); 4475 } 4476 4299 4477 4300 4478 … … 4346 4524 4347 4525 // get clipped rays 4348 mVspTree.Pr ocessRays(sampleRays, rays);4526 mVspTree.PreprocessRays(sampleRays, rays); 4349 4527 4350 4528 const int pvsSize = mVspTree.ComputePvsSize(rays); … … 4414 4592 4415 4593 // get clipped rays 4416 mOspTree.Pr ocessRays(sampleRays, rays);4594 mOspTree.PreprocessRays(sampleRays, rays); 4417 4595 4418 4596 // add first candidate for view space partition … … 4593 4771 ///////////////////////////////////////////////////////////// 4594 4772 4595 4773 #if 0 4596 4774 // makes no sense otherwise because only one kd cell available 4597 4775 // during view space partition … … 4601 4779 mVspTree.mUseKdPvsForHeuristics = false; 4602 4780 mVspTree.mStoreKdPvs = false; 4781 #endif 4603 4782 4604 4783 VspTree::VspSplitCandidate *vsc = … … 4661 4840 mOspTree.mOspStats.Stop(); 4662 4841 4842 #if 0 4663 4843 // reset parameters 4664 4844 mVspTree.mUseKdPvsForHeuristics = savedCountMethod; 4665 4845 mVspTree.mStoreKdPvs = savedStoreMethod; 4846 #endif 4666 4847 } 4667 4848 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1174 r1176 965 965 RayInfoContainer &backRays) const; 966 966 967 /** Adds the object to the pvs of the front and back leaf with a given classification. 967 /** Classfifies the object with respect to the 968 pvs of the front and back leaf and updates pvs size 969 accordingly. 968 970 969 971 @param obj the object to be added … … 973 975 974 976 */ 975 void AddObjToPvs(Intersectable *obj,977 void UpdateObjPvsContri(Intersectable *obj, 976 978 const int cf, 977 979 float &frontPvs, … … 979 981 float &totalPvs) const; 980 982 983 /** See UpdateObjPvsContri. 984 */ 985 void UpdateKdLeafPvsContri(KdLeaf *leaf, 986 const int cf, 987 float &frontPvs, 988 float &backPvs, 989 float &totalPvs) const; 990 991 981 992 /** Computes PVS size induced by the rays. 982 993 */ … … 1002 1013 */ 1003 1014 void AddSamplesToPvs(VspLeaf *leaf, 1004 const RayInfoContainer &rays, 1005 float &sampleContributions, 1006 int &contributingSamples); 1007 1008 bool AddKdLeafToPvs(KdLeaf *leaf, ViewCell *vc, float &pvs, float &contribution); 1015 const RayInfoContainer &rays, 1016 float &sampleContributions, 1017 int &contributingSamples); 1018 1019 bool AddKdLeafToPvs(KdLeaf *leaf, 1020 ViewCell *vc, 1021 float &pvs, 1022 float &contribution); 1009 1023 1010 1024 /** Propagates valid flag up the tree. … … 1025 1039 float GetMemUsage() const; 1026 1040 1041 /** Updates view cell pvs of objects. 1042 */ 1027 1043 void ProcessViewCellObjects(ViewCell *parent, 1028 1044 ViewCell *front, … … 1031 1047 void CreateViewCell(VspTraversalData &tData, const bool updatePvs); 1032 1048 1049 /** Collect split candidates which are affected by the last split 1050 and must be reevaluated. 1051 */ 1033 1052 void CollectDirtyCandidates(VspSplitCandidate *sc, 1034 1053 vector<SplitCandidate *> &dirtyList); 1035 1054 1036 KdNode *GetKdNode(VssRay &ray, const bool termination) const;1037 1038 void Pr ocessRays(const VssRayContainer &sampleRays,1055 /** Rays will be clipped to the bounding box. 1056 */ 1057 void PreprocessRays(const VssRayContainer &sampleRays, 1039 1058 RayInfoContainer &rays); 1040 1059 1060 /** Evaluate subdivision statistics. 1061 */ 1041 1062 void EvalSubdivisionStats(const SplitCandidate &tData); 1063 1064 1042 1065 protected: 1043 1066 … … 1566 1589 1567 1590 */ 1568 void AddObjToPvs(Intersectable *obj,1591 void UpdateObjPvsContri(Intersectable *obj, 1569 1592 const int cf, 1570 1593 float &frontPvs, … … 1602 1625 float GetMemUsage() const; 1603 1626 1604 /** Evaluates the influence on the pvs of the event. 1627 /** Evaluate the contributions of view cell volume of the left and the right view cell. 1628 */ 1629 void EvalVolumeContribution(const VssRay &ray, 1630 float &volLeft, 1631 float &volRight); 1632 1633 /** Evaluates the influence on the pvs of the event. 1605 1634 @param ve the visibility event 1606 1635 @param pvsLeft updates the left pvs … … 1612 1641 float &volRight, 1613 1642 int &pvsLeft, 1614 int &pvsRight, 1615 int &viewCellsLeft, 1616 int &viewCellsRight); 1617 1618 /** Evaluate the contributions of view cell volume of the left and the right view cell. 1619 */ 1620 void EvalVolumeContribution(const VssRay &ray, 1621 float &volLeft, 1622 float &volRight, 1623 int &viewCellsLeft, 1624 int &viewCellsRight); 1643 int &pvsRight); 1625 1644 1626 1645 /** Prepares objects for the cost heuristics. … … 1646 1665 ViewCellContainer &viewCells); 1647 1666 1648 void ProcessRays(const VssRayContainer &sampleRays, 1667 /** Rays will be clipped to the bounding box. 1668 */ 1669 void PreprocessRays(const VssRayContainer &sampleRays, 1649 1670 RayInfoContainer &rays); 1650 1671 … … 1658 1679 bool EndPointInsideNode(KdLeaf *leaf, VssRay &ray, bool isTermination) const; 1659 1680 1660 void AddViewCellVolume(ViewCell *vc, 1661 const int cf, 1662 float &frontPvs, 1663 float &backPvs, 1664 float &totalPvs) const; 1681 void AddViewCellVolumeContri( 1682 ViewCell *vc, 1683 float &frontVol, 1684 float &backVol, 1685 float &frontAndBackVol) const; 1686 1687 /** Classifies and mail view cell with respect to the heuristics contribution. 1688 Set view cell mail box according to it's influence on 1689 front (0), back (1) and front / back node (2). 1690 */ 1691 void MailViewCell(ViewCell *vc, const int cf) const; 1665 1692 1666 1693 int ClassifyRay(VssRay *ray, KdLeaf *leaf, const AxisAlignedPlane &plane) const; … … 1671 1698 const float renderCostDecr, 1672 1699 const float totalRenderCost); 1700 1701 void EvalViewCellsForHeuristics(const VssRay &ray, 1702 float &volLeft, 1703 float &volRight); 1673 1704 1674 1705 protected:
Note: See TracChangeset
for help on using the changeset viewer.