- Timestamp:
- 12/15/05 18:45:12 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r466 r468 27 27 environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling); 28 28 environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples); 29 29 30 30 mStats.open("stats.log"); 31 31 } … … 37 37 38 38 void 39 VssPreprocessor::SetupRay(Ray &ray, 40 const Vector3 &point, 39 VssPreprocessor::SetupRay(Ray &ray, 40 const Vector3 &point, 41 41 const Vector3 &direction 42 42 ) … … 62 62 if (!sbox.IsInside(viewPoint)) 63 63 return 0; 64 64 65 65 SetupRay(ray, viewPoint, direction); 66 66 // cast ray to KD tree to find intersection with other objects … … 81 81 } 82 82 pointA = ray.Extrap(tmax); 83 83 84 84 } 85 85 86 86 bool detectEmptyViewSpace = true; 87 87 88 88 if (detectEmptyViewSpace) { 89 89 SetupRay(ray, pointA, -direction); 90 90 } else 91 91 SetupRay(ray, viewPoint, -direction); 92 93 92 93 94 94 if (mKdTree->CastRay(ray)) { 95 95 96 96 objectB = ray.intersections[0].mObject; 97 97 pointB = ray.Extrap(ray.intersections[0].mT); … … 105 105 // cerr<<"ray"<<ray<<endl; 106 106 } 107 107 108 108 pointB = ray.Extrap(tmax); 109 109 } … … 118 118 } 119 119 } 120 120 121 121 if (validSample) { 122 122 if (objectA) { … … 128 128 hits ++; 129 129 } 130 130 131 131 if (objectB) { 132 132 vssRay = new VssRay(pointA, … … 138 138 } 139 139 } 140 140 141 141 return hits; 142 142 } … … 147 147 { 148 148 AxisAlignedBox3 box; 149 149 150 150 if (viewSpaceBox) 151 151 box =*viewSpaceBox; 152 else 152 else 153 153 box = mKdTree->GetBox(); 154 154 155 155 // shrink the box in the y direction 156 156 return box.GetRandomPoint(); … … 170 170 } else { 171 171 AxisAlignedBox3 box; 172 172 173 173 if (viewSpaceBox) 174 174 box =*viewSpaceBox; 175 else 175 else 176 176 box = mKdTree->GetBox(); 177 177 178 178 point = box.GetRandomPoint(); 179 179 point.y = viewpoint.y; 180 180 } 181 181 182 182 return point - viewpoint; 183 183 } … … 194 194 float maxRayContribution; 195 195 float avgRayContribution; 196 196 197 197 vssTree->GetRayContributionStatistics(minRayContribution, 198 198 maxRayContribution, 199 199 avgRayContribution); 200 200 201 201 cout<< 202 202 "#MIN_RAY_CONTRIB\n"<<minRayContribution<<endl<< 203 203 "#MAX_RAY_CONTRIB\n"<<maxRayContribution<<endl<< 204 204 "#AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl; 205 205 206 206 float p = desiredSamples/(float)(avgRayContribution*vssTree->stat.Leaves()); 207 207 num = vssTree->GenerateRays(p, rays); … … 210 210 num = vssTree->GenerateRays(desiredSamples, leaves, rays); 211 211 } 212 212 213 213 cout<<"Generated "<<num<<" rays."<<endl; 214 214 215 215 return num; 216 216 } … … 224 224 { 225 225 cout<<"Exporting vss rays..."<<endl<<flush; 226 226 227 227 float prob = number/(float)vssRays.size(); 228 228 … … 241 241 exporter->ResetForcedMaterial(); 242 242 } 243 243 244 244 VssRayContainer rays; for (int i=0; i < vssRays.size(); i++) 245 245 if (RandomValue(0,1) < prob) … … 247 247 248 248 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 249 249 250 250 delete exporter; 251 251 … … 280 280 exporter->SetWireframe(); 281 281 exporter->ExportKdTree(*mKdTree); 282 282 283 283 if (mViewSpaceBox) { 284 284 exporter->SetForcedMaterial(RgbColor(1,0,0)); … … 286 286 exporter->ResetForcedMaterial(); 287 287 } 288 288 289 289 exporter->SetForcedMaterial(RgbColor(0,0,1)); 290 290 exporter->ExportBox(tree->GetBBox(leaf)); 291 291 exporter->ResetForcedMaterial(); 292 292 293 293 VssRayContainer rays[4]; 294 294 for (int i=0; i < leaf->rays.size(); i++) { … … 296 296 rays[k].push_back(leaf->rays[i].mRay); 297 297 } 298 298 299 299 // SOURCE RAY 300 300 exporter->ExportRays(rays[0], RgbColor(1, 0, 0)); … … 342 342 for (it = viewcells.begin(); it != it_end; ++ it) 343 343 sum += tree->GetPvsSize(*it); 344 344 345 345 return sum/(float)viewcells.size(); 346 346 } … … 349 349 VssPreprocessor::ComputeVisibility() 350 350 { 351 351 352 352 mSceneGraph->CollectObjects(&mObjects); 353 353 354 354 long startTime = GetTime(); 355 355 356 356 int totalSamples = 0; 357 357 … … 368 368 box->SetMax(box->Max() + translation); 369 369 } else { 370 370 371 371 // sample city like heights 372 372 box->SetMin(1, box->Min(1) + box->Size(1)*0.2); … … 376 376 if (use2dSampling) 377 377 box->SetMax(1, box->Min(1)); 378 378 379 379 if (useViewSpaceBox) 380 380 mViewSpaceBox = box; 381 381 else 382 382 mViewSpaceBox = NULL; 383 383 384 384 385 385 VssTree *vssTree = NULL; … … 390 390 int passSamples = 0; 391 391 int index = 0; 392 392 393 393 int sampleContributions; 394 394 395 395 int s = Min(mSamplesPerPass, mInitialSamples); 396 396 for (int k=0; k < s; k++) { 397 397 398 398 Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 399 399 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 400 400 401 401 sampleContributions = CastRay(viewpoint, direction, mVssRays); 402 403 402 403 404 404 //-- CORR matt: put block inside loop 405 405 if (sampleContributions) { … … 410 410 totalSamples++; 411 411 } 412 412 413 413 mPass++; 414 414 415 415 int pvsSize = 0; 416 float avgRayContrib = (passContributingSamples > 0) ? 416 float avgRayContrib = (passContributingSamples > 0) ? 417 417 passSampleContributions/(float)passContributingSamples : 0; 418 418 419 419 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 420 cout << "#TotalSamples=" << totalSamples/1000 421 << "k #SampleContributions=" << passSampleContributions << " (" 420 cout << "#TotalSamples=" << totalSamples/1000 421 << "k #SampleContributions=" << passSampleContributions << " (" 422 422 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 423 << pvsSize/(float)mObjects.size() << endl 423 << pvsSize/(float)mObjects.size() << endl 424 424 << "avg ray contrib=" << avgRayContrib << endl; 425 425 426 426 mStats << 427 427 "#Pass\n" <<mPass<<endl<< 428 428 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 429 429 "#TotalSamples\n" << totalSamples<< endl<< 430 "#SampleContributions\n" << passSampleContributions << endl << 430 "#SampleContributions\n" << passSampleContributions << endl << 431 431 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 432 432 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << … … 435 435 436 436 437 438 } 439 437 438 } 439 440 440 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 441 441 cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush; 442 442 443 443 //int numExportRays = 10000; 444 444 int numExportRays = 0; … … 449 449 ExportRays(filename, mVssRays, numExportRays); 450 450 } 451 451 452 452 mSceneGraph->CollectObjects(&mObjects); 453 453 … … 457 457 vssTree = new VssTree; 458 458 // viewcells = Construct(mVssRays); 459 459 460 460 vssTree->Construct(mVssRays, mViewSpaceBox); 461 461 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 462 462 463 463 if (0) 464 464 { … … 482 482 if (RandomValue(0.0f,1.0f) < prob) 483 483 kdViewcells.push_back(mKdTree->GetBox(*it)); 484 484 485 485 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 486 486 cout<<"Initial average PVS size = "<<avgPvs<<endl; 487 487 } 488 488 489 489 490 490 int samples = 0; 491 491 int pass = 0; … … 498 498 SimpleRayContainer rays; 499 499 VssRayContainer vssRays; 500 500 501 501 if (!mUseImportanceSampling) { 502 502 for (int j=0; j < num; j++) { … … 508 508 num = GenerateImportanceRays(vssTree, num, rays); 509 509 } 510 510 511 511 for (int i=0; i < rays.size(); i++) 512 512 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 513 513 514 514 vssTree->AddRays(vssRays); 515 515 516 516 if (0) { 517 517 int subdivided = vssTree->UpdateSubdivision(); … … 528 528 else 529 529 sprintf(filename, "vss-rays-%04d.x3d", pass); 530 530 531 531 ExportRays(filename, vssRays, numExportRays); 532 532 } … … 547 547 } 548 548 549 549 550 { 550 551 VssRayContainer storedRays; … … 552 553 mViewCellsManager->GetPostProcessSamples(), 553 554 mViewCellsManager->GetVisualizationSamples())); 554 555 555 556 //-- post process view cells 556 557 mViewCellsManager->PostProcess(mObjects, storedRays); 557 558 558 559 //-- several visualizations and statistics 559 560 mViewCellsManager->PrintStatistics(Debug); … … 563 564 CLEAR_CONTAINER(storedRays); 564 565 } 566 567 //-- render simulation after merge 568 cout << "\nevaluating bsp view cells render time after merge ... "; 565 569 566 570 //-- render simulation after merge 567 571 cout << "\nevaluating bsp view cells render time after merge ... "; 568 572 569 const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 570 573 mRenderSimulator->RenderScene(); 574 SimulationStatistics ss; 575 mRenderSimulator->GetStatistics(ss); 576 571 577 cout << " finished" << endl; 572 578 cout << ss << endl; 573 579 Debug << ss << endl; 574 575 580 581 576 582 delete vssTree; 577 583 578 584 return true; 579 585 }
Note: See TracChangeset
for help on using the changeset viewer.