ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.22
Committed: Tue Jan 9 09:07:26 1990 UTC (35 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.21: +24 -3 lines
Log Message:
added option for pixel aspect ratio

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