- Timestamp:
- 01/16/06 03:23:29 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r540 r542 27 27 mViewCellsFinished(false) 28 28 { 29 m SceneBox.Initialize();29 mViewSpaceBox.Initialize(); 30 30 ParseEnvironment(); 31 31 } … … 39 39 mViewCellsFinished(false) 40 40 { 41 m SceneBox.Initialize();41 mViewSpaceBox.Initialize(); 42 42 ParseEnvironment(); 43 43 } … … 77 77 int ViewCellsManager::Construct(VssRayContainer &rays) 78 78 { 79 VssPreprocessor preprocessor; 80 81 82 83 return 0; 79 /* VssPreprocessor preprocessor; 80 81 VssRayContainer vssRays; 82 preprocessor->GenerateVssRays(mConstructionSamples, vssRays); 83 Construct(preprocessor->mObjects, vssRays); 84 85 // add rays to output rays 86 while (!vssRays.empty) 87 { 88 rays.push_back(vssRays.back()); 89 vssRays.pop_back(); 90 } 91 92 const int importanceRays = 1000000; 93 preprocessor->GenerateVssRays(max(importanceRays, mPostProcessSamples); 94 95 PostProcess(preprocesor->mObjects, importanceRays); 96 Visualize(preprocessor->mObjects, importanceRays); 97 98 // add rays to output rays 99 while (!importanceRays.empty) 100 { 101 rays.push_back(importanceRays.back()); 102 importanceRays.pop_back(); 103 } 104 */ 105 return (int)rays.size(); 84 106 } 85 107 … … 99 121 bool ViewCellsManager::GetViewPoint(Vector3 &viewPoint) const 100 122 { 101 viewPoint = m SceneBox.GetRandomPoint();123 viewPoint = mViewSpaceBox.GetRandomPoint(); 102 124 103 125 return true; … … 107 129 bool ViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 108 130 { 109 return m SceneBox.IsInside(viewPoint);131 return mViewSpaceBox.IsInside(viewPoint); 110 132 } 111 133 … … 333 355 void ViewCellsManager::SetViewSpaceBox(const AxisAlignedBox3 &box) 334 356 { 335 m SceneBox = box;357 mViewSpaceBox = box; 336 358 } 337 359 … … 339 361 AxisAlignedBox3 ViewCellsManager::GetViewSpaceBox() const 340 362 { 341 return m SceneBox;363 return mViewSpaceBox; 342 364 } 343 365 … … 358 380 void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 359 381 { 360 361 362 363 364 365 366 367 368 369 370 382 ViewCellContainer viewcells; 383 384 ray.mPvsContribution = 0; 385 ray.mRelativePvsContribution = 0.0f; 386 387 // matt TODO: remove this!! 388 Ray hray(ray); 389 float tmin = 0, tmax = 1.0; 390 391 //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 392 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 371 393 return; 372 394 373 Vector3 origin = hray.Extrap(tmin); 374 Vector3 termination = hray.Extrap(tmax); 375 376 CastLineSegment(origin, 377 termination, 378 viewcells); 379 //Debug << "constribution: " << (int)viewcells.size() << endl; 380 // copy viewcells memory efficiently 381 const bool storeViewcells = false; 382 if (storeViewcells) { 383 ray.mViewCells.reserve(viewcells.size()); 384 ray.mViewCells = viewcells; 385 } 386 387 ViewCellContainer::const_iterator it = viewcells.begin(); 388 389 bool addInPlace = false; 390 391 if (addInPlace) { 392 for (; it != viewcells.end(); ++it) { 393 ViewCell *viewcell = *it; 394 395 // if ray not outside of view space 396 float contribution; 397 bool added = 398 viewcell->GetPvs().AddSample(ray.mTerminationObject, 399 contribution 400 ); 401 if (added) 402 ray.mPvsContribution++; 403 404 ray.mRelativePvsContribution += contribution; 405 } 406 } else { 407 for (; it != viewcells.end(); ++it) { 408 ViewCell *viewcell = *it; 409 // if ray not outside of view space 410 float contribution; 411 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 412 contribution 413 )) 414 ray.mPvsContribution++; 415 416 ray.mRelativePvsContribution += contribution; 417 } 418 419 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 420 ViewCell *viewcell = *it; 421 // if ray not outside of view space 422 viewcell->GetPvs().AddSample(ray.mTerminationObject); 423 } 424 } 395 Vector3 origin = hray.Extrap(tmin); 396 Vector3 termination = hray.Extrap(tmax); 397 398 CastLineSegment(origin, 399 termination, 400 viewcells); 401 //Debug << "constribution: " << (int)viewcells.size() << endl; 402 // copy viewcells memory efficiently 403 const bool storeViewcells = false; 404 if (storeViewcells) 405 { 406 ray.mViewCells.reserve(viewcells.size()); 407 ray.mViewCells = viewcells; 408 } 409 410 ViewCellContainer::const_iterator it = viewcells.begin(); 411 412 bool addInPlace = false; 413 414 if (addInPlace) 415 { 416 for (; it != viewcells.end(); ++it) { 417 ViewCell *viewcell = *it; 418 419 // if ray not outside of view space 420 float contribution; 421 bool added = 422 viewcell->GetPvs().AddSample(ray.mTerminationObject, 423 contribution 424 ); 425 if (added) 426 ray.mPvsContribution++; 427 428 ray.mRelativePvsContribution += contribution; 429 } 430 } 431 else 432 { 433 for (; it != viewcells.end(); ++it) { 434 ViewCell *viewcell = *it; 435 // if ray not outside of view space 436 float contribution; 437 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 438 contribution 439 )) 440 ray.mPvsContribution++; 441 ray.mRelativePvsContribution += contribution; 442 } 443 444 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 445 ViewCell *viewcell = *it; 446 // if ray not outside of view space 447 viewcell->GetPvs().AddSample(ray.mTerminationObject); 448 } 449 } 425 450 } 426 451 … … 1456 1481 << (int)constructionRays.size() << " samples" << endl; 1457 1482 1458 mVspKdTree->Construct(constructionRays, &m SceneBox);1483 mVspKdTree->Construct(constructionRays, &mViewSpaceBox); 1459 1484 Debug << mVspKdTree->GetStatistics() << endl; 1460 1485 … … 1468 1493 mVspKdTree->RefineViewCells(rays); 1469 1494 1470 1495 // collapse siblings belonging to the same view cell 1471 1496 mVspKdTree->CollapseTree(); 1472 1497 … … 1827 1852 Debug << "saved rays: " << (int)savedRays.size() << endl; 1828 1853 1829 mVspBspTree->Construct(constructionRays, &m SceneBox);1854 mVspBspTree->Construct(constructionRays, &mViewSpaceBox); 1830 1855 1831 1856 Debug << mVspBspTree->GetStatistics() << endl; … … 1982 2007 } 1983 2008 1984 EvaluateViewCellsStats(); 1985 1986 // view cells already finished post processing step 2009 2010 // view cells already finished before post processing step (i.e. because they were loaded) 1987 2011 if (mViewCellsFinished) 2012 { 2013 EvaluateViewCellsStats(); 1988 2014 return 0; 2015 } 2016 2017 2018 // check if new view cells turned invalid 2019 mVspBspTree->CheckValidy(); 2020 ResetViewCells(); 2021 1989 2022 1990 2023 VssRayContainer postProcessRays; … … 2038 2071 for (int i = 0; i < limit; ++ i) 2039 2072 { 2040 viewPoint = m SceneBox.GetRandomPoint();2073 viewPoint = mViewSpaceBox.GetRandomPoint(); 2041 2074 if (mVspBspTree->ViewPointValid(viewPoint)) 2042 2075 { … … 2051 2084 bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 2052 2085 { 2053 return m SceneBox.IsInside(viewPoint) &&2086 return mViewSpaceBox.IsInside(viewPoint) && 2054 2087 mVspBspTree->ViewPointValid(viewPoint); 2055 2088 } … … 2072 2105 if (exporter) 2073 2106 { 2107 if (1) 2108 { 2109 exporter->SetWireframe(); 2110 exporter->ExportBox(mViewSpaceBox); 2111 exporter->SetFilled(); 2112 } 2113 2074 2114 if (mExportGeometry) 2115 { 2075 2116 exporter->ExportGeometry(objects); 2117 } 2076 2118 2077 2119 // export rays … … 2099 2141 } 2100 2142 2101 // export single view cells2143 //-- export single view cells 2102 2144 ExportBspPvs(objects, visRays); 2103 2145 } … … 2167 2209 VssRayContainer vcRays; 2168 2210 Intersectable::NewMail(); 2169 #if 0 2211 #if 0 // largest view cell pvs first 2170 2212 BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 2171 2213 #else … … 2301 2343 ViewCell *vc) const 2302 2344 { 2303 #if 1 2304 if (vc->GetMesh()) 2345 if (vc->GetMesh()) 2305 2346 { 2306 2347 exporter->ExportMesh(vc->GetMesh()); … … 2312 2353 ConstructGeometry(dynamic_cast<BspViewCell *>(vc), geom); 2313 2354 exporter->ExportPolygons(geom.mPolys); 2314 #else2315 2316 Material m2;2317 m2.mDiffuseColor.b = 0.3f + Random(0.7f);2318 m2.mDiffuseColor.r = 0.0f;//0.3f + Random(0.7f);2319 m2.mDiffuseColor.g = 0.3f + Random(0.7f);2320 Material m;2321 m.mDiffuseColor.b = 0.0f;2322 m.mDiffuseColor.r = 1.0f;2323 m.mDiffuseColor.g = 0.0f;2324 2325 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc);2326 vector<BspLeaf *>::const_iterator it, it_end = bspVc->mLeaves.end();2327 2328 for (it = bspVc->mLeaves.begin(); it != it_end; ++ it)2329 {2330 if ((*it)->Mailed())2331 exporter->SetForcedMaterial(m);2332 else2333 exporter->SetForcedMaterial(m2);2334 //exporter->ResetForcedMaterial();2335 BspNodeGeometry geom;2336 mVspBspTree->ConstructGeometry(*it, geom);2337 exporter->ExportPolygons(geom.mPolys);2338 }2339 #endif2340 2355 } 2341 2356
Note: See TracChangeset
for help on using the changeset viewer.