Changeset 2548 for GTP/trunk/Lib/Vis
- Timestamp:
- 08/22/07 17:35:10 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp
r2546 r2548 3 3 #include "DifferenceSampling.h" 4 4 #include "ViewCell.h" 5 #include "ViewCellsManager.h" 6 #include "Preprocessor.h" 5 7 6 8 … … 10 12 11 13 12 13 14 namespace GtpVisibilityPreprocessor { 14 15 15 16 17 /** Collects the pvs of the objects which are 18 in the first but not in the second pvs. 19 */ 20 static void GetPvsDifference(const ObjectPvs &largerPvs, 21 const ObjectPvs &smallerPvs, 22 ObjectContainer &pvsDifference) 23 { 24 Intersectable::NewMail(); 25 Intersectable *obj; 26 27 ObjectPvsIterator bit = smallerPvs.GetIterator(); 28 29 // mail smaller pvs 30 while (bit.HasMoreEntries()) 31 { 32 obj = bit.Next(); 33 obj->Mail(); 34 } 35 36 ObjectPvsIterator ait = largerPvs.GetIterator(); 37 38 // write differece pvs 39 while (ait.HasMoreEntries()) 40 { 41 obj = ait.Next(); 42 pvsDifference.push_back(obj); 43 44 //if (!obj->Mailed()) 45 // c.AddSampleDirty(obj, 0); 46 } 47 } 48 49 16 50 DifferenceSampling::DifferenceSampling(Preprocessor &preprocessor): 17 SamplingStrategy(preprocessor) 51 SamplingStrategy(preprocessor), mCurrentViewCell(0), mNumSamples(0) 18 52 {} 19 53 20 54 21 void DifferenceSampling::ComputeDifferenceSet(ViewCell *vc, ObjectContainer &differenceSet) 55 void DifferenceSampling::ComputeDifferenceSet(ViewCell *vc, 56 ObjectContainer &differenceSet) 22 57 { 58 const ObjectPvs &pvs = vc->GetPvs(); 59 const float filterSize = 100; 60 ObjectPvs filteredPvs; 61 62 PvsFilterStatistics pvsStats = mPreprocessor. 63 mViewCellsManager->ApplyFilter2(vc, 64 false, 65 filterSize, 66 filteredPvs); 67 68 //mDifferencePvs.Clear(false); 69 //mDifferencePvs.Reserve(filteredPvs.GetSize()); 70 mPvsDifference.clear(); 71 mPvsDifference.reserve(filteredPvs.GetSize()); 72 73 GetPvsDifference(filteredPvs, pvs, mPvsDifference); 23 74 } 24 75 76 77 bool DifferenceSampling::GenerateSample(SimpleRay &ray) 78 { 79 if (mNumSamples -- <= 0) 80 { 81 ViewCellContainer &viewCells = mPreprocessor.mViewCellsManager->GetViewCells(); 82 const int vcIdx = (int)RandomValue(0, (float)viewCells.size() - 0.5f); 83 84 mCurrentViewCell = viewCells[vcIdx]; 85 86 ComputeDifferenceSet(mCurrentViewCell, mPvsDifference); 87 88 // n samples per object 89 const int n = 50; 90 mNumSamples = mPvsDifference.size() * n; 91 } 92 93 Vector3 origin, direction; 94 Vector3 point; 95 Vector3 normal, vcnormal; 96 97 // get a new object from the difference set 98 const int objIdx = (int)RandomValue(0, (float)mPvsDifference.size() - 0.5f); 99 Intersectable *object = mPvsDifference[objIdx]; 100 101 // cast a ray from the view cells border towards the object 102 object->GetRandomSurfacePoint(point, normal); 103 mCurrentViewCell->GetRandomEdgePoint(origin, vcnormal); 104 105 direction = point - origin; 106 107 // $$ jb the pdf is yet not correct for all sampling methods! 108 const float c = Magnitude(direction); 109 110 if ((c <= Limits::Small) /*|| (DotProd(direction, normal) < 0)*/) 111 { 112 return false; 113 } 114 115 // $$ jb the pdf is yet not correct for all sampling methods! 116 const float pdf = 1.0f; 117 //cout << "p: " << point << " "; 118 direction *= 1.0f / c; 119 ray = SimpleRay(origin, direction, DIFFERENCE_SAMPLING_BASED_DISTRIBUTION, pdf); 120 121 //cout << "ray: " << ray.mOrigin << " " << ray.mDirection << endl; 122 123 return true; 25 124 } 125 126 127 } -
GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.h
r2546 r2548 2 2 #define _DifferenceSampling_H__ 3 3 4 #include <vector>5 // 4 #include "common.h" 5 //#include "ObjectPvs.h" 6 6 7 #include "common.h" 8 #include "Halton.h" 7 class SimpleRay; 9 8 10 9 namespace GtpVisibilityPreprocessor { … … 35 34 private: 36 35 37 virtual bool GenerateSample(SimpleRay &ray); 38 36 virtual bool GenerateSample(SimpleRay &ray); 37 38 //ObjectPvs mDifferencePvs; 39 ObjectContainer mPvsDifference; 40 41 ViewCell *mCurrentViewCell; 42 int mNumSamples; 39 43 }; 40 44 -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r2530 r2548 591 591 592 592 template <typename T, typename S> 593 typename vector< PvsEntry<T, S> >::iterator VerbosePvs<T, S>::AddSample2(T sample,594 593 typename vector< PvsEntry<T, S> >::iterator 594 VerbosePvs<T, S>::AddSample2(T sample, const float pdf) 595 595 { 596 596 ++ mSamples; -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r2353 r2548 8 8 #include "Mutation.h" 9 9 #include "Timer/PerfTimer.h" 10 #include "DifferenceSampling.h" 11 10 12 11 13 … … 711 713 mDistributions.push_back(new MutationBasedDistribution(mPreprocessor)); 712 714 } 715 else if (strcmp(curr, "difference")==0) { 716 mDistributions.push_back(new DifferenceSampling(mPreprocessor)); 717 } 713 718 714 719 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r2176 r2548 47 47 MUTATION_BASED_DISTRIBUTION, 48 48 HW_GLOBAL_LINES_DISTRIBUTION, 49 VIEWCELL_BASED_DISTRIBUTION 49 VIEWCELL_BASED_DISTRIBUTION, 50 DIFFERENCE_SAMPLING_BASED_DISTRIBUTION, 50 51 }; 51 52 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2547 r2548 3456 3456 float samples = (float)basePvs.GetSamples(); 3457 3457 3458 3458 3459 ////////// 3459 3460 //-- now compute the filter box around the current viewCell … … 3599 3600 viewCell->SetFilteredPvsSize(pvs.GetSize()); 3600 3601 3601 //cout << "pvssize: " << pvs.GetSize() << endl;3602 3602 // warning: not thread-safe! 3603 3603 if (!mUseKdPvs)
Note: See TracChangeset
for help on using the changeset viewer.