ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.1
Committed: Thu Feb 2 10:41:35 1989 UTC (36 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

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     int gotvfile = 0;
102     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     gotvfile = viewfile(argv[++i], &ourview);
150     if (gotvfile < 0) {
151     sprintf(errmsg,
152     "cannot open view file \"%s\"",
153     argv[i]);
154     error(SYSTEM, errmsg);
155     } else if (gotvfile == 0) {
156     sprintf(errmsg,
157     "bad view file \"%s\"",
158     argv[i]);
159     error(USER, errmsg);
160     }
161     break;
162     default:
163     goto unkopt;
164     }
165     break;
166     #endif
167     case 'd': /* distribute */
168     switch (argv[i][2]) {
169     #if RPICT
170     case 'p': /* pixel */
171     dstrpix = atof(argv[++i]);
172     break;
173     #endif
174     case 's': /* source */
175     dstrsrc = atof(argv[++i]);
176     break;
177     default:
178     goto unkopt;
179     }
180     break;
181     #if RPICT|RVIEW
182     case 's': /* sample */
183     switch (argv[i][2]) {
184     case 'p': /* pixel */
185     psample = atoi(argv[++i]);
186     break;
187     case 'd': /* difference */
188     maxdiff = atof(argv[++i]);
189     break;
190     default:
191     goto unkopt;
192     }
193     break;
194     case 'x': /* x resolution */
195     ourview.hresolu = atoi(argv[++i]);
196     break;
197     case 'y': /* y resolution */
198     ourview.vresolu = atoi(argv[++i]);
199     break;
200     #endif
201     #if RTRACE
202     case 'x': /* x resolution */
203     hresolu = atoi(argv[++i]);
204     break;
205     case 'y': /* y resolution */
206     vresolu = atoi(argv[++i]);
207     break;
208     #endif
209     case 'w': /* warnings */
210     wrnvec = wrnvec==NULL ? stderr_v : NULL;
211     break;
212     case 'e': /* error file */
213     errfile = argv[++i];
214     break;
215     case 'l': /* limit */
216     switch (argv[i][2]) {
217     case 'r': /* recursion */
218     maxdepth = atoi(argv[++i]);
219     break;
220     case 'w': /* weight */
221     minweight = atof(argv[++i]);
222     break;
223     default:
224     goto unkopt;
225     }
226     break;
227     #if RPICT
228     case 'r': /* recover file */
229     recover = argv[++i];
230     break;
231     case 't': /* timer */
232     ralrm = atoi(argv[++i]);
233     break;
234     #endif
235     case 'a': /* ambient */
236     switch (argv[i][2]) {
237     case 'v': /* value */
238     setcolor(ambval, atof(argv[i+1]),
239     atof(argv[i+2]),
240     atof(argv[i+3]));
241     i += 3;
242     break;
243     case 'a': /* accuracy */
244     ambacc = atof(argv[++i]);
245     break;
246     case 'r': /* resolution */
247     ambres = atoi(argv[++i]);
248     break;
249     case 'd': /* divisions */
250     ambdiv = atoi(argv[++i]);
251     break;
252     case 's': /* super-samp */
253     ambssamp = atoi(argv[++i]);
254     break;
255     case 'b': /* bounces */
256     ambounce = atoi(argv[++i]);
257     break;
258     case 'i': /* include */
259     if (ambincl != 1) {
260     ambincl = 1;
261     amblp = amblist;
262     }
263     *amblp++ = argv[++i];
264     break;
265     case 'e': /* exclude */
266     if (ambincl != 0) {
267     ambincl = 0;
268     amblp = amblist;
269     }
270     *amblp++ = argv[++i];
271     break;
272     case 'f': /* file */
273     ambfile= argv[++i];
274     break;
275     default:
276     goto unkopt;
277     }
278     break;
279     #if RTRACE
280     case 'f': /* format i/o */
281     switch (argv[i][2]) {
282     case 'a': /* ascii */
283     case 'f': /* float */
284     case 'd': /* double */
285     inform = argv[i][2];
286     break;
287     default:
288     goto unkopt;
289     }
290     switch (argv[i][3]) {
291     case '\0':
292     outform = inform;
293     break;
294     case 'a': /* ascii */
295     case 'f': /* float */
296     case 'd': /* double */
297     outform = argv[i][3];
298     break;
299     default:
300     goto unkopt;
301     }
302     break;
303     case 'o': /* output */
304     outvals = argv[i]+2;
305     break;
306     case 'h': /* no header */
307     loadflags &= ~IO_INFO;
308     break;
309     #endif
310     #if RVIEW
311     case 'b': /* black and white */
312     greyscale = !greyscale;
313     break;
314     case 'o': /* output device */
315     devname = argv[++i];
316     break;
317     #endif
318     default:
319     unkopt:
320     sprintf(errmsg, "unknown option: '%s'", argv[i]);
321     error(USER, errmsg);
322     break;
323     }
324     }
325     #if RPICT|RVIEW
326     err = setview(&ourview); /* set viewing parameters */
327     if (err != NULL)
328     error(USER, err);
329     #endif
330     /* set up signal handling */
331     sigdie(SIGINT, "Interrupt");
332     sigdie(SIGHUP, "Hangup");
333     sigdie(SIGTERM, "Terminate");
334     sigdie(SIGPIPE, "Broken pipe");
335     #ifdef SIGXCPU
336     sigdie(SIGXCPU, "CPU limit exceeded");
337     sigdie(SIGXFSZ, "File size exceeded");
338     #endif
339     #if RPICT
340     signal(SIGALRM, report);
341     diemask |= sigmask(SIGALRM);
342     #else
343     sigdie(SIGALRM, "Alarm clock");
344     #endif
345     /* open error file */
346     if (errfile != NULL) {
347     if (freopen(errfile, "a", stderr) == NULL)
348     quit(1);
349     fprintf(stderr, "**************\n*** PID %5d: ",
350     getpid());
351     printargs(argc, argv, stderr);
352     fputs("\n", stderr);
353     fflush(stderr);
354     }
355     #ifdef NICE
356     nice(NICE); /* lower priority */
357     #endif
358     #if RVIEW
359     loadflags &= ~IO_INFO;
360     #endif
361     #if RPICT
362     if (i == argc)
363     readoct(NULL, loadflags, &thescene, NULL);
364     else
365     #endif
366     if (i == argc-1)
367     readoct(argv[i], loadflags, &thescene, NULL);
368     else
369     error(USER, "single octree required");
370    
371     if (loadflags & IO_INFO) { /* print header */
372     printargs(i, argv, stdout);
373     #if RPICT
374     if (gotvfile) {
375     printf(VIEWSTR);
376     fprintview(&ourview, stdout);
377     printf("\n");
378     }
379     #endif
380     printf("\n");
381     }
382    
383     marksources(); /* find and mark sources */
384    
385     *amblp = NULL; /* initialize ambient calculation */
386     setambient(ambfile);
387    
388     #if RPICT
389     if (ralrm > 0) /* report init time */
390     report();
391     render(recover); /* render the scene */
392     #endif
393     #if RTRACE
394     rtrace(NULL); /* trace rays from stdin */
395     #endif
396     #if RVIEW
397     rview(); /* go */
398     #endif
399     quit(0);
400     }
401    
402    
403     eputs(s) /* error output */
404     char *s;
405     {
406     if (errvec != NULL)
407     (*errvec)(s);
408     }
409    
410    
411     wputs(s) /* warning output */
412     char *s;
413     {
414     if (wrnvec != NULL)
415     (*wrnvec)(s);
416     }
417    
418    
419     cputs(s) /* command error output */
420     char *s;
421     {
422     if (cmdvec != NULL)
423     (*cmdvec)(s);
424     }
425    
426    
427     stderr_v(s) /* put string to stderr */
428     register char *s;
429     {
430     static int inline = 0;
431    
432     if (!inline++) {
433     fputs(progname, stderr);
434     fputs(": ", stderr);
435     }
436     fputs(s, stderr);
437     if (*s && s[strlen(s)-1] == '\n') {
438     fflush(stderr);
439     inline = 0;
440     }
441     }
442    
443    
444     onsig(signo) /* fatal signal */
445     int signo;
446     {
447     sigblock(diemask);
448     eputs("signal - ");
449     eputs(sigerr[signo]);
450     eputs("\n");
451     quit(1);
452     }
453    
454    
455     sigdie(signo, msg) /* set fatal signal */
456     int signo;
457     char *msg;
458     {
459     if (signal(signo, onsig) == SIG_IGN)
460     signal(signo, SIG_IGN);
461     else
462     diemask |= sigmask(signo);
463     sigerr[signo] = msg;
464     }
465    
466    
467     printdefaults() /* print default values to stdout */
468     {
469     register char *cp;
470    
471     #if RPICT|RVIEW
472     printf("-vt%c\t\t\t\t# view type is %s\n", ourview.type,
473     ourview.type==VT_PER ? "perspective" :
474     ourview.type==VT_PAR ? "parallel" :
475     "unknown");
476     printf("-vp %f %f %f\t# view point\n",
477     ourview.vp[0], ourview.vp[1], ourview.vp[2]);
478     printf("-vd %f %f %f\t# view direction\n",
479     ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
480     printf("-vu %f %f %f\t# view up\n",
481     ourview.vup[0], ourview.vup[1], ourview.vup[2]);
482     printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
483     printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
484     printf("-x %-9d\t\t\t# x resolution\n", ourview.hresolu);
485     printf("-y %-9d\t\t\t# y resolution\n", ourview.vresolu);
486     #endif
487     #if RTRACE
488     printf("-x %-9d\t\t\t# x resolution\n", hresolu);
489     printf("-y %-9d\t\t\t# y resolution\n", vresolu);
490     #endif
491     #if RPICT
492     printf("-dp %f\t\t\t# distribute pixel\n", dstrpix);
493     #endif
494     printf("-ds %f\t\t\t# distribute source\n", dstrsrc);
495     #if RPICT|RVIEW
496     printf("-sp %-9d\t\t\t# sample pixel\n", psample);
497     printf("-sd %f\t\t\t# sample difference\n", maxdiff);
498     #endif
499     printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
500     colval(ambval,GRN), colval(ambval, BLU));
501     printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
502     printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
503     printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
504     printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
505     printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
506     printf("-lr %-9d\t\t\t# limit reflection\n", maxdepth);
507     printf("-lw %f\t\t\t# limit weight\n", minweight);
508     #if RPICT
509     printf("-t %-9d\t\t\t# time between reports\n", ralrm);
510     #endif
511     #if RVIEW
512     printf("-o %s\t\t\t\t# output device\n", devname);
513     #endif
514     #if RTRACE
515     printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
516     inform, outform,
517     inform=='a' ? "ascii" :
518     inform=='f' ? "float" : "double",
519     outform=='a' ? "ascii" :
520     outform=='f' ? "float" : "double");
521     printf("-o%s\t\t\t\t# output", outvals);
522     for (cp = outvals; *cp; cp++)
523     switch (*cp) {
524     case 'i': printf(" irradiance"); break;
525     case 't': printf(" trace"); break;
526     case 'o': printf(" origin"); break;
527     case 'd': printf(" direction"); break;
528     case 'v': printf(" value"); break;
529     case 'l': printf(" length"); break;
530     case 'p': printf(" point"); break;
531     case 'n': printf(" normal"); break;
532     case 's': printf(" surface"); break;
533     case 'w': printf(" weight"); break;
534     case 'm': printf(" modifier"); break;
535     }
536     printf("\n");
537     #endif
538     }