ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rmain.c
Revision: 1.11
Committed: Wed Jun 7 08:35:18 1989 UTC (35 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.10: +17 -11 lines
Log Message:
Efficient approximation to direct component with many sources
Glow type changed
Spot type eliminated

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