ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.18
Committed: Fri Jul 28 23:45:07 1989 UTC (35 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.17: +2 -1 lines
Log Message:
Made -help alias for -defaults

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