- Timestamp:
- 01/23/06 02:56:48 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r563 r564 27 27 mViewCellsFinished(false), 28 28 mMaxPvsSize(9999999), 29 mMinPvsSize( 1), //only empty view cells are invalid29 mMinPvsSize(0), // one means only empty view cells are invalid 30 30 mMaxPvsRatio(1.0) 31 31 { … … 44 44 mViewCellsFinished(false), 45 45 mMaxPvsSize(9999999), 46 mMinPvsSize( 1), //only empty view cells are invalid46 mMinPvsSize(0), // one means only empty view cells are invalid 47 47 mMaxPvsRatio(1.0) 48 48 { … … 58 58 environment->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry); 59 59 environment->GetFloatValue("ViewCells.maxPvsRatio", mMaxPvsRatio); 60 bool emptyViewCells = false; 61 environment->GetBoolValue("ViewCells.pruneEmptyViewCells", emptyViewCells); 62 environment->GetBoolValue("ViewCells.processOnlyValidViewCells", mOnlyValidViewCells); 63 64 mMinPvsSize = emptyViewCells ? 1 : 0; 60 65 61 66 char buf[50]; 62 63 67 environment->GetStringValue("ViewCells.Visualization.colorCode", buf); 64 68 … … 91 95 preprocessor->GenerateVssRays(mConstructionSamples, vssRays); 92 96 Construct(preprocessor->mObjects, vssRays); 93 97 94 98 // add rays to output rays 95 99 while (!vssRays.empty) … … 116 120 117 121 118 bool ViewCellsManager::CheckValidity(ViewCell *vc, 119 int minPvsSize, 122 bool ViewCellsManager::CheckValidity(ViewCell *vc, 123 int minPvsSize, 120 124 int maxPvsSize) const 121 125 { 122 126 if ((vc->GetPvs().GetSize() > mMaxPvsSize) || 123 127 (vc->GetPvs().GetSize() < mMinPvsSize)) 124 { 128 { 125 129 return false; 126 130 } … … 130 134 131 135 132 void ViewCellsManager::SetValidity(ViewCell *vc, 133 int minPvs, 136 void ViewCellsManager::SetValidity(ViewCell *vc, 137 int minPvs, 134 138 int maxPvs) const 135 139 { … … 179 183 if (!ViewCellsConstructed()) 180 184 return 0.0f; 181 185 182 186 VssRayContainer::const_iterator it, it_end = rays.end(); 183 187 … … 309 313 310 314 //-- merge ray sets 311 stable_sort(front.mPiercingRays.begin(), front.mPiercingRays.end()); 312 stable_sort(back.mPiercingRays.begin(), back.mPiercingRays.end()); 313 314 std::merge(front.mPiercingRays.begin(), front.mPiercingRays.end(), 315 back.mPiercingRays.begin(), back.mPiercingRays.end(), 316 vc->mPiercingRays.begin()); 315 if (0) 316 { 317 stable_sort(front.mPiercingRays.begin(), front.mPiercingRays.end()); 318 stable_sort(back.mPiercingRays.begin(), back.mPiercingRays.end()); 319 320 std::merge(front.mPiercingRays.begin(), front.mPiercingRays.end(), 321 back.mPiercingRays.begin(), back.mPiercingRays.end(), 322 vc->mPiercingRays.begin()); 323 } 317 324 318 325 return vc; … … 429 436 { 430 437 mViewCells.clear(); 431 438 432 439 CollectViewCells(); 433 440 434 441 mViewCellsStats.Reset(); 435 442 EvaluateViewCellsStats(); … … 449 456 if (!ViewCellsConstructed()) 450 457 return; 451 458 452 459 VssRayContainer::const_iterator it, it_end = rays.end(); 453 460 454 461 for (it = rays.begin(); it != it_end; ++ it) { 455 462 AddSampleContributions(*(*it)); … … 489 496 { 490 497 ViewCellContainer viewcells; 491 498 492 499 ray.mPvsContribution = 0; 493 500 ray.mRelativePvsContribution = 0.0f; 494 495 // matt TODO: remove this!! 496 Ray hray(ray); 497 float tmin = 0, tmax = 1.0; 498 499 //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 500 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 501 return 0.0f; 502 503 Vector3 origin = hray.Extrap(tmin); 504 Vector3 termination = hray.Extrap(tmax); 501 502 static Ray hray; 503 hray.Init(ray); 504 //hray.mFlags |= Ray::CULL_BACKFACES; 505 //Ray hray(ray); 506 507 float tmin = 0, tmax = 1.0; 508 509 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 510 return; 511 512 Vector3 origin = hray.Extrap(tmin); 513 Vector3 termination = hray.Extrap(tmax); 514 515 CastLineSegment(origin, termination, viewcells); 516 //Debug << "constribution: " << (int)viewcells.size() << endl; 517 // copy viewcells memory efficiently 518 const bool storeViewcells = false; 519 if (storeViewcells) 505 520 506 521 CastLineSegment(origin, 507 522 termination, 508 523 viewcells); 509 524 510 525 //Debug << "constribution: " << (int)viewcells.size() << endl; 511 526 512 527 // copy viewcells memory efficiently 513 528 const bool storeViewcells = !addRays; 514 529 515 530 if (storeViewcells) 516 531 { 517 532 ray.mViewCells.reserve(viewcells.size()); 518 533 ray.mViewCells = viewcells; 519 }520 534 } 535 521 536 ViewCellContainer::const_iterator it = viewcells.begin(); 522 523 537 538 524 539 for (; it != viewcells.end(); ++it) { 525 540 ViewCell *viewcell = *it; … … 533 548 ray.mRelativePvsContribution += contribution; 534 549 } 535 550 536 551 if (addRays) 537 552 for (it = viewcells.begin(); it != viewcells.end(); ++it) { … … 623 638 624 639 625 bool ViewCellsManager::ExportViewCells(const string filename) 626 { 640 bool ViewCellsManager::ExportViewCells(const string filename) 641 { 627 642 return false; 628 643 } … … 1847 1862 void VspBspViewCellsManager::CollectViewCells() 1848 1863 { 1849 mVspBspTree->CollectViewCells(mViewCells, false);1864 mVspBspTree->CollectViewCells(mViewCells, mOnlyValidViewCells); 1850 1865 } 1851 1866 … … 1894 1909 1895 1910 mMaxPvsSize = (int)(mMaxPvsRatio * (float)objects.size()); 1896 1911 1897 1912 mVspBspTree->Construct(constructionRays, &mViewSpaceBox); 1898 1913 … … 1996 2011 if (exporter) 1997 2012 { 1998 if ( 1)2013 if (0) 1999 2014 exporter->SetWireframe(); 2000 2015 else … … 2019 2034 2020 2035 2021 void VspBspViewCellsManager::RefineViewCells(const VssRayContainer &rays) 2036 void VspBspViewCellsManager::RefineViewCells(const VssRayContainer &rays, 2037 const ObjectContainer &objects) 2022 2038 { 2023 2039 Debug << "render time before refine:" << endl; … … 2031 2047 2032 2048 // refining the merged view cells 2033 const int refined = mVspBspTree->RefineViewCells(rays );2049 const int refined = mVspBspTree->RefineViewCells(rays, objects); 2034 2050 2035 2051 //-- stats and visualizations … … 2052 2068 } 2053 2069 2054 2070 2055 2071 // view cells already finished before post processing step (i.e. because they were loaded) 2056 2072 if (mViewCellsFinished) … … 2060 2076 return 0; 2061 2077 } 2062 2078 2063 2079 2064 2080 // check if new view cells turned invalid … … 2071 2087 2072 2088 Debug << "post processing using " << (int)postProcessRays.size() << " samples" << endl; 2073 2089 2074 2090 Debug << "\nview cell partition after sampling:\n" << mViewCellsStats << endl << endl; 2075 2091 … … 2084 2100 MergeViewCells(postProcessRays, objects); 2085 2101 //-- refines the merged view cells 2086 RefineViewCells(postProcessRays );2102 RefineViewCells(postProcessRays, objects); 2087 2103 // collapse sibling leaves that share the same view cell 2088 2104 mVspBspTree->CollapseTree(); … … 2174 2190 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 2175 2191 } 2176 2192 2177 2193 ExportViewCellsForViz(exporter); 2178 2194 delete exporter; … … 2211 2227 2212 2228 lm = vm; 2213 2229 2214 2230 vm.mDiffuseColor.r -= 0.45f; 2215 2231 vm.mDiffuseColor.g -= 0.45f; … … 2226 2242 else 2227 2243 exporter->SetForcedMaterial(vm); 2228 2244 2229 2245 BspNodeGeometry geom; 2230 2246 mVspBspTree->ConstructGeometry(leaf, geom); … … 2232 2248 } 2233 2249 } 2234 2250 2235 2251 delete exporter; 2236 2252 } … … 2410 2426 ViewCell *vc) const 2411 2427 { 2412 if (CheckValidity(vc, mMinPvsSize, mMaxPvsSize) && (mColorCode == 0)) // Random color 2428 const bool vcValid = CheckValidity(vc, mMinPvsSize, mMaxPvsSize); 2429 2430 float importance = 0; 2431 static Material m; 2432 2433 switch (mColorCode) 2434 { 2435 case 0: // Random 2436 { 2437 if (vcValid) 2438 { 2439 m = RandomMaterial(); 2440 } 2441 else 2442 { 2443 m.mDiffuseColor.r = 0.0f; 2444 m.mDiffuseColor.g = 1.0f; 2445 m.mDiffuseColor.b = 0.0f; 2446 } 2447 } 2413 2448 return; 2414 2415 float importance = 0;2416 Material m;2417 2418 switch (mColorCode)2419 {2420 2449 case 1: // pvs 2421 2450 { … … 2443 2472 } 2444 2473 2445 m.mDiffuseColor.b = CheckValidity(vc, mMinPvsSize, mMaxPvsSize) ? 1.0f : 0.0f;2474 // special color code for invalid view cells 2446 2475 m.mDiffuseColor.r = importance; 2447 2476 m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 2477 m.mDiffuseColor.b = vcValid ? 1.0f : 0.0f; 2448 2478 2449 2479 //Debug << "importance: " << importance << endl; … … 2515 2545 { 2516 2546 ViewCellsParser parser; 2517 2547 2518 2548 DEL_PTR(mVspBspTree); 2519 2549 mVspBspTree = new VspBspTree(); 2520 2550 2521 2551 bool success = parser.ParseFile(filename, mVspBspTree, this, objects); 2522 2552 mVspBspTree->RepairViewCellsLeafLists(); 2523 2553 mVspBspTree->mBox = GetViewSpaceBox(); 2524 2554 ResetViewCells(); 2525 2555 2526 2556 mViewCellsFinished = true; 2527 2557 mMaxPvsSize = (int)objects->size(); 2528 2558 2529 2559 FinalizeViewCells(true); 2530 2560 2531 2561 Debug << (int)mViewCells.size() << " view cells loaded" << endl; 2532 2562 … … 2543 2573 bool VspBspViewCellsManager::ExportViewCells(const string filename) 2544 2574 { 2545 cout << "exporting view cells to xml ... "; 2575 cout << "exporting view cells to xml ... "; 2546 2576 std::ofstream stream; 2547 2577 … … 2552 2582 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 2553 2583 stream << "<Visibility_Solution>" << endl; 2554 2584 2555 2585 //-- load the view cells itself, i.e., the ids and the pvs 2556 2586 stream << "<ViewCells>" << endl; … … 2558 2588 for (it = mViewCells.begin(); it != it_end; ++ it) 2559 2589 ExportViewCell(*it, stream); 2560 2590 2561 2591 stream << "</ViewCells>" << endl; 2562 2592 2563 2593 //-- load the hierarchy 2564 2594 stream << "<BspTree>" << endl; 2565 2595 mVspBspTree->Export(stream); 2566 2596 stream << endl << "</BspTree>" << endl; 2567 2597 2568 2598 stream << "</Visibility_Solution>" << endl; 2569 2599 stream.close();
Note: See TracChangeset
for help on using the changeset viewer.