- Timestamp:
- 02/01/06 19:29:59 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r579 r580 33 33 mViewSpaceBox.Initialize(); 34 34 ParseEnvironment(); 35 36 mViewCellsTree = new ViewCellsTree(this); 35 37 } 36 38 … … 53 55 54 56 environment->GetBoolValue("ViewCells.exportToFile", mExportViewCells); 57 58 environment->GetBoolValue("ViewCells.PostProcess.useRaysForMerge", mUseRaysForMerge); 55 59 56 60 mMinPvsSize = emptyViewCells ? 1 : 0; … … 75 79 { 76 80 DEL_PTR(mRenderer); 77 CLEAR_CONTAINER(mViewCells); 81 //CLEAR_CONTAINER(mViewCells); 82 DEL_PTR(mViewCellsTree); 83 78 84 CLEAR_CONTAINER(mMeshContainer); 79 85 } … … 302 308 float ViewCellsManager::GetViewSpaceVolume() 303 309 { 304 return mViewSpaceBox.GetVolume()*(2.0f*sqr( M_PI));310 return mViewSpaceBox.GetVolume()*(2.0f*sqr((float)M_PI)); 305 311 } 306 312 … … 356 362 357 363 358 void ViewCellsManager::EvaluateRenderStatistics(float &totalRenderCost, 364 void ViewCellsManager::EvaluateRenderStatistics(float &totalRenderCost, 359 365 float &expectedRenderCost, 360 float &variance) 366 float &deviation, 367 float &variance, 368 int &totalPvs, 369 float &avgRenderCost) 361 370 { 362 371 ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 363 372 373 364 374 //-- compute expected value 365 375 366 376 totalRenderCost = 0; 377 totalPvs = 0; 367 378 368 379 for (it = mViewCells.begin(); it != it_end; ++ it) 369 380 { 370 381 ViewCell *vc = *it; 371 372 382 totalRenderCost += vc->GetPvs().GetSize() * vc->GetVolume(); 373 } 374 383 totalPvs += (int)vc->GetPvs().GetSize(); 384 } 385 386 // normalize with view space box 387 totalRenderCost /= mViewSpaceBox.GetVolume(); 375 388 expectedRenderCost = totalRenderCost / (float)mViewCells.size(); 376 377 378 //-- compute variance 379 389 avgRenderCost = totalPvs / (float)mViewCells.size(); 390 391 392 //-- compute standard defiation 380 393 variance = 0; 394 deviation = 0; 381 395 382 396 for (it = mViewCells.begin(); it != it_end; ++ it) … … 385 399 386 400 float renderCost = vc->GetPvs().GetSize() * vc->GetVolume(); 387 388 const float var = (expectedRenderCost - renderCost) * (expectedRenderCost - renderCost); 389 390 variance += var; 391 } 392 401 float dev; 402 403 if (1) 404 dev = fabs(avgRenderCost - (float)vc->GetPvs().GetSize()); 405 else 406 dev = fabs(expectedRenderCost - renderCost); 407 408 deviation += dev; 409 variance += dev * dev; 410 } 411 393 412 variance /= (float)mViewCells.size(); 413 deviation /= (float)mViewCells.size(); 394 414 } 395 415 … … 493 513 494 514 495 ViewCell *ViewCellsManager::MergeViewCells(ViewCell &front, ViewCell &back) const496 { 497 // generate mergedview cell498 ViewCell *vc =GenerateViewCell();515 ViewCellInterior *ViewCellsManager::MergeViewCells(ViewCell &left, ViewCell &right) const 516 { 517 // generate parent view cell 518 ViewCellInterior *vc = new ViewCellInterior();//GenerateViewCell(); 499 519 500 520 // merge pvs 501 vc->GetPvs().Merge( front.GetPvs(), back.GetPvs());521 vc->GetPvs().Merge(left.GetPvs(), right.GetPvs()); 502 522 503 523 //-- merge ray sets 504 524 if (0) 505 525 { 506 stable_sort( front.mPiercingRays.begin(), front.mPiercingRays.end());507 stable_sort( back.mPiercingRays.begin(), back.mPiercingRays.end());508 509 std::merge( front.mPiercingRays.begin(), front.mPiercingRays.end(),510 back.mPiercingRays.begin(), back.mPiercingRays.end(),526 stable_sort(left.mPiercingRays.begin(), left.mPiercingRays.end()); 527 stable_sort(right.mPiercingRays.begin(), right.mPiercingRays.end()); 528 529 std::merge(left.mPiercingRays.begin(), left.mPiercingRays.end(), 530 right.mPiercingRays.begin(), right.mPiercingRays.end(), 511 531 vc->mPiercingRays.begin()); 512 532 } 513 533 534 535 vc->SetupChildLink(&left); 536 vc->SetupChildLink(&right); 537 538 514 539 return vc; 515 540 } … … 522 547 523 548 524 ViewCell *ViewCellsManager::GenerateViewCell(Mesh *mesh) const525 { 526 return new ViewCell(mesh);549 ViewCellsTree *ViewCellsManager::GetViewCellsTree() 550 { 551 return mViewCellsTree; 527 552 } 528 553 … … 814 839 { 815 840 ExportColor(exporter, *it); 816 ExportV cGeometry(exporter, *it);841 ExportViewCellGeometry(exporter, *it); 817 842 } 818 843 } … … 1186 1211 1187 1212 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 1188 << ", piercing rays=" << (int)vcRays.size() 1189 << ", leaves=" << (int)vc->mLeaves.size() << endl;1213 << ", piercing rays=" << (int)vcRays.size() << endl; 1214 // << ", leaves=" << (int)vc->mLeaves.size() << endl; 1190 1215 1191 1216 1192 1217 // export rays piercing this view cell 1193 #if 01194 1218 exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 1195 #else 1196 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 1197 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 1198 exporter->ExportRays((*lit)->mVssRays); 1199 #endif 1219 1200 1220 m.mDiffuseColor = RgbColor(1, 0, 0); 1201 1221 exporter->SetForcedMaterial(m); … … 1249 1269 { 1250 1270 BspViewCell *vc = dynamic_cast<BspViewCell *>(*vit); 1251 ray->intersections.push_back(BspIntersection(0, vc->mLea ves[0]));1271 ray->intersections.push_back(BspIntersection(0, vc->mLeaf)); 1252 1272 } 1253 1273 … … 1278 1298 case 2: // merges 1279 1299 { 1280 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 1281 1282 importance = (float)bspVc->mLeaves.size() / 1300 importance = (float)mViewCellsTree->GetSize(vc) / 1283 1301 (float)mViewCellsStats.maxLeaves; 1284 1302 } … … 1301 1319 } 1302 1320 1303 void BspViewCellsManager::ExportV cGeometry(Exporter *exporter,1321 void BspViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 1304 1322 ViewCell *vc) const 1305 1323 { … … 1332 1350 return mBspTree->GetViewCell(point); 1333 1351 } 1352 1353 1354 void BspViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates) 1355 { 1356 // TODO 1357 } 1358 1334 1359 1335 1360 /**********************************************************************/ … … 1585 1610 } 1586 1611 1587 1588 void KdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1589 ViewCell *vc) const 1590 { 1591 KdViewCell *kdVc = dynamic_cast<KdViewCell *>(vc); 1592 vector<KdLeaf *>::const_iterator it, it_end = kdVc->mLeaves.end(); 1593 1594 for (it = kdVc->mLeaves.begin(); it != it_end; ++ it) 1595 exporter->ExportBox(mKdTree->GetBox(*it)); 1612 ViewCell *KdViewCellsManager::GenerateViewCell(Mesh *mesh) const 1613 { 1614 return new KdViewCell(mesh); 1615 } 1616 1617 1618 void KdViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 1619 ViewCell *vc) const 1620 { 1621 ViewCellContainer leaves; 1622 1623 mViewCellsTree->CollectLeaves(vc, leaves); 1624 ViewCellContainer::const_iterator it, it_end = leaves.end(); 1625 1626 for (it = leaves.begin(); it != it_end; ++ it) 1627 { 1628 KdViewCell *kdVc = dynamic_cast<KdViewCell *>(*it); 1629 1630 exporter->ExportBox(mKdTree->GetBox(kdVc->mLeaf)); 1631 } 1596 1632 } 1597 1633 … … 1625 1661 // TODO 1626 1662 } 1663 1664 1665 1666 void KdViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays, 1667 vector<MergeCandidate> &candidates) 1668 { 1669 // TODO 1670 } 1671 1627 1672 1628 1673 /**********************************************************************/ … … 1798 1843 exporter->SetWireframe(); 1799 1844 1800 ExportV cGeometry(exporter, vc);1845 ExportViewCellGeometry(exporter, vc); 1801 1846 1802 1847 //-- export stored rays 1848 1803 1849 if (mExportRays) 1804 1850 { 1805 vector<VspKdLeaf *>::const_iterator it, 1806 it_end = vc->mLeaves.end(); 1807 1808 for (it = vc->mLeaves.begin(); it != it_end; ++ it) 1851 ViewCellContainer leaves; 1852 mViewCellsTree->CollectLeaves(vc, leaves); 1853 1854 ViewCellContainer::const_iterator it, 1855 it_end = leaves.end(); 1856 1857 for (it = leaves.begin(); it != it_end; ++ it) 1809 1858 { 1810 VspKdLeaf *leaf = *it; 1859 VspKdViewCell *vspKdVc = dynamic_cast<VspKdViewCell *>(*it); 1860 VspKdLeaf *leaf = vspKdVc->mLeaf; 1811 1861 AxisAlignedBox3 box = mVspKdTree->GetBBox(leaf); 1812 1862 … … 1834 1884 } 1835 1885 } 1836 1886 1837 1887 //-- output PVS of view cell 1838 1888 m.mDiffuseColor = RgbColor(1, 0, 0); … … 1927 1977 } 1928 1978 break; 1929 case 2: // merges 1930 { 1931 VspKdViewCell *vspKdVc = dynamic_cast<VspKdViewCell *>(vc); 1932 1933 importance = (float)vspKdVc->mLeaves.size() / 1979 case 2: // merged leaves 1980 { 1981 int lSize = mViewCellsTree->GetSize(vc); 1982 importance = (float)lSize / 1934 1983 (float)mViewCellsStats.maxLeaves; 1935 1984 } … … 1954 2003 1955 2004 1956 void VspKdViewCellsManager::ExportV cGeometry(Exporter *exporter,2005 void VspKdViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 1957 2006 ViewCell *vc) const 1958 2007 { 1959 2008 VspKdViewCell *kdVc = dynamic_cast<VspKdViewCell *>(vc); 1960 vector<VspKdLeaf *>::const_iterator it, it_end = kdVc->mLeaves.end();1961 2009 1962 2010 Mesh m; 1963 for (it = kdVc->mLeaves.begin(); it != it_end; ++ it) 1964 { 1965 mVspKdTree->GetBBox(*it).AddBoxToMesh(&m); 2011 2012 ViewCellContainer leaves; 2013 mViewCellsTree->CollectLeaves(vc, leaves); 2014 2015 ViewCellContainer::const_iterator it, it_end = leaves.end(); 2016 2017 for (it = leaves.begin(); it != it_end; ++ it) 2018 { 2019 VspKdLeaf *l = dynamic_cast<VspKdViewCell *>(*it)->mLeaf; 2020 mVspKdTree->GetBBox(l).AddBoxToMesh(&m); 1966 2021 } 1967 2022 … … 1975 2030 } 1976 2031 2032 2033 void VspKdViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates) 2034 { 2035 // TODO 2036 } 1977 2037 1978 2038 … … 2131 2191 long startTime = GetTime(); 2132 2192 2193 2133 2194 // TODO: should be done BEFORE the ray casting 2134 merged = mV spBspTree->MergeViewCells(rays, objects);2195 merged = mViewCellsTree->ConstructMergeTree(rays, objects); 2135 2196 2136 2197 //-- stats and visualizations … … 2194 2255 2195 2256 // refining the merged view cells 2196 const int refined = mV spBspTree->RefineViewCells(rays, objects);2257 const int refined = mViewCellsTree->RefineViewCells(rays, objects); 2197 2258 2198 2259 //-- stats and visualizations … … 2234 2295 mViewCellsStats.Reset(); 2235 2296 EvaluateViewCellsStats(); 2297 2236 2298 // has to be recomputed 2237 2299 mTotalAreaValid = false; … … 2254 2316 //-- merge the individual view cells 2255 2317 MergeViewCells(postProcessRays, objects); 2318 2256 2319 //-- refines the merged view cells 2257 2320 RefineViewCells(postProcessRays, objects); 2321 2322 if (1) 2323 { 2324 float totalCost, erc, var, dev, avg; 2325 int totalpvs; 2326 2327 mViewCellsStats.Reset(); 2328 2329 EvaluateRenderStatistics(totalCost, erc, dev, var, totalpvs, avg); 2330 2331 Debug << "statistics after merge " 2332 << " erc: " << erc 2333 << " dev: " << dev 2334 << " totalpvs: " << totalpvs 2335 << " avg: " << avg << endl; 2336 } 2337 2258 2338 2259 2339 //-- export shuffled view cells … … 2293 2373 vm.mDiffuseColor.b -= 0.45f; 2294 2374 2295 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 2296 2297 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 2375 2376 ViewCellContainer leaves; 2377 mViewCellsTree->CollectLeaves(vc, leaves); 2378 2379 ViewCellContainer::const_iterator lit, lit_end = leaves.end(); 2380 2381 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2298 2382 { 2299 BspLeaf *leaf = *lit;2383 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*lit)->mLeaf; 2300 2384 2301 2385 if (leaf->Mailed()) … … 2391 2475 if (1) // export view cells 2392 2476 { 2393 cout << "exporting view cells after post process ... ";2394 2477 Exporter *exporter = Exporter::GetExporter("final_view_cells.x3d"); 2395 2478 2396 2479 if (exporter) 2397 2480 { 2481 cout << "exporting view cells after post process ... "; 2482 2398 2483 if (1) 2399 2484 { … … 2416 2501 ExportViewCellsForViz(exporter); 2417 2502 delete exporter; 2503 cout << "finished" << endl; 2418 2504 } 2419 2505 } … … 2446 2532 BspViewCell *vc = dynamic_cast<BspViewCell *>(*vit); 2447 2533 2448 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 2449 2450 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 2534 ViewCellContainer leaves; 2535 mViewCellsTree->CollectLeaves(vc, leaves); 2536 2537 ViewCellContainer::const_iterator lit, lit_end = leaves.end(); 2538 2539 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2451 2540 { 2452 BspLeaf *leaf = *lit;2541 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*lit)->mLeaf; 2453 2542 2454 2543 Material m; … … 2573 2662 { 2574 2663 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(ray->mViewCells[j]); 2575 BspLeaf *leaf = bspVc->mLea ves[0];2664 BspLeaf *leaf = bspVc->mLeaf; 2576 2665 if (vc == bspVc) 2577 2666 vcRays.push_back(ray); … … 2589 2678 exporter->SetForcedMaterial(m); 2590 2679 2591 ExportV cGeometry(exporter, vc);2680 ExportViewCellGeometry(exporter, vc); 2592 2681 2593 2682 2594 2683 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 2595 << ", piercing rays=" << (int)vcRays.size() 2596 << ", leaves=" << (int)vc->mLeaves.size() << endl;2684 << ", piercing rays=" << (int)vcRays.size() << endl; 2685 // << ", leaves=" << (int)vc->mLeaves.size() << endl; 2597 2686 2598 2687 … … 2604 2693 else 2605 2694 { 2606 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 2607 2608 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 2609 exporter->ExportRays((*lit)->mVssRays); 2695 2696 ViewCellContainer leaves; 2697 mViewCellsTree->CollectLeaves(vc, leaves); 2698 2699 ViewCellContainer::const_iterator lit, lit_end = leaves.end(); 2700 2701 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2702 { 2703 BspLeaf *l = dynamic_cast<BspViewCell *>(*lit)->mLeaf; 2704 exporter->ExportRays(l->mVssRays); 2705 } 2610 2706 } 2611 2707 … … 2686 2782 case 2: // merges 2687 2783 { 2688 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 2689 2690 importance = (float)bspVc->mLeaves.size() / 2691 (float)mViewCellsStats.maxLeaves; 2784 int lSize = mViewCellsTree->GetSize(vc); 2785 2786 importance = (float)lSize / (float)mViewCellsStats.maxLeaves; 2692 2787 } 2693 2788 break; … … 2713 2808 2714 2809 2715 void VspBspViewCellsManager::ExportV cGeometry(Exporter *exporter,2810 void VspBspViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 2716 2811 ViewCell *vc) const 2717 2812 { … … 2731 2826 int VspBspViewCellsManager::GetMaxTreeDiff(ViewCell *vc) const 2732 2827 { 2733 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 2828 ViewCellContainer leaves; 2829 mViewCellsTree->CollectLeaves(vc, leaves); 2830 2734 2831 2735 2832 int maxDist = 0; 2833 2736 2834 // compute max height difference 2737 for (int i = 0; i < (int) bspVc->mLeaves.size(); ++ i)2738 for (int j = 0; j < (int) bspVc->mLeaves.size(); ++ j)2739 { 2740 BspLeaf *leaf = bspVc->mLeaves[i];2835 for (int i = 0; i < (int)leaves.size(); ++ i) 2836 for (int j = 0; j < (int)leaves.size(); ++ j) 2837 { 2838 BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaf; 2741 2839 2742 2840 if (i != j) 2743 2841 { 2744 BspLeaf *leaf2 = bspVc->mLeaves[j];2842 BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaf; 2745 2843 int dist = mVspBspTree->TreeDistance(leaf, leaf2); 2746 2844 if (dist > maxDist) … … 2748 2846 } 2749 2847 } 2848 2750 2849 return maxDist; 2751 2850 } … … 2871 2970 CreateMesh(vc); 2872 2971 2873 vector<BspLeaf *>::const_iterator it, it_end = vc->mLeaves.end();2874 2875 2972 float area = 0; 2876 2973 float volume = 0; 2877 2974 2878 for (it = vc->mLeaves.begin(); it != it_end; ++ it) 2975 ViewCellContainer leaves; 2976 mViewCellsTree->CollectLeaves(vc, leaves); 2977 2978 ViewCellContainer::const_iterator it, it_end = leaves.end(); 2979 2980 for (it = leaves.begin(); it != it_end; ++ it) 2879 2981 { 2880 2982 BspNodeGeometry geom; 2881 BspLeaf *leaf = *it;2983 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 2882 2984 mVspBspTree->ConstructGeometry(leaf, geom); 2883 2985 … … 2898 3000 2899 3001 2900 //////////////////////////////////77 3002 3003 void VspBspViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays, 3004 vector<MergeCandidate> &candidates) 3005 { 3006 cout << "collecting merge candidates ... " << endl; 3007 3008 if (mUseRaysForMerge) 3009 { 3010 mVspBspTree->CollectMergeCandidates(rays, candidates); 3011 } 3012 else 3013 { 3014 vector<BspLeaf *> leaves; 3015 mVspBspTree->CollectLeaves(leaves); 3016 mVspBspTree->CollectMergeCandidates(leaves, candidates); 3017 } 3018 3019 cout << "fininshed collecting candidates" << endl; 3020 } 3021 3022 3023 3024 ////////////////////////////////// 2901 3025 ViewCellsManager *ViewCellsManagerFactory::Create(const string mName) 2902 3026 { … … 2904 3028 return NULL;// new VspBspViewCellsManager(); 2905 3029 } 3030
Note: See TracChangeset
for help on using the changeset viewer.