Changeset 2739 for GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
- Timestamp:
- 06/05/08 02:49:49 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r2738 r2739 176 176 // discrepancy between predicted and actual hit point large => this is likely to be a discontinuity 177 177 178 // matt: problem: this does only findCLOSER discontinuities, but not discontinuities which are FARTHER away178 // matt: problem: this only finds CLOSER discontinuities, but not discontinuities which are FARTHER away 179 179 if ((predictedLen - len) < mThreshold) 180 //if ((fabs(predictedLen - len) < mThreshold)181 180 // q: rather use relative distance? 182 181 //if ((predictedLen / len) < mThreshold) … … 208 207 CastRayBundle16(simpleRay, reverseRays, scale); 209 208 } 209 210 mGvsStats.mReverseSamples += (int)reverseRays.size(); 211 212 EnqueueRays(reverseRays); 213 214 return (int)reverseRays.size(); 215 } 216 217 218 int GvsPreprocessor::CheckDiscontinuity2(const VssRay ¤tRay, 219 const Triangle3 &hitTriangle, 220 const VssRay &oldRay) 221 { 222 // the predicted hitpoint is the point where the ray would have intersected the hit triangle 223 Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 224 225 float predictedLen = Magnitude(predictedHit - currentRay.mOrigin); 226 float len = Magnitude(currentRay.mTermination - currentRay.mOrigin); 227 228 // discrepancy between predicted and actual hit point large 229 // => this is likely to be a discontinuity 230 if (fabs(predictedLen - len) < mThreshold) 231 return 0; 232 233 static SimpleRayContainer simpleRays; 234 simpleRays.clear(); 235 236 CreateRandomizedReverseRays(currentRay.mOrigin, predictedHit, hitTriangle, simpleRays, 16); 237 238 static VssRayContainer reverseRays; 239 reverseRays.clear(); 240 CastRays(simpleRays, reverseRays, false, false); 210 241 211 242 mGvsStats.mReverseSamples += (int)reverseRays.size(); … … 487 518 } 488 519 520 ////////// 521 //-- fill up simple rays with random rays so we can cast 16 rays at a time 522 523 const int numRandomRays = 16 - (int)simpleRays.size(); 524 GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples); 525 526 generationTimer.Exit(); 527 528 529 ///////////////////// 530 //-- cast rays to vertices and determine visibility 531 532 static VssRayContainer vssRays; 533 vssRays.clear(); 534 535 // for the original implementation we don't cast double rays 536 const bool castDoubleRays = !mPerViewCell; 537 // cannot prune invalid rays because we have to compare adjacent rays 538 const bool pruneInvalidRays = false; 539 540 //gvsTimer.Entry(); 541 castTimer.Entry(); 542 543 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 544 545 castTimer.Exit(); 546 //gvsTimer.Exit(); 547 548 const int numBorderSamples = (int)vssRays.size() - numRandomRays; 549 int castRays = (int)simpleRays.size(); 550 551 // handle cast rays 552 EnqueueRays(vssRays); 553 489 554 if (0) 490 555 { … … 493 558 dummy.enlargedTriangle = new Polygon3(enlargedTriangle); 494 559 dummy.originalTriangle = hitTriangle; 560 495 561 vizContainer.push_back(dummy); 496 } 497 498 499 ////////// 500 //-- fill up simple rays with random rays so we can cast 16 rays at a time 501 502 const int numRandomRays = 16 - (int)simpleRays.size(); 503 504 if (!mUseDeterministicGvs) 505 { 506 if (0) 507 { 508 SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), 509 currentRay.GetNormalizedDir(), 510 SamplingStrategy::GVS, 511 1.0f); 512 513 GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0, 0.01f); 514 } 515 else 516 GenerateImportanceSamples(currentRay, hitTriangle, numRandomRays, simpleRays); 517 } 518 else 519 GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples); 520 521 generationTimer.Exit(); 522 523 524 ///////////////////// 525 //-- cast rays to vertices and determine visibility 526 527 static VssRayContainer vssRays; 528 vssRays.clear(); 529 530 // for the original implementation we don't cast double rays 531 const bool castDoubleRays = !mPerViewCell; 532 // cannot prune invalid rays because we have to compare adjacent rays 533 const bool pruneInvalidRays = false; 534 535 //gvsTimer.Entry(); 536 castTimer.Entry(); 537 538 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 539 540 castTimer.Exit(); 541 //gvsTimer.Exit(); 542 543 const int numBorderSamples = (int)vssRays.size() - numRandomRays; 544 int castRays = (int)simpleRays.size(); 545 546 // handle cast rays 547 EnqueueRays(vssRays); 548 549 if (0) 550 { 562 551 563 // set flags 552 564 VssRayContainer::const_iterator rit, rit_end = vssRays.end(); … … 556 568 } 557 569 558 for (size_t i = 0; i < vssRays.size(); ++ i)559 {560 // check for discontinuity and cast reverse rays if necessary561 castRays += CheckDiscontinuity(*vssRays[i], hitTriangle, currentRay);562 }563 564 565 570 // recursivly subdivide each edge 566 571 for (int i = 0; i < numBorderSamples; ++ i) 567 572 { 573 castRays += CheckDiscontinuity(*vssRays[i], hitTriangle, currentRay); 574 568 575 castRays += SubdivideEdge(hitTriangle, 569 576 enlargedTriangle[i], … … 638 645 const int numRandomRays = 16 - ((int)simpleRays.size() % 16); 639 646 640 if (!mUseDeterministicGvs) 641 { 642 if (0) 643 { 644 SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), 645 currentRay.GetNormalizedDir(), 646 SamplingStrategy::GVS, 647 1.0f); 648 649 GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0, 0.01f); 650 } 651 else 652 GenerateImportanceSamples(currentRay, hitTriangle, numRandomRays, simpleRays); 653 } 654 else 655 GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples); 656 647 GenerateImportanceSamples(currentRay, hitTriangle, numRandomRays, simpleRays); 648 657 649 generationTimer.Exit(); 658 650 … … 689 681 { 690 682 // check for discontinuity and cast reverse rays if necessary 691 castRays += CheckDiscontinuity (*vssRays[i], hitTriangle, currentRay);683 castRays += CheckDiscontinuity2(*vssRays[i], hitTriangle, currentRay); 692 684 } 693 685 … … 794 786 795 787 ////////////// 796 //-- for per view cell sampling, we must check for intersection788 //-- for per view cell sampling, we must intersect 797 789 //-- with the current view cell 798 790 799 791 if (mPerViewCell) 800 792 { 801 // send ray to view cell 802 static Ray ray; 803 804 ray.Clear(); 805 ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY); 806 807 // check if ray intersects view cell 808 if (!mCurrentViewCell->CastRay(ray)) 793 if (!IntersectViewCell(newOrigin, newDir)) 809 794 return false; 810 811 Ray::Intersection &hit = ray.intersections[0];812 813 // the ray starts from the view cell814 newOrigin = ray.Extrap(hit.mT);815 795 } 816 796 817 797 reverseRay = SimpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 798 799 return true; 800 } 801 802 803 bool GvsPreprocessor::IntersectViewCell(Vector3 &origin, Vector3 &dir) const 804 { 805 // send ray to view cell 806 static Ray testRay; 807 808 testRay.Clear(); 809 testRay.Init(origin, -dir, Ray::LOCAL_RAY); 810 811 // check if ray intersects view cell 812 if (!mCurrentViewCell->CastRay(testRay)) 813 return false; 814 815 Ray::Intersection &hit = testRay.intersections[0]; 816 817 // the ray starts from the view cell 818 origin = testRay.Extrap(hit.mT); 818 819 819 820 return true; … … 908 909 mRayQueue.pop(); 909 910 910 if ( 0)911 if (mUseDeterministicGvs) 911 912 castSamples += AdaptiveBorderSampling(*ray); 912 913 else 913 914 castSamples += AdaptiveBorderSamplingOpt(*ray); 915 914 916 // note: don't have to delete because handled by ray pool 915 917 } … … 2033 2035 2034 2036 2035 } 2037 void GvsPreprocessor::CreateRandomizedReverseRays(const Vector3 &origin, 2038 const Vector3 &termination, 2039 const Triangle3 &triangle, 2040 SimpleRayContainer &rays, 2041 int number) 2042 { 2043 size_t currentNumber = rays.size(); 2044 2045 while ((rays.size() - currentNumber) < number) 2046 { 2047 SimpleRay ray; 2048 if (CreateRandomizedReverseRay(origin, termination, triangle, ray)) 2049 rays.push_back(ray); 2050 } 2051 } 2052 2053 2054 bool GvsPreprocessor::CreateRandomizedReverseRay(const Vector3 &origin, 2055 const Vector3 &termination, 2056 const Triangle3 &triangle, 2057 SimpleRay &ray) 2058 { 2059 Vector3 nd = triangle.GetNormal(); 2060 2061 // Compute right handed coordinate system from direction 2062 Vector3 U, V; 2063 nd.RightHandedBase(U, V); 2064 2065 float rr[2]; 2066 2067 rr[0] = RandomValue(0, 1); 2068 rr[1] = RandomValue(0, 1); 2069 2070 Vector2 vr2(rr[0], rr[1]); 2071 const float sigma = triangle.GetBoundingBox().Radius() * mRadiusOfInfluence; 2072 Vector2 gaussvec2; 2073 2074 GaussianOn2D(vr2, sigma, // input 2075 gaussvec2); // output 2076 2077 const Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V; 2078 2079 Vector3 newOrigin = origin; 2080 2081 //cout << "t: " << termination; 2082 newOrigin += shift; 2083 //cout << " new t: " << termination << endl; 2084 Vector3 direction = termination - newOrigin; 2085 2086 const float len = Magnitude(direction); 2087 2088 if (len < Limits::Small) 2089 return false; 2090 2091 direction /= len; 2092 2093 if (!IntersectViewCell(newOrigin, direction)) 2094 return false; 2095 2096 // $$ jb the pdf is yet not correct for all sampling methods! 2097 const float pdf = 1.0f; 2098 ray = SimpleRay(newOrigin, direction, SamplingStrategy::GVS, pdf); 2099 2100 return true; 2101 } 2102 2103 2104 }
Note: See TracChangeset
for help on using the changeset viewer.