#include "Mesh.h" #include "FilterBasedDistribution.h" #include "Vector3.h" #include "Preprocessor.h" #include "ViewCellsManager.h" namespace GtpVisibilityPreprocessor { bool FilterBasedDistribution::GenerateSample(SimpleRay &ray) { int tries = 0; const int maxTries = 10; while (mViewCell == NULL || samplesGenerated >= samplesToGenerate ) { // find a new viewcell to cast the sample from if (tries++ > maxTries) return false; Vector3 point; float r[3]; r[0] = RandomValue(0.0f,1.0f); r[1] = RandomValue(0.0f,1.0f); r[2] = RandomValue(0.0f,1.0f); // static HaltonSequence sHalton; // sHalton.GetNext(3, r); mPreprocessor.mViewCellsManager->GetViewPoint(point, Vector3(r[0], r[1], r[2])); mViewCell = mPreprocessor.mViewCellsManager->GetViewCell(point); if (mViewCell && mViewCell->GetPvs().GetSize()) { // cout< ApplyFilter2(mViewCell, false, mPreprocessor.mViewCellsManager->GetFilterWidth(), mFilteredPvs, NULL, true); // cout<GetPvs().GetSize()<<" "<GetRandomSurfacePoint(origin, normal); // pickup random object from the filtered pvs int id = (int)RandomValue(0, (Real)((float)mFilteredPvs.GetSize() - 0.5f)); ObjectPvsIterator pit = mFilteredPvs.GetIterator(); Intersectable *object; for (; id>=0; --id) object = pit.Next(); Vector3 point; object->GetRandomSurfacePoint(point, normal); Vector3 direction = point - origin; const float c = Magnitude(direction); if (c <= Limits::Small) return false; direction *= 1.0f / c; // $$ jb the pdf is yet not correct for all sampling methods! const float pdf = 1.0f; ray = SimpleRay(origin, direction, FILTER_BASED_DISTRIBUTION, pdf); //cout << "ray: " << ray.mOrigin << " " << ray.mDirection << endl; samplesGenerated++; return true; } }