ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
Revision: 2.3
Committed: Thu Jun 5 19:29:34 2003 UTC (20 years, 11 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.2: +5 -11 lines
Log Message:
Macros for setting binary file mode. Replacing MSDOS by _WIN32.

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 schorsch 2.3 static const char RCSid[] = "$Id: rvmain.c,v 2.2 2003/02/25 02:47:23 greg Exp $";
3 greg 2.1 #endif
4     /*
5     * rvmain.c - main for rview interactive viewer
6     */
7    
8 greg 2.2 #include "copyright.h"
9 greg 2.1
10 schorsch 2.3 #include <signal.h>
11    
12     #include "platform.h"
13 greg 2.1 #include "ray.h"
14     #include "source.h"
15     #include "ambient.h"
16     #include "random.h"
17     #include "paths.h"
18     #include "view.h"
19    
20     char *progname; /* argv[0] */
21    
22     char *octname; /* octree name */
23    
24     char *sigerr[NSIG]; /* signal error messages */
25    
26     char *shm_boundary = NULL; /* boundary of shared memory */
27    
28     char *errfile = NULL; /* error output file */
29    
30     extern int greyscale; /* map colors to brightness? */
31     extern char *dvcname; /* output device name */
32     extern double exposure; /* exposure compensation */
33    
34     extern VIEW ourview; /* viewing parameters */
35    
36     extern char rifname[]; /* rad input file name */
37    
38     extern int hresolu; /* horizontal resolution */
39     extern int vresolu; /* vertical resolution */
40    
41     extern int psample; /* pixel sample size */
42     extern double maxdiff; /* max. sample difference */
43    
44     void onsig();
45     void sigdie();
46     void printdefaults();
47    
48    
49     int
50     main(argc, argv)
51     int argc;
52     char *argv[];
53     {
54     #define check(ol,al) if (argv[i][ol] || \
55     badarg(argc-i-1,argv+i+1,al)) \
56     goto badopt
57     #define bool(olen,var) switch (argv[i][olen]) { \
58     case '\0': var = !var; break; \
59     case 'y': case 'Y': case 't': case 'T': \
60     case '+': case '1': var = 1; break; \
61     case 'n': case 'N': case 'f': case 'F': \
62     case '-': case '0': var = 0; break; \
63     default: goto badopt; }
64     char *err;
65     int rval;
66     int i;
67     /* global program name */
68     progname = argv[0] = fixargv0(argv[0]);
69     /* option city */
70     for (i = 1; i < argc; i++) {
71     /* expand arguments */
72     while ((rval = expandarg(&argc, &argv, i)) > 0)
73     ;
74     if (rval < 0) {
75     sprintf(errmsg, "cannot expand '%s'", argv[i]);
76     error(SYSTEM, errmsg);
77     }
78     if (argv[i] == NULL || argv[i][0] != '-')
79     break; /* break from options */
80     if (!strcmp(argv[i], "-version")) {
81     puts(VersionID);
82     quit(0);
83     }
84     if (!strcmp(argv[i], "-defaults") ||
85     !strcmp(argv[i], "-help")) {
86     printdefaults();
87     quit(0);
88     }
89     if (!strcmp(argv[i], "-devices")) {
90     printdevices();
91     quit(0);
92     }
93     rval = getrenderopt(argc-i, argv+i);
94     if (rval >= 0) {
95     i += rval;
96     continue;
97     }
98     rval = getviewopt(&ourview, argc-i, argv+i);
99     if (rval >= 0) {
100     i += rval;
101     continue;
102     }
103     switch (argv[i][1]) {
104     case 'v': /* view file */
105     if (argv[i][2] != 'f')
106     goto badopt;
107     check(3,"s");
108     rval = viewfile(argv[++i], &ourview, NULL);
109     if (rval < 0) {
110     sprintf(errmsg,
111     "cannot open view file \"%s\"",
112     argv[i]);
113     error(SYSTEM, errmsg);
114     } else if (rval == 0) {
115     sprintf(errmsg,
116     "bad view file \"%s\"",
117     argv[i]);
118     error(USER, errmsg);
119     }
120     break;
121     case 'b': /* grayscale */
122     bool(2,greyscale);
123     break;
124     case 'p': /* pixel */
125     switch (argv[i][2]) {
126     case 's': /* sample */
127     check(3,"i");
128     psample = atoi(argv[++i]);
129     break;
130     case 't': /* threshold */
131     check(3,"f");
132     maxdiff = atof(argv[++i]);
133     break;
134     case 'e': /* exposure */
135     check(3,"f");
136     exposure = atof(argv[++i]);
137     if (argv[i][0] == '+' || argv[i][0] == '-')
138     exposure = pow(2.0, exposure);
139     break;
140     default:
141     goto badopt;
142     }
143     break;
144     case 'w': /* warnings */
145     rval = erract[WARNING].pf != NULL;
146     bool(2,rval);
147     if (rval) erract[WARNING].pf = wputs;
148     else erract[WARNING].pf = NULL;
149     break;
150     case 'e': /* error file */
151     check(2,"s");
152     errfile = argv[++i];
153     break;
154     case 'o': /* output device */
155     check(2,"s");
156     dvcname = argv[++i];
157     break;
158     case 'R': /* render input file */
159     check(2,"s");
160     strcpy(rifname, argv[++i]);
161     break;
162     default:
163     goto badopt;
164     }
165     }
166     err = setview(&ourview); /* set viewing parameters */
167     if (err != NULL)
168     error(USER, err);
169     /* initialize object types */
170     initotypes();
171     /* initialize urand */
172     initurand(2048);
173     /* set up signal handling */
174     sigdie(SIGINT, "Interrupt");
175     sigdie(SIGHUP, "Hangup");
176     sigdie(SIGTERM, "Terminate");
177     sigdie(SIGPIPE, "Broken pipe");
178     sigdie(SIGALRM, "Alarm clock");
179     #ifdef SIGXCPU
180     sigdie(SIGXCPU, "CPU limit exceeded");
181     sigdie(SIGXFSZ, "File size exceeded");
182     #endif
183     /* open error file */
184     if (errfile != NULL) {
185     if (freopen(errfile, "a", stderr) == NULL)
186     quit(2);
187     fprintf(stderr, "**************\n*** PID %5d: ",
188     getpid());
189     printargs(argc, argv, stderr);
190     putc('\n', stderr);
191     fflush(stderr);
192     }
193     #ifdef NICE
194     nice(NICE); /* lower priority */
195     #endif
196     /* get octree */
197     if (i == argc)
198     octname = NULL;
199     else if (i == argc-1)
200     octname = argv[i];
201     else
202     goto badopt;
203     if (octname == NULL)
204     error(USER, "missing octree argument");
205     /* set up output */
206 schorsch 2.3 SET_FILE_BINARY(stdout);
207 greg 2.1 readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL);
208     nsceneobjs = nobjects;
209    
210     marksources(); /* find and mark sources */
211    
212     setambient(); /* initialize ambient calculation */
213    
214     rview(); /* run interactive viewer */
215    
216     ambsync(); /* flush ambient file */
217    
218     quit(0);
219    
220     badopt:
221     sprintf(errmsg, "command line error at '%s'", argv[i]);
222     error(USER, errmsg);
223    
224     #undef check
225     #undef bool
226     }
227    
228    
229     void
230     wputs(s) /* warning output function */
231     char *s;
232     {
233     int lasterrno = errno;
234     eputs(s);
235     errno = lasterrno;
236     }
237    
238    
239     void
240     eputs(s) /* put string to stderr */
241     register char *s;
242     {
243     static int midline = 0;
244    
245     if (!*s)
246     return;
247     if (!midline++) {
248     fputs(progname, stderr);
249     fputs(": ", stderr);
250     }
251     fputs(s, stderr);
252     if (s[strlen(s)-1] == '\n') {
253     fflush(stderr);
254     midline = 0;
255     }
256     }
257    
258    
259     void
260     onsig(signo) /* fatal signal */
261     int signo;
262     {
263     static int gotsig = 0;
264    
265     if (gotsig++) /* two signals and we're gone! */
266     _exit(signo);
267    
268     alarm(15); /* allow 15 seconds to clean up */
269     signal(SIGALRM, SIG_DFL); /* make certain we do die */
270     eputs("signal - ");
271     eputs(sigerr[signo]);
272     eputs("\n");
273     quit(3);
274     }
275    
276    
277     void
278     sigdie(signo, msg) /* set fatal signal */
279     int signo;
280     char *msg;
281     {
282     if (signal(signo, onsig) == SIG_IGN)
283     signal(signo, SIG_IGN);
284     sigerr[signo] = msg;
285     }
286    
287    
288     void
289     printdefaults() /* print default values to stdout */
290     {
291     register char *cp;
292    
293     printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" :
294     "-b-\t\t\t\t# greyscale off\n");
295     printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
296     ourview.type==VT_PER ? "perspective" :
297     ourview.type==VT_PAR ? "parallel" :
298     ourview.type==VT_HEM ? "hemispherical" :
299     ourview.type==VT_ANG ? "angular" :
300     ourview.type==VT_CYL ? "cylindrical" :
301     "unknown");
302     printf("-vp %f %f %f\t# view point\n",
303     ourview.vp[0], ourview.vp[1], ourview.vp[2]);
304     printf("-vd %f %f %f\t# view direction\n",
305     ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
306     printf("-vu %f %f %f\t# view up\n",
307     ourview.vup[0], ourview.vup[1], ourview.vup[2]);
308     printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
309     printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
310     printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore);
311     printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft);
312     printf("-vs %f\t\t\t# view shift\n", ourview.hoff);
313     printf("-vl %f\t\t\t# view lift\n", ourview.voff);
314     printf("-pe %f\t\t\t# pixel exposure\n", exposure);
315     printf("-ps %-9d\t\t\t# pixel sample\n", psample);
316     printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
317     printf("-o %s\t\t\t\t# output device\n", dvcname);
318     printf(erract[WARNING].pf != NULL ?
319     "-w+\t\t\t\t# warning messages on\n" :
320     "-w-\t\t\t\t# warning messages off\n");
321     print_rdefaults();
322     }