Example #1
0
//////////////////////////////////////////////////////////
//
// RayTracer implementation
// =========
RayTracer::RayTracer(Scene& scene, Camera* camera) :
Renderer(scene, camera),
maxRecursionLevel(6),
minWeight(MIN_WEIGHT)
//[]---------------------------------------------------[]
//|  Constructor                                        |
//[]---------------------------------------------------[]
{
	// TODO: UNCOMMENT THE CODE BELOW

	int n = scene.getNumberOfActors();

	printf("Building aggregates for %d actors...\n", n);

	clock_t t = clock();
	Array<ModelPtr> models(n);
	map<uint, ModelPtr> aggregates;
	string actorNames;
	int totalNodes = 0;
	int i = 1;

	for (ActorIterator ait(scene.getActorIterator()); ait; i++)
	{
		const Actor* a = ait++;

		printf("Processing actor %d/%d...\n", i, n);
		if (!a->isVisible())
			continue;

		Primitive* p = dynamic_cast<Primitive*>(a->getModel());
		const TriangleMesh* mesh = p->triangleMesh();
		// checking if the id already exists in idList

		if (mesh != 0)	
		{
			ModelPtr& a = aggregates[mesh->id];

			BVH* bvh = new BVH(std::move(p->refine()));

			totalNodes += bvh->size();
			a = bvh;

			models.add(new ModelInstance(*a, *p));
			
		}
	}
	printf("Building scene aggregate...\n");
	{
		BVH* bvh = new BVH(std::move(models));

		totalNodes += bvh->size();
		aggregate = bvh;
	}
	printf("BVH(s) built: %d (%d nodes)\n", aggregates.size() + 1, totalNodes);
	printElapsedTime("", clock() - t);

}