Example #1
0
// Test many metrics
TEST_F(FTDCCompressorTest, TestManyMetrics) {
    std::random_device rd;
    std::mt19937 gen(rd());

    std::uniform_int_distribution<long long> genValues(1, std::numeric_limits<long long>::max());
    const size_t metrics = 1000;

    // Test a large numbers of zeros, and incremental numbers in a full buffer
    for (int j = 0; j < 2; j++) {
        TestTie c;

        auto st = c.addSample(generateSample(rd, genValues, metrics));
        ASSERT_HAS_SPACE(st);

        for (size_t i = 0; i != FTDCConfig::kMaxSamplesPerArchiveMetricChunkDefault - 2; i++) {
            st = c.addSample(generateSample(rd, genValues, metrics));
            ASSERT_HAS_SPACE(st);
        }

        st = c.addSample(generateSample(rd, genValues, metrics));
        ASSERT_FULL(st);

        // Add Value
        st = c.addSample(generateSample(rd, genValues, metrics));
        ASSERT_HAS_SPACE(st);
    }
}
Example #2
0
void App::tracePath(const Ray& ray, World* world, Random& rng , int px, int py) {
	int bounce = 0; //Current path length
	Ray r = ray;
    Color3 cl = Color3(0.0f,0.0f,0.0f); //acumulated color
	Color3 cf = Color3(1.0f,1.0f,1.0f); //acumulated reflectance

	Vector3 dataToAdd[CBFilter::FT_SIZE];

	while (1){
		float dist = std::numeric_limits<float>::max();
		const shared_ptr<Surfel>& surfel = world->intersect(r, dist);

		if (!notNull(surfel)){
			cl += m_world->ambient;
			break ;//If ray path hits nothing, return accumulated color plus the sky color (ambient term)
		}
		
		//Properties of the intersection
		Vector3 x  = surfel->position; 
		Vector3 n  = surfel->shadingNormal; // or shadingNormal
		Vector3 nl = n.dot(r.direction()) < 0 ? n : n*-1; //Properly oriented surface normal
		nl = nl.unit();
		Color3	f  = surfel->reflectivity(rng); //surfel->finiteScatteringDensity(w_i, -ray.direction())
		Color3  emi = surfel->emittedRadiance(-ray.direction());

		//Collect aditional data only for the first bounce
		if (bounce == 0){
			dataToAdd[CBFilter::FT_TEXTURE] = Vector3(f.r,f.g,f.b);
			dataToAdd[CBFilter::FT_NORMAL] = (nl + Vector3(1,1,1))*0.5;
			dataToAdd[CBFilter::FT_DEPTH] = x;
		}
		
		//Radiance from sampling Light (for Explict PT)
		Color3 LES = Color3(0.0,0.0,0.0);
		//if (emi.max() == 0.0)
		LES = sampleLightArea(world,rng,r,surfel);
		if (bounce > 0) emi = Color3(0.0);

		cl += cf*(emi+LES);

		// max reflectivity for Russian Roulette
		float p = f.max();
		bounce++;
		if (bounce > 5){  // Dont use russian roullette until 5th bounce
			if (rng.uniform() < p) 
				f = f*(1.0/p); 
			else 
				break ;
		}

		if (bounce >= m_maxBounces || m_displayMode == DISPLAY_TEXTURE)
			break ;

		Vector3 sampledDir;
		float pdf = generateSample(nl,rng,sampledDir);
		Color3 brdf = f*pdf;
		

		cf *= brdf;
		r = Ray::fromOriginAndDirection(x + sampledDir*BUMP_DISTANCE, sampledDir);
		debugAssert(r.direction().isFinite());
	}
	cl = Color3(clamp(cl.r,0.0f,1.0f),clamp(cl.g,0.0f,1.0f),clamp(cl.b,0.0f,1.0f));
	dataToAdd[CBFilter::FT_COLOR] = Vector3(cl.r,cl.g,cl.b);

	m_featureData.addSample(px,py,dataToAdd[CBFilter::FT_COLOR],dataToAdd[CBFilter::FT_NORMAL],dataToAdd[CBFilter::FT_TEXTURE],dataToAdd[CBFilter::FT_DEPTH]);
}