#include "SceneGraph.h" #include "KdTree.h" #include "SamplingPreprocessor.h" #include "X3dExporter.h" #include "Environment.h" #include "MutualVisibility.h" #include "Polygon3.h" #include "ViewCell.h" #include "ViewCellsManager.h" #include "RenderSimulator.h" #include "VssRay.h" #include "SamplingStrategy.h" namespace GtpVisibilityPreprocessor { SamplingPreprocessor::SamplingPreprocessor(): Preprocessor(), mPass(0) { // this should increase coherence of the samples } SamplingPreprocessor::~SamplingPreprocessor() { CLEAR_CONTAINER(mSampleRays); CLEAR_CONTAINER(mVssSampleRays); } void SamplingPreprocessor::VerifyVisibility(Intersectable *object) { #if 0 // 6.10. 2006 due to kdPVS removal from intersectable // mail all nodes from the pvs Intersectable::NewMail(); KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); for (; i != object->mKdPvs.mEntries.end(); i++) { KdNode *node = (*i).first; node->Mail(); } Debug << "Get all neighbours from PVS" << endl; vector invisibleNeighbors; // get all neighbors of all PVS nodes i = object->mKdPvs.mEntries.begin(); for (; i != object->mKdPvs.mEntries.end(); i++) { KdNode *node = (*i).first; mKdTree->FindNeighbors(node, invisibleNeighbors, true); AxisAlignedBox3 box = object->GetBox(); for (int j=0; j < invisibleNeighbors.size(); j++) { int visibility = ComputeBoxVisibility(mSceneGraph, mKdTree, box, mKdTree->GetBox(invisibleNeighbors[j]), 1e-6f); // exit(0); } // now rank all the neighbors according to probability that a new // sample creates some contribution } #endif } bool SamplingPreprocessor::ComputeVisibility() { Debug << "type: sampling" << endl; cout<<"Sampling Preprocessor started\n"<GetStatistics(intersectables, faces); HaltonSequence posHalton; int samples = 0; int rssSamples = 0; map dirHalton; while (samples < mTotalSamples) { for (int i=0; i < mSamplesPerEvaluation;) { SimpleRayContainer rays; VssRayContainer vssRays; // vector viewcells; float r[5]; Vector3 origin, direction; posHalton.GetNext(3, r); mViewCellsManager->GetViewPoint(origin, Vector3(r[0], r[1], r[2])); ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); if (!viewcell || !viewcell->GetValid()) continue; for (; rays.size() < 16; ) { if (i%100000 == 0) cout<<"+"; // dirHalton.GetNext(2, r); dirHalton[viewcell].GetNext(2, r); direction = UniformRandomVector(r[0],r[1]); //direction = UniformRandomVector(); // viewcells.push_back(viewcell); // cast rays in both directions to make the number of samples comparable // with the global sampling method which also casts a "double" ray per sample rays.push_back(SimpleRay(origin, direction, SamplingStrategy::DIRECTION_BASED_DISTRIBUTION, 1.0f)); i++; samples++; } CastRays(rays, vssRays, true, true); // if (vssRays.size()!=32) { // cerr<<"wrong number of rays "<<(int)vssRays.size()<mFlags & VssRay::Valid) { Intersectable *obj = mViewCellsManager->GetIntersectable(*(vssRays[j]), true); if (obj) { // if ray not outside of view space float pdf = 1.0f; // ViewCell *viewcell = viewcells[j/2]; ObjectPvs &pvs = viewcell->GetPvs(); pvs.AddSampleDirtyCheck(obj, pdf); if (pvs.RequiresResort()) { pvs.SimpleSort(); } } } CLEAR_CONTAINER(vssRays); if (samples > mTotalSamples) break; } #if 0 Debug<<"Valid viewcells before set validity: "<CountValidViewcells()<SetValidity(0, intersectables/2); Debug<<"Valid viewcells after set validity: "<CountValidViewcells()<PrintPvsStatistics(mStats); // ComputeRenderError(); } if (0) { Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); exporter->SetExportRayDensity(true); exporter->ExportKdTree(*mKdTree); delete exporter; } // $$JB temporary removed // mViewCellsManager->PostProcess(objects, mSampleRays); //-- several visualizations and statistics Debug << "view cells after post processing: " << endl; mViewCellsManager->PrintStatistics(Debug); EvalViewCellHistogram(); //-- render simulation after merge cout << "\nevaluating bsp view cells render time after merge ... "; mRenderSimulator->RenderScene(); SimulationStatistics ss; mRenderSimulator->GetStatistics(ss); cout << " finished" << endl; cout << ss << endl; Debug << ss << endl; // $$JB temporary removed //mViewCellsManager->Visualize(objects, mSampleRays); return true; } }