ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.38
Committed: Tue Jun 18 10:29:20 1991 UTC (33 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.37: +0 -6 lines
Log Message:
got rid of psuper straggler variable

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