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
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 using namespace rcrt;
00057 using namespace std;
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00102
00103
00104
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
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
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
00180 clock_t end = clock();
00181 cout << "[RCRT]: Photonmap of size " << photons << " took " << double(end-start) / CLOCKS_PER_SEC << " seconds" << endl;
00182
00183 SimpleTracer rt(scene);
00184
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
00229
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
00259
00260
00261 rcrtAnim();
00262
00263 return 0;
00264 }
00265
00266