ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.40
Committed: Mon Jun 24 16:10:51 1991 UTC (33 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.39: +6 -0 lines
Log Message:
added virtual source visibility pretesting

File Contents

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