ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.24
Committed: Fri Jan 12 11:27:27 1990 UTC (35 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.23: +5 -2 lines
Log Message:
changed recording of ambient include/exclude set so instances work

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