ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/mkpmap.c
Revision: 2.3
Committed: Thu Mar 10 18:25:46 2016 UTC (8 years, 2 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.2: +5 -5 lines
Log Message:
newer C++ compilers have a standard type named "bool". rename macro to get rid of warnings.

File Contents

# Content
1 /*
2 ==================================================================
3 Photon map generator
4
5 Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
6 (c) Fraunhofer Institute for Solar Energy Systems,
7 Lucerne University of Applied Sciences & Arts
8 ==================================================================
9
10 $Id: mkpmap.c,v 2.2 2015/05/21 05:54:54 greg Exp $
11 */
12
13
14
15 #include "pmap.h"
16 #include "pmapmat.h"
17 #include "pmapcontrib.h"
18 #include "pmaprand.h"
19 #include "paths.h"
20 #include "ambient.h"
21 #include "resolu.h"
22 #include "source.h"
23 #include <string.h>
24 #include <sys/stat.h>
25
26
27
28 extern char VersionID [];
29
30
31
32 char* progname; /* argv[0] */
33 int dimlist [MAXDIM]; /* sampling dimensions */
34 int ndims = 0; /* number of sampling dimenshunns */
35 char* octname = NULL; /* octree name */
36 CUBE thescene; /* scene top-level octree */
37 OBJECT nsceneobjs; /* number of objects in scene */
38 double srcsizerat = 0.01; /* source partition size ratio */
39 int backvis = 1; /* back face visibility */
40 int clobber = 0; /* overwrite output */
41 COLOR cextinction = BLKCOLOR; /* global extinction coefficient */
42 COLOR salbedo = BLKCOLOR; /* global scattering albedo */
43 double seccg = 0; /* global scattering eccentricity */
44 int ambincl = -1; /* photon port flag */
45 char *amblist [AMBLLEN + 1]; /* photon port list */
46 char *diagFile = NULL; /* diagnostics output file */
47 int rand_samp = 1; /* uncorrelated random sampling */
48
49
50 /* Dummies for linkage */
51
52 COLOR ambval = BLKCOLOR;
53 double shadthresh = .05, ambacc = 0.2, shadcert = .5, minweight = 5e-3,
54 ssampdist = 0, dstrsrc = 0.0, specthresh = 0.15, specjitter = 1.0,
55 avgrefl = 0.5;
56 int ambvwt = 0, ambssamp = 0, ambres = 32, ambounce = 0, directrelay = 1,
57 directvis = 1, samplendx, do_irrad = 0, ambdiv = 128, vspretest = 512,
58 maxdepth = 6, contrib = 0;
59 char *shm_boundary = NULL, *ambfile = NULL, *RCCONTEXT = NULL;
60 void (*trace)() = NULL, (*addobjnotify [])() = {ambnotify, NULL};
61
62
63
64 void printdefaults()
65 /* print default values to stdout */
66 {
67 puts("-apg file nPhotons\t\t# global photon map");
68 puts("-apc file nPhotons\t\t# caustic photon map");
69 puts("-apd file nPhotons\t\t# direct photon map");
70 puts("-app file nPhotons bwidth\t# precomputed global photon map");
71 #if 0
72 /* Hide this option as most likely useless and confusing to user */
73 puts("-appb file nPhotons minBw maxBw\t# precomp bias comp global pmap");
74 #endif
75 puts("-apv file nPhotons\t\t# volume photon map");
76 puts("-apC file nPhotons\t\t# contribution photon map");
77
78 printf("-apD %f\t\t\t# predistribution factor\n", preDistrib);
79 printf("-apM %d\t\t\t\t# max predistrib passes\n", maxPreDistrib);
80 printf("-apm %ld\t\t\t# max photon bounces\n", photonMaxBounce);
81 puts("-apo mod\t\t\t# photon port modifier");
82 puts("-apO file\t\t\t# photon port file");
83 printf("-apP %f\t\t\t# precomputation factor\n", finalGather);
84 printf("-apr %d\t\t\t\t# random seed\n", randSeed);
85 puts("-aps mod\t\t\t# antimatter sensor modifier");
86 puts("-apS file\t\t\t# antimatter sensor file");
87
88 printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n"
89 : "-bv-\t\t\t\t# back face visibility off\n");
90 printf("-dp %.1f\t\t\t# PDF samples / sr\n", pdfSamples);
91 printf("-ds %f\t\t\t# source partition size ratio\n", srcsizerat);
92 printf("-e %s\t\t\t# diagnostics output file\n", diagFile);
93 printf(clobber ? "-fo+\t\t\t\t# force overwrite"
94 : "-fo-\t\t\t\t# do not overwrite\n");
95 printf("-i %-9ld\t\t\t# photon heap size increment\n",
96 photonHeapSizeInc);
97 printf("-ma %.2f %.2f %.2f\t\t# scattering albedo\n",
98 colval(salbedo,RED), colval(salbedo,GRN), colval(salbedo,BLU));
99 printf("-me %.2e %.2e %.2e\t# extinction coefficient\n",
100 colval(cextinction,RED), colval(cextinction,GRN),
101 colval(cextinction,BLU));
102 printf("-mg %.2f\t\t\t# scattering eccentricity\n", seccg);
103 printf("-t %-9d\t\t\t# time between reports\n", photonRepTime);
104
105 #ifdef PMAP_ROI
106 /* Ziss option for ze egg-spurtz only! */
107 printf("-api \t%.0e %.0e %.0e\n\t%.0e %.0e %.0e\t# region of interest\n",
108 pmapROI [0], pmapROI [1], pmapROI [2], pmapROI [3],
109 pmapROI [4], pmapROI [5]);
110 #endif
111 }
112
113
114
115
116 int main (int argc, char* argv [])
117 {
118 #define check(ol, al) if (argv [i][ol] || \
119 badarg(argc - i - 1,argv + i + 1, al)) \
120 goto badopt
121
122 #define check_bool(olen, var) switch (argv [i][olen]) { \
123 case '\0': var = !var; break; \
124 case 'y': case 'Y': case 't': case 'T': \
125 case '+': case '1': var = 1; break; \
126 case 'n': case 'N': case 'f': case 'F': \
127 case '-': case '0': var = 0; break; \
128 default: goto badopt; \
129 }
130
131 int loadflags = IO_CHECK | IO_SCENE | IO_TREE | IO_BOUNDS, rval, i;
132 char **portLp = NULL, **sensLp = photonSensorList;
133 struct stat pmstat;
134
135 /* Global program name */
136 progname = fixargv0(argv [0]);
137 /* Initialize object types */
138 initotypes();
139
140 /* Parse options */
141 for (i = 1; i < argc; i++) {
142 /* Eggs-pand arguments */
143 while ((rval = expandarg(&argc, &argv, i)))
144 if (rval < 0) {
145 sprintf(errmsg, "cannot eggs-pand '%s'", argv [i]);
146 error(SYSTEM, errmsg);
147 }
148
149 if (argv[i] == NULL)
150 break;
151
152 if (!strcmp(argv [i], "-version")) {
153 puts(VersionID);
154 quit(0);
155 }
156
157 if (!strcmp(argv [i], "-defaults") || !strcmp(argv [i], "-help")) {
158 printdefaults();
159 quit(0);
160 }
161
162 /* Get octree */
163 if (i == argc - 1) {
164 octname = argv [i];
165 break;
166 }
167
168 switch (argv [i][1]) {
169 case 'a':
170 if (!strcmp(argv [i] + 2, "pg")) {
171 /* Global photon map */
172 check(4, "ss");
173 globalPmapParams.fileName = argv [++i];
174 globalPmapParams.distribTarget =
175 parseMultiplier(argv [++i]);
176 if (!globalPmapParams.distribTarget)
177 goto badopt;
178 globalPmapParams.minGather = globalPmapParams.maxGather = 0;
179 }
180
181 else if (!strcmp(argv [i] + 2, "pm")) {
182 /* Max photon bounces */
183 check(4, "i");
184 photonMaxBounce = atol(argv [++i]);
185 if (!photonMaxBounce)
186 goto badopt;
187 }
188
189 else if (!strcmp(argv [i] + 2, "pp")) {
190 /* Precomputed global photon map */
191 check(4, "ssi");
192 preCompPmapParams.fileName = argv [++i];
193 preCompPmapParams.distribTarget =
194 parseMultiplier(argv [++i]);
195 if (!preCompPmapParams.distribTarget)
196 goto badopt;
197 preCompPmapParams.minGather = preCompPmapParams.maxGather =
198 atoi(argv [++i]);
199 if (!preCompPmapParams.maxGather)
200 goto badopt;
201 }
202
203 #if 0
204 else if (!strcmp(argv [i] + 2, "ppb")) {
205 /* Precomputed global photon map + bias comp. */
206 check(5, "ssii");
207 preCompPmapParams.fileName = argv [++i];
208 preCompPmapParams.distribTarget =
209 parseMultiplier(argv [++i]);
210 if (!preCompPmapParams.distribTarget)
211 goto badopt;
212 preCompPmapParams.minGather = atoi(argv [++i]);
213 preCompPmapParams.maxGather = atoi(argv [++i]);
214 if (!preCompPmapParams.minGather ||
215 preCompPmapParams.minGather >=
216 preCompPmapParams.maxGather)
217 goto badopt;
218 }
219 #endif
220
221 else if (!strcmp(argv [i] + 2, "pc")) {
222 /* Caustic photon map */
223 check(4, "ss");
224 causticPmapParams.fileName = argv [++i];
225 causticPmapParams.distribTarget =
226 parseMultiplier(argv [++i]);
227 if (!causticPmapParams.distribTarget)
228 goto badopt;
229 }
230
231 else if (!strcmp(argv [i] + 2, "pv")) {
232 /* Volume photon map */
233 check(4, "ss");
234 volumePmapParams.fileName = argv [++i];
235 volumePmapParams.distribTarget =
236 parseMultiplier(argv [++i]);
237 if (!volumePmapParams.distribTarget)
238 goto badopt;
239 }
240
241 else if (!strcmp(argv [i] + 2, "pd")) {
242 /* Direct photon map */
243 check(4, "ss");
244 directPmapParams.fileName = argv [++i];
245 directPmapParams.distribTarget =
246 parseMultiplier(argv [++i]);
247 if (!directPmapParams.distribTarget)
248 goto badopt;
249 }
250
251 else if (!strcmp(argv [i] + 2, "pC")) {
252 /* Light source contribution photon map */
253 check(4, "ss");
254 contribPmapParams.fileName = argv [++i];
255 contribPmapParams.distribTarget =
256 parseMultiplier(argv [++i]);
257 if (!contribPmapParams.distribTarget)
258 goto badopt;
259 }
260
261 else if (!strcmp(argv [i] + 2, "pD")) {
262 /* Predistribution factor */
263 check(4, "f");
264 preDistrib = atof(argv [++i]);
265 if (preDistrib <= 0)
266 error(USER, "predistribution factor must be > 0");
267 }
268
269 #ifdef PMAP_ROI
270 /* Region of interest; ziss option for ze egg-spurtz only! */
271 else if (!strcmp(argv [i] + 2, "pi")) {
272 int j;
273 check(4, "ffffff");
274 for (j = 0; j < 6; j++)
275 pmapROI [j] = atof(argv [++i]);
276 }
277 #endif
278
279 else if (!strcmp(argv [i] + 2, "pP")) {
280 /* Global photon precomputation factor */
281 check(4, "f");
282 finalGather = atof(argv [++i]);
283 if (finalGather <= 0 || finalGather > 1)
284 error(USER, "global photon precomputation factor "
285 "must be in range ]0, 1]");
286 }
287
288 else if (!strcmp(argv [i] + 2, "po") ||
289 !strcmp(argv [i] + 2, "pO")) {
290 /* Photon port */
291 check(4, "s");
292
293 if (ambincl != 1) {
294 ambincl = 1;
295 portLp = amblist;
296 }
297
298 if (argv[i][3] == 'O') {
299 /* Get port modifiers file */
300 rval = wordfile(portLp, getpath(argv [++i],
301 getrlibpath(), R_OK));
302 if (rval < 0) {
303 sprintf(errmsg, "cannot open photon port file %s",
304 argv [i]);
305 error(SYSTEM, errmsg);
306 }
307
308 portLp += rval;
309 }
310
311 else {
312 /* Append modifier to port list */
313 *portLp++ = argv [++i];
314 *portLp = NULL;
315 }
316 }
317
318 else if (!strcmp(argv [i] + 2, "pr")) {
319 /* Random seed */
320 check(4, "i");
321 randSeed = atoi(argv [++i]);
322 }
323
324 else if (!strcmp(argv [i] + 2, "ps") ||
325 !strcmp(argv [i] + 2, "pS")) {
326 /* Antimatter sensor */
327 check(4, "s");
328
329 if (argv[i][3] == 'S') {
330 /* Get sensor modifiers from file */
331 rval = wordfile(sensLp, getpath(argv [++i],
332 getrlibpath(), R_OK));
333 if (rval < 0) {
334 sprintf(errmsg, "cannot open antimatter sensor file %s",
335 argv [i]);
336 error(SYSTEM, errmsg);
337 }
338
339 sensLp += rval;
340 }
341
342 else {
343 /* Append modifier to sensor list */
344 *sensLp++ = argv [++i];
345 *sensLp = NULL;
346 }
347 }
348
349 else goto badopt;
350 break;
351
352 case 'b':
353 if (argv [i][2] == 'v') {
354 /* Back face visibility */
355 check_bool(3, backvis);
356 }
357
358 else goto badopt;
359 break;
360
361 case 'd': /* Direct */
362 switch (argv [i][2]) {
363 case 'p': /* PDF samples */
364 check(3, "f");
365 pdfSamples = atof(argv [++i]);
366 break;
367
368 case 's': /* Source partition size ratio */
369 check(3, "f");
370 srcsizerat = atof(argv [++i]);
371 break;
372
373 default: goto badopt;
374 }
375 break;
376
377 case 'e': /* Diagnostics file */
378 check(2, "s");
379 diagFile = argv [++i];
380 break;
381
382 case 'f':
383 if (argv [i][2] == 'o') {
384 /* Force overwrite */
385 check_bool(3, clobber);
386 }
387
388 else goto badopt;
389 break;
390
391 case 'i': /* Photon heap size increment */
392 check(2, "i");
393 photonHeapSizeInc = atol(argv [++i]);
394 break;
395
396 case 'm': /* Medium */
397 switch (argv[i][2]) {
398 case 'e': /* Eggs-tinction coefficient */
399 check(3, "fff");
400 setcolor(cextinction, atof(argv [i + 1]),
401 atof(argv [i + 2]), atof(argv [i + 3]));
402 i += 3;
403 break;
404
405 case 'a': /* Albedo */
406 check(3, "fff");
407 setcolor(salbedo, atof(argv [i + 1]),
408 atof(argv [i + 2]), atof(argv [i + 3]));
409 i += 3;
410 break;
411
412 case 'g': /* Scattering eccentricity */
413 check(3, "f");
414 seccg = atof(argv [++i]);
415 break;
416
417 default: goto badopt;
418 }
419 break;
420
421 case 't': /* Timer */
422 check(2, "i");
423 photonRepTime = atoi(argv [++i]);
424 break;
425
426 default: goto badopt;
427 }
428 }
429
430 /* Open diagnostics file */
431 if (diagFile) {
432 if (!freopen(diagFile, "a", stderr)) quit(2);
433 fprintf(stderr, "**************\n*** PID %5d: ", getpid());
434 printargs(argc, argv, stderr);
435 putc('\n', stderr);
436 fflush(stderr);
437 }
438
439 #ifdef NICE
440 /* Lower priority */
441 nice(NICE);
442 #endif
443
444 if (octname == NULL)
445 error(USER, "missing octree argument");
446
447 /* Allocate photon maps and set parameters */
448 for (i = 0; i < NUM_PMAP_TYPES; i++) {
449 setPmapParam(photonMaps + i, pmapParams + i);
450
451 /* Don't overwrite existing photon map unless clobbering enabled */
452 if (photonMaps [i] && !stat(photonMaps [i] -> fileName, &pmstat) &&
453 !clobber) {
454 sprintf(errmsg, "photon map file %s exists, not overwritten",
455 photonMaps [i] -> fileName);
456 error(USER, errmsg);
457 }
458 }
459
460 for (i = 0; i < NUM_PMAP_TYPES && !photonMaps [i]; i++);
461 if (i >= NUM_PMAP_TYPES)
462 error(USER, "no photon maps specified");
463
464 readoct(octname, loadflags, &thescene, NULL);
465 nsceneobjs = nobjects;
466
467 /* Get sources */
468 marksources();
469
470 /* Do forward pass and build photon maps */
471 if (contribPmap)
472 /* Just build contrib pmap, ignore others */
473 distribPhotonContrib(contribPmap);
474 else
475 distribPhotons(photonMaps);
476
477 /* Save photon maps; no idea why GCC needs an explicit cast here... */
478 savePmaps((const PhotonMap**)photonMaps, argc, argv);
479 cleanUpPmaps(photonMaps);
480
481 quit(0);
482
483 badopt:
484 sprintf(errmsg, "command line error at '%s'", argv[i]);
485 error(USER, errmsg);
486
487 #undef check
488 #undef check_bool
489 return 0;
490 }