Changeset 1381 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 09/15/06 20:55:07 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1379 r1381 732 732 } 733 733 734 #if 0 // matt: implemented interface samplestrategy735 bool736 Preprocessor::GenerateRays(737 const int number,738 const int sampleType,739 SimpleRayContainer &rays740 )741 {742 Vector3 origin, direction;743 int startSize = (int)rays.size();744 for (int i=0; (int)rays.size() - startSize < number; i ++) {745 // now get the direction746 switch (sampleType) {747 case OBJECT_BASED_DISTRIBUTION: {748 mViewCellsManager->GetViewPoint(origin);749 Vector3 point;750 Vector3 normal;751 int i = RandomValue(0, mObjects.size() - 1);752 Intersectable *object = mObjects[i];753 object->GetRandomSurfacePoint(point, normal);754 direction = point - origin;755 }756 break;757 case OBJECT_DIRECTION_BASED_DISTRIBUTION: {758 int i = RandomValue(0, mObjects.size() - 1);759 Intersectable *object = mObjects[i];760 Vector3 normal;761 object->GetRandomSurfacePoint(origin, normal);762 direction = UniformRandomVector(normal);763 origin += 0.1f*direction;764 }765 break;766 case DIRECTION_BASED_DISTRIBUTION:767 mViewCellsManager->GetViewPoint(origin);768 direction = UniformRandomVector();769 break;770 case DIRECTION_BOX_BASED_DISTRIBUTION: {771 mViewCellsManager->GetViewPoint(origin);772 float alpha = RandomValue(0.0f, 2*M_PI);773 float beta = RandomValue(-M_PI/2, M_PI/2);774 direction = VssRay::GetDirection(alpha, beta);775 break;776 }777 case SPATIAL_BOX_BASED_DISTRIBUTION:778 mViewCellsManager->GetViewPoint(origin);779 direction = mKdTree->GetBox().GetRandomPoint() - origin;780 break;781 default:782 // unsuported distribution type783 return false;784 }785 // $$ jb the pdf is yet not correct for all sampling methods!786 float pdf = 1.0f;787 float c = Magnitude(direction);788 if (c > Limits::Small) {789 direction*=1.0f/c;790 rays.AddRay(SimpleRay(origin, direction, pdf));791 }792 }793 return true;794 }795 #endif796 734 bool Preprocessor::GenerateRays(const int number, 797 735 const int sampleType, 798 736 SimpleRayContainer &rays) 799 737 { 800 Vector3 origin, direction;801 802 738 const int startSize = (int)rays.size(); 803 739 SamplingStrategy *strategy = GenerateSamplingStrategy(sampleType); 804 740 805 741 if (!strategy) 742 { 806 743 return false; 744 } 807 745 808 746 for (int i=0; (int)rays.size() - startSize < number; ++ i) 809 747 { 810 748 SimpleRay newRay; 811 bool success = strategy->GenerateSample(newRay); 812 813 if (success) 749 750 if (strategy->GenerateSample(newRay)) 751 { 752 #if 1 814 753 rays.AddRay(newRay); 754 #else 755 GenerateRayBundle(rays, newRay, 16, 0); 756 #endif 757 } 815 758 } 816 759 817 760 delete strategy; 818 819 761 return true; 820 762 } … … 1417 1359 return CastInternalRay(viewPoint, direction, probability, vssRays, box); 1418 1360 } 1419 #if DEBUG_RAYCAST 1361 #if DEBUG_RAYCAST 1420 1362 Debug<<"CRF "<<flush; 1421 1363 #endif 1364 } 1365 1366 1367 bool Preprocessor::GenerateRayBundle(SimpleRayContainer &rayBundle, 1368 const SimpleRay &mainRay, 1369 const int number, 1370 const int pertubType) const 1371 { 1372 rayBundle.push_back(mainRay); 1373 1374 const float pertubOrigin = 10.0f; 1375 const float pertubDir = 0.0f; 1376 1377 for (int i = 0; i < number - 1; ++ i) 1378 { 1379 Vector3 pertub; 1380 1381 pertub.x = RandomValue(0.0f, pertubDir); 1382 pertub.y = RandomValue(0.0f, pertubDir); 1383 pertub.z = RandomValue(0.0f, pertubDir); 1384 const Vector3 newDir = mainRay.mDirection + pertub; 1385 //const Vector3 newDir = mainRay.mDirection; 1386 1387 pertub.x = RandomValue(0.0f, pertubOrigin); 1388 pertub.y = RandomValue(0.0f, pertubOrigin); 1389 pertub.z = RandomValue(0.0f, pertubOrigin); 1390 const Vector3 newOrigin = mainRay.mOrigin + pertub; 1391 //const Vector3 newOrigin = mainRay.mOrigin; 1392 1393 rayBundle.push_back(SimpleRay(newOrigin, newDir, 0)); 1394 } 1395 1396 return true; 1422 1397 } 1423 1398 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1379 r1381 150 150 ); 151 151 152 bool GenerateRayBundle( 153 SimpleRayContainer &rayBundle, 154 const SimpleRay &mainRay, 155 const int number, 156 const int shuffleType) const; 157 152 158 virtual void CastRays(SimpleRayContainer &rays, 153 159 VssRayContainer &vssRays); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1344 r1381 324 324 int ViewCellsManager::Construct(Preprocessor *preprocessor, VssRayContainer *outRays) 325 325 { 326 mPreprocessor = preprocessor;327 328 326 int numSamples = 0; 329 327 … … 331 329 VssRayContainer initialSamples; 332 330 331 // store pointer to preprocessor for further use during construction 332 mPreprocessor = preprocessor; 333 334 335 /////////////////////////////////////////////////////// 336 //-- Initial sampling for the construction of the view cell hierarchy. 337 //-- We use uniform sampling / box based sampling. 338 339 long startTime = GetTime(); 340 333 341 cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 334 335 long startTime = GetTime(); 336 337 //-- construction rays => we use uniform samples for this 338 342 // cast initial samples 339 343 CastPassSamples(mInitialSamples, mSamplingType, initialSamples); 340 344 341 345 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 342 346 … … 356 360 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 357 361 358 // take post processing time 359 startTime = GetTime(); 360 361 //-- stats after construction 362 363 /////////////////////////////////////////// 364 //-- Initial hierarchy construction finished 365 //-- We can do some stats and visualization 366 362 367 ResetViewCells(); 363 368 Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 364 369 365 if (0) // export initial view cells 370 371 //-- optionally export initial view cells 372 if (0) 366 373 { 367 374 const char filename[] = "view_cells.wrl"; 368 375 Exporter *exporter = Exporter::GetExporter(filename); 369 370 376 371 377 if (exporter) … … 385 391 } 386 392 387 //-- guided rays are used for further sampling 393 394 //////////////////////////////////////////////// 395 // 396 //-- Cast some more sampling after initial construction. 397 //-- The additional rays can be used to gain 398 //-- some more information before the bottom-up merge 399 //-- note: guided rays could be used for this task 400 401 // time spent after initial construction 402 startTime = GetTime(); 403 388 404 const int n = mConstructionSamples; //+initialSamples; 389 390 405 // should we use directional samples? 391 406 bool dirSamples = (mSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION); 392 407 393 //-- do some more sampling394 408 while (numSamples < n) 395 409 { … … 412 426 413 427 cout << "finished" << endl; 414 415 428 cout << "computing sample contribution for " << (int)constructionSamples.size() << " samples ... "; 416 429 … … 421 434 cout << "finished" << endl; 422 435 423 424 436 disposeRays(constructionSamples, outRays); 425 426 437 cout << "total samples: " << numSamples << endl; 427 438 } 428 439 429 //-- post processing 430 VssRayContainer postProcessSamples; 431 432 cout << "casting " << mPostProcessSamples << " post processing samples ... "; 433 434 // cast post processing samples rays (storing the view cells if wanted) 435 CastPassSamples(mPostProcessSamples, 436 mSamplingType, 437 postProcessSamples); 438 439 cout << "finished" << endl; 440 441 // stats before post processing (i.e., merge) 440 441 //////////////////////////////////////////////// 442 //-- get stats after the additional sampling step 443 //-- and before the bottom-up merge step 444 442 445 EvaluateViewCellsStats(); 443 Debug << "\noriginal view cell partition before post process:\n" << mCurrentViewCellsStats << endl; 446 Debug << "\noriginal view cell partition before post process:\n" 447 << mCurrentViewCellsStats << endl; 444 448 445 449 mRenderer->RenderScene(); … … 450 454 451 455 456 457 /////////////////////////////////////////////// 458 // 459 //-- post processing of the initial construction 460 //-- We can bottom-up merge the view cells in this step 461 462 463 // we can additionally cast some post processing sample rays. 464 // These rays can be used to store the view cells with the rays 465 VssRayContainer postProcessSamples; 466 cout << "casting " << mPostProcessSamples << " post processing samples ... "; 467 468 CastPassSamples(mPostProcessSamples, mSamplingType, postProcessSamples); 469 470 cout << "finished" << endl; 452 471 cout << "starting post processing and visualization" << endl; 453 472 454 // store view cells for post processing473 // store view cells for post processing? 455 474 const bool storeViewCells = true; 456 475 … … 458 477 ComputeSampleContributions(postProcessSamples, true, storeViewCells); 459 478 460 //-- post processing (e.g.,merging) of the view cells 461 if (1) PostProcess(preprocessor->mObjects, postProcessSamples); 479 PostProcess(preprocessor->mObjects, postProcessSamples); 462 480 463 481 cout << "time needed for post processing (merge) step: " … … 470 488 471 489 472 //return 1; 473 // evaluation of the paritition, i.e., a number of new samples are cast 490 ///////////////////////////////////////////////////////////////////// 491 //-- Evaluation of the resulting view cell partition. 492 //-- We cast a number of new samples and measure the render cost 493 474 494 if (mEvaluateViewCells) 475 495 { … … 477 497 } 478 498 499 500 /////////////////////////////////// 501 //-- Finally, we do some visualization 502 479 503 if (mShowVisualization) 480 504 { 481 //-- visualization482 505 VssRayContainer visualizationSamples; 483 506 484 //-- construction rays => we use uniform samples for this507 //-- visualization rays, e.g., to show some samples in the scene 485 508 CastPassSamples(mVisualizationSamples, 486 509 Preprocessor::DIRECTION_BASED_DISTRIBUTION,
Note: See TracChangeset
for help on using the changeset viewer.