ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.42
Committed: Thu Jul 18 15:43:29 1991 UTC (33 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.41: +5 -1 lines
Log Message:
added -di option for source invisibility

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