ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.20
Committed: Sun Dec 10 13:42:42 1989 UTC (35 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.19: +6 -1 lines
Log Message:
added z-file output to rpict

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