00001
00002 #include <ctime>
00003 #include <iostream>
00004 #include <sstream>
00005
00006 #include "Renderer.h"
00007
00008
00011 void help()
00012 {
00013 std::cout << std::endl << "Grayfall - Ray tracer for rendering competition WS07-08" << std::endl;
00014 std::cout << "By Alex Busenius and Christian Engels" << std::endl << std::endl;
00015 std::cout << "usage:" << std::endl;
00016 std::cout << "\tgrayfall" << std::endl;
00017 std::cout << "\t\t- Render default scene (to test.png)" << std::endl;
00018 std::cout << "\tgrayfall <scene-file>" << std::endl;
00019 std::cout << "\t\t- Render given scene (test.png)" << std::endl;
00020 std::cout << "\tgrayfall <scene-file> <animation-file>" << std::endl;
00021 std::cout << "\t\t- Render given scene with given animation (vid/????.png)" << std::endl;
00022 std::cout << "\tgrayfall <scene-file> <animation-file> <start-frame-nr> <end-frame-nr> [OPTIONS]" << std::endl;
00023 std::cout << "\t\t- Render start..end-1 frames of given scene with given animation and options (vid/????.png)" << std::endl;
00024 std::cout << "options:" << std::endl;
00025 std::cout << "\t--samples <samples-per-pixel>" << std::endl;
00026 std::cout << "\t\tEnable supersampling" << std::endl;
00027 std::cout << "\t--phys-dump <file>" << std::endl;
00028 std::cout << "\t\tDump all physics calculation to file" << std::endl;
00029 std::cout << "\t--phys-load <file>" << std::endl;
00030 std::cout << "\t\tLoad physics calculation from file instead of calculating them" << std::endl;
00031 }
00032
00033
00036 void parse(Renderer * render, int argc, char ** argv)
00037 {
00038 std::stringstream sstream;
00039 if (argc >= 6)
00040 {
00041 int i = 5;
00042 while (i < argc)
00043 {
00044 sstream.clear();
00045 sstream.str("");
00046 sstream << argv[i];
00047 LOG("argv[" << i << "] = " << sstream.str());
00048 if (sstream.str() == "--samples" && i+1 < argc)
00049 {
00050 sstream.clear();
00051 sstream.str("");
00052 sstream << argv[i+1];
00053 if (sstream.str().length() > 1 && sstream.str()[1] == '-')
00054 {
00055 std::cout << "Sample number expected, got:" << sstream.str() << std::endl;
00056 exit(1);
00057 }
00058
00059 int samples;
00060 sstream >> samples;
00061 render->setupSupersampling(samples);
00062 i++;
00063 }
00064 else if (sstream.str() == "--phys-dump" && i+1 < argc)
00065 {
00066 sstream.clear();
00067 sstream.str("");
00068 sstream << argv[i+1];
00069 if (sstream.str().length() > 1 && sstream.str()[1] == '-')
00070 {
00071 std::cout << "File name expected, got:" << sstream.str() << std::endl;
00072 exit(1);
00073 }
00074
00075 render->physicsSave(sstream.str());
00076 i++;
00077 }
00078 else if (sstream.str() == "--phys-load" && i+1 < argc)
00079 {
00080 sstream.clear();
00081 sstream.str("");
00082 sstream << argv[i+1];
00083 if (sstream.str().length() > 1 && sstream.str()[1] == '-')
00084 {
00085 std::cout << "File name expected, got:" << sstream.str() << std::endl;
00086 exit(1);
00087 }
00088
00089 render->physicsLoad(sstream.str());
00090 i++;
00091 }
00092 else if (sstream.str() == "--help" || sstream.str() == "-h")
00093 {
00094 help();
00095 exit(0);
00096 }
00097 else
00098 {
00099 std::cout << "Unknown parameter or missing value: " << sstream.str() << std::endl;
00100 exit(1);
00101 }
00102 i++;
00103 }
00104 }
00105 }
00106
00107
00113 int main(int argc, char **argv)
00114 {
00115 Renderer* render = new Renderer("test.png");
00116
00117 bool animated = false;
00118 clock_t t = clock();
00119 if (argc >= 2)
00120 {
00121 parse(render, argc, argv);
00122 render->buildScene(argv[1]);
00123 if(argc == 3)
00124 {
00125 render->setupAnimation(argv[2]);
00126 animated = true;
00127 }
00128 else
00129 if(argc >= 5)
00130 {
00131 unsigned int start;
00132 unsigned int stop;
00133
00134 std::stringstream sstream;
00135 sstream << argv[3];
00136 sstream >> start;
00137 sstream.clear();
00138 sstream << argv[4];
00139 sstream >> stop;
00140 sstream.clear();
00141 render->setupAnimation(argv[2], start, stop);
00142 animated = true;
00143 }
00144 else
00145 {
00146 std::cout << "forgot to set an endpoint?" << std::endl;
00147 }
00148 }
00149 else
00150 {
00151 render->buildScene();
00152 }
00153 clock_t t2 = clock();
00154 if(animated)
00155 render->renderAnimated();
00156 else
00157 render->render();
00158 delete render;
00159 clock_t t3 = clock();
00160 std::cout << "\nbuild time : " << float(t2 - t)/CLOCKS_PER_SEC;
00161 std::cout << "\nrender time: " << float(t3 - t2)/CLOCKS_PER_SEC << std::endl << std::endl;
00162 return 0;
00163 }
00164