ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.4
Committed: Sun Apr 9 13:19:44 1989 UTC (36 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +9 -5 lines
Log Message:
get view from recover file for 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     #define ULIBVAR "RAYPATH"
36    
37     char *progname; /* argv[0] */
38    
39     char *libpath; /* library directory list */
40    
41     int diemask = 0; /* signals we catch */
42     char *sigerr[NSIG]; /* signal error messages */
43    
44     extern int stderr_v(); /* standard error output */
45     int (*errvec)() = stderr_v; /* error output vector */
46     int (*wrnvec)() = stderr_v; /* warning output vector */
47     int (*cmdvec)() = NULL; /* command error vector */
48    
49     int (*trace)() = NULL; /* trace call */
50    
51     CUBE thescene; /* our scene */
52    
53     extern int ralrm; /* seconds between reports */
54     extern float pctdone; /* percentage done */
55    
56     extern int greyscale; /* map colors to brightness? */
57     extern char *devname; /* output device name */
58    
59     extern int inform; /* input format */
60     extern int outform; /* output format */
61     extern char *outvals; /* output values */
62    
63     extern VIEW ourview; /* viewing parameters */
64    
65     extern int hresolu; /* horizontal resolution */
66     extern int vresolu; /* vertical resolution */
67    
68     extern int psample; /* pixel sample size */
69     extern double maxdiff; /* max. sample difference */
70    
71     extern double dstrpix; /* square pixel distribution */
72     extern double dstrsrc; /* square source distribution */
73    
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     double atof();
93     char *getenv();
94     int report();
95     char *err;
96     char *recover = NULL;
97     char *errfile = NULL;
98     char *ambfile = NULL;
99     char **amblp = amblist;
100     int loadflags = ~IO_FILES;
101 greg 1.4 int rval, gotvfile = 0;
102 greg 1.1 int i;
103     /* global program name */
104     progname = argv[0];
105     /* get library path */
106     if ((libpath = getenv(ULIBVAR)) == NULL)
107     libpath = DEFPATH;
108     /* option city */
109     for (i = 1; i < argc && argv[i][0] == '-'; i++) {
110     if (!strcmp(argv[i], "-defaults")) {
111     printdefaults();
112     quit(0);
113     }
114     #if RVIEW
115     if (!strcmp(argv[i], "-devices")) {
116     printdevices();
117     quit(0);
118     }
119     #endif
120     switch (argv[i][1]) {
121     #if RPICT|RVIEW
122     case 'v': /* view */
123     switch (argv[i][2]) {
124     case 't': /* type */
125     ourview.type = argv[i][3];
126     break;
127     case 'p': /* point */
128     ourview.vp[0] = atof(argv[++i]);
129     ourview.vp[1] = atof(argv[++i]);
130     ourview.vp[2] = atof(argv[++i]);
131     break;
132     case 'd': /* direction */
133     ourview.vdir[0] = atof(argv[++i]);
134     ourview.vdir[1] = atof(argv[++i]);
135     ourview.vdir[2] = atof(argv[++i]);
136     break;
137     case 'u': /* up */
138     ourview.vup[0] = atof(argv[++i]);
139     ourview.vup[1] = atof(argv[++i]);
140     ourview.vup[2] = atof(argv[++i]);
141     break;
142     case 'h': /* horizontal */
143     ourview.horiz = atof(argv[++i]);
144     break;
145     case 'v': /* vertical */
146     ourview.vert = atof(argv[++i]);
147     break;
148     case 'f': /* file */
149 greg 1.4 rval = viewfile(argv[++i], &ourview);
150     if (rval < 0) {
151 greg 1.1 sprintf(errmsg,
152     "cannot open view file \"%s\"",
153     argv[i]);
154     error(SYSTEM, errmsg);
155 greg 1.4 } else if (rval == 0) {
156 greg 1.1 sprintf(errmsg,
157     "bad view file \"%s\"",
158     argv[i]);
159     error(USER, errmsg);
160 greg 1.4 } else
161     gotvfile += rval;
162 greg 1.1 break;
163     default:
164     goto unkopt;
165     }
166     break;
167     #endif
168     case 'd': /* distribute */
169     switch (argv[i][2]) {
170     #if RPICT
171     case 'p': /* pixel */
172     dstrpix = atof(argv[++i]);
173     break;
174     #endif
175     case 's': /* source */
176     dstrsrc = atof(argv[++i]);
177     break;
178     default:
179     goto unkopt;
180     }
181     break;
182     #if RPICT|RVIEW
183     case 's': /* sample */
184     switch (argv[i][2]) {
185     case 'p': /* pixel */
186     psample = atoi(argv[++i]);
187     break;
188     case 'd': /* difference */
189     maxdiff = atof(argv[++i]);
190     break;
191     default:
192     goto unkopt;
193     }
194     break;
195     case 'x': /* x resolution */
196     ourview.hresolu = atoi(argv[++i]);
197     break;
198     case 'y': /* y resolution */
199     ourview.vresolu = atoi(argv[++i]);
200     break;
201     #endif
202     #if RTRACE
203     case 'x': /* x resolution */
204     hresolu = atoi(argv[++i]);
205     break;
206     case 'y': /* y resolution */
207     vresolu = atoi(argv[++i]);
208     break;
209     #endif
210     case 'w': /* warnings */
211     wrnvec = wrnvec==NULL ? stderr_v : NULL;
212     break;
213     case 'e': /* error file */
214     errfile = argv[++i];
215     break;
216     case 'l': /* limit */
217     switch (argv[i][2]) {
218     case 'r': /* recursion */
219     maxdepth = atoi(argv[++i]);
220     break;
221     case 'w': /* weight */
222     minweight = atof(argv[++i]);
223     break;
224     default:
225     goto unkopt;
226     }
227     break;
228     #if RPICT
229     case 'r': /* recover file */
230     recover = argv[++i];
231 greg 1.4 rval = viewfile(recover, &ourview);
232     if (rval > 0)
233     gotvfile += rval;
234 greg 1.1 break;
235     case 't': /* timer */
236     ralrm = atoi(argv[++i]);
237     break;
238     #endif
239     case 'a': /* ambient */
240     switch (argv[i][2]) {
241     case 'v': /* value */
242     setcolor(ambval, atof(argv[i+1]),
243     atof(argv[i+2]),
244     atof(argv[i+3]));
245     i += 3;
246     break;
247     case 'a': /* accuracy */
248     ambacc = atof(argv[++i]);
249     break;
250     case 'r': /* resolution */
251     ambres = atoi(argv[++i]);
252     break;
253     case 'd': /* divisions */
254     ambdiv = atoi(argv[++i]);
255     break;
256     case 's': /* super-samp */
257     ambssamp = atoi(argv[++i]);
258     break;
259     case 'b': /* bounces */
260     ambounce = atoi(argv[++i]);
261     break;
262     case 'i': /* include */
263     if (ambincl != 1) {
264     ambincl = 1;
265     amblp = amblist;
266     }
267     *amblp++ = argv[++i];
268     break;
269     case 'e': /* exclude */
270     if (ambincl != 0) {
271     ambincl = 0;
272     amblp = amblist;
273     }
274     *amblp++ = argv[++i];
275     break;
276     case 'f': /* file */
277     ambfile= argv[++i];
278     break;
279     default:
280     goto unkopt;
281     }
282     break;
283     #if RTRACE
284     case 'f': /* format i/o */
285     switch (argv[i][2]) {
286     case 'a': /* ascii */
287     case 'f': /* float */
288     case 'd': /* double */
289     inform = argv[i][2];
290     break;
291     default:
292     goto unkopt;
293     }
294     switch (argv[i][3]) {
295     case '\0':
296     outform = inform;
297     break;
298     case 'a': /* ascii */
299     case 'f': /* float */
300     case 'd': /* double */
301     outform = argv[i][3];
302     break;
303     default:
304     goto unkopt;
305     }
306     break;
307     case 'o': /* output */
308     outvals = argv[i]+2;
309     break;
310     case 'h': /* no header */
311     loadflags &= ~IO_INFO;
312     break;
313     #endif
314     #if RVIEW
315     case 'b': /* black and white */
316     greyscale = !greyscale;
317     break;
318     case 'o': /* output device */
319     devname = argv[++i];
320     break;
321     #endif
322     default:
323     unkopt:
324     sprintf(errmsg, "unknown option: '%s'", argv[i]);
325     error(USER, errmsg);
326     break;
327     }
328     }
329     #if RPICT|RVIEW
330     err = setview(&ourview); /* set viewing parameters */
331     if (err != NULL)
332     error(USER, err);
333     #endif
334     /* set up signal handling */
335     sigdie(SIGINT, "Interrupt");
336     sigdie(SIGHUP, "Hangup");
337     sigdie(SIGTERM, "Terminate");
338     sigdie(SIGPIPE, "Broken pipe");
339     #ifdef SIGXCPU
340     sigdie(SIGXCPU, "CPU limit exceeded");
341     sigdie(SIGXFSZ, "File size exceeded");
342     #endif
343     #if RPICT
344     signal(SIGALRM, report);
345 greg 1.3 #ifdef BSD
346 greg 1.1 diemask |= sigmask(SIGALRM);
347 greg 1.3 #endif
348 greg 1.1 #else
349     sigdie(SIGALRM, "Alarm clock");
350     #endif
351     /* open error file */
352     if (errfile != NULL) {
353     if (freopen(errfile, "a", stderr) == NULL)
354     quit(1);
355     fprintf(stderr, "**************\n*** PID %5d: ",
356     getpid());
357     printargs(argc, argv, stderr);
358     fputs("\n", stderr);
359     fflush(stderr);
360     }
361     #ifdef NICE
362     nice(NICE); /* lower priority */
363     #endif
364     #if RVIEW
365     loadflags &= ~IO_INFO;
366     #endif
367     #if RPICT
368     if (i == argc)
369     readoct(NULL, loadflags, &thescene, NULL);
370     else
371     #endif
372     if (i == argc-1)
373     readoct(argv[i], loadflags, &thescene, NULL);
374     else
375     error(USER, "single octree required");
376    
377     if (loadflags & IO_INFO) { /* print header */
378     printargs(i, argv, stdout);
379     #if RPICT
380     if (gotvfile) {
381     printf(VIEWSTR);
382     fprintview(&ourview, stdout);
383     printf("\n");
384     }
385     #endif
386     printf("\n");
387     }
388    
389     marksources(); /* find and mark sources */
390    
391     *amblp = NULL; /* initialize ambient calculation */
392     setambient(ambfile);
393    
394     #if RPICT
395     if (ralrm > 0) /* report init time */
396     report();
397     render(recover); /* render the scene */
398     #endif
399     #if RTRACE
400     rtrace(NULL); /* trace rays from stdin */
401     #endif
402     #if RVIEW
403     rview(); /* go */
404     #endif
405     quit(0);
406     }
407    
408    
409     eputs(s) /* error output */
410     char *s;
411     {
412     if (errvec != NULL)
413     (*errvec)(s);
414     }
415    
416    
417     wputs(s) /* warning output */
418     char *s;
419     {
420     if (wrnvec != NULL)
421     (*wrnvec)(s);
422     }
423    
424    
425     cputs(s) /* command error output */
426     char *s;
427     {
428     if (cmdvec != NULL)
429     (*cmdvec)(s);
430     }
431    
432    
433     stderr_v(s) /* put string to stderr */
434     register char *s;
435     {
436     static int inline = 0;
437    
438     if (!inline++) {
439     fputs(progname, stderr);
440     fputs(": ", stderr);
441     }
442     fputs(s, stderr);
443     if (*s && s[strlen(s)-1] == '\n') {
444     fflush(stderr);
445     inline = 0;
446     }
447     }
448    
449    
450     onsig(signo) /* fatal signal */
451     int signo;
452     {
453 greg 1.2 #ifdef BSD
454 greg 1.1 sigblock(diemask);
455 greg 1.2 #endif
456 greg 1.1 eputs("signal - ");
457     eputs(sigerr[signo]);
458     eputs("\n");
459     quit(1);
460     }
461    
462    
463     sigdie(signo, msg) /* set fatal signal */
464     int signo;
465     char *msg;
466     {
467     if (signal(signo, onsig) == SIG_IGN)
468     signal(signo, SIG_IGN);
469 greg 1.3 #ifdef BSD
470 greg 1.1 else
471     diemask |= sigmask(signo);
472 greg 1.3 #endif
473 greg 1.1 sigerr[signo] = msg;
474     }
475    
476    
477     printdefaults() /* print default values to stdout */
478     {
479     register char *cp;
480    
481     #if RPICT|RVIEW
482     printf("-vt%c\t\t\t\t# view type is %s\n", ourview.type,
483     ourview.type==VT_PER ? "perspective" :
484     ourview.type==VT_PAR ? "parallel" :
485     "unknown");
486     printf("-vp %f %f %f\t# view point\n",
487     ourview.vp[0], ourview.vp[1], ourview.vp[2]);
488     printf("-vd %f %f %f\t# view direction\n",
489     ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
490     printf("-vu %f %f %f\t# view up\n",
491     ourview.vup[0], ourview.vup[1], ourview.vup[2]);
492     printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
493     printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
494     printf("-x %-9d\t\t\t# x resolution\n", ourview.hresolu);
495     printf("-y %-9d\t\t\t# y resolution\n", ourview.vresolu);
496     #endif
497     #if RTRACE
498     printf("-x %-9d\t\t\t# x resolution\n", hresolu);
499     printf("-y %-9d\t\t\t# y resolution\n", vresolu);
500     #endif
501     #if RPICT
502     printf("-dp %f\t\t\t# distribute pixel\n", dstrpix);
503     #endif
504     printf("-ds %f\t\t\t# distribute source\n", dstrsrc);
505     #if RPICT|RVIEW
506     printf("-sp %-9d\t\t\t# sample pixel\n", psample);
507     printf("-sd %f\t\t\t# sample difference\n", maxdiff);
508     #endif
509     printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
510     colval(ambval,GRN), colval(ambval, BLU));
511     printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
512     printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
513     printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
514     printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
515     printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
516     printf("-lr %-9d\t\t\t# limit reflection\n", maxdepth);
517     printf("-lw %f\t\t\t# limit weight\n", minweight);
518     #if RPICT
519     printf("-t %-9d\t\t\t# time between reports\n", ralrm);
520     #endif
521     #if RVIEW
522     printf("-o %s\t\t\t\t# output device\n", devname);
523     #endif
524     #if RTRACE
525     printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
526     inform, outform,
527     inform=='a' ? "ascii" :
528     inform=='f' ? "float" : "double",
529     outform=='a' ? "ascii" :
530     outform=='f' ? "float" : "double");
531     printf("-o%s\t\t\t\t# output", outvals);
532     for (cp = outvals; *cp; cp++)
533     switch (*cp) {
534     case 'i': printf(" irradiance"); break;
535     case 't': printf(" trace"); break;
536     case 'o': printf(" origin"); break;
537     case 'd': printf(" direction"); break;
538     case 'v': printf(" value"); break;
539     case 'l': printf(" length"); break;
540     case 'p': printf(" point"); break;
541     case 'n': printf(" normal"); break;
542     case 's': printf(" surface"); break;
543     case 'w': printf(" weight"); break;
544     case 'm': printf(" modifier"); break;
545     }
546     printf("\n");
547     #endif
548     }