[2575] | 1 |
|
---|
[2546] | 2 | #include "SamplingStrategy.h"
|
---|
| 3 | #include "Intersectable.h"
|
---|
| 4 | #include "DifferenceSampling.h"
|
---|
| 5 | #include "ViewCell.h"
|
---|
[2548] | 6 | #include "ViewCellsManager.h"
|
---|
| 7 | #include "Preprocessor.h"
|
---|
[2575] | 8 | #ifdef PERFTIMER
|
---|
[2559] | 9 | #include "Timer/PerfTimer.h"
|
---|
[2575] | 10 | #endif
|
---|
[2546] | 11 |
|
---|
| 12 | #ifdef GTP_INTERNAL
|
---|
| 13 | #include "ArchModeler2MLRT.hxx"
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
[2575] | 16 |
|
---|
| 17 | #ifdef PERFTIMER
|
---|
[2559] | 18 | PerfTimer sFilterTimer;
|
---|
[2575] | 19 | #endif
|
---|
[2546] | 20 |
|
---|
| 21 | namespace GtpVisibilityPreprocessor {
|
---|
| 22 |
|
---|
| 23 |
|
---|
[2548] | 24 | /** Collects the pvs of the objects which are
|
---|
| 25 | in the first but not in the second pvs.
|
---|
| 26 | */
|
---|
| 27 | static void GetPvsDifference(const ObjectPvs &largerPvs,
|
---|
| 28 | const ObjectPvs &smallerPvs,
|
---|
| 29 | ObjectContainer &pvsDifference)
|
---|
| 30 | {
|
---|
| 31 | Intersectable::NewMail();
|
---|
| 32 | Intersectable *obj;
|
---|
| 33 |
|
---|
| 34 | ObjectPvsIterator bit = smallerPvs.GetIterator();
|
---|
| 35 |
|
---|
| 36 | // mail smaller pvs
|
---|
| 37 | while (bit.HasMoreEntries())
|
---|
| 38 | {
|
---|
| 39 | obj = bit.Next();
|
---|
| 40 | obj->Mail();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | ObjectPvsIterator ait = largerPvs.GetIterator();
|
---|
| 44 |
|
---|
| 45 | // write differece pvs
|
---|
| 46 | while (ait.HasMoreEntries())
|
---|
| 47 | {
|
---|
| 48 | obj = ait.Next();
|
---|
| 49 | pvsDifference.push_back(obj);
|
---|
| 50 |
|
---|
| 51 | //if (!obj->Mailed())
|
---|
| 52 | // c.AddSampleDirty(obj, 0);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 |
|
---|
[2546] | 57 | DifferenceSampling::DifferenceSampling(Preprocessor &preprocessor):
|
---|
[2548] | 58 | SamplingStrategy(preprocessor), mCurrentViewCell(0), mNumSamples(0)
|
---|
[2546] | 59 | {}
|
---|
| 60 |
|
---|
| 61 |
|
---|
[2548] | 62 | void DifferenceSampling::ComputeDifferenceSet(ViewCell *vc,
|
---|
| 63 | ObjectContainer &differenceSet)
|
---|
[2546] | 64 | {
|
---|
[2548] | 65 | const ObjectPvs &pvs = vc->GetPvs();
|
---|
| 66 | const float filterSize = 100;
|
---|
| 67 | ObjectPvs filteredPvs;
|
---|
| 68 |
|
---|
[2575] | 69 |
|
---|
| 70 | #ifdef PERFTIMER
|
---|
[2559] | 71 | sFilterTimer.Entry();
|
---|
[2575] | 72 | #endif
|
---|
| 73 |
|
---|
[2559] | 74 | PvsFilterStatistics pvsStats = mPreprocessor.
|
---|
[2548] | 75 | mViewCellsManager->ApplyFilter2(vc,
|
---|
| 76 | false,
|
---|
| 77 | filterSize,
|
---|
| 78 | filteredPvs);
|
---|
| 79 |
|
---|
[2575] | 80 | #ifdef PERFTIMER
|
---|
[2559] | 81 | sFilterTimer.Exit();
|
---|
[2575] | 82 | #endif
|
---|
| 83 |
|
---|
[2548] | 84 | //mDifferencePvs.Clear(false);
|
---|
| 85 | //mDifferencePvs.Reserve(filteredPvs.GetSize());
|
---|
| 86 | mPvsDifference.clear();
|
---|
| 87 | mPvsDifference.reserve(filteredPvs.GetSize());
|
---|
| 88 |
|
---|
| 89 | GetPvsDifference(filteredPvs, pvs, mPvsDifference);
|
---|
[2559] | 90 |
|
---|
| 91 | cerr << "found " << mPvsDifference.size() << " different objects" << endl;
|
---|
[2546] | 92 | }
|
---|
| 93 |
|
---|
[2548] | 94 |
|
---|
| 95 | bool DifferenceSampling::GenerateSample(SimpleRay &ray)
|
---|
| 96 | {
|
---|
[2559] | 97 | if (mNumSamples <= 0)
|
---|
[2548] | 98 | {
|
---|
[2559] | 99 | // choose random view cell
|
---|
[2548] | 100 | ViewCellContainer &viewCells = mPreprocessor.mViewCellsManager->GetViewCells();
|
---|
| 101 | const int vcIdx = (int)RandomValue(0, (float)viewCells.size() - 0.5f);
|
---|
| 102 |
|
---|
| 103 | mCurrentViewCell = viewCells[vcIdx];
|
---|
| 104 |
|
---|
[2559] | 105 | if (mCurrentViewCell->GetPvs().Empty())
|
---|
| 106 | return false;
|
---|
| 107 |
|
---|
| 108 | cout << "computing new difference set" << endl;
|
---|
| 109 |
|
---|
[2548] | 110 | ComputeDifferenceSet(mCurrentViewCell, mPvsDifference);
|
---|
| 111 |
|
---|
| 112 | // n samples per object
|
---|
| 113 | const int n = 50;
|
---|
[2560] | 114 | mNumSamples = (int)mPvsDifference.size() * n;
|
---|
[2548] | 115 | }
|
---|
| 116 |
|
---|
[2559] | 117 | if (mPvsDifference.empty())
|
---|
| 118 | return false;
|
---|
| 119 |
|
---|
| 120 | -- mNumSamples;
|
---|
| 121 |
|
---|
| 122 | cout << "x";
|
---|
[2548] | 123 | Vector3 origin, direction;
|
---|
| 124 | Vector3 point;
|
---|
| 125 | Vector3 normal, vcnormal;
|
---|
| 126 |
|
---|
| 127 | // get a new object from the difference set
|
---|
| 128 | const int objIdx = (int)RandomValue(0, (float)mPvsDifference.size() - 0.5f);
|
---|
| 129 | Intersectable *object = mPvsDifference[objIdx];
|
---|
| 130 |
|
---|
| 131 | // cast a ray from the view cells border towards the object
|
---|
| 132 | object->GetRandomSurfacePoint(point, normal);
|
---|
| 133 | mCurrentViewCell->GetRandomEdgePoint(origin, vcnormal);
|
---|
| 134 |
|
---|
| 135 | direction = point - origin;
|
---|
| 136 |
|
---|
| 137 | // $$ jb the pdf is yet not correct for all sampling methods!
|
---|
| 138 | const float c = Magnitude(direction);
|
---|
| 139 |
|
---|
| 140 | if ((c <= Limits::Small) /*|| (DotProd(direction, normal) < 0)*/)
|
---|
| 141 | {
|
---|
| 142 | return false;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | // $$ jb the pdf is yet not correct for all sampling methods!
|
---|
| 146 | const float pdf = 1.0f;
|
---|
| 147 | //cout << "p: " << point << " ";
|
---|
| 148 | direction *= 1.0f / c;
|
---|
| 149 | ray = SimpleRay(origin, direction, DIFFERENCE_SAMPLING_BASED_DISTRIBUTION, pdf);
|
---|
| 150 |
|
---|
| 151 | //cout << "ray: " << ray.mOrigin << " " << ray.mDirection << endl;
|
---|
| 152 |
|
---|
| 153 | return true;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 |
|
---|
[2575] | 157 | }
|
---|