#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 Environment::GetSingleton()->GetIntValue("SamplingPreprocessor.samplesPerPass", mSamplesPerPass); Environment::GetSingleton()->GetIntValue("SamplingPreprocessor.totalSamples", mTotalSamples); } 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); int samples = 0; int i=0; while (samples < mTotalSamples) { for (i=0; i < mSamplesPerPass;) { SimpleRayContainer rays; VssRayContainer vssRays; vector viewcells; for (; rays.size() < 16; ) { if (i%10000 == 0) cout<<"+"; Vector3 origin, direction; mViewCellsManager->GetViewPoint( origin ); direction = UniformRandomVector(); ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); if (viewcell && viewcell->GetValid()) { 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, false); 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 contribution; int pvsContribution = 0; float relativePvsContribution = 0; float pdf = 1.0f; ViewCell *viewcell = viewcells[j/2]; if (viewcell->GetPvs().GetSampleContribution(obj, pdf, contribution)) ++pvsContribution; relativePvsContribution += contribution; viewcell->GetPvs().AddSample(obj, pdf); } } 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; } }