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