ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.13
Committed: Thu Jun 8 17:04:36 1989 UTC (35 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.12: +4 -4 lines
Log Message:
Changed back to threshold testing for direct

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.1
74     extern int maxdepth; /* maximum recursion depth */
75     extern double minweight; /* minimum ray weight */
76     extern long nrays; /* number of rays traced */
77    
78     extern COLOR ambval; /* ambient value */
79     extern double ambacc; /* ambient accuracy */
80     extern int ambres; /* ambient resolution */
81     extern int ambdiv; /* ambient divisions */
82     extern int ambssamp; /* ambient super-samples */
83     extern int ambounce; /* ambient bounces */
84     extern char *amblist[]; /* ambient include/exclude list */
85     extern int ambincl; /* include == 1, exclude == 0 */
86    
87    
88     main(argc, argv)
89     int argc;
90     char *argv[];
91     {
92 greg 1.10 #define check(c,n) if (argv[i][c] || n >= argc-i) goto badopt
93 greg 1.1 double atof();
94     char *getenv();
95     int report();
96     char *err;
97     char *recover = NULL;
98     char *errfile = NULL;
99     char *ambfile = NULL;
100     char **amblp = amblist;
101     int loadflags = ~IO_FILES;
102 greg 1.4 int rval, gotvfile = 0;
103 greg 1.1 int i;
104     /* global program name */
105     progname = argv[0];
106     /* get library path */
107     if ((libpath = getenv(ULIBVAR)) == NULL)
108     libpath = DEFPATH;
109 greg 1.10 /* option city */
110 greg 1.1 for (i = 1; i < argc && argv[i][0] == '-'; i++) {
111     if (!strcmp(argv[i], "-defaults")) {
112     printdefaults();
113     quit(0);
114     }
115     #if RVIEW
116     if (!strcmp(argv[i], "-devices")) {
117     printdevices();
118     quit(0);
119     }
120     #endif
121     switch (argv[i][1]) {
122     #if RPICT|RVIEW
123     case 'v': /* view */
124     switch (argv[i][2]) {
125     case 't': /* type */
126 greg 1.12 check(4,0);
127 greg 1.1 ourview.type = argv[i][3];
128     break;
129     case 'p': /* point */
130 greg 1.10 check(3,3);
131 greg 1.1 ourview.vp[0] = atof(argv[++i]);
132     ourview.vp[1] = atof(argv[++i]);
133     ourview.vp[2] = atof(argv[++i]);
134     break;
135     case 'd': /* direction */
136 greg 1.10 check(3,3);
137 greg 1.1 ourview.vdir[0] = atof(argv[++i]);
138     ourview.vdir[1] = atof(argv[++i]);
139     ourview.vdir[2] = atof(argv[++i]);
140     break;
141     case 'u': /* up */
142 greg 1.10 check(3,3);
143 greg 1.1 ourview.vup[0] = atof(argv[++i]);
144     ourview.vup[1] = atof(argv[++i]);
145     ourview.vup[2] = atof(argv[++i]);
146     break;
147     case 'h': /* horizontal */
148 greg 1.10 check(3,1);
149 greg 1.1 ourview.horiz = atof(argv[++i]);
150     break;
151     case 'v': /* vertical */
152 greg 1.10 check(3,1);
153 greg 1.1 ourview.vert = atof(argv[++i]);
154     break;
155     case 'f': /* file */
156 greg 1.10 check(3,1);
157 greg 1.4 rval = viewfile(argv[++i], &ourview);
158     if (rval < 0) {
159 greg 1.1 sprintf(errmsg,
160     "cannot open view file \"%s\"",
161     argv[i]);
162     error(SYSTEM, errmsg);
163 greg 1.4 } else if (rval == 0) {
164 greg 1.1 sprintf(errmsg,
165     "bad view file \"%s\"",
166     argv[i]);
167     error(USER, errmsg);
168 greg 1.4 } else
169     gotvfile += rval;
170 greg 1.1 break;
171     default:
172 greg 1.10 goto badopt;
173 greg 1.1 }
174     break;
175     #endif
176 greg 1.11 case 'd': /* direct */
177 greg 1.1 switch (argv[i][2]) {
178 greg 1.13 case 't': /* threshold */
179 greg 1.10 check(3,1);
180 greg 1.11 shadthresh = atof(argv[++i]);
181 greg 1.1 break;
182 greg 1.11 case 'j': /* jitter */
183 greg 1.10 check(3,1);
184 greg 1.1 dstrsrc = atof(argv[++i]);
185     break;
186     default:
187 greg 1.10 goto badopt;
188 greg 1.1 }
189     break;
190     #if RPICT|RVIEW
191     case 's': /* sample */
192     switch (argv[i][2]) {
193     case 'p': /* pixel */
194 greg 1.10 check(3,1);
195 greg 1.1 psample = atoi(argv[++i]);
196     break;
197 greg 1.13 case 't': /* threshold */
198 greg 1.10 check(3,1);
199 greg 1.1 maxdiff = atof(argv[++i]);
200     break;
201 greg 1.11 #if RPICT
202     case 'j': /* jitter */
203     check(3,1);
204     dstrpix = atof(argv[++i]);
205     break;
206     #endif
207 greg 1.1 default:
208 greg 1.10 goto badopt;
209 greg 1.1 }
210     break;
211     case 'x': /* x resolution */
212 greg 1.10 check(2,1);
213 greg 1.1 ourview.hresolu = atoi(argv[++i]);
214     break;
215     case 'y': /* y resolution */
216 greg 1.10 check(2,1);
217 greg 1.1 ourview.vresolu = atoi(argv[++i]);
218     break;
219     #endif
220     #if RTRACE
221     case 'x': /* x resolution */
222 greg 1.10 check(2,1);
223 greg 1.1 hresolu = atoi(argv[++i]);
224     break;
225     case 'y': /* y resolution */
226 greg 1.10 check(2,1);
227 greg 1.1 vresolu = atoi(argv[++i]);
228     break;
229     #endif
230     case 'w': /* warnings */
231 greg 1.10 check(2,0);
232 greg 1.1 wrnvec = wrnvec==NULL ? stderr_v : NULL;
233     break;
234     case 'e': /* error file */
235 greg 1.10 check(2,1);
236 greg 1.1 errfile = argv[++i];
237     break;
238     case 'l': /* limit */
239     switch (argv[i][2]) {
240     case 'r': /* recursion */
241 greg 1.10 check(3,1);
242 greg 1.1 maxdepth = atoi(argv[++i]);
243     break;
244     case 'w': /* weight */
245 greg 1.10 check(3,1);
246 greg 1.1 minweight = atof(argv[++i]);
247     break;
248     default:
249 greg 1.10 goto badopt;
250 greg 1.1 }
251     break;
252     #if RPICT
253     case 'r': /* recover file */
254 greg 1.10 check(2,1);
255 greg 1.1 recover = argv[++i];
256 greg 1.4 rval = viewfile(recover, &ourview);
257 greg 1.5 if (rval <= 0) {
258     sprintf(errmsg,
259     "cannot recover view parameters from \"%s\"", recover);
260     error(WARNING, errmsg);
261     } else
262 greg 1.4 gotvfile += rval;
263 greg 1.1 break;
264     case 't': /* timer */
265 greg 1.10 check(2,1);
266 greg 1.1 ralrm = atoi(argv[++i]);
267     break;
268     #endif
269     case 'a': /* ambient */
270     switch (argv[i][2]) {
271     case 'v': /* value */
272 greg 1.10 check(3,3);
273 greg 1.1 setcolor(ambval, atof(argv[i+1]),
274     atof(argv[i+2]),
275     atof(argv[i+3]));
276     i += 3;
277     break;
278     case 'a': /* accuracy */
279 greg 1.10 check(3,1);
280 greg 1.1 ambacc = atof(argv[++i]);
281     break;
282     case 'r': /* resolution */
283 greg 1.10 check(3,1);
284 greg 1.1 ambres = atoi(argv[++i]);
285     break;
286     case 'd': /* divisions */
287 greg 1.10 check(3,1);
288 greg 1.1 ambdiv = atoi(argv[++i]);
289     break;
290     case 's': /* super-samp */
291 greg 1.10 check(3,1);
292 greg 1.1 ambssamp = atoi(argv[++i]);
293     break;
294     case 'b': /* bounces */
295 greg 1.10 check(3,1);
296 greg 1.1 ambounce = atoi(argv[++i]);
297     break;
298     case 'i': /* include */
299 greg 1.10 check(3,1);
300 greg 1.1 if (ambincl != 1) {
301     ambincl = 1;
302     amblp = amblist;
303     }
304     *amblp++ = argv[++i];
305     break;
306     case 'e': /* exclude */
307 greg 1.10 check(3,1);
308 greg 1.1 if (ambincl != 0) {
309     ambincl = 0;
310     amblp = amblist;
311     }
312     *amblp++ = argv[++i];
313     break;
314     case 'f': /* file */
315 greg 1.10 check(3,1);
316 greg 1.1 ambfile= argv[++i];
317     break;
318     default:
319 greg 1.10 goto badopt;
320 greg 1.1 }
321     break;
322     #if RTRACE
323     case 'f': /* format i/o */
324     switch (argv[i][2]) {
325     case 'a': /* ascii */
326     case 'f': /* float */
327     case 'd': /* double */
328     inform = argv[i][2];
329     break;
330     default:
331 greg 1.10 goto badopt;
332 greg 1.1 }
333     switch (argv[i][3]) {
334     case '\0':
335     outform = inform;
336     break;
337     case 'a': /* ascii */
338     case 'f': /* float */
339     case 'd': /* double */
340 greg 1.12 check(4,0);
341 greg 1.1 outform = argv[i][3];
342     break;
343     default:
344 greg 1.10 goto badopt;
345 greg 1.1 }
346     break;
347     case 'o': /* output */
348     outvals = argv[i]+2;
349     break;
350 greg 1.6 case 'h': /* toggle header */
351 greg 1.10 check(2,0);
352 greg 1.6 loadflags ^= IO_INFO;
353 greg 1.1 break;
354     #endif
355     #if RVIEW
356     case 'b': /* black and white */
357 greg 1.10 check(2,0);
358 greg 1.1 greyscale = !greyscale;
359     break;
360     case 'o': /* output device */
361 greg 1.10 check(2,1);
362 greg 1.1 devname = argv[++i];
363     break;
364     #endif
365     default:
366 greg 1.10 badopt:
367     sprintf(errmsg, "bad option: '%s'", argv[i]);
368 greg 1.1 error(USER, errmsg);
369     break;
370     }
371     }
372     #if RPICT|RVIEW
373     err = setview(&ourview); /* set viewing parameters */
374     if (err != NULL)
375     error(USER, err);
376     #endif
377     /* set up signal handling */
378     sigdie(SIGINT, "Interrupt");
379     sigdie(SIGHUP, "Hangup");
380     sigdie(SIGTERM, "Terminate");
381     sigdie(SIGPIPE, "Broken pipe");
382     #ifdef SIGXCPU
383     sigdie(SIGXCPU, "CPU limit exceeded");
384     sigdie(SIGXFSZ, "File size exceeded");
385     #endif
386     #if RPICT
387     signal(SIGALRM, report);
388     #else
389     sigdie(SIGALRM, "Alarm clock");
390     #endif
391     /* open error file */
392     if (errfile != NULL) {
393     if (freopen(errfile, "a", stderr) == NULL)
394     quit(1);
395     fprintf(stderr, "**************\n*** PID %5d: ",
396     getpid());
397     printargs(argc, argv, stderr);
398     fputs("\n", stderr);
399     fflush(stderr);
400     }
401     #ifdef NICE
402     nice(NICE); /* lower priority */
403     #endif
404     #if RVIEW
405     loadflags &= ~IO_INFO;
406     #endif
407     #if RPICT
408     if (i == argc)
409     readoct(NULL, loadflags, &thescene, NULL);
410     else
411     #endif
412     if (i == argc-1)
413     readoct(argv[i], loadflags, &thescene, NULL);
414     else
415     error(USER, "single octree required");
416    
417     if (loadflags & IO_INFO) { /* print header */
418     printargs(i, argv, stdout);
419     #if RPICT
420     if (gotvfile) {
421     printf(VIEWSTR);
422     fprintview(&ourview, stdout);
423     printf("\n");
424     }
425     #endif
426     printf("\n");
427     }
428    
429     marksources(); /* find and mark sources */
430    
431     *amblp = NULL; /* initialize ambient calculation */
432     setambient(ambfile);
433    
434     #if RPICT
435     if (ralrm > 0) /* report init time */
436     report();
437     render(recover); /* render the scene */
438     #endif
439     #if RTRACE
440     rtrace(NULL); /* trace rays from stdin */
441     #endif
442     #if RVIEW
443     rview(); /* go */
444     #endif
445     quit(0);
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     quit(1);
503     }
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     printf("-x %-9d\t\t\t# x resolution\n", ourview.hresolu);
534     printf("-y %-9d\t\t\t# y resolution\n", ourview.vresolu);
535     #endif
536     #if RTRACE
537     printf("-x %-9d\t\t\t# x resolution\n", hresolu);
538     printf("-y %-9d\t\t\t# y resolution\n", vresolu);
539     #endif
540 greg 1.13 printf("-dt %f\t\t\t# direct threshold\n", shadthresh);
541 greg 1.11 printf("-dj %f\t\t\t# direct jitter\n", dstrsrc);
542 greg 1.1 #if RPICT|RVIEW
543     printf("-sp %-9d\t\t\t# sample pixel\n", psample);
544 greg 1.13 printf("-st %f\t\t\t# sample threshold\n", maxdiff);
545 greg 1.11 #if RPICT
546     printf("-sj %f\t\t\t# sample jitter\n", dstrpix);
547     #endif
548 greg 1.1 #endif
549     printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
550     colval(ambval,GRN), colval(ambval, BLU));
551     printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
552     printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
553     printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
554     printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
555     printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
556     printf("-lr %-9d\t\t\t# limit reflection\n", maxdepth);
557     printf("-lw %f\t\t\t# limit weight\n", minweight);
558     #if RPICT
559     printf("-t %-9d\t\t\t# time between reports\n", ralrm);
560     #endif
561     #if RVIEW
562     printf("-o %s\t\t\t\t# output device\n", devname);
563     #endif
564     #if RTRACE
565     printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
566     inform, outform,
567     inform=='a' ? "ascii" :
568     inform=='f' ? "float" : "double",
569     outform=='a' ? "ascii" :
570     outform=='f' ? "float" : "double");
571     printf("-o%s\t\t\t\t# output", outvals);
572     for (cp = outvals; *cp; cp++)
573     switch (*cp) {
574     case 'i': printf(" irradiance"); break;
575     case 't': printf(" trace"); break;
576     case 'o': printf(" origin"); break;
577     case 'd': printf(" direction"); break;
578     case 'v': printf(" value"); break;
579     case 'l': printf(" length"); break;
580     case 'p': printf(" point"); break;
581     case 'n': printf(" normal"); break;
582     case 's': printf(" surface"); break;
583     case 'w': printf(" weight"); break;
584     case 'm': printf(" modifier"); break;
585     }
586     printf("\n");
587     #endif
588     }