- Timestamp:
- 01/18/07 11:44:46 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1976 r1990 1320 1320 "gvs_stats=", 1321 1321 "gvsStats.log"); 1322 1323 1322 1324 1323 /**********************************************************************/ -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r1983 r1990 15 15 #include "KdTree.h" 16 16 17 //#include <Cg/cg.h> 18 //#include <Cg/cgGL.h> 19 17 #ifdef USE_CG 18 19 #include <Cg/cg.h> 20 #include <Cg/cgGL.h> 21 22 #endif 20 23 21 24 namespace GtpVisibilityPreprocessor { … … 814 817 GlRendererBuffer::~GlRendererBuffer() 815 818 { 816 #if USE_CG 817 if (sCgFragmentProgram) 819 #if 0 820 #ifdef USE_CG 821 if (sCgFragmentProgram) 818 822 cgDestroyProgram(sCgFragmentProgram); 819 823 if (sCgContext) 820 824 cgDestroyContext(sCgContext); 825 #endif 821 826 #endif 822 827 } … … 1040 1045 glEnable(GL_TEXTURE_2D); 1041 1046 1042 #if USE_CG 1047 #if 0 1048 #ifdef USE_CG 1043 1049 // bind pixel shader implementing the front depth buffer functionality 1044 1050 cgGLBindProgram(sCgFragmentProgram); 1045 1051 cgGLEnableProfile(sCgFragmentProfile); 1046 1052 #endif 1047 1053 #endif 1048 1054 // 5. render all objects inside the beam 1049 1055 // we can use id based false color to read them back for gaining the pvs … … 1173 1179 #endif 1174 1180 1181 //////// 1175 1182 //-- cleanup 1176 1183 … … 1181 1188 glDisable(GL_STENCIL_TEST); 1182 1189 1183 #if USE_CG 1190 #if 0 1191 #ifdef USE_CG 1184 1192 cgGLDisableProfile(sCgFragmentProfile); 1185 1193 #endif 1194 #endif 1195 1186 1196 glDisable(GL_TEXTURE_2D); 1187 1197 … … 1227 1237 void GlRendererBuffer::InitGL() 1228 1238 { 1229 MakeCurrent(); 1230 GlRenderer::InitGL(); 1231 1232 #if 1 1239 MakeCurrent(); 1240 GlRenderer::InitGL(); 1241 1233 1242 // initialise dual depth buffer textures 1234 1243 glGenTextures(1, &frontDepthMap); … … 1253 1262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 1254 1263 1255 1256 #if USE_CG 1264 #if 0 1265 #ifdef USE_CG 1266 1257 1267 // cg initialization 1258 1268 cgSetErrorCallback(handleCgError); -
GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp
r1980 r1990 9 9 #include "SamplingStrategy.h" 10 10 11 12 11 // the devil library 13 12 #include <IL/il.h> … … 15 14 #include <IL/ilut.h> 16 15 16 #ifdef USE_CG 17 17 18 #include <Cg/cg.h> 18 19 #include <Cg/cgGL.h> 19 20 20 //#include <QtOpenGL>21 21 22 22 namespace GtpVisibilityPreprocessor { … … 659 659 660 660 const float leftDist = -0.5f * mWidth + mWidth * ((float)x + 0.5f) / mTexWidth; 661 //const float leftDist = 0.5f * mWidth - mWidth * ((float)x + 0.5f) / mTexWidth; 662 663 const float upDist = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / mTexHeight; 664 //const float upDist = 0.5f * mWidth - mWidth * ((float)y + 0.5f) / mTexHeight; 661 const float upDist = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / mTexHeight; 665 662 666 663 hitPoint = mViewPoint + … … 693 690 694 691 695 void GlobalLinesRenderer::ComputeBoundingQuad( float &xMin,696 float &yMin,697 float &xMax,698 float &yMax)692 void GlobalLinesRenderer::ComputeBoundingQuad(int &xMin, 693 int &yMin, 694 int &xMax, 695 int &yMax) 699 696 { 700 697 const AxisAlignedBox3 bbox = mPreprocessor->mKdTree->GetBox(); … … 704 701 m.Invert(); 705 702 706 Vector3 eye(m.x[0][0], m.x[ 0][1], m.x[0][2]);707 Vector3 up(m.x[ 1][0], m.x[1][1], m.x[1][2]);708 Vector3 left(m.x[ 2][0], m.x[2][1], m.x[2][2]);703 Vector3 eye(m.x[0][0], m.x[1][0], m.x[2][0]); 704 Vector3 up(m.x[0][0], m.x[1][1], m.x[2][1]); 705 Vector3 left(m.x[0][2], m.x[1][2], m.x[2][2]); 709 706 710 707 Vector3 boxMin(1e20f); 711 708 Vector3 boxMax(-1e20f); 712 709 713 /* for (int i = 0; i < 6; ++ i) 714 { 715 Vector3 pt; 710 for (int i = 0; i < 8; ++ i) 711 { 712 Vector3 vtx; 713 714 bbox.GetVertex(i, vtx); 715 716 Vector3 pt = vtx.x * eye + vtx.y * up + vtx.z * left; 717 716 718 // TODO 717 if (boxMin.x < pt[i].x)718 boxMin.x = pt [i].x;719 if (boxMin.x > pt.x) 720 boxMin.x = pt.x; 719 721 720 if (boxMin.y < pt[i].y) 721 boxMin.y = pt[i].y; 722 723 if (boxMin.z < pt[i].z) 724 boxMin.z = pt[i].z; 725 } 726 */ 727 xMin = boxMin.x; 728 yMin = boxMin.y; 729 730 xMax = boxMax.x; 731 yMax = boxMax.y; 722 if (boxMin.y > pt.y) 723 boxMin.y = pt.y; 724 725 if (boxMin.z > pt.z) 726 boxMin.z = pt.z; 727 728 if (boxMax.x < pt.x) 729 boxMax.x = pt.x; 730 731 if (boxMax.y < pt.y) 732 boxMax.y = pt.y; 733 734 if (boxMax.z < pt.z) 735 boxMax.z = pt.z; 736 } 737 738 cout << "xmin: " << boxMin.x << " ymin " << boxMin.y << " xmax: " << boxMax.x << " ymax: " << boxMax.y << endl; 739 740 xMin = (int)(-0.5f * mWidth + mWidth * (boxMin.x + 0.5f) / mTexWidth); 741 yMin = (int)(-0.5f * mWidth + mWidth * (boxMin.y + 0.5f) / mTexHeight); 742 xMax = (int)(-0.5f * mWidth + mWidth * (boxMax.x + 0.5f) / mTexWidth); 743 yMax = (int)(-0.5f * mWidth + mWidth * (boxMax.y + 0.5f) / mTexHeight); 732 744 } 733 745 … … 757 769 } 758 770 } 771 772 int xMin, yMin, xMax, yMax; 773 ComputeBoundingQuad(xMin, yMin, xMax, yMax); 774 775 cout << "xmin2: " << xMin << " ymin " << yMin << " xmax: " << xMax << " ymax: " << yMax << endl; 759 776 760 777 ///////////////// … … 1081 1098 } 1082 1099 1083 1084 } 1100 } 1101 1102 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h
r1980 r1990 50 50 51 51 52 void ComputeBoundingQuad( float &xMin,53 float &yMin,54 float &xMax,55 float &yMax);52 void ComputeBoundingQuad(int &xMin, 53 int &yMin, 54 int &xMax, 55 int &yMax); 56 56 57 57 void InitGl(); -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1982 r1990 10 10 #include "Exporter.h" 11 11 #include "SamplingStrategy.h" 12 #include "BvHierarchy.h" 12 13 13 14 … … 24 25 }; 25 26 27 static const float MIN_DIST = 0.01f; 28 26 29 static vector<VizStruct> vizContainer; 27 30 28 31 GvsPreprocessor::GvsPreprocessor(): 29 32 Preprocessor(), 30 mSamplingType(SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION), 33 mSamplingType(SamplingStrategy::VIEWCELL_BASED_DISTRIBUTION), 34 //mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION), 31 35 mNumViewCells(0), 32 36 mCurrentViewCell(NULL) … … 37 41 Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.epsilon", mEps); 38 42 Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.threshold", mThreshold); 39 Environment::GetSingleton()->GetBoolValue("GvsPreprocessor. UsePerViewCellSampling", mPerViewCell);43 Environment::GetSingleton()->GetBoolValue("GvsPreprocessor.perViewCell", mPerViewCell); 40 44 41 45 char gvsStatsLog[100]; … … 51 55 Debug << "stats: " << gvsStatsLog << endl; 52 56 53 if (0) 57 if (1) 58 mOnlyRandomSampling = false; 59 else 54 60 mOnlyRandomSampling = true; 55 else56 mOnlyRandomSampling = false;57 61 58 62 mGvsStats.Reset(); 63 } 64 65 66 GvsPreprocessor::~GvsPreprocessor() 67 { 68 // clean ray queue 69 while (!mRayQueue.empty()) 70 { 71 // handle next ray 72 VssRay *ray = mRayQueue.top(); 73 mRayQueue.pop(); 74 75 delete ray; 76 } 59 77 } 60 78 … … 65 83 return false; // no more view cells 66 84 67 mCurrentViewCell = mViewCellsManager->GetViewCell(mNumViewCells); 68 mViewCellsManager->CreateMesh(mCurrentViewCell); 85 if (1) 86 mCurrentViewCell = mViewCellsManager->GetViewCell(mNumViewCells); 87 else 88 { 89 // HACK 90 int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f); 91 mCurrentViewCell = mViewCellsManager->GetViewCell(idx); 92 } 93 94 if (!mCurrentViewCell->GetMesh()) 95 mViewCellsManager->CreateMesh(mCurrentViewCell); 69 96 70 97 ++ mNumViewCells; … … 106 133 delete newRay; 107 134 } 108 else if ( GVS_DEBUG && (mVssRays.size() < 9))135 else if (0 && GVS_DEBUG && (mVssRays.size() < 9)) 109 136 { 110 137 mVssRays.push_back(new VssRay(oldRay)); … … 122 149 bool GvsPreprocessor::HandleRay(VssRay *vssRay) 123 150 { 124 // compute the contribution to theview cells125 const bool storeRaysForViz = GVS_DEBUG;151 // store the rays + the intersected view cells 152 const bool storeRaysForViz = false; //GVS_DEBUG; 126 153 127 154 if (!mPerViewCell) … … 129 156 mViewCellsManager->ComputeSampleContribution(*vssRay, 130 157 true, 131 storeRaysForViz); 158 storeRaysForViz, 159 true); 132 160 } 133 161 else … … 135 163 mViewCellsManager->ComputeSampleContribution(*vssRay, 136 164 true, 137 mCurrentViewCell); 165 mCurrentViewCell, 166 true); 138 167 } 139 168 … … 141 170 if (!vssRay->mPvsContribution) 142 171 return false; 172 173 if (GVS_DEBUG) 174 mVssRays.push_back(new VssRay(*vssRay)); 143 175 144 176 // add new ray to ray queue … … 158 190 } 159 191 160 ++ mGvsStats.m PassContribution;192 ++ mGvsStats.mTotalContribution; 161 193 162 194 return true; … … 237 269 const VssRay &oldRay) 238 270 { 271 // cast reverse rays if necessary 239 272 CheckDiscontinuity(ray1, hitTriangle, oldRay); 240 273 CheckDiscontinuity(ray2, hitTriangle, oldRay); 241 274 242 if (EqualVisibility(ray1, ray2) || (Magnitude(p1 - p2) <= mEps))275 if (EqualVisibility(ray1, ray2) || (Magnitude(p1 - p2) <= MIN_DIST)) 243 276 { 244 277 return 0; 245 278 } 246 else 247 { 248 // the new subdivision point 249 const Vector3 p = (p1 + p2) * 0.5f; 250 251 //cout << "tobj " << ray1.mTerminationObject << " " << ray2.mTerminationObject << " " << p1 << " " << p2 << endl; 252 //cout << "term " << ray1.mTermination << " " << ray2.mTermination << endl; 253 254 // cast ray into the new point 255 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 256 257 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox()); 258 259 if (!newRay) return 0; 260 261 newRay->mFlags |= VssRay::BorderSample; 262 263 // add new ray to queue 264 const bool enqueued = HandleRay(newRay); 265 266 // subdivide further 267 const int samples1 = SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay); 268 const int samples2 = SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay); 269 270 // this ray will not be further processed 271 if (!enqueued) 272 delete newRay; 273 274 return samples1 + samples2 + 1; 275 } 279 280 // the new subdivision point 281 const Vector3 p = (p1 + p2) * 0.5f; 282 283 // cast ray into the new point 284 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 285 286 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), mPerViewCell); 287 288 if (!newRay) return 0; 289 290 newRay->mFlags |= VssRay::BorderSample; 291 292 // add new ray to queue 293 const bool enqueued = HandleRay(newRay); 294 295 // subdivide further 296 const int samples1 = SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay); 297 const int samples2 = SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay); 298 299 // this ray will not be further processed 300 if (!enqueued) 301 delete newRay; 302 303 return samples1 + samples2 + 1; 276 304 } 277 305 … … 301 329 simpleRays.reserve(9); 302 330 303 //cout << "currentRay: " << currentRay.mOrigin << " dir: " << currentRay.GetDir() << endl;304 305 331 VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end(); 306 332 … … 308 334 { 309 335 const Vector3 rayDir = (*vit) - currentRay.GetOrigin(); 336 310 337 SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f); 311 simpleRays.AddRay(sr); 312 313 //cout << "new: " << sr.mOrigin << " dist: " << sr.mDirection << endl; 338 simpleRays.AddRay(sr); 314 339 } 315 340 … … 328 353 // don't cast double rays as we need only the forward rays 329 354 const bool castDoubleRays = false; 330 // cannot prune invalid rays because we have to 331 // compare adjacent rays. 355 // cannot prune invalid rays because we have to compare adjacent rays. 332 356 const bool pruneInvalidRays = false; 333 357 334 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 358 // keep origin for per view cell sampling 359 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays, mPerViewCell); 335 360 336 361 // set flags … … 344 369 EnqueueRays(vssRays); 345 370 346 const int n = (int) enlargedTriangle.size();347 int castRays = (int)vssRays.size();348 371 const int n = (int)vssRays.size(); 372 int castRays = n; 373 349 374 // recursivly subdivide each edge 350 375 for (int i = 0; i < n; ++ i) … … 395 420 396 421 const float eps = mEps; 422 397 423 // the point is chosen to be on the side closer to the original ray 398 424 if (Distance(pt1, pt3) < Distance(pt2, pt3)) … … 432 458 const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 433 459 460 Vector3 newDir, newOrigin; 461 434 462 //-- Construct the mutated ray with xnew, 435 463 //-- dir = predicted(x)- pnew as direction vector 436 const Vector3newDir = predicted - newPoint;464 newDir = predicted - newPoint; 437 465 438 466 // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 439 467 // difficult to say!! 440 468 const float offset = 0.5f; 441 const Vector3 newOrigin = newPoint - newDir * offset; 442 443 static Ray ray(newOrigin, newDir, Ray::LOCAL_RAY); 444 ray.Precompute(); 445 446 // check if ray intersects view cell 447 if (mPerViewCell && !mCurrentViewCell->CastRay(ray)) 448 return NULL; 469 newOrigin = newPoint - newDir * offset; 470 471 ////////////// 472 //-- for per view cell sampling, we must check for intersection 473 //-- with the current view cell 474 475 if (mPerViewCell) 476 { 477 // send ray to view cell 478 static Ray ray; 479 ray.Clear(); 480 ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY); 481 //ray.Init(newOrigin, -newDir, Ray::LINE_SEGMENT); 482 483 //cout << "z"; 484 // check if ray intersects view cell 485 if (!mCurrentViewCell->CastRay(ray)) 486 return NULL; 487 488 Ray::Intersection &hit = ray.intersections[0]; 489 490 //cout << "q"; 491 // the ray starts from the view cell 492 newOrigin = ray.Extrap(hit.mT); 493 } 449 494 450 495 const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 451 496 452 497 VssRay *reverseRay = 453 mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox() );498 mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), mPerViewCell); 454 499 455 500 ++ mGvsStats.mReverseSamples; … … 466 511 // generate simple rays 467 512 SimpleRayContainer simpleRays; 468 GenerateRays(numSamples, sampleType, simpleRays); 469 513 514 ViewCellBasedDistribution vcStrat(*this, mCurrentViewCell); 515 516 GenerateRays(numSamples, vcStrat, simpleRays); 517 518 //cout << "sr: " << simpleRays.size() << endl; 470 519 // generate vss rays 471 520 VssRayContainer samples; 472 CastRays(simpleRays, samples, true); 521 522 const bool castDoubleRays = false; 523 const bool pruneInvalidRays = true; 524 const bool keepOrigin = mPerViewCell; 525 526 CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays, keepOrigin); 527 473 528 // add to ray queue 474 529 EnqueueRays(samples); 475 530 476 531 //Debug << "generated " << numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 477 return (int)s amples.size();532 return (int)simpleRays.size(); 478 533 } 479 534 … … 490 545 491 546 492 int GvsPreprocessor::Pass()493 {494 // reset samples495 int castSamples = 0;496 mGvsStats.mPassContribution = 0;497 498 while (castSamples < mSamplesPerPass)499 {500 // Ray queue empty =>501 // cast a number of uniform samples to fill ray queue502 castSamples += CastInitialSamples(mInitialSamples, mSamplingType);503 504 if (!mOnlyRandomSampling)505 castSamples += ProcessQueue();506 }507 508 mGvsStats.mTotalContribution += mGvsStats.mPassContribution;509 return castSamples;510 }511 512 513 547 int GvsPreprocessor::ProcessQueue() 514 548 { … … 516 550 ++ mGvsStats.mGvsPass; 517 551 518 while (!mRayQueue.empty()) 552 while (!mRayQueue.empty() 553 )//&& (mGvsStats.mTotalSamples + castSamples < mTotalSamples) ) 519 554 { 520 555 // handle next ray 521 556 VssRay *ray = mRayQueue.top(); 522 557 mRayQueue.pop(); 523 524 castSamples += AdaptiveBorderSampling(*ray); 558 if (!ray) cout << "Error!!!!!" << endl; 559 const int newSamples = AdaptiveBorderSampling(*ray); 560 561 castSamples += newSamples; 562 563 //cout << newSamples << " "; 525 564 delete ray; 526 565 } 527 566 528 567 return castSamples; 529 568 } 530 569 531 570 532 void GvsPreprocessor::VisualizeViewCells() 533 { 534 char str[64]; sprintf(str, "tmp/pass%06d_%04d-", mNumViewCells, mPass); 535 536 // visualization 537 if (mGvsStats.mPassContribution > 0) 538 { 539 const bool exportRays = true; 540 const bool exportPvs = true; 541 542 mViewCellsManager->ExportSingleViewCells(mObjects, 543 10, 544 false, 545 exportPvs, 546 exportRays, 547 1000, 548 str); 549 } 550 551 // remove pass samples 552 ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end(); 553 554 for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) 555 { 556 (*vit)->DelRayRefs(); 557 } 558 } 559 560 561 void GvsPreprocessor::PerViewCellComputation() 562 { 563 const int maxViewCells = 5; 564 565 while (NextViewCell() && mNumViewCells < maxViewCells) 566 { 567 cout << "processing view cell " << mNumViewCells << endl; 568 569 while (mGvsStats.mTotalSamples < mTotalSamples) 570 { 571 ++ mPass; 572 573 mGvsStats.mTotalSamples += Pass(); 574 575 //////// 576 //-- stats 577 578 cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples 579 << " of " << mTotalSamples << endl; 580 581 mGvsStats.mPass = mPass; 582 mGvsStats.Stop(); 583 mGvsStats.Print(mGvsStatsStream); 584 //mViewCellsManager->PrintPvsStatistics(mGvsStats); 585 586 if (GVS_DEBUG) 587 VisualizeViewCells(); 588 } 589 590 // ComputeRenderError(); 591 } 592 } 593 594 595 void GvsPreprocessor::GlobalComputation() 596 { 597 while (mGvsStats.mTotalSamples < mTotalSamples) 598 { 599 ++ mPass; 600 601 mGvsStats.mTotalSamples += Pass(); 602 603 //////// 604 //-- stats 605 606 cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples 607 << " of " << mTotalSamples << endl; 608 609 mGvsStats.mPass = mPass; 610 mGvsStats.Stop(); 611 mGvsStats.Print(mGvsStatsStream); 612 //mViewCellsManager->PrintPvsStatistics(mGvsStats); 613 614 if (GVS_DEBUG) 615 VisualizeViewCells(); 616 } 617 } 618 619 620 bool GvsPreprocessor::ComputeVisibility() 621 { 622 cout << "Gvs Preprocessor started\n" << flush; 623 const long startTime = GetTime(); 624 625 Randomize(0); 626 627 mGvsStats.Reset(); 628 mGvsStats.Start(); 629 630 if (!mLoadViewCells) 631 { 632 /// construct the view cells from the scratch 633 ConstructViewCells(); 634 // reset pvs already gathered during view cells construction 635 mViewCellsManager->ResetPvs(); 636 cout << "finished view cell construction" << endl; 637 } 638 else if (0) 639 { 640 //-- test successful view cells loading by exporting them again 641 VssRayContainer dummies; 642 mViewCellsManager->Visualize(mObjects, dummies); 643 mViewCellsManager->ExportViewCells("test.xml.gz", mViewCellsManager->GetExportPvs(), mObjects); 644 } 645 646 mGvsStats.Stop(); 647 mGvsStats.Print(mGvsStatsStream); 648 649 if (mPerViewCell) 650 { 651 PerViewCellComputation(); 652 } 653 else 654 { 655 GlobalComputation(); 656 } 657 658 cout << "cast " << 2 * mGvsStats.mTotalSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl; 659 660 if (GVS_DEBUG) 661 { 662 Visualize(); 663 CLEAR_CONTAINER(mVssRays); 664 } 665 666 return true; 667 } 668 669 670 void GvsPreprocessor::Visualize() 671 { 672 Exporter *exporter = Exporter::GetExporter("gvs.wrl"); 673 674 if (!exporter) 675 return; 676 677 vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end(); 678 for (vit = vizContainer.begin(); vit != vit_end; ++ vit) 679 { 680 exporter->SetWireframe(); 681 exporter->ExportPolygon((*vit).enlargedTriangle); 682 //Material m; 683 exporter->SetFilled(); 684 Polygon3 poly = Polygon3((*vit).originalTriangle); 685 exporter->ExportPolygon(&poly); 686 } 687 688 VssRayContainer::const_iterator rit, rit_end = mVssRays.end(); 689 for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 690 { 691 Intersectable *obj = (*rit)->mTerminationObject; 692 exporter->ExportIntersectable(obj); 693 } 694 571 void ExportVssRays(Exporter *exporter, const VssRayContainer &vssRays) 572 { 695 573 VssRayContainer vcRays, vcRays2, vcRays3; 696 574 575 VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 576 697 577 // prepare some rays for output 698 for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 699 { 700 const float p = RandomValue(0.0f, (float)mVssRays.size()); 578 for (rit = vssRays.begin(); rit != rit_end; ++ rit) 579 { 580 //const float p = RandomValue(0.0f, (float)vssRays.size()); 581 701 582 if (1)//(p < raysOut) 702 583 { … … 716 597 } 717 598 718 exporter->ExportRays(vcRays, RgbColor(1, 0, 0));599 //exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 719 600 exporter->ExportRays(vcRays2, RgbColor(0, 1, 0)); 720 exporter->ExportRays(vcRays3, RgbColor(1, 1, 1)); 721 722 //exporter->ExportRays(mVssRays); 601 //exporter->ExportRays(vcRays3, RgbColor(1, 1, 1)); 602 } 603 604 605 void GvsPreprocessor::VisualizeViewCell(ViewCell *vc) 606 { 607 Intersectable::NewMail(); 608 609 Material m; 610 611 char str[64]; sprintf(str, "pass%06d.wrl", mNumViewCells); 612 613 Exporter *exporter = Exporter::GetExporter(str); 614 if (!exporter) 615 return; 616 617 ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 618 619 // output PVS of view cell 620 while (pit.HasMoreEntries()) 621 { 622 ObjectPvsEntry entry = pit.Next(); 623 624 Intersectable *intersect = entry.mObject; 625 626 if (intersect->Mailed()) 627 continue; 628 629 intersect->Mail(); 630 //m.mDiffuseColor = RgbColor(1, 0, 0); 631 m = RandomMaterial(); 632 exporter->SetForcedMaterial(m); 633 634 exporter->ExportIntersectable(intersect); 635 } 636 637 cout << "vssrays: " << (int)mVssRays.size() << endl; 638 ExportVssRays(exporter, mVssRays); 639 640 ///////////////// 641 //-- export view cell geometry 642 643 exporter->SetWireframe(); 644 645 m.mDiffuseColor = RgbColor(0, 1, 0); 646 exporter->SetForcedMaterial(m); 647 648 mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL); 649 //exporter->SetFilled(); 650 651 DEL_PTR(exporter); 652 } 653 654 655 void GvsPreprocessor::VisualizeViewCells() 656 { 657 char str[64]; sprintf(str, "tmp/pass%06d_%04d-", mNumViewCells, mPass); 658 659 // visualization 660 if (mGvsStats.mPassContribution > 0) 661 { 662 const bool exportRays = true; 663 const bool exportPvs = true; 664 665 mViewCellsManager->ExportSingleViewCells(mObjects, 666 10, 667 false, 668 exportPvs, 669 exportRays, 670 1000, 671 str); 672 } 673 674 // remove pass samples 675 ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end(); 676 677 for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) 678 { 679 (*vit)->DelRayRefs(); 680 } 681 } 682 683 684 void GvsPreprocessor::ProcessViewCell() 685 { 686 mGvsStats.mPerViewCellSamples = 0; 687 int oldContribution = 0; 688 int passSamples = 0; 689 690 while (mGvsStats.mPerViewCellSamples < mTotalSamples) 691 { 692 // Ray queue empty => 693 // cast a number of uniform samples to fill ray queue 694 int newSamples = CastInitialSamples(mInitialSamples, mSamplingType); 695 696 if (!mOnlyRandomSampling) 697 newSamples += ProcessQueue(); 698 699 passSamples += newSamples; 700 mGvsStats.mPerViewCellSamples += newSamples; 701 702 if (0 && 703 passSamples % (mSamplesPerPass + 1) == mSamplesPerPass) 704 { 705 ++ mPass; 706 707 mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution; 708 709 //////// 710 //-- stats 711 712 mGvsStats.mPass = mPass; 713 mGvsStats.Stop(); 714 mGvsStats.Print(mGvsStatsStream); 715 716 //cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl; 717 718 // reset 719 oldContribution = mGvsStats.mTotalContribution; 720 mGvsStats.mPassContribution = 0; 721 passSamples = 0; 722 } 723 } 724 } 725 726 727 void GvsPreprocessor::PerViewCellComputation() 728 { 729 const int maxViewCells = 25; 730 731 while (mNumViewCells < maxViewCells && NextViewCell()) 732 { 733 cout << "processing view cell " << mNumViewCells << endl; 734 735 // compute the pvs of the current view cell 736 ProcessViewCell(); 737 738 // exchange triangle pvs with objects 739 UpdatePvs(mCurrentViewCell); 740 741 if (GVS_DEBUG) 742 { 743 VisualizeViewCell(mCurrentViewCell); 744 CLEAR_CONTAINER(mVssRays); 745 } 746 747 //////// 748 //-- stats 749 750 mGvsStats.mViewCells = mNumViewCells;//mPass; 751 mGvsStats.mTotalPvs += mCurrentViewCell->GetPvs().GetSize(); 752 mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples; 753 754 mGvsStats.Stop(); 755 mGvsStats.Print(mGvsStatsStream); 756 } 757 } 758 759 760 void GvsPreprocessor::UpdatePvs(ViewCell *currentViewCell) 761 { 762 ObjectPvs newPvs; 763 BvhLeaf::NewMail(); 764 765 ObjectPvsIterator pit = currentViewCell->GetPvs().GetIterator(); 766 767 // output PVS of view cell 768 while (pit.HasMoreEntries()) 769 { 770 ObjectPvsEntry entry = pit.Next(); 771 772 Intersectable *intersect = entry.mObject; 773 774 BvhLeaf *bv = intersect->mBvhLeaf; 775 776 if (!bv || bv->Mailed()) 777 continue; 778 779 bv->Mail(); 780 781 //m.mDiffuseColor = RgbColor(1, 0, 0); 782 newPvs.AddSampleDirty(bv, 1.0f); 783 } 784 785 newPvs.SimpleSort(); 786 787 currentViewCell->SetPvs(newPvs); 788 } 789 790 791 void GvsPreprocessor::GlobalComputation() 792 { 793 int passSamples = 0; 794 int oldContribution = 0; 795 796 while (mGvsStats.mTotalSamples < mTotalSamples) 797 { 798 // Ray queue empty => 799 // cast a number of uniform samples to fill ray queue 800 int newSamples = CastInitialSamples(mInitialSamples, mSamplingType); 801 802 if (!mOnlyRandomSampling) 803 newSamples += ProcessQueue(); 804 805 passSamples += newSamples; 806 mGvsStats.mTotalSamples += newSamples; 807 808 if (passSamples % (mSamplesPerPass + 1) == mSamplesPerPass) 809 { 810 ++ mPass; 811 812 mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution; 813 814 //////// 815 //-- stats 816 817 //cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl; 818 mGvsStats.mPass = mPass; 819 mGvsStats.Stop(); 820 mGvsStats.Print(mGvsStatsStream); 821 822 // reset 823 oldContribution = mGvsStats.mTotalContribution; 824 mGvsStats.mPassContribution = 0; 825 passSamples = 0; 826 827 if (GVS_DEBUG) 828 VisualizeViewCells(); 829 } 830 } 831 } 832 833 834 bool GvsPreprocessor::ComputeVisibility() 835 { 836 cout << "Gvs Preprocessor started\n" << flush; 837 const long startTime = GetTime(); 838 839 //Randomize(0); 840 841 mGvsStats.Reset(); 842 mGvsStats.Start(); 843 844 if (!mLoadViewCells) 845 { 846 /// construct the view cells from the scratch 847 ConstructViewCells(); 848 // reset pvs already gathered during view cells construction 849 mViewCellsManager->ResetPvs(); 850 cout << "finished view cell construction" << endl; 851 } 852 else if (0) 853 { 854 //-- test successful view cells loading by exporting them again 855 VssRayContainer dummies; 856 mViewCellsManager->Visualize(mObjects, dummies); 857 mViewCellsManager->ExportViewCells("test.xml.gz", mViewCellsManager->GetExportPvs(), mObjects); 858 } 859 860 mGvsStats.Stop(); 861 mGvsStats.Print(mGvsStatsStream); 862 863 if (mPerViewCell) 864 { 865 PerViewCellComputation(); 866 } 867 else 868 { 869 GlobalComputation(); 870 } 871 872 cout << "cast " << 2 * mGvsStats.mTotalSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl; 873 874 if (GVS_DEBUG) 875 { 876 Visualize(); 877 CLEAR_CONTAINER(mVssRays); 878 } 879 880 return true; 881 } 882 883 884 void GvsPreprocessor::Visualize() 885 { 886 Exporter *exporter = Exporter::GetExporter("gvs.wrl"); 887 888 if (!exporter) 889 return; 890 891 vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end(); 892 for (vit = vizContainer.begin(); vit != vit_end; ++ vit) 893 { 894 exporter->SetWireframe(); 895 exporter->ExportPolygon((*vit).enlargedTriangle); 896 //Material m; 897 exporter->SetFilled(); 898 Polygon3 poly = Polygon3((*vit).originalTriangle); 899 exporter->ExportPolygon(&poly); 900 } 901 902 VssRayContainer::const_iterator rit, rit_end = mVssRays.end(); 903 for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 904 { 905 Intersectable *obj = (*rit)->mTerminationObject; 906 exporter->ExportIntersectable(obj); 907 } 908 909 ExportVssRays(exporter, mVssRays); 910 723 911 delete exporter; 724 912 } … … 735 923 app << "#BorderSamples\n" << mBorderSamples << endl; 736 924 app << "#GvsRuns\n" << mGvsPass << endl; 737 } 738 739 740 } 925 app << "#ViewCells\n" << mViewCells << endl; 926 app << "#TotalPvs\n" << mTotalPvs << endl; 927 app << "#PerViewCellSamples\n" << mPerViewCellSamples << endl << endl; 928 } 929 930 931 } -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r1982 r1990 34 34 mBorderSamples = 0; 35 35 mGvsPass = 0; 36 37 mTotalPvs = 0; 38 mViewCells = 0; 39 mPerViewCellSamples = 0; 36 40 } 37 41 … … 46 50 int mBorderSamples; 47 51 int mGvsPass; 52 53 int mTotalPvs; 54 int mViewCells; 55 int mPerViewCellSamples; 48 56 49 57 void Print(ostream &app) const; … … 65 73 66 74 GvsPreprocessor(); 67 ~GvsPreprocessor() {}75 ~GvsPreprocessor(); 68 76 69 77 virtual bool ComputeVisibility(); … … 94 102 */ 95 103 int ProcessQueue(); 96 97 /** One pass of the sampling preprocessor.98 Continues as long as at least passSample rays have been cast.99 @returns the number of samples cast.100 */101 int Pass();102 104 103 105 /** Generates the rays starting the adaptive visibility sampling process. … … 180 182 void VisualizeViewCells(); 181 183 184 void VisualizeViewCell(ViewCell *vc); 185 186 /** Exchanges view cell triangle pvs with bvh leaf pvs. 187 */ 188 void UpdatePvs(ViewCell *currentViewCell); 189 190 void ProcessViewCell(); 182 191 183 192 ////////////////////// -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r1984 r1990 38 38 const AxisAlignedBox3 &box, 39 39 const bool castDoubleRay, 40 const bool pruneInvalidRays 40 const bool pruneInvalidRays, 41 const bool keepOrigin 41 42 ) 42 43 { … … 102 103 box, 103 104 castDoubleRay, 104 pruneInvalidRays 105 pruneInvalidRays, 106 keepOrigin 105 107 ); 106 108 } … … 112 114 const AxisAlignedBox3 &sbox, 113 115 const bool castDoubleRay, 114 const bool pruneInvalidRays) 116 const bool pruneInvalidRays, 117 const bool keepOrigin) 115 118 { 116 119 int i; … … 227 230 sbox, 228 231 castDoubleRay, 229 pruneInvalidRays 232 pruneInvalidRays, 233 keepOrigin 230 234 ); 231 235 } -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h
r1972 r1990 42 42 const AxisAlignedBox3 &box, 43 43 const bool castDoubleRay, 44 const bool pruneInvalidRays = true); 44 const bool pruneInvalidRays = true, 45 const bool keepOrigin = false); 45 46 46 47 virtual void CastRays16( … … 49 50 const AxisAlignedBox3 &sbox, 50 51 const bool castDoubleRay, 51 const bool pruneInvalidRays = true); 52 const bool pruneInvalidRays = true, 53 const bool keepOrigin = false); 52 54 53 55 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
r1984 r1990 25 25 const AxisAlignedBox3 &box, 26 26 const bool castDoubleRay, 27 const bool pruneInvalidRays 27 const bool pruneInvalidRays, 28 const bool keepOrigin 28 29 ) 29 30 { … … 74 75 box, 75 76 castDoubleRay, 76 pruneInvalidRays 77 pruneInvalidRays, 78 keepOrigin 77 79 ); 78 80 } … … 196 198 const AxisAlignedBox3 &sbox, 197 199 const bool castDoubleRays, 198 const bool pruneInvalidRays) 200 const bool pruneInvalidRays, 201 const bool keepOrigin) 199 202 { 200 203 #if DEBUG_RAYCAST … … 207 210 for (sit = rays.begin(); sit != sit_end; ++ sit) 208 211 { 209 CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays );212 CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays, keepOrigin); 210 213 } 211 214 -
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h
r1972 r1990 40 40 const AxisAlignedBox3 &box, 41 41 const bool castDoubleRay, 42 const bool pruneInvalidRays = true 42 const bool pruneInvalidRays = true, 43 const bool keepOrigin = false 43 44 ); 44 45 … … 47 48 const AxisAlignedBox3 &sbox, 48 49 const bool castDoubleRay, 49 const bool pruneInvalidRays = true 50 const bool pruneInvalidRays = true, 51 const bool keepOrigin = false 50 52 ); 51 53 -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1877 r1990 129 129 const int maxTries) = 0; 130 130 131 // virtual int GetRandomPoint(Vector3 &point, 132 // Vector3 &normal) = 0; 133 131 134 virtual ostream &Describe(ostream &s) = 0; 132 135 -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
r1981 r1990 212 212 int nearestFace = -1; 213 213 214 if (ray.GetType() == Ray::LOCAL_RAY && ray.intersections.size())214 if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) 215 215 nearestT = ray.intersections[0].mT; 216 216 … … 230 230 231 231 if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 232 if ( ray.intersections.size())232 if (!ray.intersections.empty()) 233 233 ray.intersections[0] = Ray::Intersection(nearestT, 234 235 236 234 nearestNormal, 235 instance, 236 nearestFace); 237 237 else 238 238 ray.intersections.push_back(Ray::Intersection(nearestT, 239 240 241 239 nearestNormal, 240 instance, 241 nearestFace)); 242 242 } 243 243 … … 758 758 { 759 759 int res = mMesh->CastRay(ray, this); 760 760 761 return res; 761 762 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.cpp
r1883 r1990 106 106 bool *coplanar) const 107 107 { 108 const Vector3 v = b - a; // line from A to B 109 float dv = DotProd(v, mNormal); 108 //cout << "a: " << a << " b: " << b << endl; 109 const Vector3 v = b - a; // line from A to B 110 float dv = DotProd(v, mNormal); 110 111 111 112 if (signum(dv) == 0) -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1984 r1990 211 211 DEL_PTR(renderer); 212 212 DEL_PTR(mRayCaster); 213 213 #ifdef USE_CG 214 214 DEL_PTR(mGlobalLinesRenderer); 215 #endif 215 216 } 216 217 … … 1012 1013 return strategy.GenerateSamples(number, rays); 1013 1014 } 1015 1014 1016 1015 1017 int … … 1145 1147 VssRayContainer &vssRays, 1146 1148 const bool castDoubleRays, 1147 const bool pruneInvalidRays 1149 const bool pruneInvalidRays, 1150 const bool keepOrigin 1148 1151 ) 1149 1152 { … … 1178 1181 { 1179 1182 SimpleRay ray = *rit; 1183 #ifdef USE_CG 1180 1184 // HACK: global lines must be treated special 1181 1185 if (ray.mDistribution == SamplingStrategy::HW_GLOBAL_LINES_DISTRIBUTION) … … 1184 1188 continue; 1185 1189 } 1186 1190 #endif 1187 1191 rayBucket.push_back(ray); 1188 1192 … … 1195 1199 mViewCellsManager->GetViewSpaceBox(), 1196 1200 castDoubleRays, 1197 pruneInvalidRays); 1201 pruneInvalidRays, 1202 keepOrigin); 1198 1203 1199 1204 rayBucket.clear(); … … 1210 1215 { 1211 1216 SimpleRay ray = *sit; 1217 1218 #ifdef USE_CG 1212 1219 // HACK: global lines must be treated special 1213 1220 if (ray.mDistribution == SamplingStrategy::HW_GLOBAL_LINES_DISTRIBUTION) 1214 1221 { 1215 1222 mGlobalLinesRenderer->CastGlobalLines(ray, vssRays); 1216 } 1217 else 1218 { 1219 mRayCaster->CastRay( 1220 ray, 1221 vssRays, 1222 mViewCellsManager->GetViewSpaceBox(), 1223 castDoubleRays, 1224 pruneInvalidRays); 1225 } 1223 continue; 1224 } 1225 #endif 1226 mRayCaster->CastRay( 1227 ray, 1228 vssRays, 1229 mViewCellsManager->GetViewSpaceBox(), 1230 castDoubleRays, 1231 pruneInvalidRays, 1232 keepOrigin); 1233 1226 1234 } 1227 1235 … … 1403 1411 Debug << endl; 1404 1412 1413 #ifdef USE_CG 1405 1414 globalLinesRenderer = mGlobalLinesRenderer = 1406 1415 new GlobalLinesRenderer(this, … … 1410 1419 maxDepth, 1411 1420 sampleReverse); 1412 1421 1413 1422 mGlobalLinesRenderer->InitGl(); 1414 } 1415 1416 } 1423 1424 #endif 1425 } 1426 1427 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1968 r1990 145 145 VssRayContainer &vssRays, 146 146 const bool castDoubleRays, 147 const bool pruneInvalidRays = true); 147 const bool pruneInvalidRays = true, 148 const bool keepOrigin = false); 148 149 149 150 /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */ -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1989 r1990 25 25 26 26 VssRay *RayCaster::CastRay(const SimpleRay &simpleRay, 27 const AxisAlignedBox3 &box )28 //const bool castDoubleRay)27 const AxisAlignedBox3 &box, 28 const bool keepOrigin) 29 29 { 30 30 // note: make no sense otherwise 31 31 const bool castDoubleRay = false; 32 32 33 VssRayContainer rays; 33 CastRay(simpleRay, rays, box, castDoubleRay );34 CastRay(simpleRay, rays, box, castDoubleRay, true, keepOrigin); 34 35 35 36 if (!rays.empty()) … … 38 39 return NULL; 39 40 } 41 40 42 41 43 bool … … 143 145 _SortRays(rays, 144 146 0, 145 rays.size()-1,147 (int)rays.size()-1, 146 148 0, 147 149 b … … 162 164 // get the largest axis 163 165 int offset = 0; 166 int i; 164 167 165 168 if (depth%5==0) 166 169 offset = 3; 167 170 168 for (i nt i=offset; i < offset+3; i++) {171 for (i=offset; i < offset+3; i++) { 169 172 float diff = box[i+6] - box[i]; 170 173 if (diff > maxDiff) { … … 176 179 // cout<<depth<<" "<<axis<<endl; 177 180 178 int i=l,j=r; 181 i=l; 182 int j=r; 183 179 184 float x = (box[axis] + box[axis+6])*0.5f; 180 185 // float x = rays[(l+r)/2].GetParam(axis); … … 216 221 const AxisAlignedBox3 &box, 217 222 const bool castDoubleRay, 218 const bool pruneInvalidRays) 223 const bool pruneInvalidRays, 224 const bool keepOrigin) 219 225 { 220 226 int hits = 0; … … 235 241 // regardless of the pruneInvalidRays setting reject rays whic degenerate to a point 236 242 if (EpsilonEqualV3(hitA.mPoint, hitB.mPoint, Limits::Small)) { 237 243 return 0; 238 244 } 239 245 … … 277 283 if (!pruneInvalidRays || hitA.mObject) { 278 284 VssRay *vssRay = new VssRay( 279 clipB,285 keepOrigin ? simpleRay.mOrigin : clipB, 280 286 hitA.mPoint, 281 287 hitB.mObject, … … 303 309 { 304 310 VssRay *vssRay = new VssRay( 305 clipA,311 keepOrigin ? simpleRay.mOrigin : clipA, 306 312 hitB.mPoint, 307 313 hitA.mObject, -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r1984 r1990 44 44 */ 45 45 VssRay *CastRay(const SimpleRay &simpleRay, 46 const AxisAlignedBox3 &box); 46 const AxisAlignedBox3 &box, 47 const bool keepOrigin); 47 48 48 49 virtual int CastRay(const SimpleRay &simpleRay, … … 50 51 const AxisAlignedBox3 &box, 51 52 const bool castDoubleRay, 52 const bool pruneInvalidRays = true 53 const bool pruneInvalidRays = true, 54 const bool keepOrigin = false 53 55 ) = 0; 54 56 55 57 virtual void CastRays16( 56 58 SimpleRayContainer &rays, 57 59 VssRayContainer &vssRays, 58 60 const AxisAlignedBox3 &sbox, 59 61 const bool castDoubleRay, 60 const bool pruneInvalidRays = true 62 const bool pruneInvalidRays = true, 63 const bool keepOrigin = false 61 64 ) = 0; 62 65 … … 98 101 const AxisAlignedBox3 &box, 99 102 const bool castDoubleRay, 100 const bool pruneInvalidRays = true); 103 const bool pruneInvalidRays = true, 104 const bool keepOrigin = false); 101 105 102 106 /** Checks if ray is valid. … … 109 113 Intersection &hit); 110 114 111 112 113 const Vector3 &termination,114 Vector3 &clippedOrigin,115 Vector3 &clippedTermination);115 bool 116 ClipToViewSpaceBox(const Vector3 &origin, 117 const Vector3 &termination, 118 Vector3 &clippedOrigin, 119 Vector3 &clippedTermination); 116 120 117 121 const Preprocessor &mPreprocessor; -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1989 r1990 15 15 struct SimpleRay; 16 16 class SimpleRayContainer; 17 class ViewCell; 17 18 18 19 struct VssRayContainer; … … 45 46 GVS, 46 47 MUTATION_BASED_DISTRIBUTION, 47 HW_GLOBAL_LINES_DISTRIBUTION 48 HW_GLOBAL_LINES_DISTRIBUTION, 49 VIEWCELL_BASED_DISTRIBUTION 48 50 }; 49 51 … … 257 259 }; 258 260 259 /** This strategy generates samples inside of the objects, e.g., 260 for sampling the inside of a colon. 261 */ 262 /*class ObjectsInteriorDistribution: public SamplingStrategy 263 { 264 public: 265 ObjectsInteriorDistribution(Preprocessor &preprocessor): 266 SamplingStrategy(preprocessor) {} 267 268 virtual bool GenerateSample(SimpleRay &ray); 269 }; 270 */ 261 class ViewCellBasedDistribution: public SamplingStrategy 262 { 263 public: 264 ViewCellBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell) 265 : SamplingStrategy(preprocessor), mViewCell(viewCell) 266 { 267 mType = VIEWCELL_BASED_DISTRIBUTION; 268 } 269 270 private: 271 272 virtual bool GenerateSample(SimpleRay &ray); 273 274 ViewCell *mViewCell; 275 static HaltonSequence sHalton; 276 }; 277 271 278 272 279 class MixtureDistribution: public SamplingStrategy -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1989 r1990 1679 1679 ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 1680 1680 const bool addRays, 1681 const bool storeViewCells) 1681 const bool storeViewCells, 1682 const bool useHitObjects) 1682 1683 { 1683 1684 float sum = 0.0f; … … 1693 1694 sum += (*it)->Length(); 1694 1695 } else { 1695 sum += ComputeSampleContribution(*(*it), addRays, storeViewCells );1696 sum += ComputeSampleContribution(*(*it), addRays, storeViewCells, useHitObjects); 1696 1697 } 1697 1698 } … … 2242 2243 { 2243 2244 // todo: maybe not correct for kd node pvs 2244 if (addRays) { 2245 float pdf = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf); 2246 if (pdf == ray.mPdf) { 2247 absContribution = 1.0f; 2248 if (viewCell->GetPvs().RequiresResort()) 2249 viewCell->GetPvs().SimpleSort(); 2250 } 2251 } else { 2252 if (viewCell->GetPvs().GetSampleContribution( 2253 obj, 2254 ray.mPdf, 2255 relContribution)) 2256 absContribution = 1.0f; 2257 } 2245 if (addRays) 2246 { 2247 float pdf = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf); 2248 2249 if (pdf == ray.mPdf) 2250 { 2251 absContribution = 1.0f; 2252 if (viewCell->GetPvs().RequiresResort()) 2253 viewCell->GetPvs().SimpleSort(); 2254 } 2255 } 2256 else 2257 { 2258 if (viewCell->GetPvs().GetSampleContribution( 2259 obj, 2260 ray.mPdf, 2261 relContribution)) 2262 { 2263 absContribution = 1.0f; 2264 } 2265 } 2266 2258 2267 // $$ clear the relative contribution as it is currently not correct anyway 2259 2268 relContribution = 0.0f; 2260 2269 2261 if (absContribution == 1.0f) { 2270 if (absContribution == 1.0f) 2271 { 2262 2272 ++ ray.mPvsContribution; 2263 2273 relContribution = 1.0f; … … 2297 2307 float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 2298 2308 const bool addRays, 2299 ViewCell *currentViewCell) 2309 ViewCell *currentViewCell, 2310 const bool useHitObjects) 2300 2311 { 2301 2312 ray.mPvsContribution = 0; … … 2306 2317 2307 2318 // optain pvs entry (can be different from hit object) 2308 Intersectable *terminationObj = GetIntersectable(ray, true); 2319 Intersectable *terminationObj; 2320 2321 if (!useHitObjects) 2322 terminationObj = GetIntersectable(ray, true); 2323 else 2324 terminationObj = ray.mTerminationObject; 2309 2325 2310 2326 ComputeViewCellContribution(currentViewCell, … … 2331 2347 ViewCellsManager::ComputeSampleContribution(VssRay &ray, 2332 2348 const bool addRays, 2333 const bool storeViewCells) 2349 const bool storeViewCells, 2350 const bool useHitObjects) 2334 2351 { 2335 2352 ray.mPvsContribution = 0; … … 2361 2378 CastLineSegment(origin, termination, viewCells); 2362 2379 2363 mSamplesStat.mViewCells +=viewCells.size();2380 mSamplesStat.mViewCells += (int)viewCells.size(); 2364 2381 2365 2382 if (storeViewCells) … … 2375 2392 } 2376 2393 2377 // optain pvs entry (can be different from hit object) 2378 Intersectable *terminationObj = GetIntersectable(ray, true); 2394 Intersectable *terminationObj; 2395 2396 // obtain pvs entry (can be different from hit object) 2397 if (!useHitObjects) 2398 terminationObj = GetIntersectable(ray, true); 2399 else 2400 terminationObj = ray.mTerminationObject; 2379 2401 2380 2402 ViewCellContainer::const_iterator it = viewCells.begin(); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1983 r1990 152 152 float ComputeSampleContributions(const VssRayContainer &rays, 153 153 const bool addContributions, 154 const bool storeViewCells); 154 const bool storeViewCells, 155 const bool useHitObject = false); 155 156 156 157 /** Computes sample contribution of a simgle ray to the view cells PVS. … … 162 163 virtual float ComputeSampleContribution(VssRay &ray, 163 164 const bool addContributions, 164 const bool storeViewCells); 165 const bool storeViewCells, 166 const bool useHitObject = false); 165 167 166 168 /** Compute sample contribution only for current view cell. … … 168 170 virtual float ComputeSampleContribution(VssRay &ray, 169 171 const bool addContributions, 170 ViewCell *currentViewCell); 172 ViewCell *currentViewCell, 173 const bool useHitObject = false); 171 174 172 175 /** Prints out statistics of the view cells. … … 1036 1039 1037 1040 bool ViewCellsConstructed() const; 1038 1039 1041 1040 1042 int CastLineSegment(const Vector3 &origin, -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1977 r1990 468 468 //mMemoryConst = (float)(sizeof(VspLeaf) + sizeof(VspViewCell)); 469 469 //mMemoryConst = 50;//(float)(sizeof(VspViewCell)); 470 471 470 //mMemoryConst = (float)(sizeof(VspLeaf) + sizeof(ObjectPvs)); 471 472 472 mMemoryConst = 16;//(float)sizeof(ObjectPvs); 473 cout << "vsp memcost: " << mMemoryConst << endl;473 474 474 475 475 ////////////// 476 476 //-- debug output 477 477 478 Debug << "******* VSP options ******** 478 Debug << "******* VSP options ********" << endl; 479 479 480 480 Debug << "max depth: " << mTermMaxDepth << endl; … … 501 501 502 502 Debug << "vsp mem const: " << mMemoryConst << endl; 503 504 cout << "use cost heuristics: " << mUseCostHeuristics << endl;505 503 506 504 Debug << endl;
Note: See TracChangeset
for help on using the changeset viewer.