ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rcmain.c
Revision: 2.16
Committed: Wed Jun 1 03:00:06 2016 UTC (7 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R1
Changes since 2.15: +2 -2 lines
Log Message:
Added missing -c option in usage message

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: rcmain.c,v 2.15 2016/03/10 18:25:46 schorsch Exp $";
3 #endif
4 /*
5 * rcmain.c - main for rtcontrib ray contribution tracer
6 */
7
8 #include "copyright.h"
9
10 #include <signal.h>
11 #include <time.h>
12 #include "rcontrib.h"
13 #include "random.h"
14 #include "source.h"
15 #include "ambient.h"
16 #include "pmapray.h"
17 #include "pmapcontrib.h"
18
19 int gargc; /* global argc */
20 char **gargv; /* global argv */
21 char *octname; /* global octree name */
22 char *progname; /* global argv[0] */
23
24 char *sigerr[NSIG]; /* signal error messages */
25
26 int nproc = 1; /* number of processes requested */
27 int nchild = 0; /* number of children (-1 in child) */
28
29 int inpfmt = 'a'; /* input format */
30 int outfmt = 'a'; /* output format */
31
32 int header = 1; /* output header? */
33 int force_open = 0; /* truncate existing output? */
34 int recover = 0; /* recover previous output? */
35 int accumulate = 1; /* input rays per output record */
36 int contrib = 0; /* computing contributions? */
37
38 int xres = 0; /* horizontal (scan) size */
39 int yres = 0; /* vertical resolution */
40
41 int using_stdout = 0; /* are we using stdout? */
42
43 int imm_irrad = 0; /* compute immediate irradiance? */
44 int lim_dist = 0; /* limit distance? */
45
46 const char *modname[MAXMODLIST]; /* ordered modifier name list */
47 int nmods = 0; /* number of modifiers */
48
49 void (*addobjnotify[8])() = {ambnotify, NULL};
50
51 char RCCONTEXT[] = "RC"; /* our special evaluation context */
52
53
54 static void
55 printdefaults(void) /* print default values to stdout */
56 {
57 printf("-c %-5d\t\t\t# accumulated rays per record\n", accumulate);
58 printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-',
59 contrib ? "contributions" : "coefficients");
60 if (imm_irrad)
61 printf("-I+\t\t\t\t# immediate irradiance on\n");
62 printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
63 printf("-x %-9d\t\t\t# %s\n", xres,
64 yres && xres ? "x resolution" : "flush interval");
65 printf("-y %-9d\t\t\t# y resolution\n", yres);
66 printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
67 "-ld-\t\t\t\t# limit distance off\n");
68 printf("-h%c\t\t\t\t# %s header\n", header ? '+' : '-',
69 header ? "output" : "no");
70 printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
71 inpfmt, outfmt, formstr(inpfmt), formstr(outfmt));
72 printf(erract[WARNING].pf != NULL ?
73 "-w+\t\t\t\t# warning messages on\n" :
74 "-w-\t\t\t\t# warning messages off\n");
75 print_rdefaults();
76 }
77
78
79 static void
80 onsig( /* fatal signal */
81 int signo
82 )
83 {
84 static int gotsig = 0;
85
86 if (gotsig++) /* two signals and we're gone! */
87 _exit(signo);
88
89 #ifdef SIGALRM
90 alarm(15); /* allow 15 seconds to clean up */
91 signal(SIGALRM, SIG_DFL); /* make certain we do die */
92 #endif
93 eputs("signal - ");
94 eputs(sigerr[signo]);
95 eputs("\n");
96 quit(3);
97 }
98
99
100 static void
101 sigdie( /* set fatal signal */
102 int signo,
103 char *msg
104 )
105 {
106 if (signal(signo, onsig) == SIG_IGN)
107 signal(signo, SIG_IGN);
108 sigerr[signo] = msg;
109 }
110
111
112 /* set input/output format */
113 static void
114 setformat(const char *fmt)
115 {
116 switch (fmt[0]) {
117 case 'f':
118 case 'd':
119 SET_FILE_BINARY(stdin);
120 /* fall through */
121 case 'a':
122 inpfmt = fmt[0];
123 break;
124 default:
125 goto fmterr;
126 }
127 switch (fmt[1]) {
128 case '\0':
129 outfmt = inpfmt;
130 return;
131 case 'a':
132 case 'f':
133 case 'd':
134 case 'c':
135 outfmt = fmt[1];
136 break;
137 default:
138 goto fmterr;
139 }
140 if (!fmt[2])
141 return;
142 fmterr:
143 sprintf(errmsg, "Illegal i/o format: -f%s", fmt);
144 error(USER, errmsg);
145 }
146
147
148 /* Set overriding options */
149 static void
150 override_options(void)
151 {
152 shadthresh = 0;
153 ambssamp = 0;
154 ambacc = 0;
155 if (accumulate <= 0) /* no output flushing for single record */
156 xres = yres = 0;
157 }
158
159
160 int
161 main(int argc, char *argv[])
162 {
163 #define check(ol,al) if (argv[i][ol] || \
164 badarg(argc-i-1,argv+i+1,al)) \
165 goto badopt
166 #define check_bool(olen,var) switch (argv[i][olen]) { \
167 case '\0': var = !var; break; \
168 case 'y': case 'Y': case 't': case 'T': \
169 case '+': case '1': var = 1; break; \
170 case 'n': case 'N': case 'f': case 'F': \
171 case '-': case '0': var = 0; break; \
172 default: goto badopt; }
173 char *curout = NULL;
174 char *prms = NULL;
175 char *binval = NULL;
176 int bincnt = 0;
177 int rval;
178 int i;
179 /* global program name */
180 progname = argv[0] = fixargv0(argv[0]);
181 gargv = argv;
182 gargc = argc;
183 /* initialize calcomp routines early */
184 initfunc();
185 setcontext(RCCONTEXT);
186 /* option city */
187 for (i = 1; i < argc; i++) {
188 /* expand arguments */
189 while ((rval = expandarg(&argc, &argv, i)) > 0)
190 ;
191 if (rval < 0) {
192 sprintf(errmsg, "cannot expand '%s'", argv[i]);
193 error(SYSTEM, errmsg);
194 }
195 if (argv[i] == NULL || argv[i][0] != '-')
196 break; /* break from options */
197 if (!strcmp(argv[i], "-version")) {
198 puts(VersionID);
199 quit(0);
200 }
201 if (!strcmp(argv[i], "-defaults") ||
202 !strcmp(argv[i], "-help")) {
203 override_options();
204 printdefaults();
205 quit(0);
206 }
207 rval = getrenderopt(argc-i, argv+i);
208 if (rval >= 0) {
209 i += rval;
210 continue;
211 }
212 switch (argv[i][1]) {
213 case 'n': /* number of cores */
214 check(2,"i");
215 nproc = atoi(argv[++i]);
216 if (nproc <= 0)
217 error(USER, "bad number of processes");
218 break;
219 case 'V': /* output contributions */
220 check_bool(2,contrib);
221 break;
222 case 'x': /* x resolution */
223 check(2,"i");
224 xres = atoi(argv[++i]);
225 break;
226 case 'y': /* y resolution */
227 check(2,"i");
228 yres = atoi(argv[++i]);
229 break;
230 case 'w': /* warnings */
231 rval = (erract[WARNING].pf != NULL);
232 check_bool(2,rval);
233 if (rval) erract[WARNING].pf = wputs;
234 else erract[WARNING].pf = NULL;
235 break;
236 case 'e': /* expression */
237 check(2,"s");
238 scompile(argv[++i], NULL, 0);
239 break;
240 case 'l': /* limit distance */
241 if (argv[i][2] != 'd')
242 goto badopt;
243 check_bool(3,lim_dist);
244 break;
245 case 'I': /* immed. irradiance */
246 check_bool(2,imm_irrad);
247 break;
248 case 'f': /* file or force or format */
249 if (!argv[i][2]) {
250 check(2,"s");
251 loadfunc(argv[++i]);
252 break;
253 }
254 if (argv[i][2] == 'o') {
255 check_bool(3,force_open);
256 break;
257 }
258 setformat(argv[i]+2);
259 break;
260 case 'o': /* output */
261 check(2,"s");
262 curout = argv[++i];
263 break;
264 case 'c': /* input rays per output */
265 check(2,"i");
266 accumulate = atoi(argv[++i]);
267 break;
268 case 'r': /* recover output */
269 check_bool(2,recover);
270 break;
271 case 'h': /* header output */
272 check_bool(2,header);
273 break;
274 case 'p': /* parameter setting(s) */
275 check(2,"s");
276 set_eparams(prms = argv[++i]);
277 break;
278 case 'b': /* bin expression/count */
279 if (argv[i][2] == 'n') {
280 check(3,"s");
281 bincnt = (int)(eval(argv[++i]) + .5);
282 break;
283 }
284 check(2,"s");
285 binval = argv[++i];
286 break;
287 case 'm': /* modifier name */
288 check(2,"s");
289 addmodifier(argv[++i], curout, prms, binval, bincnt);
290 break;
291 case 'M': /* modifier file */
292 check(2,"s");
293 addmodfile(argv[++i], curout, prms, binval, bincnt);
294 break;
295 default:
296 goto badopt;
297 }
298 }
299 if (nmods <= 0)
300 error(USER, "missing required modifier argument");
301 /* override some option settings */
302 override_options();
303 /* initialize object types */
304 initotypes();
305 /* initialize urand */
306 if (rand_samp) {
307 srandom((long)time(0));
308 initurand(0);
309 } else {
310 srandom(0L);
311 initurand(2048);
312 }
313 /* set up signal handling */
314 sigdie(SIGINT, "Interrupt");
315 #ifdef SIGHUP
316 sigdie(SIGHUP, "Hangup");
317 #endif
318 sigdie(SIGTERM, "Terminate");
319 #ifdef SIGPIPE
320 sigdie(SIGPIPE, "Broken pipe");
321 #endif
322 #ifdef SIGALRM
323 sigdie(SIGALRM, "Alarm clock");
324 #endif
325 #ifdef SIGXCPU
326 sigdie(SIGXCPU, "CPU limit exceeded");
327 sigdie(SIGXFSZ, "File size exceeded");
328 #endif
329 #ifdef NICE
330 nice(NICE); /* lower priority */
331 #endif
332 /* get octree */
333 if (i == argc)
334 octname = NULL;
335 else if (i == argc-1)
336 octname = argv[i];
337 else
338 goto badopt;
339 if (octname == NULL)
340 error(USER, "missing octree argument");
341
342 readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL);
343 nsceneobjs = nobjects;
344
345 /* PMAP: set up & load photon maps */
346 ray_init_pmap();
347
348 marksources(); /* find and mark sources */
349
350 /* PMAP: init photon map for light source contributions */
351 initPmapContrib(&modconttab, nmods);
352
353 setambient(); /* initialize ambient calculation */
354
355 rcontrib(); /* trace ray contributions (loop) */
356
357 ambsync(); /* flush ambient file */
358
359 /* PMAP: free photon maps */
360 ray_done_pmap();
361
362 quit(0); /* exit clean */
363
364 badopt:
365 fprintf(stderr,
366 "Usage: %s [-n nprocs][-V][-c count][-r][-e expr][-f source][-o ospec][-p p1=V1,p2=V2][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n",
367 progname);
368 sprintf(errmsg, "command line error at '%s'", argv[i]);
369 error(USER, errmsg);
370 return(1); /* pro forma return */
371
372 #undef check
373 #undef check_bool
374 }
375
376
377 void
378 wputs( /* warning output function */
379 char *s
380 )
381 {
382 int lasterrno = errno;
383 eputs(s);
384 errno = lasterrno;
385 }
386
387
388 void
389 eputs( /* put string to stderr */
390 char *s
391 )
392 {
393 static int midline = 0;
394
395 if (!*s)
396 return;
397 if (!midline++) {
398 fputs(progname, stderr);
399 fputs(": ", stderr);
400 }
401 fputs(s, stderr);
402 if (s[strlen(s)-1] == '\n') {
403 fflush(stderr);
404 midline = 0;
405 }
406 }