- Timestamp:
- 03/08/07 13:23:13 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility.env
r2075 r2210 24 24 useGlDebugger false 25 25 # 0 = INTERNAL 1 = MLRT 26 rayCastMethod 026 rayCastMethod 1 27 27 28 28 type combined … … 128 128 importRandomViewCells false 129 129 130 useKdPvs true130 useKdPvs false 131 131 useKdPvsAfterFiltering true 132 132 # samples used for view cell construction -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r2206 r2210 237 237 mRoot(NULL), 238 238 mTimeStamp(1), 239 mIsInitialSubdivision(false), 240 mCachedObjects(NULL) 239 mIsInitialSubdivision(false) 241 240 { 242 241 ReadEnvironment(); … … 394 393 mNodeTimer.Entry(); 395 394 395 /* 396 396 #if STORE_VIEWCELLS_WITH_BVH 397 AssociateViewCellsWithObjects(sc.m FrontObjects);398 AssociateViewCellsWithObjects(sc.m BackObjects);397 AssociateViewCellsWithObjects(sc.mSampledFrontObjects); 398 AssociateViewCellsWithObjects(sc.mSampledBackObjects); 399 399 #endif 400 */ 400 401 const BvhTraversalData &tData = sc.mParentData; 401 402 BvhLeaf *leaf = tData.mNode; … … 451 452 backData.mNode = back; 452 453 454 backData.mSampledObjects = new ObjectContainer(); 455 frontData.mSampledObjects = new ObjectContainer(); 456 457 *backData.mSampledObjects = sc.mSampledBackObjects; 458 *frontData.mSampledObjects = sc.mSampledFrontObjects; 459 453 460 back->mObjects = sc.mBackObjects; 454 461 front->mObjects = sc.mFrontObjects; … … 456 463 // if the number of rays is too low, no assumptions can be made 457 464 // (=> switch to surface area heuristics?) 458 frontData.mNumRays = CountRays(sc.m FrontObjects);459 backData.mNumRays = CountRays(sc.m BackObjects);465 frontData.mNumRays = CountRays(sc.mSampledFrontObjects); 466 backData.mNumRays = CountRays(sc.mSampledBackObjects); 460 467 461 468 AssociateObjectsWithLeaf(back); … … 465 472 //-- compute pvs correction to cope with undersampling 466 473 467 frontData.mPvs = (float) CountViewCells(front->mObjects);468 backData.mPvs = (float) CountViewCells(back->mObjects);474 frontData.mPvs = (float)sc.mNumFrontViewCells;//(float)CountViewCells(sc.mSampledFrontObjects); 475 backData.mPvs = (float)sc.mNumBackViewCells;//(float)CountViewCells(sc.mSampledBackObjects); 469 476 470 477 frontData.mCorrectedPvs = sc.mCorrectedFrontPvs; … … 474 481 // compute probability of this node being visible, 475 482 // i.e., volume of the view cells that can see this node 476 frontData.mVolume = EvalViewCellsVolume(sc.mFrontObjects) / GetViewSpaceVolume();477 backData.mVolume = EvalViewCellsVolume(sc.mBackObjects) / GetViewSpaceVolume();483 frontData.mVolume = sc.mVolumeFrontViewCells;//EvalViewCellsVolume(sc.mSampledFrontObjects) / GetViewSpaceVolume(); 484 backData.mVolume = sc.mVolumeBackViewCells;//EvalViewCellsVolume(sc.mSampledBackObjects) / GetViewSpaceVolume(); 478 485 479 486 frontData.mCorrectedVolume = sc.mCorrectedFrontVolume; … … 493 500 AssignSortedObjects(sc, frontData, backData); 494 501 } 495 502 /* 496 503 #if STORE_VIEWCELLS_WITH_BVH 497 ReleaseViewCells(sc.m FrontObjects);498 ReleaseViewCells(sc.m BackObjects);504 ReleaseViewCells(sc.mSampledFrontObjects); 505 ReleaseViewCells(sc.mSampledBackObjects); 499 506 #endif 500 507 */ 501 508 mNodeTimer.Exit(); 502 509 … … 637 644 #if STORE_VIEWCELLS_WITH_BVH 638 645 // fill view cells cache 639 AssociateViewCellsWithObjects(*splitCandidate.mParentData.mS ortedObjects[3]);646 AssociateViewCellsWithObjects(*splitCandidate.mParentData.mSampledObjects); 640 647 #endif 641 648 642 649 if (computeSplitPlane) 643 650 { 651 splitCandidate.mFrontObjects.clear(); 652 splitCandidate.mBackObjects.clear(); 653 splitCandidate.mSampledFrontObjects.clear(); 654 splitCandidate.mSampledBackObjects.clear(); 655 644 656 const bool sufficientSamples = 645 657 splitCandidate.mParentData.mNumRays > mMinRaysForVisibility; … … 663 675 splitCandidate.SetMaxCostMisses(maxCostRatioViolated ? 664 676 previousMisses + 1 : previousMisses); 665 } 677 678 StoreSampledObjects(splitCandidate.mSampledFrontObjects, splitCandidate.mFrontObjects); 679 StoreSampledObjects(splitCandidate.mSampledBackObjects, splitCandidate.mBackObjects); 680 } 681 666 682 mPlaneTimer.Exit(); 667 683 … … 672 688 673 689 // avg contribution of a ray to a pvs 674 const float pvs = (float)CountViewCells( leaf->mObjects);690 const float pvs = (float)CountViewCells(*tData.mSampledObjects); 675 691 const float avgRayContri = AvgRayContribution((int)pvs, tData.mNumRays); 676 692 … … 679 695 const float viewSpaceVol = GetViewSpaceVolume(); 680 696 681 const float oldVolume = EvalViewCellsVolume( leaf->mObjects) / viewSpaceVol;697 const float oldVolume = EvalViewCellsVolume(*tData.mSampledObjects) / viewSpaceVol; 682 698 const float oldRatio = (tData.mVolume) > 0 ? oldVolume / tData.mVolume : 1; 683 699 const float parentVol = tData.mCorrectedVolume * oldRatio; … … 685 701 // this leaf is a pvs entry in all the view cells 686 702 // that see one of the objects. 687 const float frontVol = EvalViewCellsVolume(splitCandidate.mFrontObjects) / viewSpaceVol; 688 const float backVol = EvalViewCellsVolume(splitCandidate.mBackObjects) / viewSpaceVol; 703 splitCandidate.mVolumeFrontViewCells = EvalViewCellsVolume(splitCandidate.mSampledFrontObjects) / viewSpaceVol; 704 splitCandidate.mVolumeBackViewCells = EvalViewCellsVolume(splitCandidate.mSampledBackObjects) / viewSpaceVol; 705 706 splitCandidate.mNumFrontViewCells = CountViewCells(splitCandidate.mSampledFrontObjects); 707 splitCandidate.mNumBackViewCells = CountViewCells(splitCandidate.mSampledBackObjects); 689 708 690 709 splitCandidate.mCorrectedFrontVolume = 691 mHierarchyManager->EvalCorrectedPvs( frontVol, parentVol, avgRayContri);710 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, parentVol, avgRayContri); 692 711 693 712 splitCandidate.mCorrectedBackVolume = 694 mHierarchyManager->EvalCorrectedPvs( backVol, parentVol, avgRayContri);713 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeBackViewCells, parentVol, avgRayContri); 695 714 696 715 const float relfrontCost = splitCandidate.mCorrectedFrontVolume * … … 707 726 708 727 // increase in pvs entries 709 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, avgRayContri); 728 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, 729 avgRayContri, 730 (int)pvs, 731 splitCandidate.mNumFrontViewCells, 732 splitCandidate.mNumBackViewCells); 733 710 734 splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 711 735 … … 715 739 << " avg ray contri: " << avgRayContri << " ratio: " << oldRatio 716 740 << " parent: " << parentVol << " old vol: " << oldVolume 717 << " frontvol: " << frontVol<< " corr. " << splitCandidate.mCorrectedFrontVolume718 << " backvol: " << backVol<< " corr. " << splitCandidate.mCorrectedBackVolume << endl;741 << " frontvol: " << splitCandidate.mVolumeFrontViewCells << " corr. " << splitCandidate.mCorrectedFrontVolume 742 << " backvol: " << splitCandidate.mVolumeBackViewCells << " corr. " << splitCandidate.mCorrectedBackVolume << endl; 719 743 } 720 744 … … 733 757 734 758 #if STORE_VIEWCELLS_WITH_BVH 735 ReleaseViewCells(*splitCandidate.mParentData.mS ortedObjects[3]);759 ReleaseViewCells(*splitCandidate.mParentData.mSampledObjects); 736 760 #endif 737 761 … … 741 765 742 766 int BvHierarchy::EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate, 743 const float avgRayContri) //const 744 { 745 const float oldPvsSize = (float)CountViewCells(splitCandidate.mParentData.mNode->mObjects); 767 const float avgRayContri, 768 const int numParentViewCells, 769 const int numFrontViewCells, 770 const int numBackViewCells) //const 771 { 772 const float oldPvsSize = (float)numParentViewCells;//CountViewCells(*splitCandidate.mParentData.mSampledObjects); 746 773 const float oldPvsRatio = (splitCandidate.mParentData.mPvs > 0) ? oldPvsSize / splitCandidate.mParentData.mPvs : 1; 747 774 748 775 const float parentPvs = splitCandidate.mParentData.mCorrectedPvs * oldPvsRatio; 749 776 750 const int frontViewCells = CountViewCells(splitCandidate.mFrontObjects);751 const int backViewCells = CountViewCells(splitCandidate.mBackObjects);777 const int frontViewCells = numFrontViewCells;//CountViewCells(splitCandidate.mSampledFrontObjects); 778 const int backViewCells = numBackViewCells;//CountViewCells(splitCandidate.mSampledBackObjects); 752 779 753 780 splitCandidate.mCorrectedFrontPvs = … … 976 1003 const float cost = (tData.mNode->GetBoundingBox().Size().DrivingAxis() == axis) ? -1.0f : 0.0f; 977 1004 #else 978 const float oldRenderCost = Eval RenderCost(tData.mNode->mObjects);1005 const float oldRenderCost = EvalAbsCost(tData.mLeaf->mObjects) / EvalProbability(tData.mSampledObjects); 979 1006 const float newRenderCost = EvalRenderCost(objectsFront) + EvalRenderCost(objectsBack); 980 1007 … … 1196 1223 Intersectable *obj = (*cit).mObject; 1197 1224 1198 const float renderCost = mViewCellsManager->EvalRenderCost(obj);1225 const float renderCost = ViewCellsManager::EvalRenderCost(obj); 1199 1226 1200 1227 objectsLeft += renderCost; … … 1329 1356 float volRight = totalVol; 1330 1357 1331 #if USE_BETTER_RENDERCOST_EST1358 #if 1//USE_BETTER_RENDERCOST_EST 1332 1359 const float nTotalObjects = EvalAbsCost(tData.mNode->mObjects); 1333 1360 float nObjectsLeft = 0; … … 1386 1413 nObjectsLeft += rc; 1387 1414 nObjectsRight -= rc; 1388 1389 // split is only valid if #objects on left and right is not zero 1390 const bool noValidSplit = ((nObjectsLeft <= Limits::Small) || 1391 (nObjectsRight <= Limits::Small)); 1415 1392 1416 #else 1393 1417 ++ nObjectsLeft; 1394 1418 -- nObjectsRight; 1395 1419 #endif 1420 1396 1421 // split is only valid if #objects on left and right is not zero 1397 const bool noValidSplit = !nObjectsLeft || !nObjectsRight; 1398 1399 #endif 1400 1422 const bool noValidSplit = (nObjectsRight <= Limits::Small); 1423 1401 1424 // the heuristics 1402 1425 const float sum = noValidSplit ? … … 1531 1554 1532 1555 1533 CollectViewCells( tData.mNode->mObjects,1556 CollectViewCells(*tData.mSampledObjects, 1534 1557 viewCells, 1535 1558 setCounter, … … 1851 1874 /////////////// 1852 1875 //-- render cost heuristics 1876 const float objRenderCost = EvalAbsCost(objects); 1853 1877 1854 1878 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); … … 1856 1880 // probability that view point lies in a view cell which sees this node 1857 1881 const float p = EvalViewCellsVolume(objects) / viewSpaceVol; 1858 const float objRenderCost = EvalAbsCost(objects);1859 1882 1860 1883 return objRenderCost * p; 1884 } 1885 1886 1887 float BvHierarchy::EvalProbability(const ObjectContainer &objects)// const 1888 { 1889 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1890 1891 // probability that view point lies in a view cell which sees this node 1892 return EvalViewCellsVolume(objects) / viewSpaceVol; 1861 1893 } 1862 1894 … … 1941 1973 1942 1974 1975 int BvHierarchy::CollectViewCells(const ObjectContainer &objects, 1976 ViewCellContainer &viewCells, 1977 const bool setCounter, 1978 const bool onlyUnmailedRays)// const 1979 { 1980 ViewCell::NewMail(); 1981 1982 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1983 1984 // use mailing to avoid dublicates 1985 const bool useMailBoxing = true; 1986 1987 int numRays = 0; 1988 // loop through all object and collect view cell pvs of this node 1989 for (oit = objects.begin(); oit != oit_end; ++ oit) 1990 { 1991 // use mailing to avoid duplicates 1992 numRays += CollectViewCells(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays); 1993 } 1994 1995 return numRays; 1996 } 1997 1943 1998 1944 1999 #if STORE_VIEWCELLS_WITH_BVH … … 1953 2008 (*oit)->DelViewCells(); 1954 2009 } 1955 1956 DEL_PTR(mCachedObjects); 1957 } 1958 1959 1960 void BvHierarchy::AssociateViewCellsWithObjects(const ObjectContainer &objects)// const 2010 } 2011 2012 2013 void BvHierarchy::AssociateViewCellsWithObjects(const ObjectContainer &objects) const 1961 2014 { 1962 2015 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1963 2016 1964 2017 const bool useMailBoxing = true; 1965 1966 mCachedObjects = new ObjectContainer(); 2018 VssRay::NewMail(); 1967 2019 1968 2020 for (oit = objects.begin(); oit != oit_end; ++ oit) 1969 2021 { 1970 if (!(*oit)->GetOrCreateRays()->empty())1971 {1972 2022 ViewCell::NewMail(); 1973 2023 // use mailing to avoid duplicates 1974 2024 AssociateViewCellsWithObject(*oit, useMailBoxing); 1975 1976 mCachedObjects->push_back(*oit);1977 }1978 2025 } 1979 2026 } … … 1982 2029 int BvHierarchy::AssociateViewCellsWithObject(Intersectable *obj, const bool useMailBoxing) const 1983 2030 { 2031 int nRays = 0; 2032 1984 2033 if (!obj->GetOrCreateViewCells()->empty()) 1985 2034 { 1986 cerr << "AssociateViewCellsWithObject: view cells cache error" << endl; 1987 exit(0); 2035 cerr << "AssociateViewCellsWithObject: view cells cache not working" << endl; 1988 2036 } 1989 2037 … … 2001 2049 // continue; 2002 2050 mHierarchyManager->mVspTree->GetViewCells(*ray, *objViewCells); 2003 } 2004 2005 return (int)vssRays->size(); 2051 2052 if (!useMailBoxing || !ray->Mailed()) 2053 { 2054 if (useMailBoxing) 2055 ray->Mail(); 2056 2057 ++ nRays; 2058 } 2059 } 2060 2061 return nRays; 2006 2062 } 2007 2063 … … 2014 2070 if (obj->GetOrCreateViewCells()->empty()) 2015 2071 { 2016 cerr << "h";//CountViewCells: view cells empty, view cells cache not working" << endl;2072 //cerr << "h";//CountViewCells: view cells empty, view cells cache not working" << endl; 2017 2073 return CountViewCellsFromRays(obj); 2018 2074 } … … 2177 2233 } 2178 2234 2179 2180 int BvHierarchy::CollectViewCells(const ObjectContainer &objects,2181 ViewCellContainer &viewCells,2182 const bool setCounter,2183 const bool onlyUnmailedRays)// const2184 {2185 ViewCell::NewMail();2186 2187 // use mailing to avoid dublicates2188 const bool useMailBoxing = true;2189 2190 int numRays = 0;2191 2192 if (mCachedObjects)2193 {2194 ObjectContainer::const_iterator oit, oit_end = mCachedObjects->end();2195 2196 // loop through all object and collect view cell pvs of this node2197 for (oit = mCachedObjects->begin(); oit != oit_end; ++ oit)2198 {2199 // use mailing to avoid duplicates2200 numRays += CollectViewCells(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays);2201 }2202 }2203 else2204 {2205 ObjectContainer::const_iterator oit, oit_end = objects.end();2206 2207 // loop through all object and collect view cell pvs of this node2208 for (oit = objects.begin(); oit != oit_end; ++ oit)2209 {2210 // use mailing to avoid duplicates2211 numRays += CollectViewCellsFromRays(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays);2212 }2213 }2214 2215 return numRays;2216 }2217 2218 2219 int BvHierarchy::CountViewCells(const ObjectContainer &objects)// const2220 {2221 int nViewCells = 0;2222 2223 ViewCell::NewMail();2224 2225 if (mCachedObjects)2226 {2227 ObjectContainer::const_iterator oit, oit_end = mCachedObjects->end();2228 2229 // loop through all object and collect view cell pvs of this node2230 for (oit = mCachedObjects->begin(); oit != oit_end; ++ oit)2231 {2232 // use mailing to avoid duplicates2233 nViewCells += CountViewCells(*oit);2234 }2235 }2236 else2237 {2238 ObjectContainer::const_iterator oit, oit_end = objects.end();2239 2240 // loop through all object and collect view cell pvs of this node2241 for (oit = objects.begin(); oit != oit_end; ++ oit)2242 {2243 nViewCells += CountViewCellsFromRays(*oit);2244 }2245 }2246 2247 return nViewCells;2248 }2249 2250 2251 2235 #else 2252 2253 int BvHierarchy::CollectViewCells(const ObjectContainer &objects,2254 ViewCellContainer &viewCells,2255 const bool setCounter,2256 const bool onlyUnmailedRays)// const2257 {2258 ViewCell::NewMail();2259 2260 ObjectContainer::const_iterator oit, oit_end = objects.end();2261 2262 // use mailing to avoid dublicates2263 const bool useMailBoxing = true;2264 2265 int numRays = 0;2266 // loop through all object and collect view cell pvs of this node2267 for (oit = objects.begin(); oit != oit_end; ++ oit)2268 {2269 // use mailing to avoid duplicates2270 numRays += CollectViewCells(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays);2271 }2272 2273 return numRays;2274 }2275 2276 2277 int BvHierarchy::CountViewCells(const ObjectContainer &objects)// const2278 {2279 int nViewCells = 0;2280 2281 ViewCell::NewMail();2282 ObjectContainer::const_iterator oit, oit_end = objects.end();2283 2284 // loop through all object and collect view cell pvs of this node2285 for (oit = objects.begin(); oit != oit_end; ++ oit)2286 {2287 nViewCells += CountViewCells(*oit);2288 }2289 2290 return nViewCells;2291 }2292 2293 2236 2294 2237 int BvHierarchy::CountViewCells(Intersectable *obj) //const … … 2377 2320 2378 2321 2322 int BvHierarchy::CountViewCells(const ObjectContainer &objects)// const 2323 { 2324 int nViewCells = 0; 2325 2326 ViewCell::NewMail(); 2327 ObjectContainer::const_iterator oit, oit_end = objects.end(); 2328 2329 // loop through all object and collect view cell pvs of this node 2330 for (oit = objects.begin(); oit != oit_end; ++ oit) 2331 { 2332 nViewCells += CountViewCells(*oit); 2333 } 2334 2335 return nViewCells; 2336 } 2337 2379 2338 2380 2339 void BvHierarchy::CollectDirtyCandidates(BvhSubdivisionCandidate *sc, … … 2387 2346 ViewCellContainer viewCells; 2388 2347 //ViewCell::NewMail(); 2389 int numRays = CollectViewCells( node->mObjects, viewCells, false, false);2348 int numRays = CollectViewCells(*tData.mSampledObjects, viewCells, false, false); 2390 2349 2391 2350 if (0) cout << "collected " << (int)viewCells.size() << " dirty candidates" << endl; … … 2435 2394 } 2436 2395 2437 2396 #if 0 2438 2397 BvhLeaf *BvHierarchy::GetLeaf(Intersectable *object, BvhNode *node) const 2439 2398 { 2440 // rather use the simpleversion2399 // hack: we use the simpler but faster version 2441 2400 if (!object) 2442 2401 return NULL; 2402 2443 2403 return object->mBvhLeaf; 2444 2404 2445 2405 /////////////////////////////////////// 2446 2406 // start from root of tree 2447 2407 /* 2448 2408 if (node == NULL) 2449 2409 node = mRoot; … … 2489 2449 2490 2450 return leaf; 2491 } 2492 2451 */ 2452 } 2453 #endif 2493 2454 2494 2455 bool BvHierarchy::Export(OUT_STREAM &stream) … … 2586 2547 2587 2548 2588 /* 2589 Mesh *BvHierarchy::MergeLeafToMesh() 2590 { 2591 vector<BvhLeaf *> leaves; 2592 CollectLeaves(leaves); 2593 2594 vector<BvhLeaf *>::const_iterator lit, lit_end = leaves.end(); 2595 2596 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2597 { 2598 Mesh *mesh = MergeLeafToMesh(*lit); 2599 } 2600 }*/ 2549 void BvHierarchy::StoreSampledObjects(ObjectContainer &sampledObjects, const ObjectContainer &objects) 2550 { 2551 ObjectContainer::const_iterator oit, oit_end = objects.end(); 2552 2553 for (oit = objects.begin(); oit != objects.end(); ++ oit) 2554 { 2555 Intersectable *obj = *oit; 2556 2557 if (!obj->GetOrCreateRays()->empty()) 2558 { 2559 sampledObjects.push_back(obj); 2560 } 2561 } 2562 } 2601 2563 2602 2564 … … 2624 2586 //cout << "using " << nRays << " of " << (int)sampleRays.size() << " rays" << endl; 2625 2587 2588 ObjectContainer *sampledObjects = new ObjectContainer(); 2589 StoreSampledObjects(*sampledObjects, objects); 2590 2626 2591 #if STORE_VIEWCELLS_WITH_BVH 2627 AssociateViewCellsWithObjects( objects);2592 AssociateViewCellsWithObjects(*sampledObjects); 2628 2593 #endif 2629 2594 2630 2595 // probability that volume is "seen" from the view cells 2631 const float prop = EvalViewCellsVolume( objects) / GetViewSpaceVolume();2596 const float prop = EvalViewCellsVolume(*sampledObjects) / GetViewSpaceVolume(); 2632 2597 2633 2598 // create bvh traversal data … … 2640 2605 } 2641 2606 2607 oData.mSampledObjects = sampledObjects; 2608 2642 2609 /////////////////// 2643 2610 //-- add first candidate for object space partition 2644 2611 2645 2612 mTotalCost = EvalRenderCost(objects); 2646 mPvsEntries = CountViewCells( objects);2613 mPvsEntries = CountViewCells(*sampledObjects); 2647 2614 2648 2615 oData.mCorrectedPvs = oData.mPvs = (float)mPvsEntries; … … 2655 2622 2656 2623 #if STORE_VIEWCELLS_WITH_BVH 2657 ReleaseViewCells( objects);2624 ReleaseViewCells(*sampledObjects); 2658 2625 #endif 2659 2626 … … 2727 2694 } 2728 2695 2729 // last sorted list: by size2696 // next sorted list: by size (for initial criteria) 2730 2697 tData.mSortedObjects[3] = new ObjectContainer(); 2731 2698 tData.mSortedObjects[3]->reserve((int)objects.size()); … … 2734 2701 2735 2702 stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 2736 //sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize);2737 2703 } 2738 2704 … … 2796 2762 mRoot = bvhleaf; 2797 2763 2764 ObjectContainer *sampledObjects = new ObjectContainer(); 2765 StoreSampledObjects(*sampledObjects, objects); 2766 2798 2767 #if STORE_VIEWCELLS_WITH_BVH 2799 AssociateViewCellsWithObjects( objects);2768 AssociateViewCellsWithObjects(*sampledObjects); 2800 2769 #endif 2801 2770 … … 2803 2772 // probability that volume is "seen" from the view cells 2804 2773 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 2805 const float prop = EvalViewCellsVolume( objects);2806 2807 const int nRays = CountRays( objects);2774 const float prop = EvalViewCellsVolume(*sampledObjects); 2775 2776 const int nRays = CountRays(*sampledObjects); 2808 2777 BvhLeaf *bvhLeaf = static_cast<BvhLeaf *>(mRoot); 2809 2778 … … 2811 2780 BvhTraversalData oData(bvhLeaf, 0, prop, nRays); 2812 2781 2782 oData.mSampledObjects = sampledObjects; 2783 2813 2784 if (mUseGlobalSorting) 2814 2785 AssignInitialSortedObjectList(oData, objects); 2815 2786 2816 2787 #if STORE_VIEWCELLS_WITH_BVH 2817 ReleaseViewCells( objects);2788 ReleaseViewCells(*sampledObjects); 2818 2789 #endif 2819 2790 /////////////////// -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r2206 r2210 407 407 mPvs(0), 408 408 mCorrectedVolume(0), 409 mVolume(v) 409 mVolume(v), 410 mSampledObjects(NULL) 410 411 { 411 412 for (int i = 0; i < 4; ++ i) … … 420 421 for (int i = 0; i < 4; ++ i) 421 422 DEL_PTR(mSortedObjects[i]); 423 424 DEL_PTR(mSampledObjects); 422 425 } 423 426 … … 441 444 float mCorrectedPvs; 442 445 443 /// the sorted objects for the three dimensions 446 /** the sorted objects for the three dimensions + one for the original 447 order + one for the objects which have been sampled at least once 448 */ 444 449 ObjectContainer *mSortedObjects[4]; 450 ObjectContainer *mSampledObjects; 445 451 }; 446 452 … … 511 517 ObjectContainer mBackObjects; 512 518 519 /// the sampled objects on the front of the potential split 520 ObjectContainer mSampledFrontObjects; 521 /// the sampled objects on the back of the potential split 522 ObjectContainer mSampledBackObjects; 523 513 524 float mCorrectedFrontPvs; 514 525 float mCorrectedBackPvs; … … 516 527 float mCorrectedFrontVolume; 517 528 float mCorrectedBackVolume; 529 530 //int mNumFrontRays; 531 //int mNumBackRays; 532 533 int mNumFrontViewCells; 534 int mNumBackViewCells; 535 536 float mVolumeFrontViewCells; 537 float mVolumeBackViewCells; 518 538 }; 519 539 … … 620 640 /** Returns leaf the point pt lies in, starting from root. 621 641 */ 622 BvhLeaf *GetLeaf(Intersectable *obj, BvhNode *root = NULL) const; 642 inline BvhLeaf *GetLeaf(Intersectable *object, BvhNode *root = NULL) const 643 { 644 // hack: we use the simpler but faster version 645 if (!object) 646 return NULL; 647 648 return object->mBvhLeaf; 649 } 623 650 624 651 /** Sets a pointer to the view cells tree. … … 638 665 void SetActive(BvhNode *node) const; 639 666 667 668 void StoreSampledObjects(ObjectContainer &sampledObjects, const ObjectContainer &objects); 640 669 641 670 /////////////////////////// … … 711 740 float EvalRenderCost(const ObjectContainer &objects);// const; 712 741 742 float EvalProbability(const ObjectContainer &objects); 743 713 744 /** Evaluates tree stats in the BSP tree leafs. 714 745 */ … … 860 891 int AssociateViewCellsWithObject(Intersectable *obj, const bool useMailBoxing) const; 861 892 862 void AssociateViewCellsWithObjects(const ObjectContainer &objects) ;//const;893 void AssociateViewCellsWithObjects(const ObjectContainer &objects) const; 863 894 864 895 void ReleaseViewCells(const ObjectContainer &objects); … … 876 907 */ 877 908 int EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate, 878 const float avgRayContri);// const; 909 const float avgRayContri, 910 const int numParentViewCells, 911 const int numFrontViewCells, 912 const int numBackViewCells);// const; 879 913 880 914 /** Rays will be clipped to the bounding box. … … 975 1009 HierarchyManager *mHierarchyManager; 976 1010 977 978 ObjectContainer *mCachedObjects;979 1011 980 1012 //////////////////// -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r2206 r2210 2524 2524 // delete old "base" view cells: only pvss in the leaves are allowed 2525 2525 ViewCellContainer::const_iterator oit, oit_end = mOldViewCells.end(); 2526 2526 2527 for (oit = mOldViewCells.begin(); oit != oit_end; ++ oit) 2527 2528 { -
GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp
r2172 r2210 92 92 Intersectable *newObject = vssRays[i]->mTerminationObject; 93 93 94 Intersectable *oldObject = mRays[vssRays[i]->mGeneratorId].mRay->mTerminationObject;94 Intersectable *oldObject = mRays[vssRays[i]->mGeneratorId].mRay->mTerminationObject; 95 95 96 96 if (oldObject == newObject) … … 600 600 //rr[0] = RandomValue(0,1); 601 601 // use binary search to find index with this cdf 602 int l=0, r= mRays.size()-1;602 int l=0, r=(int)mRays.size()-1; 603 603 while(l<r) { 604 604 int i = (l+r)/2; -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r2205 r2210 438 438 439 439 440 // has to called before first usage 440 /******************************************************************/ 441 /* class MixtureDistribution implementation */ 442 /******************************************************************/ 443 444 445 // has to be called before first usage 441 446 void 442 447 MixtureDistribution::Init() … … 683 688 } 684 689 690 685 691 bool HwGlobalLinesDistribution::GenerateSample(SimpleRay &ray) 686 692 { -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r2205 r2210 238 238 { 239 239 const bool result = mPvs.AddSample(sample, pdf); 240 // have to recompute pvs size240 // we have to recompute pvs size 241 241 mPvsSizeValid = false; 242 242 … … 515 515 ///////////// 516 516 //-- fill merge queue 517 517 518 vector<MergeCandidate> candidates; 518 519 … … 527 528 } 528 529 529 Debug << "********************** *** merge ***********************************" << endl;530 Debug << "********************** merge ******************************" << endl; 530 531 Debug << "deviation: " << mDeviation << endl; 531 532 Debug << "avg render cost: " << mAvgRenderCost << endl; … … 648 649 totalRenderCost += renderCostIncr; 649 650 mDeviation += mc.GetDeviationIncr(); 650 651 651 652 /////////// 652 653 //-- merge the view cells of leaf1 and leaf2 654 653 655 float pvsDiff; 654 656 ViewCellInterior *mergedVc = … … 834 836 if (!obj->Mailed()) 835 837 { 836 renderCost += mViewCellsManager->EvalRenderCost(obj);838 renderCost += ViewCellsManager::EvalRenderCost(obj); 837 839 } 838 840 } … … 1028 1030 // set scalars 1029 1031 mViewCellsManager->UpdateScalarPvsSize(right, 1030 right->GetPvs().EvalPvsCost(),1031 right->GetPvs().GetSize());1032 right->GetPvs().EvalPvsCost(), 1033 right->GetPvs().GetSize()); 1032 1034 1033 1035 right->mPvsSizeValid = true; … … 1804 1806 return vc->GetPvs().GetSize(); 1805 1807 } 1806 1807 // interior node1808 1808 1809 1809 // interior nodes: pvs is either stored as a scalar or … … 1987 1987 Intersectable::NewMail(); 1988 1988 1989 ///////////////////////// ///////////////////////1990 // for interiors, pvs can be stored using different methods1989 ///////////////////////// 1990 //-- different storage methods for interiors 1991 1991 1992 1992 switch (mViewCellsStorage) -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r2206 r2210 881 881 splitCandidate.GetAvgRayContribution()); 882 882 883 splitCandidate.mFrontPvs = fPvsSize; 884 splitCandidate.mBackPvs = bPvsSize; 885 883 886 if (0) 884 887 cout << "vsp pvs" … … 902 905 903 906 const VspTraversalData &tData = sc.mParentData; 904 const AxisAlignedPlane splitPlane = sc.mSplitPlane;907 const AxisAlignedPlane &splitPlane = sc.mSplitPlane; 905 908 906 909 /////////////// … … 917 920 918 921 //-- compute pvs 919 frontData.mPvs = (float)EvalPvsEntriesSize(*frontData.mRays);920 backData.mPvs = (float)EvalPvsEntriesSize(*backData.mRays);922 frontData.mPvs = sc.mFrontPvs;//(float)EvalPvsEntriesSize(*frontData.mRays); 923 backData.mPvs = sc.mBackPvs;//(float)EvalPvsEntriesSize(*backData.mRays); 921 924 922 925 //-- compute pvs correction for coping with undersampling … … 934 937 935 938 //-- compute render cost 936 frontData.mRenderCost = (float)EvalPvsCost(*frontData.mRays);937 backData.mRenderCost = (float)EvalPvsCost(*backData.mRays);939 frontData.mRenderCost = sc.mFrontRenderCost;//(float)EvalPvsCost(*frontData.mRays); 940 backData.mRenderCost = sc.mBackRenderCost;//(float)EvalPvsCost(*backData.mRays); 938 941 939 942 frontData.mCorrectedRenderCost = sc.mCorrectedFrontRenderCost; … … 1275 1278 const float maxBand = minBox + mMaxBand * sizeBox; 1276 1279 1280 // sort by the current dimension 1277 1281 SortSubdivisionCandidates(usedRays, axis, minBand, maxBand); 1278 1282 … … 1589 1593 sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(pvsBack, penaltyOld, avgRayContri); 1590 1594 1595 sc.mFrontRenderCost = pvsFront; 1596 sc.mBackRenderCost = pvsBack; 1597 1591 1598 const float oldRenderCost = pOverall * penaltyOld; 1592 1599 const float newRenderCost = sc.mCorrectedFrontRenderCost * pFront + … … 1727 1734 1728 1735 const float renderCost = countEntries ? 1 : 1729 m HierarchyManager->mBvHierarchy->EvalAbsCost(leaf->mObjects);1736 mBvHierarchy->EvalAbsCost(leaf->mObjects); 1730 1737 1731 1738 // leaf in no pvs => new … … 2286 2293 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 2287 2294 { 2288 BvhLeaf *bvhleaf = m HierarchyManager->mBvHierarchy->GetLeaf(obj);2295 BvhLeaf *bvhleaf = mBvHierarchy->GetLeaf(obj); 2289 2296 2290 2297 if (!bvhleaf->Mailed()) … … 2901 2908 VspSubdivisionCandidate::sVspTree = this; 2902 2909 2910 mBvHierarchy = mHierarchyManager->mBvHierarchy; 2911 2903 2912 // initialise termination criteria 2904 2913 mTermMinProbability *= mBoundingBox.GetVolume(); … … 2969 2978 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 2970 2979 { 2971 BvhLeaf *leaf = m HierarchyManager->mBvHierarchy->GetLeaf(obj);2980 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 2972 2981 2973 2982 if (!leaf->Mailed()) … … 3049 3058 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 3050 3059 { 3051 BvhLeaf *leaf = m HierarchyManager->mBvHierarchy->GetLeaf(obj);3060 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 3052 3061 3053 3062 if (-- leaf->mCounter == 0) … … 3098 3107 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 3099 3108 { 3100 BvhLeaf *leaf = m HierarchyManager->mBvHierarchy->GetLeaf(obj);3109 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 3101 3110 3102 3111 if (!leaf->Mailed()) … … 3151 3160 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 3152 3161 { 3153 BvhLeaf *leaf = m HierarchyManager->mBvHierarchy->GetLeaf(obj);3162 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 3154 3163 if (!leaf->Mailed()) 3155 3164 { … … 3198 3207 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 3199 3208 { 3200 BvhLeaf *leaf = m HierarchyManager->mBvHierarchy->GetLeaf(obj);3209 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 3201 3210 UpdateContributionsToPvs(leaf, cf, frontPvs, backPvs, totalPvs, false); 3202 3211 break; … … 3227 3236 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 3228 3237 { 3229 BvhLeaf *leaf = m HierarchyManager->mBvHierarchy->GetLeaf(obj);3238 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 3230 3239 UpdateContributionsToPvs(leaf, cf, pvsFront, pvsBack, totalPvs, true); 3231 3240 break; … … 3269 3278 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 3270 3279 { 3271 BvhLeaf *bvhleaf = m HierarchyManager->mBvHierarchy->GetLeaf(obj);3280 BvhLeaf *bvhleaf = mBvHierarchy->GetLeaf(obj); 3272 3281 3273 3282 if (!bvhleaf->Mailed()) -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r2199 r2210 551 551 float mCorrectedBackPvs; 552 552 553 float mFrontPvs; 554 float mBackPvs; 555 553 556 float mCorrectedFrontRenderCost; 554 557 float mCorrectedBackRenderCost; 555 float mCorrectedFrontVolume; 556 float mCorrectedBackVolume; 558 //float mCorrectedFrontVolume; 559 //float mCorrectedBackVolume; 560 561 float mFrontRenderCost; 562 float mBackRenderCost; 557 563 }; 558 564 … … 1092 1098 1093 1099 HierarchyManager *mHierarchyManager; 1100 BvHierarchy *mBvHierarchy; 1101 1094 1102 //OspTree *mOspTree; 1095 1103 //bool mUseKdPvsForHeuristics;
Note: See TracChangeset
for help on using the changeset viewer.