src/rcrt/tracing/DebugTracer.cpp

Go to the documentation of this file.
00001 #include "DebugTracer.h"
00002 #include "../Intersection.h"
00003 
00004 namespace rcrt
00005 {
00006 
00007 DebugTracer::DebugTracer(Scene* s):TracingStrategy(s)
00008 {
00009 }
00010 
00011 DebugTracer::~DebugTracer()
00012 {
00013 }
00014 
00015 RGBColor DebugTracer::trace(Ray& r) const
00016 {
00017         Intersection is = scene->intersect(r);
00018 //      if(is.isValid())
00019 //              std::cout << "shading Normal in IS: " << is.getSNormal() << std::endl;
00020         if(is.isValid()){
00021                 //std::cout << "[T]: Intersection at d=" << is.getDistance() << " pos="<<is.getPosition() << "tris=" <<r.tris << std::endl;
00022                 Vec3D no = is.getSNormalW();
00023                 if(is.backSide())
00024                         no = Vec3D(1,1,1);
00025                 
00026                 no = no.abs();
00027                 return RGBColor(no.x(),no.y(),no.z());
00028         }
00029         //std::cout << "[T]: no intersection" << std::endl;
00030         return RGBColor::BLACK;
00031 }
00032 
00033 Image DebugTracer::trace(Camera* cam, std::vector<Primitive*>* trList) const
00034 {
00035         const int& resX = cam->getResolutionX();
00036         const int& resY = cam->getResolutionY();
00037         float triangles = 0;
00038         Image img(resX, resY);
00039         clock_t start = clock();
00040         double dif;
00041         for(int x=0; x < resX; x++){
00042                 for(int y=0; y < resY; y++){
00043                         // primary ray to trace
00044             Ray ray = cam->getRay(Point2D(x,y));
00045             
00046             // ray trace the list
00047             Intersection hit;
00048             for(unsigned int i=0; i< trList->size(); i++){
00049                 Intersection curr = trList->at(i)->intersect(ray);
00050                 if(curr.isValid() && curr.getDistance() <= hit.getDistance()){
00051                                         hit = curr;
00052                                 }
00053             }
00054             
00055             if(hit.isValid()){
00056                 Vec3D no = hit.getSNormalW();
00057                 //if(r.dir()*no >= numeric_limits<float>::epsilon())
00058                 //if(hit.backSide())
00059                 //      no = Vec3D(1,1,1);
00060                 
00061                 no = no.abs();
00062                 img.setPixel(RGBColor(no.x(),no.y(),no.z()), x, y);
00063             } else {
00064                 img.setPixel(RGBColor(0), x, y);
00065             }
00066             
00067 
00068             triangles += ray.tris;
00069         }
00070         }
00071         clock_t end = clock();
00072         dif = end-start;
00073         float triPray = triangles/(resX*resY);
00074         std::cout << "Average Triangle-Intersections per ray: " << triPray << "Triangles intersected: " << triangles << " Time for tracing: "<< dif/CLOCKS_PER_SEC << std::endl;
00075     return img;
00076 }
00077 
00078 }

Generated on Thu Jan 31 19:26:20 2008 for RenderingCompetitionRayTracer by  doxygen 1.5.3