00001
00007 #include "Background.h"
00008 #include "Camera.h"
00009 #include "ConstantBackground.h"
00010 #include "Color.h"
00011 #include "Group.h"
00012 #include "Image.h"
00013 #include "LambertianMaterial.h"
00014 #include "Light.h"
00015 #include "Material.h"
00016 #include "Object.h"
00017 #include "PinholeCamera.h"
00018 #include "Plane.h"
00019 #include "PointLight.h"
00020 #include "Ray.h"
00021 #include "Scene.h"
00022 #include "Sphere.h"
00023 #include "Time.h"
00024 #include "Parser.h"
00025 #include <iomanip>
00026 #include <iostream>
00027 #include <fstream>
00028
00029 #include <unistd.h>
00030 #include <string.h>
00031
00032 using namespace std;
00033
00034
00035
00036 char *options = "hb:";
00037 extern char *optarg;
00038 extern int optind, opterr, getopt();
00039
00040 char *progname = "(noname)";
00041
00042 int xpixel;
00043 int ypixel;
00044 bool one_only;
00045
00046
00050 void usage(char *s)
00051 {
00052 if (s) (void)fputs(s, stderr);
00053
00054 (void) fprintf(stderr, "Usage: %s [ -%s ] [<] infile > outfile]\n",
00055 progname, options);
00056 exit(1);
00057 }
00058
00062 int parse_args(int ac, char *av[])
00063 {
00064 int c;
00065
00066 if ( ! (progname=strrchr(*av, '/')) )
00067 progname = *av;
00068 else
00069 ++progname;
00070
00071
00072 opterr = 0;
00073
00074
00075 while ((c=getopt(ac,av,options)) != EOF)
00076 switch (c) {
00077 case 'b' :
00078 if (sscanf(optarg, "%d,%d", &xpixel, &ypixel) == 2) {
00079 one_only = true;
00080 }
00081 break;
00082 case '?' :
00083 case 'h' :
00084 default : usage("Bad or help flag specified\n"); break;
00085 }
00086
00087 return(optind);
00088 }
00089
00090
00091 int main(int argc, char** argv)
00092 {
00093 double t1 = Time::currentSeconds();
00094
00095 int arg_count = parse_args(argc, argv);
00096
00097 if ( argc - arg_count < 1 ) {
00098 cerr << "Usage: specter scene " << argc - arg_count << " " << arg_count << endl;
00099 return 1;
00100 }
00101 ifstream scene_file( argv[ arg_count ] );
00102 if ( !scene_file.good() ) {
00103 cerr << "Unable to read scene file: " << argv[ 1 ] << endl;
00104 return 1;
00105 }
00106 Parser reader( scene_file );
00107 string filename = "image.png";
00108 Scene *scene = reader.parseScene( filename );
00109
00110 scene->preprocess();
00111
00112 double t2 = Time::currentSeconds();
00113 scene->render();
00114
00115 double t3 = Time::currentSeconds();
00116 scene->getImage()->write(filename);
00117
00118 double t4 = Time::currentSeconds();
00119 cerr << "Setup/load time:\t" << setprecision(3) << t2-t1 << " seconds\n";
00120 cerr << "Render time:\t\t" << setprecision(3) << t3-t2 << " seconds\n";
00121 cerr << "Post-process time:\t" << setprecision(3) << t4-t3 << " seconds\n";
00122
00123 return 0;
00124 }