ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
Revision: 2.8
Committed: Tue Mar 11 02:21:47 2008 UTC (16 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R9
Changes since 2.7: +2 -1 lines
Log Message:
Added planisphere view type (-vts option) as requested by Axel Jacobs

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.8 static const char RCSid[] = "$Id: rvmain.c,v 2.7 2006/04/05 06:22:57 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 greg 2.5 #include <time.h>
12 schorsch 2.3
13     #include "platform.h"
14 greg 2.1 #include "ray.h"
15     #include "source.h"
16     #include "ambient.h"
17 schorsch 2.4 #include "rpaint.h"
18 greg 2.1 #include "random.h"
19     #include "paths.h"
20     #include "view.h"
21    
22     char *progname; /* argv[0] */
23    
24     char *octname; /* octree name */
25    
26     char *sigerr[NSIG]; /* signal error messages */
27    
28     char *shm_boundary = NULL; /* boundary of shared memory */
29    
30     char *errfile = NULL; /* error output file */
31    
32     extern int greyscale; /* map colors to brightness? */
33     extern char *dvcname; /* output device name */
34     extern double exposure; /* exposure compensation */
35    
36     extern VIEW ourview; /* viewing parameters */
37    
38     extern char rifname[]; /* rad input file name */
39    
40     extern int hresolu; /* horizontal resolution */
41     extern int vresolu; /* vertical resolution */
42    
43     extern int psample; /* pixel sample size */
44     extern double maxdiff; /* max. sample difference */
45    
46 schorsch 2.4 static void onsig(int signo);
47     static void sigdie(int signo, char *msg);
48     static void printdefaults(void);
49 greg 2.1
50    
51     int
52 schorsch 2.4 main(int argc, char *argv[])
53 greg 2.1 {
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 greg 2.7 if (rand_samp) {
173     srandom((long)time(0));
174     initurand(0);
175     } else {
176     srandom(0L);
177     initurand(2048);
178     }
179 greg 2.1 /* set up signal handling */
180     sigdie(SIGINT, "Interrupt");
181     sigdie(SIGHUP, "Hangup");
182     sigdie(SIGTERM, "Terminate");
183     sigdie(SIGPIPE, "Broken pipe");
184     sigdie(SIGALRM, "Alarm clock");
185     #ifdef SIGXCPU
186     sigdie(SIGXCPU, "CPU limit exceeded");
187     sigdie(SIGXFSZ, "File size exceeded");
188     #endif
189     /* open error file */
190     if (errfile != NULL) {
191     if (freopen(errfile, "a", stderr) == NULL)
192     quit(2);
193     fprintf(stderr, "**************\n*** PID %5d: ",
194     getpid());
195     printargs(argc, argv, stderr);
196     putc('\n', stderr);
197     fflush(stderr);
198     }
199     #ifdef NICE
200     nice(NICE); /* lower priority */
201     #endif
202     /* get octree */
203     if (i == argc)
204     octname = NULL;
205     else if (i == argc-1)
206     octname = argv[i];
207     else
208     goto badopt;
209     if (octname == NULL)
210     error(USER, "missing octree argument");
211     /* set up output */
212 schorsch 2.3 SET_FILE_BINARY(stdout);
213 greg 2.1 readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL);
214     nsceneobjs = nobjects;
215    
216     marksources(); /* find and mark sources */
217    
218     setambient(); /* initialize ambient calculation */
219    
220     rview(); /* run interactive viewer */
221    
222     ambsync(); /* flush ambient file */
223    
224     quit(0);
225    
226     badopt:
227     sprintf(errmsg, "command line error at '%s'", argv[i]);
228     error(USER, errmsg);
229 schorsch 2.4 return 1; /* pro forma return */
230 greg 2.1
231     #undef check
232     #undef bool
233     }
234    
235    
236     void
237 schorsch 2.4 wputs( /* warning output function */
238     char *s
239     )
240 greg 2.1 {
241     int lasterrno = errno;
242     eputs(s);
243     errno = lasterrno;
244     }
245    
246    
247     void
248 schorsch 2.4 eputs( /* put string to stderr */
249     register char *s
250     )
251 greg 2.1 {
252     static int midline = 0;
253    
254     if (!*s)
255     return;
256     if (!midline++) {
257     fputs(progname, stderr);
258     fputs(": ", stderr);
259     }
260     fputs(s, stderr);
261     if (s[strlen(s)-1] == '\n') {
262     fflush(stderr);
263     midline = 0;
264     }
265     }
266    
267    
268 schorsch 2.4 static void
269     onsig( /* fatal signal */
270     int signo
271     )
272 greg 2.1 {
273     static int gotsig = 0;
274    
275     if (gotsig++) /* two signals and we're gone! */
276     _exit(signo);
277    
278     alarm(15); /* allow 15 seconds to clean up */
279     signal(SIGALRM, SIG_DFL); /* make certain we do die */
280     eputs("signal - ");
281     eputs(sigerr[signo]);
282     eputs("\n");
283     quit(3);
284     }
285    
286    
287 schorsch 2.4 static void
288     sigdie( /* set fatal signal */
289     int signo,
290     char *msg
291     )
292 greg 2.1 {
293     if (signal(signo, onsig) == SIG_IGN)
294     signal(signo, SIG_IGN);
295     sigerr[signo] = msg;
296     }
297    
298    
299 schorsch 2.4 static void
300     printdefaults(void) /* print default values to stdout */
301 greg 2.1 {
302     printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" :
303     "-b-\t\t\t\t# greyscale off\n");
304     printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
305     ourview.type==VT_PER ? "perspective" :
306     ourview.type==VT_PAR ? "parallel" :
307     ourview.type==VT_HEM ? "hemispherical" :
308     ourview.type==VT_ANG ? "angular" :
309     ourview.type==VT_CYL ? "cylindrical" :
310 greg 2.8 ourview.type==VT_PLS ? "planisphere" :
311 greg 2.1 "unknown");
312     printf("-vp %f %f %f\t# view point\n",
313     ourview.vp[0], ourview.vp[1], ourview.vp[2]);
314     printf("-vd %f %f %f\t# view direction\n",
315     ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
316     printf("-vu %f %f %f\t# view up\n",
317     ourview.vup[0], ourview.vup[1], ourview.vup[2]);
318     printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
319     printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
320     printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore);
321     printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft);
322     printf("-vs %f\t\t\t# view shift\n", ourview.hoff);
323     printf("-vl %f\t\t\t# view lift\n", ourview.voff);
324     printf("-pe %f\t\t\t# pixel exposure\n", exposure);
325     printf("-ps %-9d\t\t\t# pixel sample\n", psample);
326     printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
327     printf("-o %s\t\t\t\t# output device\n", dvcname);
328     printf(erract[WARNING].pf != NULL ?
329     "-w+\t\t\t\t# warning messages on\n" :
330     "-w-\t\t\t\t# warning messages off\n");
331     print_rdefaults();
332     }