void StratifiedSampler::prepareSamples(int nAASamplesSqrt, int nAOSamplesSqrt) { int nSqrt = nAASamplesSqrt*nAOSamplesSqrt; aoSamples = QVector<Vector3f>(nSqrt*nSqrt); aaSamples = QVector<Vector3f>(nAASamplesSqrt*nAASamplesSqrt); lensSamples = QVector<Vector3f>(nAASamplesSqrt*nAASamplesSqrt); int count = 0; for (int i = 0; i < nSqrt; i++) { for (int j = 0; j < nSqrt; j++) { // we need a uniform number in the interval // [i/nSqrt;(i+1)/nSqrt] double x = rg->getDouble( ((double)i)/(double)nSqrt,((double)(i+1.0))/(double)nSqrt); double y = rg->getDouble( ((double)j)/(double)nSqrt,((double)(j+1.0))/(double)nSqrt); aoSamples[count++] = sampleSphere(x,y); } } count = 0; for (int i = 0; i < nAASamplesSqrt; i++) { for (int j = 0; j < nAASamplesSqrt; j++) { // we need a uniform number in the interval // [i/nSqrt;(i+1)/nSqrt] double x = rg->getDouble( ((double)i)/(double)nAASamplesSqrt,((double)(i+1.0))/(double)nAASamplesSqrt); double y = rg->getDouble( ((double)j)/(double)nAASamplesSqrt,((double)(j+1.0))/(double)nAASamplesSqrt); aaSamples[count] = Vector3f(x-0.5,y-0.5,1); x = rg->getDouble( ((double)i)/(double)nSqrt,((double)(i+1.0))/(double)nSqrt); y = rg->getDouble( ((double)j)/(double)nSqrt,((double)(j+1.0))/(double)nSqrt); lensSamples[count++] = concentricSampleDisk(x,y); } } // We randomize the samples to avoid coherence. aaSamples = rg->randomize(aaSamples); lensSamples = rg->randomize(lensSamples); };
Vector3f ProgressiveStratifiedSampler::getAODirection(int index) { if (index>=aoSamplesSqrt*aoSamplesSqrt) throw 1; int j = index / aoSamplesSqrt; int i = index % aoSamplesSqrt; double x = rg->getDouble( ((double)i)/(double)aoSamplesSqrt,((double)(i+1.0))/(double)aoSamplesSqrt); double y = rg->getDouble( ((double)j)/(double)aoSamplesSqrt,((double)(j+1.0))/(double)aoSamplesSqrt); return sampleSphere(x,y); }
//compute Sphere Jaccard Index void computeSphereJaccardIndex(MyPointCloud& source_mpc, Point cenPoint, float r, float grid_length, float *result){ MyPointCloud sample_mpc; sampleSphere(cenPoint, r, grid_length, sample_mpc); /*PointCloudPtr pc(new PointCloud); MyPointCloud2PointCloud(sample_mpc,pc); showPointCloud2(pc,"sphere");*/ int intr_points_num; get_intr_points(source_mpc, sample_mpc, 0.0025, &intr_points_num); cout<<"source_mpc_sphere.mypoints.size():"<<source_mpc.mypoints.size()<<endl; cout<<"sample_mpc_sphere.mypoints.size():"<<sample_mpc.mypoints.size()<<endl; cout<<"intr_points_num_sphere:"<<intr_points_num<<endl; float rate=intr_points_num*1.0/sample_mpc.mypoints.size(); cout<<"rate_sphere>>>>>>>>>>>>>>>>>>>>>>>>>>>:"<<rate<<endl; computeJaccardIndex(source_mpc.mypoints.size(), intr_points_num, result); }
Intersection Scene::sampleLight() { int index = myrandom(RNGen) * emitters.size(); return sampleSphere((Sphere*)emitters[index]); }
bool ccSSAOFilter::init(int width, int height, bool enableBilateralFilter, bool useReflectTexture, const char* shadersPath, GLenum textureMinMagFilter /*= GL_LINEAR*/) { //in case of reinit if (!fbo) fbo = new ccFrameBufferObject(); if (!fbo->init(width,height)) { //ccConsole::Warning("[SSAO] FrameBufferObject initialization failed!"); reset(); return false; } fbo->initTexture(0,GL_RGBA32F,GL_RGBA,GL_FLOAT,textureMinMagFilter); if (!shader) { shader = new ccShader(); if (!shader->fromFile(shadersPath,"SSAO/ssao")) { //ccConsole::Warning("[SSAO] Can't load SSAO program!"); reset(); return false; } } bilateralFilterEnabled = enableBilateralFilter; if (bilateralFilterEnabled) { if (!bilateralFilter) bilateralFilter = new ccBilateralFilter(); if (!bilateralFilter->init(width,height,shadersPath)) { delete bilateralFilter; bilateralFilter = 0; bilateralFilterEnabled = false; } else { bilateralFilter->useExistingViewport(true); } } else if (bilateralFilter) { delete bilateralFilter; bilateralFilter=0; } w = width; h = height; sampleSphere(); if (useReflectTexture) initReflectTexture(); else { if (texReflect>0) glDeleteTextures(1,&texReflect); texReflect = 0; } return true; }