ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.33
Committed: Thu Jan 3 12:30:37 1991 UTC (34 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.32: +0 -7 lines
Log Message:
removed setcompat() call for Mac II, instead use -B compiler option

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