Changeset 1933 for GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
- Timestamp:
- 01/03/07 16:48:59 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1932 r1933 61 61 62 62 // distance large => this is likely to be a discontinuity 63 #if 1 63 64 if ((predictedLen - len) > mThreshold) 65 #else // rather use relative distance 66 if ((predictedLen / len) > mThreshold) 67 #endif 64 68 { 65 69 cout << "d"; 70 // apply reverse sampling to find the gap 66 71 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 67 72 73 if (!newRay) 74 return false; 75 68 76 // set flag for visualization 69 77 newRay->mFlags |= VssRay::ReverseSample; … … 71 79 // if ray is not further processed => can delete ray 72 80 if (!HandleRay(newRay)) 81 { 73 82 delete newRay; 74 83 } 84 else if (mVssRays.size() < 3) 85 { 86 mVssRays.push_back(new VssRay(oldRay)); 87 mVssRays.push_back(new VssRay(currentRay)); 88 mVssRays.push_back(new VssRay(*newRay)); 89 } 90 75 91 return true; 76 92 } … … 84 100 // compute the contribution to the view cells 85 101 const bool storeRaysForViz = true; 102 86 103 mViewCellsManager->ComputeSampleContribution(*vssRay, 87 104 true, … … 317 334 318 335 319 Vector3 GvsPreprocessor::GetPassingPoint(const VssRay ¤tRay,336 /*Vector3 GvsPreprocessor::GetPassingPoint(const VssRay ¤tRay, 320 337 const Triangle3 &hitTriangle, 321 338 const VssRay &oldRay) const … … 333 350 334 351 return newPoint; 352 }*/ 353 354 355 Vector3 GvsPreprocessor::GetPassingPoint(const VssRay ¤tRay, 356 const Triangle3 &occluder, 357 const VssRay &oldRay) const 358 { 359 //-- The plane p = (xp, hit(x), hit(xold)) is intersected 360 //-- with the newly found occluder (xold is the previous ray from 361 //-- which x was generated). On the intersecting line, we select a point 362 //-- pnew which lies just outside of the new triangle so the ray 363 //-- just passes through the gap 364 365 const Plane3 plane(currentRay.GetOrigin(), 366 currentRay.GetTermination(), 367 oldRay.GetTermination()); 368 369 Vector3 pt1, pt2; 370 371 const bool intersects = occluder.GetPlaneIntersection(plane, pt1, pt2); 372 373 cout << "triangle: " << occluder << " pt1: " << pt1 << " pt2: " << pt2 << endl; 374 if (!intersects) 375 cerr << "big error!! no intersection" << endl; 376 377 // get the intersection point on the old ray 378 const Plane3 triPlane(occluder.GetNormal(), occluder.mVertices[0]); 379 380 const float t = triPlane.FindT(oldRay.mOrigin, oldRay.mTermination); 381 const Vector3 pt3 = oldRay.mOrigin + t * (oldRay.mTermination - oldRay.mOrigin); 382 383 // Evaluate new hitpoint just outside the triangle 384 Vector3 newPoint; 385 386 const float eps = mEps; 387 // the point is chosen to be on the side closer to the original ray 388 if (Distance(pt1, pt3) < Distance(pt2, pt3)) 389 { 390 newPoint = pt1 + eps * (pt1 - pt2); 391 } 392 else 393 { 394 newPoint = pt2 + eps * (pt2 - pt1); 395 } 396 397 cout << "passing point: " << newPoint << endl << endl; 398 return newPoint; 335 399 } 336 400 … … 340 404 const VssRay &oldRay) 341 405 { 342 //-- The plane p = (xp, hit(x), hit(xold)) is intersected 343 //-- with the newly found triangle (xold is the previous ray from 344 //-- which x was generated). On the intersecting line, we select a point 345 //-- pnew which lies just outside of the new triangle so the ray 346 //-- just passes by inside the gap 347 const Vector3 newPoint = GetPassingPoint(currentRay, hitTriangle, oldRay); 406 // get triangle occluding the path to the hit mesh 407 Triangle3 occluder; 408 Intersectable *tObj = currentRay.mTerminationObject; 409 // q: why can this happen? 410 if (!tObj) 411 return NULL; 412 413 // other types not implemented yet 414 if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 415 occluder = dynamic_cast<TriangleIntersectable *>(tObj)->GetItem(); 416 else 417 cout << "not yet implemented" << endl; 418 419 // get a point which is passing just outside of the occluder 420 const Vector3 newPoint = GetPassingPoint(currentRay, occluder, oldRay); 348 421 const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 349 422 350 423 //-- Construct the mutated ray with xnew, 351 424 //-- dir = predicted(x)- pnew as direction vector 352 const Vector3 newDir = predicted - newPoint 353 354 // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ?425 const Vector3 newDir = predicted - newPoint; 426 427 // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 355 428 // difficult to say!! 356 const Vector3 newOrigin = newDir * -5000.0f; 357 358 ++ mReverseSamples; 359 360 return new VssRay(currentRay); 429 const Vector3 newOrigin = newPoint + newDir * -5000.0f; 430 431 const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 432 433 VssRay *reverseRay = 434 mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox()); 435 436 ++ mReverseSamples; 437 438 return reverseRay; 361 439 } 362 440 … … 533 611 } 534 612 535 exporter->ExportRays(mVssRays); 613 VssRayContainer::const_iterator rit, rit_end = mVssRays.end(); 614 for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 615 { 616 Intersectable *obj = (*rit)->mTerminationObject; 617 exporter->ExportIntersectable(obj); 618 } 619 620 VssRayContainer vcRays, vcRays2, vcRays3; 621 622 // prepare some rays for output 623 for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 624 { 625 const float p = RandomValue(0.0f, (float)mVssRays.size()); 626 if (1)//(p < raysOut) 627 { 628 if ((*rit)->mFlags & VssRay::BorderSample) 629 { 630 vcRays.push_back(*rit); 631 } 632 else if ((*rit)->mFlags & VssRay::ReverseSample) 633 { 634 vcRays2.push_back(*rit); 635 } 636 else 637 { 638 vcRays3.push_back(*rit); 639 } 640 } 641 } 642 643 exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 644 exporter->ExportRays(vcRays2, RgbColor(0, 1, 0)); 645 exporter->ExportRays(vcRays3, RgbColor(1, 1, 1)); 646 647 //exporter->ExportRays(mVssRays); 536 648 delete exporter; 537 649 }
Note: See TracChangeset
for help on using the changeset viewer.