00001 #include "TracingStrategy.h"
00002 #include <algorithm>
00003
00004 namespace rcrt
00005 {
00006
00007 TracingStrategy::TracingStrategy(Scene* s):scene(s)
00008 {
00009 }
00010
00011 TracingStrategy::~TracingStrategy()
00012 {
00013 }
00014
00015 Scene* TracingStrategy::getScene() const
00016 {
00017 return scene;
00018 }
00019
00020 Image TracingStrategy::trace(Camera* cam) const
00021 {
00022 return trace(cam, 0, 0, cam->getResolutionX()-1, cam->getResolutionY()-1);
00023 }
00024
00025 Image TracingStrategy::trace(Camera* cam, const int& x0, const int& y0,
00026 const int& x1, const int& y1) const
00027 {
00028 int resX = x1-x0+1;
00029 int resY = y1-y0+1;
00030 float triangles = 0;
00031 Image img(resX, resY);
00032
00033 double dif;
00034 for(int x=x0; x <= x1; x++){
00035 for(int y=y0; y <= y1; y++){
00036
00037 Ray ray = cam->getRay(Point2D(x,y));
00038
00039
00040 RGBColor col = trace(ray);
00041 col = RGBColor(std::min(1.0f,col.r()),std::min(1.0f,col.g()),std::min(1.0f,col.b()));
00042 img.setPixel(col, x-x0, y-y0);
00043
00044 triangles += ray.tris;
00045 }
00046 }
00047
00048 float triPray = triangles/(resX*resY);
00049 std::cout << " average Triangle-Intersections per ray: " << triPray << std::endl;
00050 return img;
00051 }
00052
00053 }