src/rcrt/RCRTTrace.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <ctime>
00003 #include <string>
00004 #include "loaders/AnimLoader.h"
00005 #include "cameras/Camera.h"
00006 #include "Scene.h"
00007 #include "tracing/SimpleTracer.h"
00008 #include "tracing/ThreadedMetaTracer.h"
00009 #include "tracing/SuperMetaTracer.h"
00010 #include "textures/Image.h"
00011 
00012 #include "gi/PhotonMap.h"
00013 #include "tracing/PhotonTracer.h"
00014 
00015 /*
00016 #include <iostream>
00017 #include <exception>
00018 #include <ctime>
00019 #include <string>
00020 #include <limits>
00021 #include "math/rcrtmath.h"
00022 #include "RGBAColor.h"
00023 #include "primitives/Triangle.h"
00024 #include "primitives/Sphere.h"
00025 #include "BIH.hpp"
00026 #include "loaders/ObjectLoader.h"
00027 #include "loaders/SceneLoader.h"
00028 #include "loaders/AnimLoader.h"
00029 #include "lights/lights.h"
00030 #include "lights/sampling/AreaLightSampler.h"
00031 #include "cameras/PerspectiveCamera.h"
00032 #include "Scene.h"
00033 #include "textures/Texture.hpp"
00034 #include "tracing/DebugTracer.h"
00035 #include "tracing/RayCaster.h"
00036 #include "tracing/SimpleTracer.h"
00037 #include "tracing/BIHTracer.h"
00038 #include "tracing/StereoMetaTracer.h"
00039 #include "tracing/ThreadedMetaTracer.h"
00040 #include "textures/Image.h"
00041 #include "materials/Material.h"
00042 #include "materials/BSDFMaterial.h"
00043 #include "materials/DebugMaterial.h"
00044 #include "materials/BlackMaterial.h"
00045 #include "materials/MirrorMaterial.h"
00046 #include "materials/DielectricMaterial.h"
00047 #include "bxdf/BSDF.h"
00048 #include "bxdf/Lambertian.h"
00049 #include "bxdf/Phong.h"
00050 #include "bxdf/CookTorrance.h"
00051 #include "primitives/ConvexQuad.h"
00052 #include "primitives/DisplacedTriangle.h"
00053 #include "textures/ImageTexture.h"
00054 */
00055 
00056 using namespace rcrt;
00057 using namespace std;
00058 
00059 //void testDispl() 
00060 //{
00061 //      //ConvexQuad quad(0,Point3D(-1,0,0), Point3D(-1,0,1), Point3D(1,0,1), Point3D(1,0,0));
00062 //      vector<Traceable*>* list = new vector<Traceable*>();
00063 //      //list->push_back(&quad);
00064 //      
00065 //      Image texIm;
00066 //              
00067 //      std::cout << "reading texture" << std::endl;
00068 //      bool success = texIm.ReadPNG("StoneWall5.png");
00069 //      std::cout << "textureread " << success << std::endl;
00070 //      
00071 //      ImageTexture tex(&texIm);
00072 //      
00073 //      AffineObject bumpTest("hurz");
00074 //      
00075 //      bumpTest.setDisplMap(&tex);
00076 //      bumpTest.setDisplDens(3);
00077 //      bumpTest.setMaxDispl(0.2);
00078 //      
00079 //      bumpTest.setWorldMatrix(Matrix4D::identity());
00080 //      
00081 //      Vec3D vn1 = Vec3D(-0.2,1,-0.2).normalize();
00082 //      Vec3D vn2 = Vec3D(0.2,1,-0.2).normalize();
00083 //      Vec3D vn3 = Vec3D(0.2,1,0.2).normalize();
00084 //      
00088 //      
00089 //      DisplacedTriangle t(new Vertex(Point3D(-2,0,-2),vn1,Point2D(0.1,0.1)),new Vertex(Point3D(2,0,-1),vn2,Point2D(0.1,0.9)),new Vertex(Point3D(1,0,2),vn3,Point2D(0.9,0.9)),&bumpTest);
00090 //      vector<Primitive*>* prList = new vector<Primitive*>();
00091 //      prList->push_back(&t);
00092 //      
00093 //      BSDF lambert;
00094 //      BSDF phong;
00095 //      lambert.addBXDF(new Lambertian(RGBColor(0.6,0.5,0.9)));
00096 //      phong.addBXDF(new Phong(RGBColor(0.6,0.5,0.9),0.6,0.4,10));
00097 //      BSDFMaterial matP = BSDFMaterial(phong);
00098 //      BSDFMaterial matL = BSDFMaterial(lambert);
00099 //      
00102 //      
00103 //      DebugMaterial dm;
00104 //      
00108 //      
00109 //      bumpTest.setMaterial(&dm);
00110 //      bumpTest.setPrimitives(prList);
00111 //      
00112 //      list->push_back(&bumpTest);
00113 //      
00114 //      Scene scene(list);
00115 //      
00116 //      PointLight* light1 = new PointLight(RGBColor(15,15,15),Point3D(0.25,2,0));
00117 //      scene.addLight(light1);
00118 //      
00119 //      DebugTracer rt(&scene);
00120 //      PerspectiveCamera cam(60, Point3D(4,2,0), Vec3D(-1,-0.5,0), Vec3D(0,1,0), 640, 480);
00121 //      std::cout << "tracing" << std::endl;
00122 //      Ray r = cam.getRay(Point2D(540,360));
00123 //      //rt.trace(r);
00124 //      Image img = rt.trace(&cam);
00125 //      std::cout << "blubb" << std::endl;
00126 //      img.WritePNG("displ.png");
00127 //      //Ray r(Point3D(0,5,0),Vec3D(0,-1,0))
00128 //}
00129 
00130 void rcrtAnim()
00131 {
00132         cout << "[RCRT]: Loading animation rcrt.xml" << endl;
00133         AnimLoader animL("rcrt.xml");
00134         Scene* scene = animL.getScene();
00135         scene->setShadows(true);
00136         Camera* cam = animL.getCamera();
00137         cout << "[RCRT]: Initialising multithreaded simple tracer" << endl;
00138         SimpleTracer rt(scene);
00139         ThreadedMetaTracer st(&rt);
00140         double tracingTime = 0;
00141         int frames = 0;
00142         do{
00143                 clock_t start = clock();
00144                 cout << "[RCRT]: tracing frame: "<< animL.getFrame() << endl;
00145                 Image img = st.trace(cam);
00146                 clock_t end = clock();
00147                 float dif = end-start;
00148                 cout << "        finished frame in " << (dif / CLOCKS_PER_SEC) << endl;
00149                 string no(toString(animL.getFrame()));
00150                 string zeros("");
00151                 for(int i = 0; i < 5 - int(no.length()); i++)
00152                         zeros.append("0");
00153                 
00154                 string file("rcrtAnim-"+zeros+no+".png"); 
00155                 //img.ToneMapping(0.);
00156                 img.WritePNG(file.c_str());
00157                 
00158                 tracingTime += dif;
00159                 frames++;
00160         }while(animL.nextFrame());
00161         int rays = frames * cam->getResolutionX() * cam->getResolutionY();
00162         cout << "[RCRT]: finished rendering " << endl;
00163         cout << "        traced an average of "<< (tracingTime / CLOCKS_PER_SEC)/frames << " seconds per frame" << endl;
00164         cout << "        traced an average of "<< (rays / (tracingTime / CLOCKS_PER_SEC)) << " rays per second" << endl;
00165 }
00166 
00167 void testPhoton()
00168 {
00169         cout << "[RCRT]: Loading animation" << endl;
00170         AnimLoader animL("pmaptest.xml");
00171         Scene* scene = animL.getScene();
00172         scene->setShadows(true);
00173         Camera* cam = animL.getCamera();
00174         cout << "[RCRT]: Initialising photon map tracing" << endl;
00175         PhotonMap pMap(scene, 0.50, 15);
00176         cout << "[RCRT]:     generating Photonmap..." << endl;
00177         clock_t start = clock();
00178         int photons = 400000;
00179         //pMap.generate(photons);
00180         clock_t end = clock();
00181         cout << "[RCRT]: Photonmap of size " << photons << " took " << double(end-start) / CLOCKS_PER_SEC << " seconds" << endl;
00182         //PhotonTracer rt(scene, &pMap, 1500, 600);
00183         SimpleTracer rt(scene);
00184         //SuperMetaTracer smt(&rt);
00185         ThreadedMetaTracer tmt(&rt);
00186         double tracingTime = 0;
00187         int frames = 0;
00188         do{
00189                 clock_t start = clock();
00190                 cout << "[RCRT]: tracing frame: "<< animL.getFrame() << endl;
00191                 Image img = tmt.trace(cam);
00192                 clock_t end = clock();
00193                 float dif = end-start;
00194                 cout << "        finished frame in " << (dif / CLOCKS_PER_SEC) << endl;
00195                 string no(toString(animL.getFrame()));
00196                 string zeros("");
00197                 for(int i = 0; i < 5 - int(no.length()); i++)
00198                         zeros.append("0");
00199                 
00200                 string file("photon-"+zeros+no+".png"); 
00201                 img.WritePNG(file.c_str());
00202                 
00203                 tracingTime += dif;
00204                 frames++;
00205         }while(animL.nextFrame());
00206         int rays = frames * cam->getResolutionX() * cam->getResolutionY();
00207         cout << "[RCRT]: finished rendering " << endl;
00208         cout << "        traced an average of "<< (tracingTime / CLOCKS_PER_SEC)/frames << " seconds per frame" << endl;
00209         cout << "        traced an average of "<< (rays / (tracingTime / CLOCKS_PER_SEC)) << " primary rays per second" << endl;
00210 }
00211 
00212 void testPhotonRCRT()
00213 {
00214         cout << "[RCRT]: Loading animation" << endl;
00215         AnimLoader animL("rcrt5.xml");
00216         Scene* scene = animL.getScene();
00217         scene->setShadows(false);
00218         Camera* cam = animL.getCamera();
00219         cout << "[RCRT]: Initialising photon map tracing" << endl;
00220         PhotonMap pMap(scene, 0.250, 10);
00221         cout << "[RCRT]:     generating Photonmap..." << endl;
00222         clock_t start = clock();
00223         int photons = 500000;
00224         pMap.generate(photons);
00225         clock_t end = clock();
00226         cout << "[RCRT]: Photonmap of size " << photons << " took " << double(end-start) / CLOCKS_PER_SEC << " seconds" << endl;
00227         PhotonTracer rt(scene, &pMap, 1500, 600);
00228         //SimpleTracer rt(scene);
00229         //SuperMetaTracer smt(&rt);
00230         ThreadedMetaTracer tmt(&rt);
00231         double tracingTime = 0;
00232         int frames = 0;
00233         do{
00234                 clock_t start = clock();
00235                 cout << "[RCRT]: tracing frame: "<< animL.getFrame() << endl;
00236                 Image img = tmt.trace(cam);
00237                 clock_t end = clock();
00238                 float dif = end-start;
00239                 cout << "        finished frame in " << (dif / CLOCKS_PER_SEC) << endl;
00240                 string no(toString(animL.getFrame()));
00241                 string zeros("");
00242                 for(int i = 0; i < 5 - int(no.length()); i++)
00243                         zeros.append("0");
00244                 
00245                 string file("rcrtphoton-"+zeros+no+".png"); 
00246                 img.WritePNG(file.c_str());
00247                 
00248                 tracingTime += dif;
00249                 frames++;
00250         }while(animL.nextFrame());
00251         int rays = frames * cam->getResolutionX() * cam->getResolutionY();
00252         cout << "[RCRT]: finished rendering " << endl;
00253         cout << "        traced an average of "<< (tracingTime / CLOCKS_PER_SEC)/frames << " seconds per frame" << endl;
00254         cout << "        traced an average of "<< (rays / (tracingTime / CLOCKS_PER_SEC)) << " primary rays per second" << endl;
00255 }
00256 
00257 int main(int argc, char *argv[]){
00258         //testDispl();
00259         //testPhoton();
00260         
00261         rcrtAnim();
00262                 
00263         return 0;
00264 }
00265 
00266 

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