ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.5
Committed: Mon Apr 10 09:32:53 1989 UTC (36 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +5 -1 lines
Log Message:
Added warnings for inappropriate recover files

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