PageRenderTime 40ms CodeModel.GetById 1ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 0ms

/src/argparser.h

https://github.com/linkinpark342/parashader
C Header | 204 lines | 179 code | 18 blank | 7 comment | 37 complexity | 20844232db4489f63dfa17d6ff6ffe2d MD5 | raw file
  1#ifndef __ARG_PARSER_H__
  2#define __ARG_PARSER_H__
  3
  4#include "string.h"
  5#include "stdio.h"
  6#include "assert.h"
  7#include "stdlib.h"
  8
  9#include "vectors.h"
 10#include "utils.h"
 11
 12enum RENDER_MODE { RENDER_MATERIALS, RENDER_RADIANCE, RENDER_FORM_FACTORS, RENDER_LIGHTS, RENDER_UNDISTRIBUTED, RENDER_ABSORBED };
 13#define NUM_RENDER_MODES 6
 14
 15class ArgParser {
 16
 17public:
 18
 19  ArgParser() { DefaultValues(); }
 20
 21  ArgParser(int argc, char *argv[]) {
 22    DefaultValues();
 23
 24    for (int i = 1; i < argc; i++) {
 25      if (!strcmp(argv[i],"-input")) {
 26	i++; assert (i < argc); 
 27	input_file = argv[i];
 28      } else if (!strcmp(argv[i],"-output")) {
 29	i++; assert (i < argc); 
 30	output_file = argv[i];
 31      } else if (!strcmp(argv[i],"-size")) {
 32	i++; assert (i < argc); 
 33	width = atoi(argv[i]);
 34	i++; assert (i < argc); 
 35         height = atoi(argv[i]);
 36      } else if (!strcmp(argv[i],"-sphere_rasterization")) {
 37	i++; assert (i < argc); 
 38	sphere_horiz = atoi(argv[i]);
 39         if (sphere_horiz % 2 == 1) sphere_horiz++; 
 40	i++; assert (i < argc); 
 41	sphere_vert = atoi(argv[i]);
 42      } else if (!strcmp(argv[i],"-num_bounces")) {
 43	i++; assert (i < argc); 
 44	num_bounces = atoi(argv[i]);
 45      } else if (!strcmp(argv[i],"-num_shadow_samples")) {
 46	i++; assert (i < argc); 
 47	num_shadow_samples = atoi(argv[i]);
 48      } else if (!strcmp(argv[i],"-num_glossy_samples")) {
 49	i++; assert (i < argc); 
 50	num_glossy_samples = atoi(argv[i]);
 51      } else if (!strcmp(argv[i],"-num_form_factor_samples")) {
 52	i++; assert (i < argc); 
 53	num_form_factor_samples = atoi(argv[i]);
 54      } else if (!strcmp(argv[i],"-background_color")) {
 55         i++; assert (i < argc);
 56         double r = atof(argv[i]);
 57         i++; assert (i < argc);
 58         double g = atof(argv[i]);
 59         i++; assert (i < argc);
 60         double b = atof(argv[i]);
 61	 // background color input is assumed to be sRGB
 62         background_color = Vec3f(r,g,b);
 63         background_color_linear = 
 64	   Vec3f(srgb_to_linear(r),srgb_to_linear(g),srgb_to_linear(b));
 65      } else if (!strcmp(argv[i],"-cam_pos")) {
 66         i++; assert (i < argc);
 67         double x = atof(argv[i]);
 68         i++; assert (i < argc);
 69         double y = atof(argv[i]);
 70         i++; assert (i < argc);
 71         double z = atof(argv[i]);
 72         camera_position = Vec3f(x,y,z);
 73      } else if (!strcmp(argv[i],"-cam_dir")) {
 74         i++; assert (i < argc);
 75         double x = atof(argv[i]);
 76         i++; assert (i < argc);
 77         double y = atof(argv[i]);
 78         i++; assert (i < argc);
 79         double z = atof(argv[i]);
 80         camera_direction = Vec3f(x,y,z);
 81      } else if (!strcmp(argv[i],"-cam_ori")) {
 82         i++; assert (i < argc);
 83         double x = atof(argv[i]);
 84         i++; assert (i < argc);
 85         double y = atof(argv[i]);
 86         i++; assert (i < argc);
 87         double z = atof(argv[i]);
 88         camera_orientation = Vec3f(x,y,z);
 89         //make sure the camera orientation is some direction
 90         if( camera_orientation.Length() == 0 )
 91           camera_orientation.Set( 0, 1, 0 );
 92         else
 93           camera_orientation.Normalize();
 94      } else if (!strcmp(argv[i],"-npr")) {
 95         i++; assert (i < argc);
 96         double x = atof(argv[i]);
 97         i++; assert (i < argc);
 98         double y = atof(argv[i]);
 99         i++; assert (i < argc);
100         double z = atof(argv[i]);
101         npr = Vec3f(x,y,z);
102      } else if (!strcmp(argv[i],"-gray")) {
103        i++; assert (i < argc);
104        double x = atof(argv[i]);
105        assert (x >= 0);
106        i++; assert (i < argc);
107        double y = atof(argv[i]);
108        assert (y >= 0);
109        i++; assert (i < argc);
110        double z = atof(argv[i]);
111        assert (z >= 0);
112        gray_scale = Vec3f(x,y,z);
113        //default the gray scales
114        if( gray_scale.Length() == 0 )
115          gray_scale.Set( 0.299, 0.587, 0.114 );
116        else
117          gray_scale.Normalize();
118      } else if (!strcmp(argv[i],"-ambient")) {
119	i++; assert (i < argc);
120         double r = atof(argv[i]);
121         i++; assert (i < argc);
122         double g = atof(argv[i]);
123         i++; assert (i < argc);
124         double b = atof(argv[i]);
125	 // ambient color input is assumed to be sRGB
126         ambient_light = Vec3f(r,g,b);
127         ambient_light_linear = 
128	   Vec3f(srgb_to_linear(r),srgb_to_linear(g),srgb_to_linear(b));
129      } else {
130	printf ("whoops error with command line argument %d: '%s'\n",i,argv[i]);
131	assert(0);
132      }
133    }
134  }
135
136  void DefaultValues() {
137    input_file = NULL;
138	  output_file = NULL;
139    width = 100;
140    height = 100;
141    wireframe = false;
142    interpolate = false;
143    render_mode = RENDER_MATERIALS;
144    raytracing_animation = false;
145    radiosity_animation = false;
146    num_bounces = 0;
147    num_shadow_samples = 0;
148    num_glossy_samples = 0;
149    num_form_factor_samples = 1;
150    sphere_horiz = 8;
151    sphere_vert = 6;
152    intersect_backfacing = false;
153    background_color = Vec3f(1,1,1);
154    camera_position = Vec3f(0,0,0);
155    camera_direction = Vec3f(0,0,0);
156    camera_orientation = Vec3f(0,1,0);
157    npr = Vec3f(-1,-1,-1);
158    background_color_linear = Vec3f(1,1,1);
159    ambient_light = Vec3f(0.2,0.2,0.2);
160    ambient_light_linear = 
161      Vec3f(srgb_to_linear(ambient_light.r()),
162	    srgb_to_linear(ambient_light.g()),
163	    srgb_to_linear(ambient_light.b()));
164    gray_scale = Vec3f(0,0,0);
165  }
166
167  // ==============
168  // REPRESENTATION
169  // all public! (no accessors)
170
171  char *input_file;
172  char *output_file;
173  int width;
174  int height;
175  bool wireframe;
176  bool interpolate;
177  enum RENDER_MODE render_mode;
178  bool raytracing_animation;
179  bool radiosity_animation;
180
181  Vec3f ambient_light;
182  Vec3f ambient_light_linear;
183  Vec3f background_color;
184  Vec3f camera_position;
185  Vec3f camera_direction;
186  Vec3f camera_orientation;
187  Vec3f background_color_linear;
188  Vec3f npr;
189  Vec3f gray_scale;
190
191  int num_bounces;
192  int num_shadow_samples;
193  int num_glossy_samples;
194
195  int num_form_factor_samples;
196
197  int sphere_horiz;
198  int sphere_vert;
199
200  bool intersect_backfacing;
201
202};
203
204#endif