ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rcmain.c
Revision: 2.23
Committed: Wed Oct 19 23:10:34 2022 UTC (18 months, 4 weeks ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.22: +3 -3 lines
Log Message:
fix(rcontrib): removed AdaptiveShadowTesting from feature list (didn't belong)

File Contents

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