- Timestamp:
- 06/02/08 04:11:30 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh
r2727 r2729 42 42 -gvs_total_samples=1000000 \ 43 43 -gvs_samples_per_pass=1000000 \ 44 -gvs_initial_samples= 50\45 -gvs_max_viewcells= 1\44 -gvs_initial_samples=4 \ 45 -gvs_max_viewcells=2 \ 46 46 -gvs_min_contribution=500 \ 47 47 -gvs_per_viewcell=true \ -
GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj
r2727 r2729 102 102 <Tool 103 103 Name="VCCLCompilerTool" 104 Optimization="3" 105 InlineFunctionExpansion="2" 106 EnableIntrinsicFunctions="true" 107 FavorSizeOrSpeed="1" 108 OmitFramePointers="true" 104 109 AdditionalIncludeDirectories="..\src;Timer;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;"..\..\..\..\..\..\NonGTP\Xerces\xerces-c_2_8_0\include";..\..\..\..\..\..\NonGTP\Boost;..\src\havran;..\MultiLevelRayTracing;"$(CG_INC_PATH)"" 105 110 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;USE_VERBOSE_PVS;USE_QT;GTP_INTERNAL;USE_CG" 111 StringPooling="true" 106 112 RuntimeLibrary="2" 113 BufferSecurityCheck="false" 114 RuntimeTypeInfo="false" 107 115 WarningLevel="3" 108 116 Detect64BitPortabilityProblems="true" -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r2728 r2729 159 159 { 160 160 // the predicted hitpoint: we expect to hit the same mesh again 161 constVector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);162 163 constfloat predictedLen = Magnitude(predictedHit - currentRay.mOrigin);164 constfloat len = Magnitude(currentRay.mTermination - currentRay.mOrigin);161 Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 162 163 float predictedLen = Magnitude(predictedHit - currentRay.mOrigin); 164 float len = Magnitude(currentRay.mTermination - currentRay.mOrigin); 165 165 166 166 // distance large => this is likely to be a discontinuity 167 if ( (predictedLen - len) > mThreshold)167 if (!((predictedLen - len) > mThreshold)) 168 168 // q: rather use relative distance? 169 169 //if ((predictedLen / len) > mThreshold) 170 { 171 #if 0 172 // apply reverse sampling to find the gap 173 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 174 175 // check if reverse sampling was successful 176 if (newRay) 177 { 178 // set flag for visualization 179 if (0) newRay->mFlags |= VssRay::ReverseSample; 180 181 rayTimer.Entry(); 182 // check if ray can be processed further 183 // note: ray deletion handled by ray pool) 184 HandleRay(newRay); 185 rayTimer.Exit(); 186 187 return 1; 188 } 189 #else 190 static VssRayContainer reverseRays; 191 reverseRays.clear(); 192 193 // apply reverse sampling to find the gap 194 ReverseSampling2(currentRay, hitTriangle, oldRay, reverseRays); 195 196 rayTimer.Entry(); 197 198 int castRays = 0; 199 // check if reverse sampling was successful 200 for (size_t i = 0; i < reverseRays.size(); ++ i) 201 { 202 // check if ray can be processed further 203 // note: ray deletion handled by ray pool) 204 if (reverseRays[i]) 205 { 206 ++ castRays; 207 HandleRay(reverseRays[i]); 208 } 209 } 210 211 rayTimer.Exit(); 212 213 return castRays; 214 215 #endif 216 } 217 218 return 0; 170 return 0; 171 172 SimpleRay simpleRay; 173 174 // apply reverse sampling to find the gap 175 if (!ComputeReverseRay(currentRay, hitTriangle, oldRay, simpleRay)) 176 return 0; 177 178 static VssRayContainer reverseRays; 179 reverseRays.clear(); 180 181 if (0) 182 { 183 VssRay *reverseRay = 184 mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 185 186 reverseRays.push_back(reverseRay); 187 } 188 else 189 { 190 if (0) 191 CastRayBundle4(simpleRay, reverseRays, mViewCellsManager->GetViewSpaceBox()); 192 else 193 CastRayBundle16(simpleRay, reverseRays); 194 } 195 196 mGvsStats.mReverseSamples += (int)reverseRays.size(); 197 198 EnqueueRays(reverseRays); 199 200 return (int)reverseRays.size(); 219 201 } 220 202 … … 422 404 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 423 405 424 #if 1 406 VssRay *newRay; 407 408 // cast single ray 425 409 castTimer.Entry(); 426 // cast single ray to check if a triangle was missed 427 // note: not efficient!!428 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell);410 411 // cast single ray to check if a triangle was missed. note: not efficient!! 412 newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 429 413 castTimer.Exit(); 414 430 415 ++ castRays; 431 416 … … 440 425 441 426 rayTimer.Exit(); 442 443 #else 444 445 // cast ray into the new point 446 static SimpleRayContainer importanceRays; 447 importanceRays.clear(); 448 449 generationTimer.Entry(); 450 451 452 importanceRays.push_back(sray); 453 454 const int numRandomRays = 15; 455 456 GenerateJitteredRays(importanceRays, sray, numRandomRays, 0); 457 GenerateRays(numRandomRays, *mDistribution, importanceRays, sInvalidSamples); 458 459 generationTimer.Exit(); 460 461 // for the original implementation we don't cast double rays 462 const bool castDoubleRays = !mPerViewCell; 463 // cannot prune invalid rays because we have to compare adjacent rays 464 const bool pruneInvalidRays = false; 465 466 static VssRayContainer vssRays; 467 vssRays.clear(); 468 469 castTimer.Entry(); 470 CastRays(importanceRays, vssRays, castDoubleRays, pruneInvalidRays); 471 castTimer.Exit(); 472 473 castRays += (int)vssRays.size(); 474 475 VssRay *newRay = vssRays.empty() ? NULL : vssRays[0]; 476 477 // new triangle discovered? => add new ray to queue 478 rayTimer.Entry(); 479 for (size_t i = 0; i < vssRays.size(); ++ i) 480 { 481 if (vssRays[i]) 482 HandleRay(vssRays[i]); 483 } 484 485 rayTimer.Exit(); 486 487 // this ray will not be further processed 488 // note: ray deletion is handled by ray pool 489 if (!newRay) return castRays; 490 #endif 491 427 492 428 //newRay->mFlags |= VssRay::BorderSample; 493 429 … … 516 452 517 453 //cout << "type: " << Intersectable::GetTypeName(tObj) << endl; 518 519 VertexContainer enlargedTriangle; 520 454 generationTimer.Entry(); 455 456 static VertexContainer enlargedTriangle; 457 enlargedTriangle.clear(); 458 521 459 /// create 3 new hit points for each vertex 522 460 EnlargeTriangle(enlargedTriangle, hitTriangle, currentRay); … … 525 463 static SimpleRayContainer simpleRays; 526 464 simpleRays.clear(); 527 //simpleRays.reserve(9);528 465 529 466 VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end(); … … 551 488 552 489 const int numRandomRays = 16 - (int)simpleRays.size(); 553 SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), currentRay.GetNormalizedDir(), SamplingStrategy::GVS, 1.0f); 490 SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), 491 currentRay.GetNormalizedDir(), 492 SamplingStrategy::GVS, 493 1.0f); 554 494 555 495 GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0); 556 496 //GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples); 557 497 498 generationTimer.Exit(); 558 499 559 500 ///////////////////// 560 501 //-- cast rays to vertices and determine visibility 561 502 562 VssRayContainer vssRays; 503 static VssRayContainer vssRays; 504 vssRays.clear(); 563 505 564 506 // for the original implementation we don't cast double rays … … 567 509 const bool pruneInvalidRays = false; 568 510 511 //gvsTimer.Entry(); 569 512 castTimer.Entry(); 513 570 514 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 515 571 516 castTimer.Exit(); 517 //gvsTimer.Exit(); 572 518 573 519 const int numBorderSamples = (int)vssRays.size() - numRandomRays; … … 576 522 // handle cast rays 577 523 EnqueueRays(vssRays); 578 579 #if 0 580 // set flags 581 VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 582 for (rit = vssRays.begin(); rit != rit_end; ++ rit, ++ i) 583 (*rit)->mFlags |= VssRay::BorderSample; 584 #endif 585 524 525 if (0) 526 { 527 // set flags 528 VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 529 530 for (rit = vssRays.begin(); rit != rit_end; ++ rit) 531 (*rit)->mFlags |= VssRay::BorderSample; 532 } 586 533 587 534 // recursivly subdivide each edge … … 602 549 603 550 551 int GvsPreprocessor::AdaptiveBorderSamplingOpt(const VssRay ¤tRay) 552 { 553 Intersectable *tObj = currentRay.mTerminationObject; 554 555 // question matt: can this be possible? 556 if (!tObj) return 0; 557 558 Triangle3 hitTriangle; 559 560 // other types not implemented yet 561 if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 562 hitTriangle = static_cast<TriangleIntersectable *>(tObj)->GetItem(); 563 else 564 cout << "border sampling: " << Intersectable::GetTypeName(tObj) << " not yet implemented" << endl; 565 566 generationTimer.Entry(); 567 568 static VertexContainer enlargedTriangle; 569 enlargedTriangle.clear(); 570 571 /// create 3 new hit points for each vertex 572 EnlargeTriangle(enlargedTriangle, hitTriangle, currentRay); 573 574 static VertexContainer subdivEnlargedTri; 575 subdivEnlargedTri.clear(); 576 577 for (size_t i = 0; i < enlargedTriangle.size(); ++ i) 578 { 579 const Vector3 p1 = enlargedTriangle[i]; 580 const Vector3 p2 = enlargedTriangle[(i + 1) % enlargedTriangle.size()]; 581 582 // the new subdivision point 583 const Vector3 p = (p1 + p2) * 0.5f; 584 585 subdivEnlargedTri.push_back(p1); 586 subdivEnlargedTri.push_back(p); 587 } 588 589 /// create rays from sample points and handle them 590 static SimpleRayContainer simpleRays; 591 simpleRays.clear(); 592 593 VertexContainer::const_iterator vit, vit_end = subdivEnlargedTri.end(); 594 595 for (vit = subdivEnlargedTri.begin(); vit != vit_end; ++ vit) 596 { 597 const Vector3 rayDir = (*vit) - currentRay.GetOrigin(); 598 599 SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f); 600 simpleRays.AddRay(sr); 601 } 602 603 604 ////////// 605 //-- fill up simple rays with random rays so we can cast 16 rays at a time 606 607 const int numRandomRays = 16 - ((int)simpleRays.size() % 16); 608 609 SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), 610 currentRay.GetNormalizedDir(), 611 SamplingStrategy::GVS, 1.0f); 612 613 GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0); 614 //GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples); 615 616 generationTimer.Exit(); 617 618 619 ///////////////////// 620 //-- cast rays to vertices and determine visibility 621 622 static VssRayContainer vssRays; 623 vssRays.clear(); 624 625 // for the original implementation we don't cast double rays 626 const bool castDoubleRays = !mPerViewCell; 627 // cannot prune invalid rays because we have to compare adjacent rays 628 const bool pruneInvalidRays = false; 629 630 //if ((simpleRays.size() % 16) != 0) cerr << "ray size not aligned" << endl; 631 632 //gvsTimer.Entry(); 633 castTimer.Entry(); 634 635 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 636 637 castTimer.Exit(); 638 //gvsTimer.Exit(); 639 640 const int numBorderSamples = (int)vssRays.size() - numRandomRays; 641 int castRays = (int)simpleRays.size(); 642 643 // handle cast rays 644 EnqueueRays(vssRays); 645 646 #if 0 647 648 // recursivly subdivide each edge 649 for (int i = 0; i < numBorderSamples; ++ i) 650 { 651 castRays += SubdivideEdge(hitTriangle, 652 subdivEnlargedTri[i], 653 subdivEnlargedTri[(i + 1) % numBorderSamples], 654 *vssRays[i], 655 *vssRays[(i + 1) % numBorderSamples], 656 currentRay); 657 } 658 659 #endif 660 661 662 mGvsStats.mBorderSamples += castRays; 663 664 return castRays; 665 } 666 667 604 668 bool GvsPreprocessor::GetPassingPoint(const VssRay ¤tRay, 605 669 const Triangle3 &occluder, … … 607 671 Vector3 &newPoint) const 608 672 { 609 //-- The plane p = (xp, hit(x), hit(xold)) is intersected 673 ///////////////////////// 674 //-- We interserct the plane p = (xp, hit(x), hit(xold)) 610 675 //-- with the newly found occluder (xold is the previous ray from 611 676 //-- which x was generated). On the intersecting line, we select a point … … 619 684 Vector3 pt1, pt2; 620 685 621 const bool intersects = occluder.GetPlaneIntersection(plane, pt1, pt2); 622 623 if (!intersects) 624 { 625 //cerr << "big error!! no intersection " << pt1 << " " << pt2 << endl; 686 if (!occluder.GetPlaneIntersection(plane, pt1, pt2)) 626 687 return false; 627 }628 688 629 689 // get the intersection point on the old ray … … 635 695 // evaluate new hitpoint just outside the triangle 636 696 // the point is chosen to be on the side closer to the original ray 637 if ( Distance(pt1, pt3) <Distance(pt2, pt3))697 if (SqrDistance(pt1, pt3) < SqrDistance(pt2, pt3)) 638 698 newPoint = pt1 + mEps * (pt1 - pt2); 639 699 else … … 645 705 646 706 647 VssRay *GvsPreprocessor::ReverseSampling(const VssRay ¤tRay, 648 const Triangle3 &hitTriangle, 649 const VssRay &oldRay) 707 bool GvsPreprocessor::ComputeReverseRay(const VssRay ¤tRay, 708 const Triangle3 &hitTriangle, 709 const VssRay &oldRay, 710 SimpleRay &reverseRay) 650 711 { 651 712 // get triangle occluding the path to the hit mesh … … 655 716 // q: why can this happen? 656 717 if (!tObj) 657 return NULL;718 return false; 658 719 659 720 // other types not implemented yet … … 668 729 // q: why is there sometimes no intersecton found? 669 730 if (!GetPassingPoint(currentRay, occluder, oldRay, newPoint)) 670 return NULL; 671 672 const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 673 674 Vector3 newDir, newOrigin; 675 676 ////////////// 677 //-- Construct the mutated ray with xnew, 678 //-- dir = predicted(x)- pnew as direction vector 679 680 newDir = predicted - newPoint; 681 682 // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 683 // difficult to say!! 684 const float offset = 0.5f; 685 newOrigin = newPoint - newDir * offset; 686 687 688 ////////////// 689 //-- for per view cell sampling, we must check for intersection 690 //-- with the current view cell 691 692 if (mPerViewCell) 693 { 694 // send ray to view cell 695 static Ray ray; 696 ray.Clear(); 697 ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY); 698 699 //cout << "z"; 700 // check if ray intersects view cell 701 if (!mCurrentViewCell->CastRay(ray)) 702 return NULL; 703 704 Ray::Intersection &hit = ray.intersections[0]; 705 706 //cout << "q"; 707 // the ray starts from the view cell 708 newOrigin = ray.Extrap(hit.mT); 709 } 710 711 ++ mGvsStats.mReverseSamples; 712 713 const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 714 715 VssRay *reverseRay = 716 mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 717 718 return reverseRay; 719 } 720 721 722 bool GvsPreprocessor::ReverseSampling2(const VssRay ¤tRay, 723 const Triangle3 &hitTriangle, 724 const VssRay &oldRay, 725 VssRayContainer &reverseRays) 726 { 727 // get triangle occluding the path to the hit mesh 728 Triangle3 occluder; 729 Intersectable *tObj = currentRay.mTerminationObject; 730 731 // q: why can this happen? 732 if (!tObj) 733 return NULL; 734 735 // other types not implemented yet 736 if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 737 occluder = static_cast<TriangleIntersectable *>(tObj)->GetItem(); 738 else 739 cout << "reverse sampling: " << tObj->Type() << " not yet implemented" << endl; 740 741 // get a point which is passing just outside of the occluder 742 Vector3 newPoint; 743 744 // q: why is there sometimes no intersecton found? 745 if (!GetPassingPoint(currentRay, occluder, oldRay, newPoint)) 746 return NULL; 731 return false; 747 732 748 733 const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); … … 784 769 } 785 770 786 static SimpleRayContainer reverseSimpleRays; 787 reverseSimpleRays.clear(); 788 789 SimpleRay mainRay = SimpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 790 791 reverseSimpleRays.push_back(mainRay); 792 GenerateJitteredRays(reverseSimpleRays, mainRay, 15, 0); 793 794 castTimer.Entry(); 795 CastRays(reverseSimpleRays, reverseRays, false, false); 796 castTimer.Exit(); 797 798 mGvsStats.mReverseSamples += (int)reverseRays.size(); 771 reverseRay = SimpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 799 772 800 773 return true; … … 818 791 819 792 // cast generated samples 820 static VssRayContainer samples; 821 samples.clear(); 822 823 const bool castDoubleRays = !mPerViewCell; 824 const bool pruneInvalidRays = true; 825 826 #if 0 793 static VssRayContainer vssRays; 794 vssRays.clear(); 795 827 796 castTimer.Entry(); 828 797 829 CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays); 830 798 if (0) 799 { 800 const bool castDoubleRays = !mPerViewCell; 801 const bool pruneInvalidRays = false; 802 //const bool pruneInvalidRays = true; 803 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 804 } 805 else 806 { 807 if (0) 808 // casting bundles of 4 rays generated from the simple rays 809 CastRayBundles4(simpleRays, vssRays); 810 else 811 CastRayBundles16(simpleRays, vssRays); 812 } 813 831 814 castTimer.Exit(); 832 815 833 #else834 static SimpleRayContainer jitteredRays;835 836 for (size_t i = 0; i < simpleRays.size(); ++ i)837 {838 SimpleRay mainRay = simpleRays[i];839 840 jitteredRays.clear();841 jitteredRays.push_back(mainRay);842 843 generationTimer.Entry();844 845 GenerateJitteredRays(jitteredRays, mainRay, 15, 0);846 847 generationTimer.Exit();848 castTimer.Entry();849 850 CastRays(jitteredRays, samples, castDoubleRays, pruneInvalidRays);851 852 castTimer.Entry();853 }854 #endif855 856 816 // add to ray queue 857 EnqueueRays( samples);817 EnqueueRays(vssRays); 858 818 859 819 initialTimer.Exit(); 860 820 861 return (int) samples.size();821 return (int)vssRays.size(); 862 822 } 863 823 … … 894 854 mRayQueue.pop(); 895 855 896 castSamples += AdaptiveBorderSampling(*ray); 856 if (1) 857 castSamples += AdaptiveBorderSampling(*ray); 858 else 859 castSamples += AdaptiveBorderSamplingOpt(*ray); 897 860 // note: don't have to delete because handled by ray pool 898 861 } … … 976 939 void GvsPreprocessor::VisualizeViewCells() 977 940 { 978 char str[64]; sprintf (str, "tmp/pass%06d_%04d-", mProcessedViewCells, mPass);941 char str[64]; sprintf_s(str, "tmp/pass%06d_%04d-", mProcessedViewCells, mPass); 979 942 980 943 // visualization … … 1458 1421 // initialise 1459 1422 mGvsStats.mPerViewCellSamples = 0; 1423 mGvsStats.mRandomSamples = 0; 1424 mGvsStats.mGvsSamples = 0; 1460 1425 1461 1426 int oldContribution = 0; … … 1630 1595 mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples; 1631 1596 1632 cout << "id: " << mCurrentViewCell->GetId() << " pvs cost: " 1633 << mGvsStats.mPvsCost << " pvs tri: " << mTrianglePvs.size() << endl; 1597 cout << "id: " << mCurrentViewCell->GetId() << endl; 1598 cout << "pvs cost " << mGvsStats.mPvsCost / 1000000 << " M" << endl; 1599 cout << "pvs tri: " << mTrianglePvs.size() << endl; 1600 cout << "samples: " << mGvsStats.mTotalSamples / 1000000 << " M" << endl; 1601 printf("contri: %f tri / K rays\n", 1000.0f * (float)mTrianglePvs.size() / mGvsStats.mTotalSamples); 1634 1602 1635 1603 //cout << "invalid samples ratio: " << (float)sInvalidSamples / mGvsStats.mPerViewCellSamples << endl; 1636 1604 1637 float rayTime = rayTimer.TotalTime(); 1638 float kdPvsTime = kdPvsTimer.TotalTime(); 1639 float gvsTime = gvsTimer.TotalTime(); 1640 float initialTime = initialTimer.TotalTime(); 1641 float intersectionTime = intersectionTimer.TotalTime(); 1642 float preparationTime = preparationTimer.TotalTime(); 1643 float mainLoopTime = mainLoopTimer.TotalTime(); 1644 float contributionTime = contributionTimer.TotalTime(); 1645 float castTime = castTimer.TotalTime(); 1646 float generationTime = generationTimer.TotalTime(); 1605 double rayTime = rayTimer.TotalTime(); 1606 double kdPvsTime = kdPvsTimer.TotalTime(); 1607 double gvsTime = gvsTimer.TotalTime(); 1608 double initialTime = initialTimer.TotalTime(); 1609 double intersectionTime = intersectionTimer.TotalTime(); 1610 double preparationTime = preparationTimer.TotalTime(); 1611 double mainLoopTime = mainLoopTimer.TotalTime(); 1612 double contributionTime = contributionTimer.TotalTime(); 1613 double castTime = castTimer.TotalTime(); 1614 double generationTime = generationTimer.TotalTime(); 1615 double rawCastTime = mRayCaster->rawCastTimer.TotalTime(); 1647 1616 1648 1617 cout << "handleRay : " << rayTime << endl; … … 1655 1624 cout << "has contribution : " << contributionTime << endl; 1656 1625 cout << "cast time : " << castTime << endl; 1657 cout << "generation time : " << generationTime << endl; 1626 cout << "generation time : " << generationTime << endl; 1627 cout << "raw cast time : " << rawCastTime << endl; 1658 1628 1659 1629 float randomRaysPerSec = mGvsStats.mRandomSamples / (1e6f * initialTime); 1660 1630 float gvsRaysPerSec = mGvsStats.mGvsSamples / (1e6f * gvsTime); 1631 float rawRaysPerSec = mGvsStats.mPerViewCellSamples / (1e6f * rawCastTime); 1661 1632 1662 1633 cout << "cast " << randomRaysPerSec << " M random rays/s: " << endl; 1663 1634 cout << "cast " << gvsRaysPerSec << " M gvs rays/s: " << endl; 1664 1635 cout << "cast " << rawRaysPerSec << " M raw rays/s: " << endl; 1636 1665 1637 mGvsStats.Stop(); 1666 1638 mGvsStats.Print(mGvsStatsStream); 1667 1668 } 1669 1639 } 1670 1640 1671 1641 … … 1707 1677 1708 1678 mTrianglePvs.push_back(triObj); 1709 //mDummyBuffer.push_back(mGvsStats.mGvsRuns);1710 1679 mGenericStats[0] = (int)mTrianglePvs.size(); 1680 1711 1681 return true; 1712 1682 } … … 1716 1686 1717 1687 1718 void Preprocessor::CastRays4(SimpleRayContainer &rays, VssRayContainer &vssRays) 1719 { 1720 const int packetSize = 4; 1721 1722 static int hit_triangles[packetSize]; 1723 static float dist[packetSize]; 1724 static Vector3 dirs[packetSize]; 1725 static Vector3 shifts[packetSize]; 1726 static Vector3 origs[packetSize]; 1727 1688 void GvsPreprocessor::CastRayBundles4(const SimpleRayContainer &rays, VssRayContainer &vssRays) 1689 { 1690 AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 1728 1691 1729 1692 SimpleRayContainer::const_iterator it, it_end = rays.end(); 1730 1693 1731 1694 for (it = rays.begin(); it != it_end; ++ it) 1732 { 1733 1734 SimpleRay mainRay = *it; 1735 1736 origs[0] = mainRay.mOrigin; 1737 dirs[0] = mainRay.mDirection; 1738 1739 for (i = 1; i < packetSize; i++) 1695 CastRayBundle4(*it, vssRays, box); 1696 } 1697 1698 1699 void GvsPreprocessor::CastRayBundle4(const SimpleRay &ray, 1700 VssRayContainer &vssRays, 1701 const AxisAlignedBox3 &box) 1702 { 1703 const float pertubDir = 0.01f; 1704 static Vector3 pertub; 1705 1706 static int hit_triangles[4]; 1707 static float dist[4]; 1708 static Vector3 dirs[4]; 1709 static Vector3 origs[4]; 1710 1711 origs[0] = ray.mOrigin; 1712 dirs[0] = ray.mDirection; 1713 1714 for (int i = 1; i < 4; ++ i) 1715 { 1716 origs[i] = ray.mOrigin; 1717 1718 pertub.x = RandomValue(-pertubDir, pertubDir); 1719 pertub.y = RandomValue(-pertubDir, pertubDir); 1720 pertub.z = RandomValue(-pertubDir, pertubDir); 1721 1722 dirs[i] = ray.mDirection + pertub; 1723 dirs[i] *= 1.0f / Magnitude(dirs[i]); 1724 } 1725 1726 Cast4Rays(dist, dirs, origs, vssRays, box); 1727 } 1728 1729 1730 void GvsPreprocessor::CastRays4(const SimpleRayContainer &rays, VssRayContainer &vssRays) 1731 { 1732 SimpleRayContainer::const_iterator it, it_end = rays.end(); 1733 1734 static float dist[4]; 1735 static Vector3 dirs[4]; 1736 static Vector3 origs[4]; 1737 1738 AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 1739 1740 for (it = rays.begin(); it != it_end; ++ it) 1741 { 1742 for (int i = 1; i < 4; ++ i) 1740 1743 { 1741 origs[i] = mainRay.mOrigin; 1742 1743 const float pertubDir = 0.01f; 1744 Vector3 pertub; 1745 1746 pertub.x = RandomValue(-pertubDir, pertubDir); 1747 pertub.y = RandomValue(-pertubDir, pertubDir); 1748 pertub.z = RandomValue(-pertubDir, pertubDir); 1749 1750 dirs[i] = mainRay.mDirection + pertub; 1751 const float c = Magnitude(newDir); 1752 dirs{i] *= 1.0f / c; 1744 origs[i] = rays[i].mOrigin; 1745 dirs[i] = rays[i].mDirection; 1753 1746 } 1754 1755 AxisAlignedBox3 box; 1756 preprocessor->mRayCaster->CastRaysPacket4(box.Min(), 1757 box.Max(), 1758 origs, 1759 dirs, 1760 hit_triangles, 1761 dist); 1762 } 1763 1764 DeterminePvsObjects(vssRays); 1765 } 1766 1767 1768 } 1747 } 1748 1749 Cast4Rays(dist, dirs, origs, vssRays, box); 1750 } 1751 1752 1753 void GvsPreprocessor::Cast4Rays(float *dist, 1754 Vector3 *dirs, 1755 Vector3 *origs, 1756 VssRayContainer &vssRays, 1757 const AxisAlignedBox3 &box) 1758 { 1759 static int hit_triangles[4]; 1760 1761 mRayCaster->CastRaysPacket4(box.Min(), box.Max(), origs, dirs, hit_triangles, dist); 1762 1763 VssRay *ray; 1764 1765 for (int i = 0; i < 4; ++ i) 1766 { 1767 if (hit_triangles[i] != -1) 1768 { 1769 TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(mObjects[hit_triangles[i]]); 1770 1771 if (DotProd(triObj->GetItem().GetNormal(), dirs[i] >= 0)) 1772 ray = NULL; 1773 else 1774 ray = mRayCaster->RequestRay(origs[i], origs[i] + dirs[i] * dist[i], NULL, triObj, mPass, 1.0f); 1775 } 1776 else 1777 { 1778 ray = NULL; 1779 } 1780 1781 vssRays.push_back(ray); 1782 } 1783 } 1784 1785 1786 void GvsPreprocessor::CastRayBundle16(const SimpleRay &ray, VssRayContainer &vssRays) 1787 { 1788 static SimpleRayContainer simpleRays; 1789 simpleRays.clear(); 1790 1791 simpleRays.push_back(ray); 1792 GenerateJitteredRays(simpleRays, ray, 15, 0); 1793 1794 CastRays(simpleRays, vssRays, false, false); 1795 } 1796 1797 1798 void GvsPreprocessor::CastRayBundles16(const SimpleRayContainer &rays, VssRayContainer &vssRays) 1799 { 1800 SimpleRayContainer::const_iterator it, it_end = rays.end(); 1801 1802 for (it = rays.begin(); it != it_end; ++ it) 1803 CastRayBundle16(*it, vssRays); 1804 } 1805 1806 } -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r2728 r2729 146 146 */ 147 147 inline bool HandleRay(VssRay *ray); 148 149 148 /** The adaptive border sampling step. It aims to find neighbouring 150 149 triangles of the one hit by the current ray. 151 150 */ 152 151 int AdaptiveBorderSampling(const VssRay ¤tRay); 153 152 int AdaptiveBorderSamplingOpt(const VssRay ¤tRay); 154 153 /** The reverse sampling step. It is started once the cast 155 154 ray finds a discontinuity, i.e., a closer triangle. … … 157 156 triangle passing through a gap. 158 157 */ 159 VssRay *ReverseSampling(const VssRay ¤tRay, 160 const Triangle3 &hitTriangle, 161 const VssRay &oldRay); 162 163 bool ReverseSampling2(const VssRay ¤tRay, 164 const Triangle3 &hitTriangle, 165 const VssRay &oldRay, 166 VssRayContainer &reverseRays); 167 168 virtual void CastRays4(SimpleRayContainer &rays, 169 VssRayContainer &vssRays); 170 158 bool ComputeReverseRay(const VssRay ¤tRay, 159 const Triangle3 &hitTriangle, 160 const VssRay &oldRay, 161 SimpleRay &reverseRay); 171 162 /** Returns true if we sampled a closer triangle than with the previous ray. 172 163 Does reverse sampling if gap found. … … 175 166 const Triangle3 &hitTriangle, 176 167 const VssRay &oldRay); 177 178 168 /** Adds new samples to the ray queue and classifies them 179 169 with respect to the previous ray. 180 170 */ 181 171 void EnqueueRays(VssRayContainer &samples); 182 183 172 /** Hepler function for adaptive border sampling. It finds 184 173 new sample points around a triangle in a eps environment … … 264 253 265 254 inline void AddKdNodeToPvs(const Vector3 &termination); 255 /** For all rayys of the ray container, generates a ray bundle of 4 jittered rays 256 and casts them using optimized 4 eye ray casting. 257 */ 258 void CastRayBundles4(const SimpleRayContainer &rays, VssRayContainer &vssRays); 259 260 void CastRayBundles16(const SimpleRayContainer &rays, VssRayContainer &vssRays); 261 262 /** Generates a ray bundle of 4 jittered rays and casts them using optimized 4 eye ray casting. 263 */ 264 void CastRayBundle4(const SimpleRay &ray, VssRayContainer &vssRays, const AxisAlignedBox3 &box); 265 /** Cast rays using the optimized 4 eye ray casting routine. 266 */ 267 void CastRays4(const SimpleRayContainer &rays, VssRayContainer &vssRays); 268 /** Wrapper for optized ray casting routine taking 4 eye rays and a bounding box for ray clipping. 269 */ 270 void Cast4Rays(float *dist, Vector3 *dirs, Vector3 *origs, VssRayContainer &vssRays, const AxisAlignedBox3 &box); 271 272 void CastRayBundle16(const SimpleRay &ray, VssRayContainer &vssRays); 266 273 267 274 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r2710 r2729 80 80 } 81 81 82 rawCastTimer.Entry(); 82 83 mlrtaTraverseGroupASEye4(&minBox.x, &maxBox.x, result4, dist4); 84 rawCastTimer.Exit(); 83 85 84 86 if (saveMutationRays) { … … 126 128 float dist1, dist2; 127 129 double normal[3]; 130 131 rawCastTimer.Entry(); 128 132 129 133 hittriangle = mlrtaIntersectAS( … … 132 136 normal, 133 137 dist); 138 139 rawCastTimer.Exit(); 134 140 dist1 = dist; 135 141 … … 152 158 { 153 159 Vector3 dir = -simpleRay.mDirection; 154 hittriangle = mlrtaIntersectAS( 160 161 rawCastTimer.Entry(); 162 163 hittriangle = mlrtaIntersectAS( 155 164 &simpleRay.mOrigin.x, 156 165 &dir.x, 157 166 normal, 158 167 dist); 168 169 rawCastTimer.Exit(); 170 159 171 dist2 = dist; 160 172 … … 265 277 } 266 278 #endif 279 267 280 mlrtaStoreRayAS16(&rays[k].mOrigin.x, 268 281 &rays[k].mDirection.x, … … 273 286 Debug<<"TA\n"<<flush; 274 287 #endif 275 288 rawCastTimer.Entry(); 289 276 290 mlrtaTraverseGroupAS16(&min.x, 277 291 &max.x, 278 292 forward_hit_triangles, 279 293 forward_dist); 294 295 rawCastTimer.Exit(); 280 296 281 297 #if DEBUG_RAYCAST … … 294 310 Debug<<"TB\n"<<flush; 295 311 #endif 296 312 rawCastTimer.Entry(); 297 313 mlrtaTraverseGroupAS16(&min.x, 298 314 &max.x, 299 315 backward_hit_triangles, 300 316 backward_dist); 317 318 rawCastTimer.Exit(); 301 319 } 302 320 … … 439 457 &rays[k].mDirection.x, 440 458 j); 441 459 rawCastTimer.Entry(); 460 442 461 mlrtaTraverseGroupAS16(&min.x, 443 462 &max.x, 444 463 hit_triangles, 445 464 dist); 465 rawCastTimer.Exit(); 446 466 } // for 447 467 … … 449 469 for (; k < rays.size(); k++) { 450 470 double normal[3]; 471 rawCastTimer.Entry(); 451 472 hit_triangles[0] = mlrtaIntersectAS( 452 473 &rays[k].mOrigin.x, … … 454 475 normal, 455 476 dist[0]); 477 rawCastTimer.Exit(); 456 478 } 457 479 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2726 r2729 1181 1181 { 1182 1182 const int n = 4; 1183 cout << "hack: setting ray pool size to multiple " << n << " of samples per pass" << endl;1184 1183 reserveRays = mSamplesPerPass * n; 1184 cout << "setting ray pool size to " << reserveRays << endl; 1185 1185 1186 } 1186 1187 1187 1188 cout << "======================" << endl; 1188 1189 cout << "reserving " << reserveRays << " rays " << endl; 1190 1189 1191 mRayCaster->ReserveVssRayPool(reserveRays); 1192 1190 1193 cout<<"done."<<endl<<flush; 1194 1191 1195 return true; 1192 1196 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r2660 r2729 8 8 #include "Vector3.h" 9 9 #include "VssRay.h" 10 11 using namespace std; 10 #include "Timer/PerfTimer.h" 12 11 13 12 // … … 124 123 SortRays2(SimpleRayContainer &rays); 125 124 126 // pool of vss rays to be used in one pass of the sampling127 struct VssRayPool128 {129 VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)130 {}131 132 ~VssRayPool()133 {134 delete []mRays;135 }136 137 void Reserve(const int number)138 {139 DEL_PTR(mRays);140 mRays = new VssRay[number];141 mNumber = number;142 }143 144 void Clear()145 {146 mIndex = 0;147 }148 149 VssRay *Alloc()150 {151 // reset pool152 if (mIndex == mNumber)153 mIndex = 0;154 return mRays + mIndex ++;155 }156 protected:157 VssRay *mRays;158 int mIndex;159 int mNumber;160 };161 162 163 VssRayPool mVssRayPool;164 165 void ReserveVssRayPool(const int n)166 {167 mVssRayPool.Reserve(n);168 }169 170 void InitPass()171 {172 mVssRayPool.Clear();173 }174 175 176 protected:177 178 125 VssRay *RequestRay(const Vector3 &origin, 179 126 const Vector3 &termination, … … 182 129 const int pass, 183 130 const float pdf); 131 132 // pool of vss rays to be used in one pass of the sampling 133 struct VssRayPool 134 { 135 VssRayPool(): mRays(NULL), mIndex(0), mNumber(0) 136 {} 137 138 ~VssRayPool() 139 { 140 delete []mRays; 141 } 142 143 void Reserve(const int number) 144 { 145 DEL_PTR(mRays); 146 mRays = new VssRay[number]; 147 mNumber = number; 148 } 149 150 void Clear() 151 { 152 mIndex = 0; 153 } 154 155 VssRay *Alloc() 156 { 157 #if 1 158 // reset pool 159 if (mIndex == mNumber) 160 { 161 std::cerr << "warning: ray pool too small! " << std::endl; 162 mIndex = 0; 163 } 164 165 // raypool larger index => enlarge ray pool 166 #else 167 if (mNumber == mIndex) 168 { 169 cerr << "warning: ray pool too small! " << "reserving " << mNumber * 2 << " rays" << std::endl; 170 Reserve(mNumber * 2); 171 } 172 #endif 173 return mRays + mIndex ++; 174 } 175 protected: 176 VssRay *mRays; 177 int mIndex; 178 int mNumber; 179 }; 180 181 182 VssRayPool mVssRayPool; 183 184 void ReserveVssRayPool(const int n) 185 { 186 mVssRayPool.Reserve(n); 187 } 188 189 void InitPass() 190 { 191 mVssRayPool.Clear(); 192 } 193 194 PerfTimer rawCastTimer; 195 196 protected: 197 184 198 185 199 void _SortRays(SimpleRayContainer &rays, -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor05.vcproj
r2725 r2729 104 104 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 105 105 CharacterSet="2" 106 WholeProgramOptimization="1" 106 107 > 107 108 <Tool … … 123 124 Name="VCCLCompilerTool" 124 125 Optimization="2" 125 InlineFunctionExpansion=" 0"126 EnableIntrinsicFunctions=" false"126 InlineFunctionExpansion="2" 127 EnableIntrinsicFunctions="true" 127 128 FavorSizeOrSpeed="1" 128 OmitFramePointers=" false"129 EnableFiberSafeOptimizations=" false"129 OmitFramePointers="true" 130 EnableFiberSafeOptimizations="true" 130 131 WholeProgramOptimization="true" 131 132 AdditionalIncludeDirectories="..\src;..\include;..\..\..\..\..\..\NonGTP\Boost;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;"$(QTDIR)\include\QtOpenGl";"$(QTDIR)\include\Qt";"$(QTDIR)\include\QtCore";"$(QTDIR)\include";QtInterface;..\src\sparsehash\src\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;$(NOINHERIT)" … … 135 136 ExceptionHandling="1" 136 137 RuntimeLibrary="2" 138 BufferSecurityCheck="false" 137 139 EnableEnhancedInstructionSet="0" 138 140 RuntimeTypeInfo="false" -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2726 r2729 3217 3217 ) 3218 3218 { 3219 3220 3221 pvs.Reserve(viewCell->GetFilteredPvsSize()); 3219 pvs.Reserve(viewCell->GetFilteredPvsSize()); 3222 3220 3223 3221 PvsFilterStatistics stats; -
GTP/trunk/Lib/Vis/Preprocessing/src/common.h
r2726 r2729 531 531 #endif 532 532 533 #define DYN_ERROR_STRING do {std::cout << "error: dynamic objects not supported" << endl;} while (0)533 #define DYN_ERROR_STRING do {std::cout << "error: dynamic objects not supported" << std::endl;} while (0) 534 534 535 535 /** view cell id belonging to empty view space.
Note: See TracChangeset
for help on using the changeset viewer.