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 (8 years, 2 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.15: +8 -3 lines
Log Message:
prepare for winrview integration

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: rvmain.c,v 2.15 2016/03/10 18:25:46 schorsch Exp $";
3 #endif
4 /*
5 * rvmain.c - main for rview interactive viewer
6 */
7
8 #include "copyright.h"
9
10 #include <signal.h>
11 #include <time.h>
12
13 #include "platform.h"
14 #include "ray.h"
15 #include "source.h"
16 #include "ambient.h"
17 #include "rpaint.h"
18 #include "random.h"
19 #include "paths.h"
20 #include "view.h"
21 #include "pmapray.h"
22
23 extern char *progname; /* global argv[0] */
24
25 VIEW ourview = STDVIEW; /* viewing parameters */
26 int hresolu, vresolu; /* image resolution */
27
28 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
36 int newparam = 1; /* parameter setting changed */
37
38 struct driver *dev = NULL; /* driver functions */
39
40 char rifname[128]; /* rad input file name */
41
42 VIEW oldview; /* previous view parameters */
43
44 PNODE ptrunk; /* the base of our image */
45 RECT pframe; /* current frame boundaries */
46 int pdepth; /* image depth in current frame */
47
48 char *errfile = NULL; /* error output file */
49
50 int nproc = 1; /* number of processes */
51
52 char *sigerr[NSIG]; /* signal error messages */
53
54 static void onsig(int signo);
55 static void sigdie(int signo, char *msg);
56 static void printdefaults(void);
57
58 main(int argc, char *argv[])
59 {
60 #define check(ol,al) if (argv[i][ol] || \
61 badarg(argc-i-1,argv+i+1,al)) \
62 goto badopt
63 #define check_bool(olen,var) switch (argv[i][olen]) { \
64 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 char *octnm = NULL;
71 char *err;
72 int rval;
73 int i;
74 /* global program name */
75 progname = argv[0] = fixargv0(argv[0]);
76 /* 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 /* 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 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 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 check_bool(2,greyscale);
150 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 check_bool(2,rval);
174 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 /* set up signal handling */
197 sigdie(SIGINT, "Interrupt");
198 sigdie(SIGTERM, "Terminate");
199 #if !defined(_WIN32) && !defined(_WIN64)
200 sigdie(SIGHUP, "Hangup");
201 sigdie(SIGPIPE, "Broken pipe");
202 sigdie(SIGALRM, "Alarm clock");
203 #endif
204 /* 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 octnm = NULL;
220 else if (i == argc-1)
221 octnm = argv[i];
222 else
223 goto badopt;
224 if (octnm == NULL)
225 error(USER, "missing octree argument");
226 /* set up output & start process(es) */
227 SET_FILE_BINARY(stdout);
228
229 ray_init(octnm); /* also calls ray_init_pmap() */
230
231 /* temporary shortcut, until winrview is refactored into a "device" */
232 #ifndef WIN_RVIEW
233 rview(); /* run interactive viewer */
234
235
236 devclose(); /* close output device */
237 #endif
238
239 /* PMAP: free photon maps */
240 ray_done_pmap();
241
242 #ifdef WIN_RVIEW
243 return 1;
244 #endif
245 quit(0);
246
247 badopt:
248 sprintf(errmsg, "command line error at '%s'", argv[i]);
249 error(USER, errmsg);
250 return 1; /* pro forma return */
251
252 #undef check
253 #undef check_bool
254 }
255
256
257 void
258 wputs( /* warning output function */
259 char *s
260 )
261 {
262 int lasterrno = errno;
263 eputs(s);
264 errno = lasterrno;
265 }
266
267
268 void
269 eputs( /* put string to stderr */
270 char *s
271 )
272 {
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 static void
290 onsig( /* fatal signal */
291 int signo
292 )
293 {
294 static int gotsig = 0;
295
296 if (gotsig++) /* two signals and we're gone! */
297 _exit(signo);
298
299 #if !defined(_WIN32) && !defined(_WIN64)
300 alarm(15); /* allow 15 seconds to clean up */
301 signal(SIGALRM, SIG_DFL); /* make certain we do die */
302 #endif
303 eputs("signal - ");
304 eputs(sigerr[signo]);
305 eputs("\n");
306 devclose();
307 quit(3);
308 }
309
310
311 static void
312 sigdie( /* set fatal signal */
313 int signo,
314 char *msg
315 )
316 {
317 if (signal(signo, onsig) == SIG_IGN)
318 signal(signo, SIG_IGN);
319 sigerr[signo] = msg;
320 }
321
322
323 static void
324 printdefaults(void) /* print default values to stdout */
325 {
326 printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
327 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 ourview.type==VT_PLS ? "planisphere" :
336 "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 }