ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rcmain.c
Revision: 2.33
Committed: Fri Nov 17 20:02:07 2023 UTC (5 months, 3 weeks ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.32: +6 -28 lines
Log Message:
fix: multiple bug fixes in hyperspectral code, added rvu, mkillum, rsensor, and ranimove to "working except photon map" status

File Contents

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