ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
Revision: 2.13
Committed: Thu Apr 23 17:42:04 2015 UTC (9 years ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R0
Changes since 2.12: +2 -5 lines
Log Message:
Fixed assignment of octname and removed redundant call to ray_init_pmap()

File Contents

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