1 /*
2  * options.c
3  *
4  * Copyright (C) 1989, 1991, Craig E. Kolb
5  * All rights reserved.
6  *
7  * This software may be freely copied, modified, and redistributed
8  * provided that this copyright notice is preserved on all copies.
9  *
10  * You may not distribute this software, in whole or in part, as part of
11  * any commercial product without the express consent of the authors.
12  *
13  * There is no warranty or other guarantee of fitness of this software
14  * for any purpose.  It is provided solely "as is".
15  *
16  * $Id: options.c,v 4.0.1.3 92/01/14 18:29:59 cek Exp Locker: cek $
17  *
18  * $Log:	options.c,v $
19  * Revision 4.0.1.3  92/01/14  18:29:59  cek
20  * patch3: Added "-u" (cpp) option.
21  *
22  * Revision 4.0.1.2  91/12/13  12:09:53  cek
23  * patch3: Fixed "-W" option typo.
24  *
25  * Revision 4.0.1.1  91/10/05  18:23:15  cek
26  * patch1: Changes for new window/crop options.
27  * patch1: Corrected help message.
28  *
29  * Revision 4.0  91/07/17  14:46:47  kolb
30  * Initial version.
31  *
32  */
33 #include "rayshade.h"
34 #include "options.h"
35 #include "stats.h"
36 #include "viewing.h"
37 
38 RSOptions	Options;
39 
40 static void usage();
41 
42 void
RSOptionsSet(argc,argv)43 RSOptionsSet(argc, argv)
44 int argc;
45 char **argv;
46 {
47 	extern void OpenStatsFile();
48 
49 	Options.progname = strsave(argv[0]);
50 	Options.inputname = (char *)NULL;
51 
52 	while (--argc) {
53 		argv++;
54 		if (argv[0][0] != '-') {
55 			/*
56 			 * Must be the input file name.
57 			 * If already given, complain and then exit.
58 			 */
59 			if (Options.inputname != (char *)NULL) {
60 				usage();
61 				exit(1);
62 			}
63 			Options.inputname = strsave(argv[0]);
64 			continue;
65 		}
66 		/* else */
67 		switch(argv[0][1]) {
68 			case 'A':
69 				/*
70 				 * First frame number
71 				 */
72 				Options.startframe = atoi(argv[1]);
73 				argv++; argc--;
74 				break;
75 #ifdef URT
76 			case 'a':
77 				Options.alpha = !Options.alpha;
78 				break;
79 #endif
80 			case 'C':
81 				Options.cutoff.r = atof(argv[1]);
82 				Options.cutoff.g = atof(argv[2]);
83 				Options.cutoff.b = atof(argv[3]);
84 				Options.cutoff_set = TRUE;
85 				argv += 3; argc -= 3;
86 				break;
87 #ifdef URT
88 			case 'c':
89 				Options.appending = TRUE;
90 				break;
91 #endif
92 			case 'D':
93 				Options.maxdepth = atoi(argv[1]);
94 				Options.maxdepth_set = TRUE;
95 				argv++; argc--;
96 				break;
97 			case 'E':
98 				Options.eyesep = atof(argv[1]);
99 				Options.eyesep_set = TRUE;
100 				argc--; argv++;
101 				break;
102 #ifdef URT
103 			case 'e':
104 				Options.exp_output = TRUE;
105 				break;
106 #endif
107 			case 'F':
108 				Options.report_freq = atoi(argv[1]);
109 				if (Options.report_freq < 1)
110 					Options.report_freq = 1;
111 				Options.freq_set = TRUE;
112 				argv++; argc--;
113 				break;
114 			case 'f':
115 				Options.flipnorm = !Options.flipnorm;
116 				break;
117 			case 'G':
118 				Options.gamma = atof(argv[1]);
119 				argv++; argc--;
120 				break;
121 			case 'g':
122 				Options.gaussian = !Options.gaussian;
123 				break;
124 			case 'h':
125 				usage();
126 				exit(0);
127 				break;
128 			case 'j':
129 				Options.jitter = !Options.jitter;
130 				Options.jitter_set = TRUE;
131 				break;
132 			case 'l':
133 				Options.stereo = LEFT;
134 				break;
135 #ifdef URT
136 			case 'm':
137 				Options.samplemap = !Options.samplemap;
138 				break;
139 #endif
140 			case 'N':
141 				Options.totalframes = atof(argv[1]);
142 				Options.totalframes_set = TRUE;
143 				argv++; argc--;
144 				break;
145 			case 'n':
146 				Options.no_shadows = !Options.no_shadows;
147 				break;
148 			case 'O':
149 				Options.imgname = strsave(argv[1]);
150 				argv++;
151 				argc--;
152 				break;
153 			case 'o':
154 				Options.shadowtransp = !Options.shadowtransp;
155 				break;
156 			case 'P':
157 				Options.cppargs = argv[1];
158 				argv++; argc--;
159 				break;
160 			case 'p':
161 				/*
162 				 * Preview-quality rendering
163 				 * no shadows
164 				 * max depth of 0
165 				 * 1 jittered sample/pixel
166 				 */
167 				Options.no_shadows = TRUE;
168 				Options.maxdepth = 0;
169 				Options.maxdepth_set = TRUE;
170 				Options.jitter = TRUE;
171 				Options.jitter_set = TRUE;
172 				Options.samples = 1;
173 				Options.samples_set = TRUE;
174 				break;
175 			case 'q':
176 				Options.quiet = TRUE;
177 				break;
178 			case 'R':
179 				Screen.xres = atoi(argv[1]);
180 				Screen.yres = atoi(argv[2]);
181 				Options.resolution_set = TRUE;
182 				argv += 2;
183 				argc -= 2;
184 				break;
185 			case 'r':
186 				Options.stereo = RIGHT;
187 				break;
188 			case 'S':
189 				Options.samples = atoi(argv[1]);
190 				if (Options.samples < 1)
191 					Options.samples = 1;
192 				Options.samples_set = TRUE;
193 				argv++; argc--;
194 				break;
195 			case 's':
196 				Options.cache = !Options.cache;
197 				break;
198 			case 'T':
199 				Options.contrast.r = atof(argv[1]);
200 				Options.contrast.g = atof(argv[2]);
201 				Options.contrast.b = atof(argv[3]);
202 				Options.contrast_set = TRUE;
203 				argv += 3;
204 				argc -= 3;
205 				break;
206 			case 'u':
207 				Options.cpp = !Options.cpp;
208 				break;
209 			case 'v':
210 				Options.verbose = TRUE;
211 				break;
212 			case 'V':
213 				Options.verbose = TRUE;
214 				if (argv[1][0] == '-') {
215 					/* User probably blew it, and
216 					 * it's difficult to remove a file
217 					 * that begins with '-'...
218 					 */
219 					usage();
220 					exit(2);
221 				}
222 				Options.statsname = strsave(argv[1]);
223 				OpenStatsFile();
224 				argv++; argc--;
225 				break;
226 			case 'W':
227 				Options.window[LOW][X] = atoi(argv[1]);
228 				Options.window[HIGH][X] = atoi(argv[2]);
229 				Options.window[LOW][Y] = atoi(argv[3]);
230 				Options.window[HIGH][Y] = atoi(argv[4]);
231 				Options.window_set = TRUE;
232 				argv += 4; argc -= 4;
233 				break;
234 			case 'X':
235 				Options.crop[LOW][X] = atof(argv[1]);
236 				Options.crop[HIGH][X] = atof(argv[2]);
237 				Options.crop[LOW][Y] = atof(argv[3]);
238 				Options.crop[HIGH][Y] = atof(argv[4]);
239 				Options.crop_set = TRUE;
240 				argv += 4; argc -= 4;
241 				break;
242 			default:
243 				RLerror(RL_PANIC,"Bad argument: %s\n",argv[0]);
244 		}
245 	}
246 }
247 
248 void
RSOptionsList()249 RSOptionsList()
250 {
251 	if (Options.totalframes > 1) {
252 		fprintf(Stats.fstats,"Rendering frames %d through %d.\n",
253 			Options.startframe, Options.endframe);
254 	} else {
255 		fprintf(Stats.fstats,"Rendering frame %d.\n", Options.startframe);
256 	}
257 
258 	fprintf(Stats.fstats,"Screen resolution: %d x %d\n",
259 		Screen.xres,Screen.yres);
260 	fprintf(Stats.fstats,"Image window: (%d - %d), (%d - %d).\n",
261 			Screen.minx, Screen.maxx, Screen.miny, Screen.maxy);
262 
263 	if (Options.jitter)
264 		fprintf(Stats.fstats,"Using jittered sampling, ");
265 	fprintf(Stats.fstats,"Max sampling rate %d %s/pixel.\n",
266 		Options.samples*Options.samples,
267 		Options.samples == 1 ? "sample" : "samples");
268 
269 	fprintf(Stats.fstats,
270 		"Maximum contrast: %g red, %g green, %g blue.\n",
271 		Options.contrast.r, Options.contrast.g,
272 		Options.contrast.b);
273 	fprintf(Stats.fstats,"Maximum ray depth: %d.  Cutoff thresh: %g %g %g.\n",
274 			Options.maxdepth,
275 			Options.cutoff.r, Options.cutoff.g, Options.cutoff.b);
276 	if (Options.stereo == LEFT)
277 		fprintf(Stats.fstats,"Rendering image for left eye.\n");
278 	else if (Options.stereo == RIGHT)
279 		fprintf(Stats.fstats,"Rendering image for right eye.\n");
280 	if (Options.no_shadows) {
281 		fprintf(Stats.fstats,"No shadows are rendered.\n");
282 	} else if (Options.shadowtransp) {
283 		fprintf(Stats.fstats,
284 			"Object opacity affects depth of shadowing.\n");
285 	}
286 	if (!Options.cache)
287 		fprintf(Stats.fstats,"Shadow caching is disabled.\n");
288 	if (Options.totalframes != 1)
289 		fprintf(Stats.fstats,"Rendering %d frames.\n",
290 			Options.totalframes);
291 }
292 
293 static void
usage()294 usage()
295 {
296 	fprintf(stderr,"usage: %s [options] [filename]\n", Options.progname);
297 	fprintf(stderr,"Where options include:\n");
298 	fprintf(stderr,"\t-A frame\t(Begin with given frame #.)\n");
299 #ifdef URT
300 	fprintf(stderr,"\t-a \t\t(Toggle writing of alpha channel.)\n");
301 #endif
302 	fprintf(stderr,"\t-C thresh\t(Set adaptive ray tree cutoff value.)\n");
303 #ifdef URT
304 	fprintf(stderr,"\t-c \t\t(Continue interrupted rendering.)\n");
305 #endif
306 	fprintf(stderr,"\t-D depth\t(Set maximum ray tree depth.)\n");
307 	fprintf(stderr,"\t-E eye_sep\t(Set eye separation in stereo pairs.)\n");
308 #ifdef URT
309 	fprintf(stderr,"\t-e \t\t(Write exponential RLE file.)\n");
310 #endif
311 	fprintf(stderr,"\t-F freq\t\t(Set frequency of status report.)\n");
312 	fprintf(stderr,"\t-f \t\t(Flip all triangle normals.)\n");
313 	fprintf(stderr,"\t-G gamma\t(Use given gamma correction exponent.)\n");
314 	fprintf(stderr,"\t-g \t\t(Use Gaussian pixel filter.)\n");
315 	fprintf(stderr,"\t-h \t\t(Print this message.)\n");
316 	fprintf(stderr,"\t-j \t\t(Toggle jittered sampling.)\n");
317 	fprintf(stderr,"\t-l \t\t(Render image for left eye view.)\n");
318 #ifdef URT
319 	fprintf(stderr,"\t-m \t\t(Output sample map in alpha channel.)\n");
320 #endif
321 	fprintf(stderr,"\t-N number\t(Render given number of frames.)\n");
322 	fprintf(stderr,"\t-n \t\t(Do not render shadows.)\n");
323 	fprintf(stderr,"\t-O outfile \t(Set output file name.)\n");
324 	fprintf(stderr,"\t-o \t\t(Toggle opacity effect on shadowing.)\n");
325 	fprintf(stderr,"\t-P cpp-args\t(Options to pass to C pre-processor.\n");
326 	fprintf(stderr,"\t-p \t\t(Preview-quality rendering.)\n");
327 	fprintf(stderr,"\t-q \t\t(Run quietly.)\n");
328 	fprintf(stderr,"\t-R xres yres\t(Render at given resolution.)\n");
329 	fprintf(stderr,"\t-r \t\t(Render image for right eye view.)\n");
330 	fprintf(stderr,"\t-S samples\t(Max density of samples^2 samples.)\n");
331 	fprintf(stderr,"\t-s \t\t(Don't cache shadowing information.)\n");
332 	fprintf(stderr,"\t-T r g b\t(Set contrast threshold (0. - 1.).)\n");
333 	fprintf(stderr,"\t-V filename \t(Write verbose output to filename.)\n");
334 	fprintf(stderr,"\t-v \t\t(Verbose output.)\n");
335 	fprintf(stderr,"\t-W x x y y \t(Render subwindow.)\n");
336 	fprintf(stderr,"\t-X l r b t \t(Crop window.)\n");
337 }
338