ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.21
Committed: Mon Jan 8 13:37:58 1990 UTC (35 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.20: +25 -64 lines
Log Message:
Changed handling of view parameters

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1986 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * rmain.c - main for ray tracing programs
9     *
10     * 3/24/87
11     */
12    
13     /* for flaky pre-processors */
14     #ifndef RPICT
15     #define RPICT 0
16     #endif
17     #ifndef RTRACE
18     #define RTRACE 0
19     #endif
20     #ifndef RVIEW
21     #define RVIEW 0
22     #endif
23    
24     #include "ray.h"
25    
26     #include "octree.h"
27    
28     #include <signal.h>
29    
30     #include "view.h"
31    
32     #ifndef DEFPATH
33     #define DEFPATH ":/usr/local/lib/ray"
34     #endif
35 greg 1.17 #ifndef ULIBVAR
36 greg 1.1 #define ULIBVAR "RAYPATH"
37 greg 1.17 #endif
38 greg 1.1
39     char *progname; /* argv[0] */
40    
41 greg 1.19 char *octname; /* octree name */
42    
43 greg 1.1 char *libpath; /* library directory list */
44    
45     char *sigerr[NSIG]; /* signal error messages */
46    
47     extern int stderr_v(); /* standard error output */
48     int (*errvec)() = stderr_v; /* error output vector */
49     int (*wrnvec)() = stderr_v; /* warning output vector */
50     int (*cmdvec)() = NULL; /* command error vector */
51    
52     int (*trace)() = NULL; /* trace call */
53    
54     CUBE thescene; /* our scene */
55    
56     extern int ralrm; /* seconds between reports */
57     extern float pctdone; /* percentage done */
58    
59     extern int greyscale; /* map colors to brightness? */
60     extern char *devname; /* output device name */
61    
62     extern int inform; /* input format */
63     extern int outform; /* output format */
64     extern char *outvals; /* output values */
65    
66     extern VIEW ourview; /* viewing parameters */
67    
68     extern int hresolu; /* horizontal resolution */
69     extern int vresolu; /* vertical resolution */
70    
71     extern int psample; /* pixel sample size */
72     extern double maxdiff; /* max. sample difference */
73 greg 1.11 extern double dstrpix; /* square pixel distribution */
74 greg 1.1
75     extern double dstrsrc; /* square source distribution */
76 greg 1.11 extern double shadthresh; /* shadow threshold */
77 greg 1.15 extern double shadcert; /* shadow testing certainty */
78 greg 1.1
79     extern int maxdepth; /* maximum recursion depth */
80     extern double minweight; /* minimum ray weight */
81     extern long nrays; /* number of rays traced */
82    
83     extern COLOR ambval; /* ambient value */
84     extern double ambacc; /* ambient accuracy */
85     extern int ambres; /* ambient resolution */
86     extern int ambdiv; /* ambient divisions */
87     extern int ambssamp; /* ambient super-samples */
88     extern int ambounce; /* ambient bounces */
89     extern char *amblist[]; /* ambient include/exclude list */
90     extern int ambincl; /* include == 1, exclude == 0 */
91    
92    
93     main(argc, argv)
94     int argc;
95     char *argv[];
96     {
97 greg 1.16 #define check(olen,narg) if (argv[i][olen] || narg >= argc-i) goto badopt
98 greg 1.1 double atof();
99     char *getenv();
100     int report();
101     char *err;
102     char *recover = NULL;
103 greg 1.20 char *zfile = NULL;
104 greg 1.1 char *errfile = NULL;
105     char *ambfile = NULL;
106     char **amblp = amblist;
107     int loadflags = ~IO_FILES;
108 greg 1.4 int rval, gotvfile = 0;
109 greg 1.1 int i;
110     /* global program name */
111     progname = argv[0];
112     /* get library path */
113     if ((libpath = getenv(ULIBVAR)) == NULL)
114     libpath = DEFPATH;
115 greg 1.10 /* option city */
116 greg 1.1 for (i = 1; i < argc && argv[i][0] == '-'; i++) {
117 greg 1.18 if (!strcmp(argv[i], "-defaults") ||
118     !strcmp(argv[i], "-help")) {
119 greg 1.1 printdefaults();
120     quit(0);
121     }
122     #if RVIEW
123     if (!strcmp(argv[i], "-devices")) {
124     printdevices();
125     quit(0);
126     }
127     #endif
128 greg 1.21 #if RPICT|RVIEW
129     rval = getviewopt(&ourview, argc-i, argv+i);
130     if (rval >= 0) {
131     i += rval;
132     continue;
133     }
134     #endif
135 greg 1.1 switch (argv[i][1]) {
136     #if RPICT|RVIEW
137 greg 1.21 case 'v': /* view file */
138     if (argv[i][2] != 'f')
139 greg 1.10 goto badopt;
140 greg 1.21 check(3,1);
141     rval = viewfile(argv[++i], &ourview);
142     if (rval < 0) {
143     sprintf(errmsg,
144     "cannot open view file \"%s\"",
145     argv[i]);
146     error(SYSTEM, errmsg);
147     } else if (rval == 0) {
148     sprintf(errmsg,
149     "bad view file \"%s\"",
150     argv[i]);
151     error(USER, errmsg);
152     } else
153     gotvfile += rval;
154 greg 1.1 break;
155     #endif
156 greg 1.11 case 'd': /* direct */
157 greg 1.1 switch (argv[i][2]) {
158 greg 1.13 case 't': /* threshold */
159 greg 1.10 check(3,1);
160 greg 1.11 shadthresh = atof(argv[++i]);
161 greg 1.1 break;
162 greg 1.15 case 'c': /* certainty */
163     check(3,1);
164     shadcert = atof(argv[++i]);
165     break;
166 greg 1.11 case 'j': /* jitter */
167 greg 1.10 check(3,1);
168 greg 1.1 dstrsrc = atof(argv[++i]);
169     break;
170     default:
171 greg 1.10 goto badopt;
172 greg 1.1 }
173     break;
174     #if RPICT|RVIEW
175     case 's': /* sample */
176     switch (argv[i][2]) {
177     case 'p': /* pixel */
178 greg 1.10 check(3,1);
179 greg 1.1 psample = atoi(argv[++i]);
180     break;
181 greg 1.13 case 't': /* threshold */
182 greg 1.10 check(3,1);
183 greg 1.1 maxdiff = atof(argv[++i]);
184     break;
185 greg 1.11 #if RPICT
186     case 'j': /* jitter */
187     check(3,1);
188     dstrpix = atof(argv[++i]);
189     break;
190     #endif
191 greg 1.1 default:
192 greg 1.10 goto badopt;
193 greg 1.1 }
194     break;
195     #endif
196     case 'x': /* x resolution */
197 greg 1.10 check(2,1);
198 greg 1.1 hresolu = atoi(argv[++i]);
199     break;
200     case 'y': /* y resolution */
201 greg 1.10 check(2,1);
202 greg 1.1 vresolu = atoi(argv[++i]);
203     break;
204     case 'w': /* warnings */
205 greg 1.10 check(2,0);
206 greg 1.1 wrnvec = wrnvec==NULL ? stderr_v : NULL;
207     break;
208     case 'e': /* error file */
209 greg 1.10 check(2,1);
210 greg 1.1 errfile = argv[++i];
211     break;
212     case 'l': /* limit */
213     switch (argv[i][2]) {
214     case 'r': /* recursion */
215 greg 1.10 check(3,1);
216 greg 1.1 maxdepth = atoi(argv[++i]);
217     break;
218     case 'w': /* weight */
219 greg 1.10 check(3,1);
220 greg 1.1 minweight = atof(argv[++i]);
221     break;
222     default:
223 greg 1.10 goto badopt;
224 greg 1.1 }
225     break;
226     #if RPICT
227 greg 1.20 case 'z': /* z file */
228     check(2,1);
229     zfile = argv[++i];
230     break;
231 greg 1.1 case 'r': /* recover file */
232 greg 1.10 check(2,1);
233 greg 1.1 recover = argv[++i];
234 greg 1.4 rval = viewfile(recover, &ourview);
235 greg 1.5 if (rval <= 0) {
236     sprintf(errmsg,
237     "cannot recover view parameters from \"%s\"", recover);
238     error(WARNING, errmsg);
239     } else
240 greg 1.4 gotvfile += rval;
241 greg 1.1 break;
242     case 't': /* timer */
243 greg 1.10 check(2,1);
244 greg 1.1 ralrm = atoi(argv[++i]);
245     break;
246     #endif
247     case 'a': /* ambient */
248     switch (argv[i][2]) {
249     case 'v': /* value */
250 greg 1.10 check(3,3);
251 greg 1.1 setcolor(ambval, atof(argv[i+1]),
252     atof(argv[i+2]),
253     atof(argv[i+3]));
254     i += 3;
255     break;
256     case 'a': /* accuracy */
257 greg 1.10 check(3,1);
258 greg 1.1 ambacc = atof(argv[++i]);
259     break;
260     case 'r': /* resolution */
261 greg 1.10 check(3,1);
262 greg 1.1 ambres = atoi(argv[++i]);
263     break;
264     case 'd': /* divisions */
265 greg 1.10 check(3,1);
266 greg 1.1 ambdiv = atoi(argv[++i]);
267     break;
268     case 's': /* super-samp */
269 greg 1.10 check(3,1);
270 greg 1.1 ambssamp = atoi(argv[++i]);
271     break;
272     case 'b': /* bounces */
273 greg 1.10 check(3,1);
274 greg 1.1 ambounce = atoi(argv[++i]);
275     break;
276     case 'i': /* include */
277 greg 1.10 check(3,1);
278 greg 1.1 if (ambincl != 1) {
279     ambincl = 1;
280     amblp = amblist;
281     }
282     *amblp++ = argv[++i];
283     break;
284     case 'e': /* exclude */
285 greg 1.10 check(3,1);
286 greg 1.1 if (ambincl != 0) {
287     ambincl = 0;
288     amblp = amblist;
289     }
290     *amblp++ = argv[++i];
291     break;
292     case 'f': /* file */
293 greg 1.10 check(3,1);
294 greg 1.1 ambfile= argv[++i];
295     break;
296     default:
297 greg 1.10 goto badopt;
298 greg 1.1 }
299     break;
300     #if RTRACE
301     case 'f': /* format i/o */
302     switch (argv[i][2]) {
303     case 'a': /* ascii */
304     case 'f': /* float */
305     case 'd': /* double */
306     inform = argv[i][2];
307     break;
308     default:
309 greg 1.10 goto badopt;
310 greg 1.1 }
311     switch (argv[i][3]) {
312     case '\0':
313     outform = inform;
314     break;
315     case 'a': /* ascii */
316     case 'f': /* float */
317     case 'd': /* double */
318 greg 1.12 check(4,0);
319 greg 1.1 outform = argv[i][3];
320     break;
321     default:
322 greg 1.10 goto badopt;
323 greg 1.1 }
324     break;
325     case 'o': /* output */
326     outvals = argv[i]+2;
327     break;
328 greg 1.6 case 'h': /* toggle header */
329 greg 1.10 check(2,0);
330 greg 1.6 loadflags ^= IO_INFO;
331 greg 1.1 break;
332     #endif
333     #if RVIEW
334     case 'b': /* black and white */
335 greg 1.10 check(2,0);
336 greg 1.1 greyscale = !greyscale;
337     break;
338     case 'o': /* output device */
339 greg 1.10 check(2,1);
340 greg 1.1 devname = argv[++i];
341     break;
342     #endif
343     default:
344 greg 1.19 goto badopt;
345 greg 1.1 }
346     }
347     #if RPICT|RVIEW
348     err = setview(&ourview); /* set viewing parameters */
349     if (err != NULL)
350     error(USER, err);
351     #endif
352     /* set up signal handling */
353     sigdie(SIGINT, "Interrupt");
354     sigdie(SIGHUP, "Hangup");
355     sigdie(SIGTERM, "Terminate");
356     sigdie(SIGPIPE, "Broken pipe");
357     #ifdef SIGXCPU
358     sigdie(SIGXCPU, "CPU limit exceeded");
359     sigdie(SIGXFSZ, "File size exceeded");
360     #endif
361     #if RPICT
362     signal(SIGALRM, report);
363     #else
364     sigdie(SIGALRM, "Alarm clock");
365     #endif
366     /* open error file */
367     if (errfile != NULL) {
368     if (freopen(errfile, "a", stderr) == NULL)
369 greg 1.14 quit(2);
370 greg 1.1 fprintf(stderr, "**************\n*** PID %5d: ",
371     getpid());
372     printargs(argc, argv, stderr);
373     fputs("\n", stderr);
374     fflush(stderr);
375     }
376     #ifdef NICE
377     nice(NICE); /* lower priority */
378     #endif
379 greg 1.19 /* get octree */
380 greg 1.1 #if RVIEW
381     loadflags &= ~IO_INFO;
382     #endif
383     if (i == argc)
384 greg 1.19 octname = NULL;
385     else if (i == argc-1)
386     octname = argv[i];
387 greg 1.1 else
388 greg 1.19 goto badopt;
389     #if RVIEW|RTRACE
390     if (octname == NULL)
391     error(USER, "missing octree argument");
392 greg 1.1 #endif
393 greg 1.19 readoct(octname, loadflags, &thescene, NULL);
394 greg 1.1
395     if (loadflags & IO_INFO) { /* print header */
396     printargs(i, argv, stdout);
397     #if RPICT
398     if (gotvfile) {
399     printf(VIEWSTR);
400     fprintview(&ourview, stdout);
401     printf("\n");
402     }
403     #endif
404     printf("\n");
405     }
406    
407     marksources(); /* find and mark sources */
408    
409     *amblp = NULL; /* initialize ambient calculation */
410     setambient(ambfile);
411    
412     #if RPICT
413     if (ralrm > 0) /* report init time */
414     report();
415 greg 1.20 render(zfile, recover); /* render the scene */
416 greg 1.1 #endif
417     #if RTRACE
418     rtrace(NULL); /* trace rays from stdin */
419     #endif
420     #if RVIEW
421     rview(); /* go */
422     #endif
423     quit(0);
424 greg 1.19
425     badopt:
426     sprintf(errmsg, "command line error at '%s'", argv[i]);
427     error(USER, errmsg);
428    
429 greg 1.10 #undef check
430 greg 1.1 }
431    
432    
433     eputs(s) /* error output */
434     char *s;
435     {
436     if (errvec != NULL)
437     (*errvec)(s);
438     }
439    
440    
441     wputs(s) /* warning output */
442     char *s;
443     {
444     if (wrnvec != NULL)
445     (*wrnvec)(s);
446     }
447    
448    
449     cputs(s) /* command error output */
450     char *s;
451     {
452     if (cmdvec != NULL)
453     (*cmdvec)(s);
454     }
455    
456    
457     stderr_v(s) /* put string to stderr */
458     register char *s;
459     {
460     static int inline = 0;
461    
462     if (!inline++) {
463     fputs(progname, stderr);
464     fputs(": ", stderr);
465     }
466     fputs(s, stderr);
467     if (*s && s[strlen(s)-1] == '\n') {
468     fflush(stderr);
469     inline = 0;
470     }
471     }
472    
473    
474     onsig(signo) /* fatal signal */
475     int signo;
476     {
477 greg 1.8 static int gotsig = 0;
478    
479     if (gotsig++) /* two signals and we're gone! */
480 greg 1.9 _exit(signo);
481 greg 1.8
482 greg 1.1 eputs("signal - ");
483     eputs(sigerr[signo]);
484     eputs("\n");
485 greg 1.14 quit(3);
486 greg 1.1 }
487    
488    
489     sigdie(signo, msg) /* set fatal signal */
490     int signo;
491     char *msg;
492     {
493     if (signal(signo, onsig) == SIG_IGN)
494     signal(signo, SIG_IGN);
495     sigerr[signo] = msg;
496     }
497    
498    
499     printdefaults() /* print default values to stdout */
500     {
501     register char *cp;
502    
503     #if RPICT|RVIEW
504 greg 1.7 printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
505 greg 1.1 ourview.type==VT_PER ? "perspective" :
506     ourview.type==VT_PAR ? "parallel" :
507     "unknown");
508     printf("-vp %f %f %f\t# view point\n",
509     ourview.vp[0], ourview.vp[1], ourview.vp[2]);
510     printf("-vd %f %f %f\t# view direction\n",
511     ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
512     printf("-vu %f %f %f\t# view up\n",
513     ourview.vup[0], ourview.vup[1], ourview.vup[2]);
514     printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
515     printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
516 greg 1.21 printf("-vs %f\t\t\t# view shift\n", ourview.hoff);
517     printf("-vl %f\t\t\t# view lift\n", ourview.voff);
518 greg 1.1 #endif
519     printf("-x %-9d\t\t\t# x resolution\n", hresolu);
520     printf("-y %-9d\t\t\t# y resolution\n", vresolu);
521 greg 1.13 printf("-dt %f\t\t\t# direct threshold\n", shadthresh);
522 greg 1.15 printf("-dc %f\t\t\t# direct certainty\n", shadcert);
523 greg 1.11 printf("-dj %f\t\t\t# direct jitter\n", dstrsrc);
524 greg 1.1 #if RPICT|RVIEW
525     printf("-sp %-9d\t\t\t# sample pixel\n", psample);
526 greg 1.13 printf("-st %f\t\t\t# sample threshold\n", maxdiff);
527 greg 1.11 #if RPICT
528     printf("-sj %f\t\t\t# sample jitter\n", dstrpix);
529     #endif
530 greg 1.1 #endif
531     printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
532     colval(ambval,GRN), colval(ambval, BLU));
533     printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
534     printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
535     printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
536     printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
537     printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
538     printf("-lr %-9d\t\t\t# limit reflection\n", maxdepth);
539     printf("-lw %f\t\t\t# limit weight\n", minweight);
540     #if RPICT
541     printf("-t %-9d\t\t\t# time between reports\n", ralrm);
542     #endif
543     #if RVIEW
544     printf("-o %s\t\t\t\t# output device\n", devname);
545     #endif
546     #if RTRACE
547     printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
548     inform, outform,
549     inform=='a' ? "ascii" :
550     inform=='f' ? "float" : "double",
551     outform=='a' ? "ascii" :
552     outform=='f' ? "float" : "double");
553     printf("-o%s\t\t\t\t# output", outvals);
554     for (cp = outvals; *cp; cp++)
555     switch (*cp) {
556     case 'i': printf(" irradiance"); break;
557     case 't': printf(" trace"); break;
558     case 'o': printf(" origin"); break;
559     case 'd': printf(" direction"); break;
560     case 'v': printf(" value"); break;
561     case 'l': printf(" length"); break;
562     case 'p': printf(" point"); break;
563     case 'n': printf(" normal"); break;
564     case 's': printf(" surface"); break;
565     case 'w': printf(" weight"); break;
566     case 'm': printf(" modifier"); break;
567     }
568     printf("\n");
569     #endif
570     }