ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.19
Committed: Sat Jul 29 00:01:24 1989 UTC (35 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.18: +17 -10 lines
Log Message:
Changed client name from progname to octname (octree name)

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