- Timestamp:
- 05/30/08 02:37:07 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh
r2725 r2726 13 13 #SCENE=../data/Arena/arena-high-lods.obj 14 14 SCENE=../data/Arena/arena_trees.obj 15 VIEWCELLS=../data/Arena/arena-high-lods-5000-viewcells.xml.gz15 #VIEWCELLS=../data/Arena/arena-high-lods-5000-viewcells.xml.gz 16 16 #SCENE=../data/vienna/vienna_cropped.obj 17 17 #SCENE=../data/roofs_new.obj 18 #SCENE=../data/vienna/city_full_hp.obj18 SCENE=../data/vienna/city_full_hp.obj 19 19 #SCENE=../data/vienna/vienna_rep.obj 20 20 21 21 #SCENE=../data/vienna/vienna_cropped.obj 22 #VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz23 #VIEWPOINTS=../data/vienna/testwalk.vp24 VIEWPOINTS=../data/arena/arena_key_cropped.vp22 VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz 23 VIEWPOINTS=../data/vienna/testwalk.vp 24 #VIEWPOINTS=../data/arena/arena_key_cropped.vp 25 25 26 26 #LOG_PREFIX=../src/SG08/rebut-arena-pixel2 27 #LOG_PREFIX=../src/SG08/full 27 LOG_PREFIX=../src/SG08/speedtest 28 28 LOG_PREFIX=../src/SG08/arena_trees 29 29 … … 40 40 -preprocessor_use_vbos- \ 41 41 -gvs_epsilon=0.0001 \ 42 -gvs_total_samples=100000 \43 -gvs_samples_per_pass=100000 \44 -gvs_initial_samples= 16\45 -gvs_max_viewcells= 200000\46 -gvs_min_contribution= 2000 \42 -gvs_total_samples=1000000 \ 43 -gvs_samples_per_pass=1000000 \ 44 -gvs_initial_samples=2000 \ 45 -gvs_max_viewcells=1 \ 46 -gvs_min_contribution=50 \ 47 47 -gvs_per_viewcell=true \ 48 48 -preprocessor_detect_empty_viewspace+ \ -
GTP/trunk/Lib/Vis/Preprocessing/src/CombinedPreprocessor.cpp
r2723 r2726 92 92 vssRays.clear(); 93 93 94 95 mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays );94 int invalidSamples = 0; 95 mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays, invalidSamples); 96 96 97 97 cerr<<"Casting rays..."<<endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r2725 r2726 1587 1587 mViewDirection = sray.mDirection; 1588 1588 1589 cout << "handling vp " << mFrame << " " << mViewPoint << " " << mViewDirection << endl;1589 //cout << "handling vp " << mFrame << " " << mViewPoint << " " << mViewDirection << endl; 1590 1590 // skip all frames which have already 0 pixel error 1591 1591 // $$ Reverted back by JB for efficiency 1592 1592 if (1)//mPvsErrorBuffer[i].mError > 0.0f) 1593 1593 { 1594 cout << "here3" << endl;1595 1594 // compute the pixel error 1596 1595 mPvsErrorBuffer[i].mError = GetPixelError(pvsSize, mPvsStat.pass); -
GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp
r2552 r2726 169 169 170 170 SimpleRayContainer simpleRays; 171 glStrategy.GenerateSamples(5, simpleRays); 171 int invalidSamples = 0; 172 glStrategy.GenerateSamples(5, simpleRays, invalidSamples); 172 173 173 174 //cout << "simple ray: " << simpleRays[4] << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r2725 r2726 13 13 #include "Polygon3.h" 14 14 #include "IntersectableWrapper.h" 15 15 #include "Timer/PerfTimer.h" 16 16 17 17 … … 27 27 28 28 static ObjectContainer myobjects; 29 static int sInvalidSamples = 0; 30 31 /////////// 32 //-- timers 33 34 35 static PerfTimer rayTimer; 36 static PerfTimer kdPvsTimer; 37 static PerfTimer gvsTimer; 38 static PerfTimer initialTimer; 39 static PerfTimer intersectionTimer; 40 static PerfTimer preparationTimer; 41 static PerfTimer mainLoopTimer; 42 static PerfTimer contributionTimer; 43 static PerfTimer castTimer; 44 static PerfTimer generationTimer; 45 46 47 ///////////////////// 29 48 30 49 … … 145 164 const float len = Magnitude(currentRay.mTermination - currentRay.mOrigin); 146 165 147 #if 1148 166 // distance large => this is likely to be a discontinuity 149 if ((predictedLen - len) > mThreshold) 150 #else 167 if ((predictedLen - len) > mThreshold) 151 168 // q: rather use relative distance? 152 if ((predictedLen / len) > mThreshold)153 #endif 154 { 169 //if ((predictedLen / len) > mThreshold) 170 { 171 #if 0 155 172 // apply reverse sampling to find the gap 156 173 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); … … 162 179 if (0) newRay->mFlags |= VssRay::ReverseSample; 163 180 181 rayTimer.Entry(); 164 182 // check if ray can be processed further 165 183 // note: ray deletion handled by ray pool) 166 184 HandleRay(newRay); 185 rayTimer.Exit(); 167 186 168 187 return 1; 169 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 170 216 } 171 217 … … 193 239 void GvsPreprocessor::UpdateStatsForVisualization(KdIntersectable *kdInt) 194 240 { 241 int numObj = 0; 242 195 243 // count new objects in pvs due to kd node conversion 196 244 myobjects.clear(); … … 198 246 mKdTree->CollectObjectsWithDublicates(kdInt->GetItem(), myobjects); 199 247 200 int numObj;201 202 248 ObjectContainer::const_iterator oit, oit_end = myobjects.end(); 203 249 204 250 for (oit = myobjects.begin(); oit != oit_end; ++ oit) 205 numObj = CountObject(*oit);251 numObj += CountObject(*oit); 206 252 207 253 mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt, numObj); … … 209 255 210 256 257 void GvsPreprocessor::AddKdNodeToPvs(const Vector3 &termination) 258 { 259 kdPvsTimer.Entry(); 260 261 // exchange the triangle with the node in the pvs for kd pvs 262 KdNode *node = mKdTree->GetPvsNode(termination); 263 264 //KdNode *node = mKdTree->GetPvsNodeCheck(ray.mTermination, obj); 265 //if (!node) cerr << "e " << obj->GetBox() << " " << ray.mTermination << endl; else 266 if (!node->Mailed()) 267 { 268 // add to pvs 269 node->Mail(); 270 KdIntersectable *kdInt = mKdTree->GetOrCreateKdIntersectable(node); 271 mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f); 272 273 if (QT_VISUALIZATION_SHOWN) UpdateStatsForVisualization(kdInt); 274 } 275 276 kdPvsTimer.Exit(); 277 } 278 279 211 280 bool GvsPreprocessor::HasContribution(VssRay &ray) 212 281 { … … 214 283 return false; 215 284 285 contributionTimer.Entry(); 286 216 287 bool result; 217 288 … … 219 290 { 220 291 // store the rays + the intersected view cells 221 const bool storeViewCells = false; //GVS_DEBUG;292 const bool storeViewCells = false; 222 293 223 294 mViewCellsManager->ComputeSampleContribution(ray, … … 230 301 else // original per view cell gvs 231 302 { 232 Intersectable *obj = ray.mTerminationObject;233 234 303 // test if triangle was accounted for yet 235 result = AddTriangleObject( obj);304 result = AddTriangleObject(ray.mTerminationObject); 236 305 237 if (mUseKdPvs && (1 || result)) 238 { 239 // exchange the triangle with the node in the pvs for kd pvs 240 KdNode *node = mKdTree->GetPvsNode(ray.mTermination); 241 242 //KdNode *node = mKdTree->GetPvsNodeCheck(ray.mTermination, obj); 243 //if (!node) cerr << "e " << obj->GetBox() << " " << ray.mTermination << endl; else 244 if (!node->Mailed()) 245 { 246 // add to pvs 247 node->Mail(); 248 KdIntersectable *kdInt = mKdTree->GetOrCreateKdIntersectable(node); 249 mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f); 250 251 if (QT_VISUALIZATION_SHOWN) UpdateStatsForVisualization(kdInt); 252 } 253 } 254 } 306 if (mUseKdPvs) 307 AddKdNodeToPvs(ray.mTermination); 308 } 309 310 contributionTimer.Exit(); 255 311 256 312 return result; … … 363 419 const Vector3 p = (p1 + p2) * 0.5f; 364 420 //cout << "p: " << p << " " << p1 << " " << p2 << endl; 421 422 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 423 424 #if 1 425 castTimer.Entry(); 426 // cast single ray to check if a triangle was missed 427 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 428 castTimer.Exit(); 429 ++ castRays; 430 431 // this ray will not be further processed 432 // note: ray deletion is handled by ray pool 433 if (!newRay) return castRays; 434 435 // new triangle discovered? => add new ray to queue 436 rayTimer.Entry(); 437 HandleRay(newRay); 438 rayTimer.Exit(); 439 440 441 442 #else 443 365 444 // cast ray into the new point 366 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 367 368 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell); 369 370 ++ castRays; 371 445 static SimpleRayContainer importanceRays; 446 importanceRays.clear(); 447 448 generationTimer.Entry(); 449 450 451 importanceRays.push_back(sray); 452 453 const int numRandomRays = 15; 454 455 GenerateJitteredRays(importanceRays, sray, numRandomRays, 0); 456 GenerateRays(numRandomRays, *mDistribution, importanceRays, sInvalidSamples); 457 458 generationTimer.Exit(); 459 460 // for the original implementation we don't cast double rays 461 const bool castDoubleRays = !mPerViewCell; 462 // cannot prune invalid rays because we have to compare adjacent rays 463 const bool pruneInvalidRays = false; 464 465 static VssRayContainer vssRays; 466 vssRays.clear(); 467 468 castTimer.Entry(); 469 CastRays(importanceRays, vssRays, castDoubleRays, pruneInvalidRays); 470 castTimer.Exit(); 471 472 castRays += (int)vssRays.size(); 473 474 VssRay *newRay = vssRays.empty() ? NULL : vssRays[0]; 475 476 // new triangle discovered? => add new ray to queue 477 rayTimer.Entry(); 478 for (size_t i = 0; i < vssRays.size(); ++ i) 479 { 480 if (vssRays[i]) 481 HandleRay(vssRays[i]); 482 } 483 484 rayTimer.Exit(); 485 486 // this ray will not be further processed 487 // note: ray deletion is handled by ray pool 372 488 if (!newRay) return castRays; 489 #endif 373 490 374 491 //newRay->mFlags |= VssRay::BorderSample; 375 376 // add new ray to queue377 const bool enqueued = HandleRay(newRay);378 492 379 493 // subdivide further 380 494 castRays += SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay); 381 495 castRays += SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay); 382 383 // this ray will not be further processed 384 // note: ray deletion is handled by ray pool 385 496 386 497 return castRays; 387 498 } … … 391 502 { 392 503 Intersectable *tObj = currentRay.mTerminationObject; 393 // q matt: can this be possible 504 505 // question matt: can this be possible? 394 506 if (!tObj) return 0; 395 507 … … 410 522 411 523 /// create rays from sample points and handle them 412 SimpleRayContainer simpleRays; 413 simpleRays.reserve(9); 524 static SimpleRayContainer simpleRays; 525 simpleRays.clear(); 526 //simpleRays.reserve(9); 414 527 415 528 VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end(); … … 432 545 } 433 546 434 // cast rays to triangle vertices and determine visibility 547 548 ////////// 549 //-- fill up simple rays with random rays so we can cast 16 rays at a time 550 551 const int numRandomRays = 16 - (int)simpleRays.size(); 552 SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), currentRay.GetNormalizedDir(), SamplingStrategy::GVS, 1.0f); 553 554 GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0); 555 //GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples); 556 557 558 ///////////////////// 559 //-- cast rays to vertices and determine visibility 560 435 561 VssRayContainer vssRays; 436 562 437 // don't cast double rays as we need only the forwardrays563 // for the original implementation we don't cast double rays 438 564 const bool castDoubleRays = !mPerViewCell; 439 // cannot prune invalid rays because we have to compare adjacent rays.565 // cannot prune invalid rays because we have to compare adjacent rays 440 566 const bool pruneInvalidRays = false; 441 567 442 443 ////////// 444 //-- fill up simple rays with random rays so we can cast 16 rays simultaniosly 445 446 //const int numRandomRays = 0; 447 const int numRandomRays = 16 - (int)simpleRays.size(); 448 449 GenerateRays(numRandomRays, *mDistribution, simpleRays); 450 451 452 ///////////////////// 453 454 // keep origin for per view cell sampling 568 castTimer.Entry(); 455 569 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 570 castTimer.Exit(); 456 571 457 572 const int numBorderSamples = (int)vssRays.size() - numRandomRays; 458 573 int castRays = (int)simpleRays.size(); 574 575 // handle cast rays 576 EnqueueRays(vssRays); 577 459 578 #if 0 460 579 // set flags … … 464 583 #endif 465 584 466 int castRays = (int)simpleRays.size();467 468 VssRayContainer invalidSamples;469 470 // handle rays471 EnqueueRays(vssRays, invalidSamples);472 585 473 586 // recursivly subdivide each edge … … 483 596 484 597 mGvsStats.mBorderSamples += castRays; 485 486 598 487 599 return castRays; … … 546 658 // other types not implemented yet 547 659 if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 548 {549 660 occluder = static_cast<TriangleIntersectable *>(tObj)->GetItem(); 550 }551 661 else 552 {553 662 cout << "reverse sampling: " << tObj->Type() << " not yet implemented" << endl; 554 }663 555 664 // get a point which is passing just outside of the occluder 556 665 Vector3 newPoint; … … 564 673 Vector3 newDir, newOrigin; 565 674 675 ////////////// 566 676 //-- Construct the mutated ray with xnew, 567 677 //-- dir = predicted(x)- pnew as direction vector 678 568 679 newDir = predicted - newPoint; 569 680 … … 608 719 609 720 721 bool GvsPreprocessor::ReverseSampling2(const VssRay ¤tRay, 722 const Triangle3 &hitTriangle, 723 const VssRay &oldRay, 724 VssRayContainer &reverseRays) 725 { 726 // get triangle occluding the path to the hit mesh 727 Triangle3 occluder; 728 Intersectable *tObj = currentRay.mTerminationObject; 729 730 // q: why can this happen? 731 if (!tObj) 732 return NULL; 733 734 // other types not implemented yet 735 if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 736 occluder = static_cast<TriangleIntersectable *>(tObj)->GetItem(); 737 else 738 cout << "reverse sampling: " << tObj->Type() << " not yet implemented" << endl; 739 740 // get a point which is passing just outside of the occluder 741 Vector3 newPoint; 742 743 // q: why is there sometimes no intersecton found? 744 if (!GetPassingPoint(currentRay, occluder, oldRay, newPoint)) 745 return NULL; 746 747 const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 748 749 Vector3 newDir, newOrigin; 750 751 ////////////// 752 //-- Construct the mutated ray with xnew, 753 //-- dir = predicted(x)- pnew as direction vector 754 755 newDir = predicted - newPoint; 756 757 // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 758 // difficult to say!! 759 const float offset = 0.5f; 760 newOrigin = newPoint - newDir * offset; 761 762 763 ////////////// 764 //-- for per view cell sampling, we must check for intersection 765 //-- with the current view cell 766 767 if (mPerViewCell) 768 { 769 // send ray to view cell 770 static Ray ray; 771 772 ray.Clear(); 773 ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY); 774 775 // check if ray intersects view cell 776 if (!mCurrentViewCell->CastRay(ray)) 777 return NULL; 778 779 Ray::Intersection &hit = ray.intersections[0]; 780 781 // the ray starts from the view cell 782 newOrigin = ray.Extrap(hit.mT); 783 } 784 785 static SimpleRayContainer reverseSimpleRays; 786 reverseSimpleRays.clear(); 787 788 SimpleRay mainRay = SimpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f); 789 790 reverseSimpleRays.push_back(mainRay); 791 GenerateJitteredRays(reverseSimpleRays, mainRay, 15, 0); 792 793 castTimer.Entry(); 794 CastRays(reverseSimpleRays, reverseRays, false, false); 795 castTimer.Exit(); 796 797 mGvsStats.mReverseSamples += reverseRays.size(); 798 799 return true; 800 } 801 802 610 803 int GvsPreprocessor::CastInitialSamples(int numSamples) 611 804 { 612 const long startTime = GetTime();805 initialTimer.Entry(); 613 806 614 807 // generate simple rays 615 SimpleRayContainer simpleRays; 616 808 static SimpleRayContainer simpleRays; 809 simpleRays.clear(); 810 811 812 generationTimer.Entry(); 617 813 ViewCellBorderBasedDistribution vcStrat(*this, mCurrentViewCell); 618 GenerateRays(numSamples, *mDistribution, simpleRays); 814 GenerateRays(numSamples, *mDistribution, simpleRays, sInvalidSamples); 815 generationTimer.Exit(); 619 816 620 817 //cout << "sr: " << simpleRays.size() << endl; 621 818 // generate vss rays 622 VssRayContainer samples; 623 819 static VssRayContainer samples; 820 samples.clear(); 821 624 822 const bool castDoubleRays = !mPerViewCell; 625 823 const bool pruneInvalidRays = true; 626 824 825 castTimer.Entry(); 627 826 CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays); 628 629 VssRayContainer invalidSamples; 827 castTimer.Exit(); 630 828 631 829 // add to ray queue 632 EnqueueRays(samples , invalidSamples);633 634 //CLEAR_CONTAINER(invalidSamples);635 //Debug << "generated " << numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 830 EnqueueRays(samples); 831 832 initialTimer.Exit(); 833 636 834 return (int)simpleRays.size(); 637 835 } 638 836 639 837 640 void GvsPreprocessor::EnqueueRays(VssRayContainer &samples, VssRayContainer &invalidSamples) 641 { 838 void GvsPreprocessor::EnqueueRays(VssRayContainer &samples) 839 { 840 rayTimer.Entry(); 841 642 842 // add samples to ray queue 643 843 VssRayContainer::const_iterator vit, vit_end = samples.end(); … … 645 845 { 646 846 VssRay *ray = *vit; 647 648 847 HandleRay(ray); 649 //if (!HandleRay(ray)) invalidSamples.push_back(ray); 650 } 848 // note: deletion of invalid samples handked by ray pool 849 } 850 851 rayTimer.Exit(); 651 852 } 652 853 … … 654 855 int GvsPreprocessor::ProcessQueue() 655 856 { 857 gvsTimer.Entry(); 858 656 859 ++ mGvsStats.mGvsRuns; 657 860 658 861 int castSamples = 0; 659 862 660 while (!mRayQueue.empty()) //&& (mGvsStats.mTotalSamples + castSamples < mTotalSamples) )863 while (!mRayQueue.empty()) 661 864 { 662 865 // handle next ray … … 664 867 mRayQueue.pop(); 665 868 666 const int newSamples = AdaptiveBorderSampling(*ray); 667 668 castSamples += newSamples; 869 castSamples += AdaptiveBorderSampling(*ray); 669 870 // note: don't have to delete because handled by ray pool 670 871 } 671 872 672 /*if (mRayCaster->mVssRayPool.mIndex > mSamplesPerPass) 673 { 674 cout << "warning: new samples: " << castSamples << " " << "queue: " << (int)mRayQueue.size() << endl; 675 Debug << "warning: new samples: " << castSamples << " " << "queue: " << (int)mRayQueue.size() << endl; 676 }*/ 873 gvsTimer.Exit(); 677 874 678 875 return castSamples; … … 694 891 { 695 892 if ((*rit)->mFlags & VssRay::BorderSample) 696 {697 893 vcRays.push_back(*rit); 698 }699 894 else if ((*rit)->mFlags & VssRay::ReverseSample) 700 {701 895 vcRays2.push_back(*rit); 702 }703 896 else 704 {705 897 vcRays3.push_back(*rit); 706 } 707 } 898 } 708 899 } 709 900 … … 719 910 Material m; 720 911 721 char str[64]; sprintf (str, "pass%06d.wrl", mProcessedViewCells);912 char str[64]; sprintf_s(str, "pass%06d.wrl", mProcessedViewCells); 722 913 723 914 Exporter *exporter = Exporter::GetExporter(str); … … 880 1071 void GvsPreprocessor::ComputeViewCellGeometryIntersection() 881 1072 { 1073 intersectionTimer.Entry(); 1074 882 1075 AxisAlignedBox3 box = mCurrentViewCell->GetBox(); 883 1076 … … 927 1120 928 1121 cout << "added " << (int)mTrianglePvs.size() - oldTrianglePvs << " triangles (" << newKdObj << " objects) by intersection" << endl; 1122 1123 intersectionTimer.Exit(); 929 1124 } 930 1125 … … 934 1129 while (mCurrentViewCell = NextViewCell()) 935 1130 { 936 // hack: reset counters 1131 preparationTimer.Entry(); 1132 1133 // hack: reset counters (could be done with a mailing-like approach 937 1134 ObjectContainer::const_iterator oit, oit_end = mObjects.end(); 938 939 1135 for (oit = mObjects.begin(); oit != oit_end; ++ oit) 940 1136 (*oit)->mCounter = NOT_ACCOUNTED_OBJECT; 941 1137 1138 preparationTimer.Exit(); 1139 942 1140 mDistribution->SetViewCell(mCurrentViewCell); 1141 943 1142 ComputeViewCell(); 944 1143 } … … 1041 1240 { 1042 1241 int passSamples = 0; 1242 int randomSamples = 0; 1243 int gvsSamples = 0; 1043 1244 int oldContribution = 0; 1044 1245 … … 1046 1247 { 1047 1248 mRayCaster->InitPass(); 1249 1250 int newRandomSamples, newGvsSamples; 1048 1251 1049 1252 // Ray queue empty => 1050 1253 // cast a number of uniform samples to fill ray queue 1051 int newSamples = CastInitialSamples(mInitialSamples);1052 1254 newRandomSamples = CastInitialSamples(mInitialSamples); 1255 1053 1256 if (!mOnlyRandomSampling) 1054 newSamples += ProcessQueue(); 1055 1056 passSamples += newSamples; 1057 mGvsStats.mTotalSamples += newSamples; 1257 newGvsSamples = ProcessQueue(); 1258 1259 passSamples += newRandomSamples + newGvsSamples; 1260 mGvsStats.mTotalSamples += newRandomSamples + newGvsSamples; 1261 1262 mGvsStats.mRandomSamples += newRandomSamples; 1263 mGvsStats.mGvsSamples += newGvsSamples; 1264 1058 1265 1059 1266 if (passSamples % (mGvsSamplesPerPass + 1) == mGvsSamplesPerPass) … … 1062 1269 1063 1270 mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution; 1064 1271 1065 1272 //////// 1066 1273 //-- stats … … 1220 1427 void GvsPreprocessor::ComputeViewCell() 1221 1428 { 1222 //if (mCurrentViewCell->GetId() != 499) return; 1223 1224 // clean up 1429 const long startTime = GetTime(); 1430 1431 // initialise 1432 mGvsStats.mPerViewCellSamples = 0; 1433 1434 int oldContribution = 0; 1435 int passSamples = 0; 1436 for (int i = 0; i < 0; ++ i) 1437 mGenericStats[i] = 0; 1438 1225 1439 mTrianglePvs.clear(); 1226 1440 1441 1442 // hack: take bounding box of view cell as view cell bounds 1227 1443 mCurrentViewCell->GetMesh()->ComputeBoundingBox(); 1228 1444 1445 // use mailing for kd node pvs 1229 1446 KdNode::NewMail(); 1230 1231 const long startTime = GetTime();1232 1447 1233 1448 cout << "\n***********************\n" … … 1236 1451 cout << "bb: " << mCurrentViewCell->GetBox() << endl; 1237 1452 1238 mGvsStats.mPerViewCellSamples = 0; 1239 1240 int oldContribution = 0; 1241 int passSamples = 0; 1242 1243 for (int i = 0; i < 0; ++ i) 1244 mGenericStats[i] = 0; 1453 mainLoopTimer.Entry(); 1245 1454 1246 1455 while (1) 1247 1456 { 1457 sInvalidSamples = 0; 1248 1458 int oldPvsSize = mCurrentViewCell->GetPvs().GetSize(); 1249 1459 1250 1460 mRayCaster->InitPass(); 1251 1461 1462 int newRandomSamples, newGvsSamples, newSamples; 1463 1252 1464 // Ray queue empty => 1253 1465 // cast a number of uniform samples to fill ray queue 1254 int newSamples = CastInitialSamples(mInitialSamples);1255 1466 newRandomSamples = CastInitialSamples(mInitialSamples); 1467 1256 1468 if (!mOnlyRandomSampling) 1257 { 1258 int samplesPerRun = ProcessQueue(); 1259 newSamples += samplesPerRun; 1260 //if (samplesPerRun > 0) cout << "spr: " << samplesPerRun << " "; 1261 } 1469 newGvsSamples = ProcessQueue(); 1470 1471 newSamples = newRandomSamples + newGvsSamples; 1262 1472 1263 1473 passSamples += newSamples; 1264 mGvsStats.mPerViewCellSamples += newSamples; 1474 mGvsStats.mPerViewCellSamples += newSamples; 1475 1476 mGvsStats.mRandomSamples += newRandomSamples; 1477 mGvsStats.mGvsSamples += newGvsSamples; 1478 1265 1479 1266 1480 if (passSamples >= mGvsSamplesPerPass) … … 1303 1517 } 1304 1518 1519 mainLoopTimer.Exit(); 1520 1305 1521 // at last compute objects that directly intersect view cell 1306 1522 ComputeViewCellGeometryIntersection(); 1307 1308 1523 1524 1309 1525 //////// 1310 1526 //-- stats … … 1321 1537 // compute pvs size using larger (bvh objects) 1322 1538 // note: for kd pvs we had to do this during gvs computation 1323 1324 1539 if (!mUseKdPvs) 1325 1540 { … … 1343 1558 mGvsStats.mPvsCost = 0; // todo objectPvs.EvalPvsCost(); 1344 1559 } 1345 else if (0) 1346 { 1347 //KdNode::NewMail(); 1348 1349 // compute pvs kd nodes that intersect view cell 1560 else if (0) // compute pvs kd nodes that intersect view cell 1561 { 1350 1562 ObjectContainer mykdobjects; 1351 1563 … … 1387 1599 mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples; 1388 1600 1601 cout << "id: " << mCurrentViewCell->GetId() << " pvs cost: " 1602 << mGvsStats.mPvsCost << " pvs tri: " << mTrianglePvs.size() << endl; 1603 1604 cout << "invalid samples ratio: " << (float)sInvalidSamples / mGvsStats.mPerViewCellSamples << endl; 1605 1606 float rayTime = rayTimer.TotalTime(); 1607 float kdPvsTime = kdPvsTimer.TotalTime(); 1608 float gvsTime = gvsTimer.TotalTime(); 1609 float initialTime = initialTimer.TotalTime(); 1610 float intersectionTime = intersectionTimer.TotalTime(); 1611 float preparationTime = preparationTimer.TotalTime(); 1612 float mainLoopTime = mainLoopTimer.TotalTime(); 1613 float contributionTime = contributionTimer.TotalTime(); 1614 float castTime = castTimer.TotalTime(); 1615 float generationTime = generationTimer.TotalTime(); 1616 1617 cout << "handleRay : " << rayTime << endl; 1618 cout << "kd pvs : " << kdPvsTime << endl; 1619 cout << "gvs sampling : " << gvsTime << endl; 1620 cout << "initial sampling : " << initialTime << endl; 1621 cout << "view cell intersection : " << intersectionTime << endl; 1622 cout << "preparation : " << preparationTime << endl; 1623 cout << "main loop : " << mainLoopTime << endl; 1624 cout << "has contribution : " << contributionTime << endl; 1625 cout << "cast time : " << castTime << endl; 1626 cout << "generation time : " << generationTime << endl; 1627 1628 float randomRaysPerSec = mGvsStats.mRandomSamples / (1e6f * initialTime); 1629 float gvsRaysPerSec = mGvsStats.mGvsSamples / (1e6f * gvsTime); 1630 1631 cout << "cast " << randomRaysPerSec << " M random rays/s: " << endl; 1632 cout << "cast " << gvsRaysPerSec << " M gvs rays/s: " << endl; 1633 1389 1634 mGvsStats.Stop(); 1390 1635 mGvsStats.Print(mGvsStatsStream); 1391 1636 1392 cout << "id: " << mCurrentViewCell->GetId() << " pvs cost: " 1393 << mGvsStats.mPvsCost << " pvs tri: " << mTrianglePvs.size() << endl; 1394 } 1395 1396 1397 ObjectContainer triangles; 1637 } 1638 1639 1398 1640 1399 1641 int GvsPreprocessor::ConvertObjectPvs() 1400 1642 { 1643 static ObjectContainer triangles; 1644 1401 1645 int newObjects = 0; 1402 1646 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r2705 r2726 39 39 mGvsRuns = 0; 40 40 41 mRandomSamples = 0; 42 mGvsSamples = 0; 41 43 mTotalPvs = 0; 42 44 mViewCells = 0; … … 54 56 public: 55 57 58 int mRandomSamples; 59 int mGvsSamples; 56 60 int mPass; 57 61 int mTotalSamples; … … 141 145 b) if triangle was found reverse sampling 142 146 */ 143 bool HandleRay(VssRay *ray);147 inline bool HandleRay(VssRay *ray); 144 148 145 149 /** The adaptive border sampling step. It aims to find neighbouring … … 157 161 const VssRay &oldRay); 158 162 163 bool ReverseSampling2(const VssRay ¤tRay, 164 const Triangle3 &hitTriangle, 165 const VssRay &oldRay, 166 VssRayContainer &reverseRays); 167 159 168 /** Returns true if we sampled a closer triangle than with the previous ray. 160 169 Does reverse sampling if gap found. … … 167 176 with respect to the previous ray. 168 177 */ 169 void EnqueueRays(VssRayContainer &samples , VssRayContainer &invalidSamples);178 void EnqueueRays(VssRayContainer &samples); 170 179 171 180 /** Hepler function for adaptive border sampling. It finds … … 239 248 */ 240 249 void UpdateStatsForVisualization(KdIntersectable *kdInt); 250 251 void CompileViewCellsFromPointList(); 252 253 void ComputeStats(); 254 255 int ConvertObjectPvs(); 241 256 /** Keep count of new objects for stats. Returns number of new pvs entries. 242 257 */ 243 int CountObject(Intersectable *triObj); 244 245 void CompileViewCellsFromPointList(); 246 247 bool AddTriangleObject(Intersectable *triObj); 248 249 void ComputeStats(); 250 251 int ConvertObjectPvs(); 258 inline int CountObject(Intersectable *triObj); 259 260 inline bool AddTriangleObject(Intersectable *triObj); 261 262 inline void AddKdNodeToPvs(const Vector3 &termination); 252 263 253 264 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2724 r2726 966 966 SimpleRayContainer &rays) 967 967 { 968 return strategy.GenerateSamples(number, rays); 968 int invalidSamples; 969 return strategy.GenerateSamples(number, rays, invalidSamples); 970 } 971 972 973 int Preprocessor::GenerateRays(const int number, 974 SamplingStrategy &strategy, 975 SimpleRayContainer &rays, int &invalidSamples) 976 { 977 return strategy.GenerateSamples(number, rays, invalidSamples); 969 978 } 970 979 … … 975 984 SimpleRayContainer &rays) 976 985 { 977 const int startSize = (int)rays.size();978 986 SamplingStrategy *strategy = GenerateSamplingStrategy(sampleType); 987 988 if (!strategy) 989 return 0; 990 979 991 int castRays = 0; 980 981 if (!strategy) 982 { 983 return 0; 984 } 985 992 int invalidSamples; 986 993 #if 1 987 castRays = strategy->GenerateSamples(number, rays );994 castRays = strategy->GenerateSamples(number, rays, invalidSamples); 988 995 #else 989 996 GenerateRayBundle(rays, newRay, 16, 0); … … 1197 1204 1198 1205 // !!!!!!!!!!!!!!!! VH no sorting 1199 if ( 1200 rays.size() > 10000 1201 ) 1206 if (rays.size() > 10000) 1202 1207 { 1203 1208 mRayCaster->SortRays(rays); … … 1316 1321 1317 1322 1318 bool Preprocessor::GenerateRayBundle(SimpleRayContainer &rayBundle, 1319 const SimpleRay &mainRay, 1320 const int number, 1321 const int pertubType) const 1322 { 1323 rayBundle.push_back(mainRay); 1324 1325 const float pertubOrigin = 0.0f; 1326 const float pertubDir = 0.2f; 1327 1328 for (int i = 0; i < number - 1; ++ i) 1329 { 1330 Vector3 pertub; 1331 1332 pertub.x = RandomValue(0.0f, pertubDir); 1333 pertub.y = RandomValue(0.0f, pertubDir); 1334 pertub.z = RandomValue(0.0f, pertubDir); 1335 1336 const Vector3 newDir = mainRay.mDirection + pertub; 1323 bool Preprocessor::GenerateJitteredRays(SimpleRayContainer &rayBundle, 1324 const SimpleRay &mainRay, 1325 int number, 1326 int pertubType) const 1327 { 1328 //rayBundle.push_back(mainRay); 1329 //const float pertubOrigin = 0.0f; 1330 const float pertubDir = 0.01f; 1331 Vector3 pertub; 1332 1333 for (int i = 0; i < number; ++ i) 1334 { 1335 pertub.x = RandomValue(-pertubDir, pertubDir); 1336 pertub.y = RandomValue(-pertubDir, pertubDir); 1337 pertub.z = RandomValue(-pertubDir, pertubDir); 1338 1339 Vector3 newDir = mainRay.mDirection + pertub; 1340 const float c = Magnitude(newDir); 1341 newDir *= 1.0f / c; 1342 1337 1343 //const Vector3 newDir = mainRay.mDirection; 1338 1344 #if 0 1339 1345 pertub.x = RandomValue(0.0f, pertubOrigin); 1340 1346 pertub.y = RandomValue(0.0f, pertubOrigin); … … 1342 1348 1343 1349 const Vector3 newOrigin = mainRay.mOrigin + pertub; 1344 //const Vector3 newOrigin = mainRay.mOrigin; 1350 #endif 1351 const Vector3 newOrigin = mainRay.mOrigin; 1345 1352 1346 1353 rayBundle.push_back(SimpleRay(newOrigin, newDir, 0, 1.0f)); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r2720 r2726 132 132 SimpleRayContainer &rays); 133 133 134 virtual int GenerateRays(const int number, 135 SamplingStrategy &strategy, 136 SimpleRayContainer &rays, 137 int &invalidSamples); 138 134 139 virtual int GenerateRays(const int number, 135 140 const int raysType, 136 141 SimpleRayContainer &rays); 137 142 138 bool Generate RayBundle(SimpleRayContainer &rayBundle,139 140 constint number,141 constint shuffleType) const;143 bool GenerateJitteredRays(SimpleRayContainer &rayBundle, 144 const SimpleRay &mainRay, 145 int number, 146 int shuffleType) const; 142 147 143 148 virtual void CastRays(SimpleRayContainer &rays, -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r2105 r2726 492 492 493 493 } else { 494 int invalidSamples = 0; 494 495 for (int i=0; i < mInitialSamples; i+=batch) { 495 496 rays.clear(); 496 497 mVssRays.clear(); 497 mMixtureDistribution->GenerateSamples(batch, rays );498 mMixtureDistribution->GenerateSamples(batch, rays, invalidSamples); 498 499 CastRays(rays, mVssRays, true, pruneInvalidRays); 499 500 mMixtureDistribution->ComputeContributions(mVssRays); -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r2698 r2726 54 54 55 55 int 56 SamplingStrategy::GenerateSamples(const int number, 57 SimpleRayContainer &rays) 56 SamplingStrategy::GenerateSamples(int number, 57 SimpleRayContainer &rays, 58 int &invalidSamples) 58 59 { 59 60 SimpleRay ray; 60 int samples = 0; 61 int i = 0; 62 const int maxTries = 20; 61 int oldSamples = (int)rays.size(); 62 63 static const int maxTries = 20; 64 63 65 // tmp changed matt. Q: should one rejected sample 64 66 // terminate the whole method? 65 for ( ; i < number; i++)67 for (int i = 0; i < number; ++ i) 66 68 { 67 int j = 0; 68 bool sampleGenerated = false; 69 70 for (j = 0; !sampleGenerated && (j < maxTries); ++ j) 69 for (int j = 0; j < maxTries; ++ j) 71 70 { 72 sampleGenerated = GenerateSample(ray); 73 74 if (sampleGenerated) 71 if (GenerateSample(ray)) 75 72 { 76 ++ samples;77 73 rays.push_back(ray); 78 //cout << "d " << ray.mDirection << " ";74 break; 79 75 } 76 cerr<<"x"; 77 ++ invalidSamples; 80 78 } 81 79 } 82 80 83 return samples;81 return (int)rays.size() - oldSamples; 84 82 } 85 83 … … 722 720 723 721 int 724 MixtureDistribution::GenerateSamples(const int number, 725 SimpleRayContainer &rays) 722 MixtureDistribution::GenerateSamples(int number, 723 SimpleRayContainer &rays, 724 int &invalidSamples) 726 725 { 727 726 for (int i=0; i < mDistributions.size(); i++) 728 727 mDistributions[i]->mGeneratedRays = 0; 729 728 730 return SamplingStrategy::GenerateSamples(number, rays );729 return SamplingStrategy::GenerateSamples(number, rays, invalidSamples); 731 730 } 732 731 … … 804 803 bool ViewCellBasedDistribution::GenerateSample(SimpleRay &ray) 805 804 { 806 Vector3 origin, direction;807 808 Vector3 point;809 Vector3 normal;810 811 float r[2];812 //for (int i=0; i < 2; i++)813 // r[i] = RandomValue(0, 1);814 815 805 sHalton.GetNext(2, r); 816 817 806 direction = UniformRandomVector(r[0], r[1]); 807 808 #if 0 818 809 const float c = Magnitude(direction); 819 810 811 if (!((c < 1.00001f) && (c > 0.999999f))) 812 cerr << "len wrong" << endl; 820 813 if (c <= Limits::Small) 821 814 return false; 822 815 823 816 direction *= 1.0f / c; 817 #endif 824 818 825 819 // get point on view cell surface 826 if ( 0)820 if (1) 827 821 { 828 822 //mViewCell->GetRandomEdgePoint(origin, normal); 829 mViewCell->GetRandomSurfacePoint(origin, normal);823 origin = mViewCell->GetBox().GetRandomSurfacePoint(); 830 824 831 825 // move a little bit back to avoid piercing through walls 832 826 // that bound the view cell 833 if (0)origin -= 0.01f * normal;827 //origin -= 0.01f * normal; 834 828 } 835 829 else 836 830 origin = mViewCell->GetBox().GetUniformRandomSurfacePoint(); 837 831 838 //direction = point - origin; 839 840 // $$ jb the pdf is yet not correct for all sampling methods! 841 const float pdf = 1.0f; 832 static const float pdf = 1.0f; 842 833 843 834 ray = SimpleRay(origin, direction, VIEWCELL_BASED_DISTRIBUTION, pdf); -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r2694 r2726 7 7 #include "common.h" 8 8 #include "Halton.h" 9 #include "Vector3.h" 10 9 11 namespace GtpVisibilityPreprocessor { 10 12 … … 59 61 virtual ~SamplingStrategy(); 60 62 63 virtual int GenerateSamples(int number, SimpleRayContainer &rays, int &invalidSamples); 61 64 /** Each strategy has to implement this function. 62 @returns true if generated valid sample.65 @returns true if generated valid sample. 63 66 */ 64 65 virtual int GenerateSamples(const int number, SimpleRayContainer &rays);66 67 67 virtual bool GenerateSample(SimpleRay &ray) = 0; 68 68 … … 262 262 263 263 ViewCell *mViewCell; 264 265 Vector3 origin; 266 Vector3 direction; 267 Vector3 point; 268 Vector3 normal; 269 float r[2]; 270 264 271 static HaltonSequence sHalton; 265 272 }; … … 307 314 } 308 315 309 virtual int GenerateSamples( const int number, SimpleRayContainer &rays);316 virtual int GenerateSamples(int number, SimpleRayContainer &rays, int &invalidSamples); 310 317 311 318 private: -
GTP/trunk/Lib/Vis/Preprocessing/src/SimpleRay.h
r2588 r2726 55 55 SimpleRay(const Vector3 &o, 56 56 const Vector3 &d, 57 constunsigned char distribution,58 constfloat weight,59 constunsigned char flags = F_BIDIRECTIONAL57 unsigned char distribution, 58 float weight, 59 unsigned char flags = F_BIDIRECTIONAL 60 60 ): 61 61 mOrigin(o), -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2723 r2726 137 137 //rays.clear(); 138 138 //passSamples.clear(); 139 140 mMixtureDistribution->GenerateSamples(samplesPerPass, rays );139 int invalidSamples = 0; 140 mMixtureDistribution->GenerateSamples(samplesPerPass, rays, invalidSamples); 141 141 142 142 const bool doubleRays = true; -
GTP/trunk/Lib/Vis/Preprocessing/src/common.h
r2705 r2726 538 538 539 539 540 #define QT_VISUALIZATION_SHOWN 1541 542 543 #endif 544 545 546 547 548 549 550 551 540 #define QT_VISUALIZATION_SHOWN 0 541 542 543 #endif 544 545 546 547 548 549 550 551
Note: See TracChangeset
for help on using the changeset viewer.