ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.15
Committed: Tue Jun 13 10:57:35 1989 UTC (35 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.14: +6 -0 lines
Log Message:
Added direct certainty variable (compromise btwn. thresh. & tol.)

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