Changeset 1999 for GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
- Timestamp:
- 01/20/07 00:14:25 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1996 r1999 16 16 { 17 17 18 #define GVS_DEBUG 018 #define GVS_DEBUG 1 19 19 20 20 struct VizStruct … … 31 31 GvsPreprocessor::GvsPreprocessor(): 32 32 Preprocessor(), 33 mSamplingType(SamplingStrategy::VIEWCELL_BASED_DISTRIBUTION),34 //mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION),33 //mSamplingType(SamplingStrategy::VIEWCELL_BASED_DISTRIBUTION), 34 mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION), 35 35 mProcessedViewCells(0), 36 36 mCurrentViewCell(NULL) … … 144 144 delete newRay; 145 145 } 146 else if (0 && GVS_DEBUG && (mVssRays.size() < 9)) 146 147 148 return 1; 149 } 150 151 return 0; 152 } 153 154 // #id: 1270 155 bool GvsPreprocessor::HasContribution(VssRay &ray) 156 { 157 if (!ray.mTerminationObject) 158 return false; 159 160 bool result; 161 162 if (!mPerViewCell) 163 { 164 // store the rays + the intersected view cells 165 const bool storeViewCells = false; //GVS_DEBUG; 166 167 mViewCellsManager->ComputeSampleContribution(ray, 168 true, 169 storeViewCells, 170 true); 171 172 result = ray.mPvsContribution > 0; 173 } 174 else 175 { 176 Intersectable *obj = ray.mTerminationObject; 177 178 if (!obj->mCounter) 147 179 { 148 mVssRays.push_back(new VssRay(oldRay)); 149 mVssRays.push_back(new VssRay(currentRay)); 150 mVssRays.push_back(new VssRay(*newRay)); 151 } 152 153 return 1; 154 } 155 156 return 0; 157 } 158 159 160 bool GvsPreprocessor::HandleRay(VssRay *vssRay) 161 { 162 // store the rays + the intersected view cells 163 const bool storeRaysForViz = false; //GVS_DEBUG; 164 165 if (!mPerViewCell) 166 { 167 mViewCellsManager->ComputeSampleContribution(*vssRay, 168 true, 169 storeRaysForViz, 170 true); 171 } 172 else 173 { 174 mViewCellsManager->ComputeSampleContribution(*vssRay, 180 obj->mCounter = 1; 181 mTrianglePvs.push_back(obj); 182 183 /*mViewCellsManager->ComputeSampleContribution(ray, 175 184 true, 176 185 mCurrentViewCell, 177 true); 178 } 179 180 // some pvs contribution for this ray? 181 if (!vssRay->mPvsContribution) 186 true);*/ 187 188 result = true; 189 } 190 else 191 { 192 result = false; 193 } 194 } 195 196 return result; 197 } 198 199 200 bool GvsPreprocessor::HandleRay(VssRay *vssRay) 201 { 202 if (!HasContribution(*vssRay)) 182 203 return false; 183 204 184 if ( GVS_DEBUG)205 if (0 && GVS_DEBUG) 185 206 mVssRays.push_back(new VssRay(*vssRay)); 186 207 187 208 // add new ray to ray queue 188 209 mRayQueue.push(vssRay); 189 190 if (storeRaysForViz)191 {192 VssRay *nray = new VssRay(*vssRay);193 nray->mFlags = vssRay->mFlags;194 195 // store ray in contributing view cell196 ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end();197 for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit)198 {199 (*vit)->GetOrCreateRays()->push_back(nray);200 }201 }202 210 203 211 ++ mGvsStats.mTotalContribution; … … 399 407 } 400 408 409 int castRays = (int)simpleRays.size(); 410 411 VssRayContainer invalidSamples; 412 401 413 // handle rays 402 EnqueueRays(vssRays); 403 404 int castRays = simpleRays.size(); 405 414 EnqueueRays(vssRays, invalidSamples); 415 406 416 // recursivly subdivide each edge 407 417 for (int i = 0; i < numBorderSamples; ++ i) … … 414 424 currentRay); 415 425 } 416 426 417 427 mGvsStats.mBorderSamples += castRays; 428 429 CLEAR_CONTAINER(invalidSamples); 418 430 419 431 return castRays; … … 442 454 if (!intersects) 443 455 { 444 cerr << "big error!! no intersection " << pt1 << " " << pt2 << endl;456 //cerr << "big error!! no intersection " << pt1 << " " << pt2 << endl; 445 457 return false; 446 458 } … … 562 574 CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays); 563 575 576 VssRayContainer invalidSamples; 577 564 578 // add to ray queue 565 EnqueueRays(samples); 566 579 EnqueueRays(samples, invalidSamples); 580 581 CLEAR_CONTAINER(invalidSamples); 567 582 //Debug << "generated " << numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 568 583 return (int)simpleRays.size(); … … 570 585 571 586 572 void GvsPreprocessor::EnqueueRays(VssRayContainer &samples )587 void GvsPreprocessor::EnqueueRays(VssRayContainer &samples, VssRayContainer &invalidSamples) 573 588 { 574 589 // add samples to ray queue … … 576 591 for (vit = samples.begin(); vit != vit_end; ++ vit) 577 592 { 578 HandleRay(*vit); 593 VssRay *ray = *vit; 594 595 if (!HandleRay(ray)) 596 invalidSamples.push_back(ray); 579 597 } 580 598 } … … 597 615 castSamples += newSamples; 598 616 599 //cout << newSamples << " ";617 //cout << "new samples: " << newSamples << " " << "queue: " << (int)mRayQueue.size() << endl; 600 618 delete ray; 601 619 } … … 639 657 640 658 641 void GvsPreprocessor::VisualizeViewCell(ViewCell *vc) 659 //void GvsPreprocessor::VisualizeViewCell(ViewCell *vc) 660 void GvsPreprocessor::VisualizeViewCell(const ObjectContainer &objects) 642 661 { 643 662 Intersectable::NewMail(); … … 651 670 return; 652 671 653 ObjectPvsIterator pit = vc->GetPvs().GetIterator();672 /*ObjectPvsIterator pit = vc->GetPvs().GetIterator(); 654 673 655 674 // output PVS of view cell … … 669 688 670 689 exporter->ExportIntersectable(intersect); 690 }*/ 691 ObjectContainer::const_iterator oit, oit_end = objects.end(); 692 693 for (oit = objects.begin(); oit != oit_end; ++ oit) 694 { 695 Intersectable *intersect = *oit; 696 697 m = RandomMaterial(); 698 exporter->SetForcedMaterial(m); 699 exporter->ExportIntersectable(intersect); 671 700 } 672 701 … … 682 711 exporter->SetForcedMaterial(m); 683 712 684 mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL); 713 //mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL); 714 //mViewCellsManager->ExportViewCellGeometry(exporter, mCurrentViewCell, NULL, NULL); 715 716 AxisAlignedBox3 bbox = mCurrentViewCell->GetMesh()->mBox; 717 exporter->ExportBox(bbox); 685 718 //exporter->SetFilled(); 686 719 … … 720 753 void GvsPreprocessor::ProcessViewCell() 721 754 { 755 //Intersectable::NewMail(); 756 // compute direct intersections with view cell 757 IntersectWithViewCell(); 758 722 759 mGvsStats.mPerViewCellSamples = 0; 723 760 int oldContribution = mGvsStats.mTotalContribution; … … 736 773 passSamples += newSamples; 737 774 mGvsStats.mPerViewCellSamples += newSamples; 738 //cout << "here 4" << passSamples % (mSamplesPerPass + 1) << endl;775 //cout << "here2 " << passSamples % (mSamplesPerPass + 1) << endl; 739 776 740 777 if (passSamples >= mSamplesPerPass) … … 774 811 { 775 812 mViewCells.push_back(mViewCellsManager->GetViewCell((int)mViewCells.size())); 813 continue; 776 814 } 777 else 815 816 // HACK 817 const int tries = 10000; 818 int i = 0; 819 820 for (i = 0; i < tries; ++ i) 778 821 { 779 // HACK780 const int tries = 10000;781 int i = 0;782 783 for (i = 0; i < tries; ++ i)822 const int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f); 823 824 ViewCell *viewCell = mViewCellsManager->GetViewCell(idx); 825 826 if (!viewCell->Mailed()) 784 827 { 785 const int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f); 786 787 ViewCell *viewCell = mViewCellsManager->GetViewCell(idx); 788 789 if (!viewCell->Mailed()) 828 viewCell->Mail(); 829 break; 830 } 831 832 mViewCells.push_back(viewCell); 833 } 834 835 if (i == tries) 836 { 837 cerr << "big error! no view cell found" << endl; 838 return; 839 } 840 } 841 } 842 843 844 void GvsPreprocessor::IntersectWithViewCell() 845 { 846 mCurrentViewCell->GetMesh()->ComputeBoundingBox(); 847 AxisAlignedBox3 box = mCurrentViewCell->GetMesh()->mBox; 848 //cout << "box: " << box << endl; 849 vector<KdLeaf *> leaves; 850 851 mKdTree->GetBoxIntersections(box, leaves); 852 853 vector<KdLeaf *>::const_iterator lit, lit_end = leaves.end(); 854 855 for (lit = leaves.begin(); lit != leaves.end(); ++ lit) 856 { 857 KdLeaf *leaf = *lit; 858 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 859 860 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 861 { 862 TriangleIntersectable *triObj = dynamic_cast<TriangleIntersectable *>(*oit); 863 864 if (box.Intersects(triObj->GetItem())) 865 { 866 if (!triObj->mCounter) 790 867 { 791 viewCell->Mail();792 break;868 triObj->mCounter = 1; 869 mTrianglePvs.push_back(triObj); 793 870 } 794 795 mViewCells.push_back(viewCell);796 }797 798 if (i == tries)799 {800 cerr << "big error! no view cell found" << endl;801 return;802 871 } 803 872 } … … 808 877 void GvsPreprocessor::PerViewCellComputation() 809 878 { 879 // hack: reset counter 880 ObjectContainer::const_iterator oit, oit_end = mObjects.end(); 881 882 for (oit = mObjects.begin(); oit != oit_end; ++ oit) 883 { 884 (*oit)->mCounter = 0; 885 } 886 810 887 while (NextViewCell()) 811 888 { 812 cout << "\n***********************\nprocessing view cell " << mProcessedViewCells << endl; 889 cout << "\n***********************\n" 890 << "processing view cell " << mProcessedViewCells 891 << " (id: " << mCurrentViewCell->GetId() << ")" << endl; 813 892 814 893 // compute the pvs of the current view cell 815 894 ProcessViewCell(); 816 895 817 mGvsStats.mTrianglePvs = mCurrentViewCell->GetPvs().GetSize(); 896 //mGvsStats.mTrianglePvs = mCurrentViewCell->GetPvs().GetSize(); 897 mGvsStats.mTrianglePvs = (int)mTrianglePvs.size(); 898 899 ObjectContainer objectPvs; 818 900 819 901 // exchange triangle pvs with objects 820 UpdatePvs(mCurrentViewCell); 821 822 if (GVS_DEBUG) 823 { 824 VisualizeViewCell(mCurrentViewCell); 825 CLEAR_CONTAINER(mVssRays); 826 } 902 //UpdatePvs(mCurrentViewCell); 903 GetObjectPvs(objectPvs); 904 905 cout << "triangle pvs of " << (int)mTrianglePvs.size() << " was converted to object pvs of " << (int)objectPvs.size() << endl; 827 906 828 907 //////// … … 830 909 831 910 mGvsStats.mViewCells = mProcessedViewCells;//mPass; 832 mGvsStats.mPerViewCellPvs = mCurrentViewCell->GetPvs().GetSize(); 833 mGvsStats.mTotalPvs += mCurrentViewCell->GetPvs().GetSize(); 911 //mGvsStats.mPerViewCellPvs = mCurrentViewCell->GetPvs().GetSize(); 912 mGvsStats.mPerViewCellPvs = (int)mTrianglePvs.size(); 913 914 mGvsStats.mTotalPvs += mGvsStats.mPerViewCellPvs; 834 915 mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples; 835 916 836 917 mGvsStats.Stop(); 837 918 mGvsStats.Print(mGvsStatsStream); 919 920 mTrianglePvs.clear(); 921 922 if (GVS_DEBUG) 923 { 924 //VisualizeViewCell(mCurrentViewCell); 925 VisualizeViewCell(objectPvs); 926 CLEAR_CONTAINER(mVssRays); 927 } 838 928 839 929 // is this really necessary? … … 871 961 872 962 currentViewCell->SetPvs(newPvs); 963 } 964 965 966 void GvsPreprocessor::GetObjectPvs(ObjectContainer &objectPvs) const 967 { 968 BvhLeaf::NewMail(); 969 970 ObjectContainer::const_iterator oit, oit_end = mTrianglePvs.end(); 971 972 for (oit = mTrianglePvs.begin(); oit != oit_end; ++ oit) 973 { 974 Intersectable *intersect = *oit; 975 976 BvhLeaf *bv = intersect->mBvhLeaf; 977 978 if (!bv || bv->Mailed()) 979 continue; 980 981 bv->Mail(); 982 983 objectPvs.push_back(bv); 984 // hack: reset counter 985 (*oit)->mCounter = 0; 986 } 873 987 } 874 988 … … 978 1092 979 1093 vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end(); 1094 980 1095 for (vit = vizContainer.begin(); vit != vit_end; ++ vit) 981 1096 { … … 989 1104 990 1105 VssRayContainer::const_iterator rit, rit_end = mVssRays.end(); 1106 991 1107 for (rit = mVssRays.begin(); rit != rit_end; ++ rit) 992 1108 {
Note: See TracChangeset
for help on using the changeset viewer.