ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.28
Committed: Sat Oct 13 21:32:22 1990 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.27: +2 -0 lines
Log Message:
added fisheye view types

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