ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
Revision: 2.16
Committed: Sat Mar 19 12:51:36 2016 UTC (9 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.15: +8 -3 lines
Log Message:
prepare for winrview integration

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 schorsch 2.16 static const char RCSid[] = "$Id: rvmain.c,v 2.15 2016/03/10 18:25:46 schorsch 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 greg 2.12 #include "pmapray.h"
22 greg 2.1
23 greg 2.9 extern char *progname; /* global argv[0] */
24 greg 2.1
25 greg 2.9 VIEW ourview = STDVIEW; /* viewing parameters */
26     int hresolu, vresolu; /* image resolution */
27 greg 2.1
28 greg 2.9 int psample = 8; /* pixel sample size */
29     double maxdiff = .15; /* max. sample difference */
30    
31     int greyscale = 0; /* map colors to brightness? */
32     char *dvcname = dev_default; /* output device name */
33    
34     double exposure = 1.0; /* exposure for scene */
35 greg 2.1
36 greg 2.9 int newparam = 1; /* parameter setting changed */
37    
38     struct driver *dev = NULL; /* driver functions */
39 greg 2.1
40 greg 2.9 char rifname[128]; /* rad input file name */
41 greg 2.1
42 greg 2.9 VIEW oldview; /* previous view parameters */
43 greg 2.1
44 greg 2.9 PNODE ptrunk; /* the base of our image */
45     RECT pframe; /* current frame boundaries */
46     int pdepth; /* image depth in current frame */
47 greg 2.1
48 greg 2.9 char *errfile = NULL; /* error output file */
49 greg 2.1
50 greg 2.9 int nproc = 1; /* number of processes */
51 greg 2.1
52 greg 2.9 char *sigerr[NSIG]; /* signal error messages */
53 greg 2.1
54 schorsch 2.4 static void onsig(int signo);
55     static void sigdie(int signo, char *msg);
56     static void printdefaults(void);
57 greg 2.1
58 greg 2.9 main(int argc, char *argv[])
59 greg 2.1 {
60     #define check(ol,al) if (argv[i][ol] || \
61     badarg(argc-i-1,argv+i+1,al)) \
62     goto badopt
63 schorsch 2.15 #define check_bool(olen,var) switch (argv[i][olen]) { \
64 greg 2.1 case '\0': var = !var; break; \
65     case 'y': case 'Y': case 't': case 'T': \
66     case '+': case '1': var = 1; break; \
67     case 'n': case 'N': case 'f': case 'F': \
68     case '-': case '0': var = 0; break; \
69     default: goto badopt; }
70 greg 2.9 char *octnm = NULL;
71 greg 2.1 char *err;
72     int rval;
73     int i;
74     /* global program name */
75     progname = argv[0] = fixargv0(argv[0]);
76 greg 2.9 /* set our defaults */
77     shadthresh = .1;
78     shadcert = .25;
79     directrelay = 0;
80     vspretest = 128;
81     srcsizerat = 0.;
82     specthresh = .3;
83     specjitter = 1.;
84     maxdepth = 6;
85     minweight = 1e-2;
86     ambacc = 0.3;
87     ambres = 32;
88     ambdiv = 256;
89     ambssamp = 64;
90 greg 2.1 /* option city */
91     for (i = 1; i < argc; i++) {
92     /* expand arguments */
93     while ((rval = expandarg(&argc, &argv, i)) > 0)
94     ;
95     if (rval < 0) {
96     sprintf(errmsg, "cannot expand '%s'", argv[i]);
97     error(SYSTEM, errmsg);
98     }
99     if (argv[i] == NULL || argv[i][0] != '-')
100     break; /* break from options */
101     if (!strcmp(argv[i], "-version")) {
102     puts(VersionID);
103     quit(0);
104     }
105     if (!strcmp(argv[i], "-defaults") ||
106     !strcmp(argv[i], "-help")) {
107     printdefaults();
108     quit(0);
109     }
110     if (!strcmp(argv[i], "-devices")) {
111     printdevices();
112     quit(0);
113     }
114     rval = getrenderopt(argc-i, argv+i);
115     if (rval >= 0) {
116     i += rval;
117     continue;
118     }
119     rval = getviewopt(&ourview, argc-i, argv+i);
120     if (rval >= 0) {
121     i += rval;
122     continue;
123     }
124     switch (argv[i][1]) {
125 greg 2.9 case 'n': /* # processes */
126     check(2,"i");
127     nproc = atoi(argv[++i]);
128     if (nproc <= 0)
129     error(USER, "bad number of processes");
130     break;
131 greg 2.1 case 'v': /* view file */
132     if (argv[i][2] != 'f')
133     goto badopt;
134     check(3,"s");
135     rval = viewfile(argv[++i], &ourview, NULL);
136     if (rval < 0) {
137     sprintf(errmsg,
138     "cannot open view file \"%s\"",
139     argv[i]);
140     error(SYSTEM, errmsg);
141     } else if (rval == 0) {
142     sprintf(errmsg,
143     "bad view file \"%s\"",
144     argv[i]);
145     error(USER, errmsg);
146     }
147     break;
148     case 'b': /* grayscale */
149 schorsch 2.15 check_bool(2,greyscale);
150 greg 2.1 break;
151     case 'p': /* pixel */
152     switch (argv[i][2]) {
153     case 's': /* sample */
154     check(3,"i");
155     psample = atoi(argv[++i]);
156     break;
157     case 't': /* threshold */
158     check(3,"f");
159     maxdiff = atof(argv[++i]);
160     break;
161     case 'e': /* exposure */
162     check(3,"f");
163     exposure = atof(argv[++i]);
164     if (argv[i][0] == '+' || argv[i][0] == '-')
165     exposure = pow(2.0, exposure);
166     break;
167     default:
168     goto badopt;
169     }
170     break;
171     case 'w': /* warnings */
172     rval = erract[WARNING].pf != NULL;
173 schorsch 2.15 check_bool(2,rval);
174 greg 2.1 if (rval) erract[WARNING].pf = wputs;
175     else erract[WARNING].pf = NULL;
176     break;
177     case 'e': /* error file */
178     check(2,"s");
179     errfile = argv[++i];
180     break;
181     case 'o': /* output device */
182     check(2,"s");
183     dvcname = argv[++i];
184     break;
185     case 'R': /* render input file */
186     check(2,"s");
187     strcpy(rifname, argv[++i]);
188     break;
189     default:
190     goto badopt;
191     }
192     }
193     err = setview(&ourview); /* set viewing parameters */
194     if (err != NULL)
195     error(USER, err);
196 greg 2.9 /* set up signal handling */
197 greg 2.1 sigdie(SIGINT, "Interrupt");
198 greg 2.11 sigdie(SIGTERM, "Terminate");
199 schorsch 2.14 #if !defined(_WIN32) && !defined(_WIN64)
200 greg 2.1 sigdie(SIGHUP, "Hangup");
201     sigdie(SIGPIPE, "Broken pipe");
202     sigdie(SIGALRM, "Alarm clock");
203 greg 2.11 #endif
204 greg 2.1 /* open error file */
205     if (errfile != NULL) {
206     if (freopen(errfile, "a", stderr) == NULL)
207     quit(2);
208     fprintf(stderr, "**************\n*** PID %5d: ",
209     getpid());
210     printargs(argc, argv, stderr);
211     putc('\n', stderr);
212     fflush(stderr);
213     }
214     #ifdef NICE
215     nice(NICE); /* lower priority */
216     #endif
217     /* get octree */
218     if (i == argc)
219 greg 2.9 octnm = NULL;
220 greg 2.1 else if (i == argc-1)
221 greg 2.9 octnm = argv[i];
222 greg 2.1 else
223     goto badopt;
224 greg 2.9 if (octnm == NULL)
225 greg 2.1 error(USER, "missing octree argument");
226 greg 2.9 /* set up output & start process(es) */
227 schorsch 2.3 SET_FILE_BINARY(stdout);
228 greg 2.9
229 greg 2.13 ray_init(octnm); /* also calls ray_init_pmap() */
230 greg 2.12
231 schorsch 2.16 /* temporary shortcut, until winrview is refactored into a "device" */
232     #ifndef WIN_RVIEW
233 greg 2.1 rview(); /* run interactive viewer */
234    
235 schorsch 2.16
236 greg 2.9 devclose(); /* close output device */
237 schorsch 2.16 #endif
238 greg 2.1
239 greg 2.12 /* PMAP: free photon maps */
240     ray_done_pmap();
241    
242 schorsch 2.16 #ifdef WIN_RVIEW
243     return 1;
244     #endif
245 greg 2.1 quit(0);
246    
247     badopt:
248     sprintf(errmsg, "command line error at '%s'", argv[i]);
249     error(USER, errmsg);
250 schorsch 2.4 return 1; /* pro forma return */
251 greg 2.1
252     #undef check
253 schorsch 2.15 #undef check_bool
254 greg 2.1 }
255    
256    
257     void
258 schorsch 2.4 wputs( /* warning output function */
259     char *s
260     )
261 greg 2.1 {
262     int lasterrno = errno;
263     eputs(s);
264     errno = lasterrno;
265     }
266    
267    
268     void
269 schorsch 2.4 eputs( /* put string to stderr */
270 greg 2.9 char *s
271 schorsch 2.4 )
272 greg 2.1 {
273     static int midline = 0;
274    
275     if (!*s)
276     return;
277     if (!midline++) {
278     fputs(progname, stderr);
279     fputs(": ", stderr);
280     }
281     fputs(s, stderr);
282     if (s[strlen(s)-1] == '\n') {
283     fflush(stderr);
284     midline = 0;
285     }
286     }
287    
288    
289 schorsch 2.4 static void
290     onsig( /* fatal signal */
291     int signo
292     )
293 greg 2.1 {
294     static int gotsig = 0;
295    
296     if (gotsig++) /* two signals and we're gone! */
297     _exit(signo);
298    
299 schorsch 2.14 #if !defined(_WIN32) && !defined(_WIN64)
300 greg 2.1 alarm(15); /* allow 15 seconds to clean up */
301     signal(SIGALRM, SIG_DFL); /* make certain we do die */
302 greg 2.11 #endif
303 greg 2.1 eputs("signal - ");
304     eputs(sigerr[signo]);
305     eputs("\n");
306 greg 2.9 devclose();
307 greg 2.1 quit(3);
308     }
309    
310    
311 schorsch 2.4 static void
312     sigdie( /* set fatal signal */
313     int signo,
314     char *msg
315     )
316 greg 2.1 {
317     if (signal(signo, onsig) == SIG_IGN)
318     signal(signo, SIG_IGN);
319     sigerr[signo] = msg;
320     }
321    
322    
323 schorsch 2.4 static void
324     printdefaults(void) /* print default values to stdout */
325 greg 2.1 {
326 greg 2.9 printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
327 greg 2.1 printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" :
328     "-b-\t\t\t\t# greyscale off\n");
329     printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
330     ourview.type==VT_PER ? "perspective" :
331     ourview.type==VT_PAR ? "parallel" :
332     ourview.type==VT_HEM ? "hemispherical" :
333     ourview.type==VT_ANG ? "angular" :
334     ourview.type==VT_CYL ? "cylindrical" :
335 greg 2.8 ourview.type==VT_PLS ? "planisphere" :
336 greg 2.1 "unknown");
337     printf("-vp %f %f %f\t# view point\n",
338     ourview.vp[0], ourview.vp[1], ourview.vp[2]);
339     printf("-vd %f %f %f\t# view direction\n",
340     ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
341     printf("-vu %f %f %f\t# view up\n",
342     ourview.vup[0], ourview.vup[1], ourview.vup[2]);
343     printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
344     printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
345     printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore);
346     printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft);
347     printf("-vs %f\t\t\t# view shift\n", ourview.hoff);
348     printf("-vl %f\t\t\t# view lift\n", ourview.voff);
349     printf("-pe %f\t\t\t# pixel exposure\n", exposure);
350     printf("-ps %-9d\t\t\t# pixel sample\n", psample);
351     printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
352     printf("-o %s\t\t\t\t# output device\n", dvcname);
353     printf(erract[WARNING].pf != NULL ?
354     "-w+\t\t\t\t# warning messages on\n" :
355     "-w-\t\t\t\t# warning messages off\n");
356     print_rdefaults();
357     }