1 |
+ |
#ifndef lint |
2 |
+ |
static const char RCSid[] = "$Id$"; |
3 |
+ |
#endif |
4 |
+ |
|
5 |
+ |
|
6 |
|
/* |
7 |
< |
================================================================== |
7 |
> |
====================================================================== |
8 |
|
Photon map generator |
9 |
|
|
10 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
11 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
12 |
|
Lucerne University of Applied Sciences & Arts |
13 |
< |
================================================================== |
13 |
> |
(c) Lucerne University of Applied Sciences and Arts, |
14 |
> |
supported by the Swiss National Science Foundation (SNSF, #147053) |
15 |
> |
====================================================================== |
16 |
|
|
17 |
|
$Id$ |
18 |
|
*/ |
19 |
|
|
20 |
|
|
14 |
– |
|
21 |
|
#include "pmap.h" |
22 |
|
#include "pmapmat.h" |
23 |
|
#include "pmapcontrib.h" |
30 |
|
#include <sys/stat.h> |
31 |
|
|
32 |
|
|
27 |
– |
|
33 |
|
extern char VersionID []; |
34 |
|
|
35 |
|
|
36 |
+ |
char* progname; /* argv[0] */ |
37 |
+ |
int dimlist [MAXDIM]; /* sampling dimensions */ |
38 |
+ |
int ndims = 0; /* number of sampling dimenshunns */ |
39 |
+ |
char* octname = NULL; /* octree name */ |
40 |
+ |
CUBE thescene; /* scene top-level octree */ |
41 |
+ |
OBJECT nsceneobjs; /* number of objects in scene */ |
42 |
+ |
double srcsizerat = 0.01; /* source partition size ratio */ |
43 |
+ |
int backvis = 1; /* back face visibility */ |
44 |
+ |
int clobber = 0; /* overwrite output */ |
45 |
+ |
COLOR cextinction = BLKCOLOR; /* global extinction coefficient */ |
46 |
+ |
COLOR salbedo = BLKCOLOR; /* global scattering albedo */ |
47 |
+ |
double seccg = 0; /* global scattering eccentricity */ |
48 |
+ |
int ambincl = -1; /* photon port flag */ |
49 |
+ |
char *amblist [AMBLLEN + 1]; /* photon port list */ |
50 |
+ |
char *diagFile = NULL; /* diagnostics output file */ |
51 |
+ |
int rand_samp = 1; /* uncorrelated random sampling */ |
52 |
+ |
unsigned nproc = 1; /* number of parallel processes */ |
53 |
+ |
#ifdef EVALDRC_HACK |
54 |
+ |
char *angsrcfile = NULL; /* angular source file for EvalDRC */ |
55 |
+ |
#endif |
56 |
|
|
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 */ |
57 |
|
|
49 |
– |
|
58 |
|
/* Dummies for linkage */ |
59 |
|
|
60 |
|
COLOR ambval = BLKCOLOR; |
67 |
|
char *shm_boundary = NULL, *ambfile = NULL, *RCCONTEXT = NULL; |
68 |
|
void (*trace)() = NULL, (*addobjnotify [])() = {ambnotify, NULL}; |
69 |
|
|
62 |
– |
|
70 |
|
|
71 |
|
void printdefaults() |
72 |
|
/* print default values to stdout */ |
75 |
|
puts("-apc file nPhotons\t\t# caustic photon map"); |
76 |
|
puts("-apd file nPhotons\t\t# direct photon map"); |
77 |
|
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 |
78 |
|
puts("-apv file nPhotons\t\t# volume photon map"); |
79 |
|
puts("-apC file nPhotons\t\t# contribution photon map"); |
80 |
|
|
93 |
|
printf("-dp %.1f\t\t\t# PDF samples / sr\n", pdfSamples); |
94 |
|
printf("-ds %f\t\t\t# source partition size ratio\n", srcsizerat); |
95 |
|
printf("-e %s\t\t\t# diagnostics output file\n", diagFile); |
96 |
< |
printf(clobber ? "-fo+\t\t\t\t# force overwrite" |
96 |
> |
printf(clobber ? "-fo+\t\t\t\t# force overwrite\n" |
97 |
|
: "-fo-\t\t\t\t# do not overwrite\n"); |
95 |
– |
printf("-i %-9ld\t\t\t# photon heap size increment\n", |
96 |
– |
photonHeapSizeInc); |
98 |
|
printf("-ma %.2f %.2f %.2f\t\t# scattering albedo\n", |
99 |
|
colval(salbedo,RED), colval(salbedo,GRN), colval(salbedo,BLU)); |
100 |
|
printf("-me %.2e %.2e %.2e\t# extinction coefficient\n", |
101 |
|
colval(cextinction,RED), colval(cextinction,GRN), |
102 |
|
colval(cextinction,BLU)); |
103 |
|
printf("-mg %.2f\t\t\t# scattering eccentricity\n", seccg); |
104 |
+ |
#if NIX |
105 |
+ |
/* Multiprocessing on NIX only */ |
106 |
+ |
printf("-n %d\t\t\t\t# number of parallel processes\n", nproc); |
107 |
+ |
#endif |
108 |
|
printf("-t %-9d\t\t\t# time between reports\n", photonRepTime); |
109 |
< |
|
109 |
> |
printf(verbose ? "-v+\t\t\t\t# verbose console output\n" |
110 |
> |
: "-v-\t\t\t\t# terse console output\n"); |
111 |
|
#ifdef PMAP_ROI |
112 |
|
/* Ziss option for ze egg-spurtz only! */ |
113 |
< |
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]); |
113 |
> |
puts("-api xmin ymin zmin\n xmax ymax zmax\t\t# region of interest"); |
114 |
|
#endif |
115 |
+ |
#ifdef EVALDRC_HACK |
116 |
+ |
/* ... and ziss one... */ |
117 |
+ |
puts("-A\t\t\t\t# angular source file"); |
118 |
+ |
#endif |
119 |
|
} |
120 |
|
|
121 |
|
|
114 |
– |
|
115 |
– |
|
122 |
|
int main (int argc, char* argv []) |
123 |
|
{ |
124 |
|
#define check(ol, al) if (argv [i][ol] || \ |
186 |
|
|
187 |
|
else if (!strcmp(argv [i] + 2, "pm")) { |
188 |
|
/* Max photon bounces */ |
189 |
< |
check(4, "i"); |
189 |
> |
check(4, "i"); |
190 |
|
photonMaxBounce = atol(argv [++i]); |
191 |
< |
if (!photonMaxBounce) |
192 |
< |
goto badopt; |
191 |
> |
if (photonMaxBounce <= 0) |
192 |
> |
error(USER, "max photon bounces must be > 0"); |
193 |
|
} |
194 |
|
|
195 |
|
else if (!strcmp(argv [i] + 2, "pp")) { |
206 |
|
goto badopt; |
207 |
|
} |
208 |
|
|
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 |
– |
|
209 |
|
else if (!strcmp(argv [i] + 2, "pc")) { |
210 |
|
/* Caustic photon map */ |
211 |
|
check(4, "ss"); |
252 |
|
preDistrib = atof(argv [++i]); |
253 |
|
if (preDistrib <= 0) |
254 |
|
error(USER, "predistribution factor must be > 0"); |
255 |
< |
} |
255 |
> |
} |
256 |
> |
|
257 |
> |
else if (!strcmp(argv [i] + 2, "pM")) { |
258 |
> |
/* Max predistribution passes */ |
259 |
> |
check(4, "i"); |
260 |
> |
maxPreDistrib = atoi(argv [++i]); |
261 |
> |
if (maxPreDistrib <= 0) |
262 |
> |
error(USER, "max predistribution passes must be > 0"); |
263 |
> |
} |
264 |
|
|
265 |
|
#ifdef PMAP_ROI |
266 |
< |
/* Region of interest; ziss option for ze egg-spurtz only! */ |
266 |
> |
/* Add region of interest; for ze egg-spurtz only! */ |
267 |
|
else if (!strcmp(argv [i] + 2, "pi")) { |
268 |
< |
int j; |
268 |
> |
unsigned j, n = pmapNumROI; |
269 |
|
check(4, "ffffff"); |
270 |
< |
for (j = 0; j < 6; j++) |
271 |
< |
pmapROI [j] = atof(argv [++i]); |
272 |
< |
} |
270 |
> |
|
271 |
> |
pmapROI = realloc(pmapROI, |
272 |
> |
++pmapNumROI * sizeof(PhotonMapROI)); |
273 |
> |
if (!pmapROI) |
274 |
> |
error(SYSTEM, "failed to allocate ROI"); |
275 |
> |
|
276 |
> |
pmapROI [n].min [0] = atof(argv [++i]); |
277 |
> |
pmapROI [n].min [1] = atof(argv [++i]); |
278 |
> |
pmapROI [n].min [2] = atof(argv [++i]); |
279 |
> |
pmapROI [n].max [0] = atof(argv [++i]); |
280 |
> |
pmapROI [n].max [1] = atof(argv [++i]); |
281 |
> |
pmapROI [n].max [2] = atof(argv [++i]); |
282 |
> |
|
283 |
> |
for (j = 0; j < 3; j++) |
284 |
> |
if (pmapROI [n].min [j] >= pmapROI [n].max [j]) |
285 |
> |
error(USER, |
286 |
> |
"invalid region of interest (swapped min/max?)"); |
287 |
> |
} |
288 |
|
#endif |
289 |
|
|
290 |
|
else if (!strcmp(argv [i] + 2, "pP")) { |
307 |
|
} |
308 |
|
|
309 |
|
if (argv[i][3] == 'O') { |
310 |
< |
/* Get port modifiers file */ |
311 |
< |
rval = wordfile(portLp, getpath(argv [++i], |
312 |
< |
getrlibpath(), R_OK)); |
310 |
> |
/* Get port modifiers from file */ |
311 |
> |
rval = wordfile(portLp, AMBLLEN-(portLp-amblist), |
312 |
> |
getpath(argv [++i], getrlibpath(), R_OK)); |
313 |
> |
|
314 |
|
if (rval < 0) { |
315 |
|
sprintf(errmsg, "cannot open photon port file %s", |
316 |
|
argv [i]); |
340 |
|
|
341 |
|
if (argv[i][3] == 'S') { |
342 |
|
/* Get sensor modifiers from file */ |
343 |
< |
rval = wordfile(sensLp, getpath(argv [++i], |
344 |
< |
getrlibpath(), R_OK)); |
343 |
> |
rval = wordfile(sensLp, MAXSET-(sensLp-photonSensorList), |
344 |
> |
getpath(argv [++i], getrlibpath(), R_OK)); |
345 |
> |
|
346 |
|
if (rval < 0) { |
347 |
|
sprintf(errmsg, "cannot open antimatter sensor file %s", |
348 |
|
argv [i]); |
400 |
|
|
401 |
|
else goto badopt; |
402 |
|
break; |
403 |
< |
|
391 |
< |
case 'i': /* Photon heap size increment */ |
392 |
< |
check(2, "i"); |
393 |
< |
photonHeapSizeInc = atol(argv [++i]); |
394 |
< |
break; |
395 |
< |
|
403 |
> |
|
404 |
|
case 'm': /* Medium */ |
405 |
|
switch (argv[i][2]) { |
406 |
|
case 'e': /* Eggs-tinction coefficient */ |
425 |
|
default: goto badopt; |
426 |
|
} |
427 |
|
break; |
428 |
< |
|
428 |
> |
#if NIX |
429 |
> |
case 'n': /* Num parallel processes (NIX only) */ |
430 |
> |
check(2, "i"); |
431 |
> |
nproc = atoi(argv [++i]); |
432 |
> |
|
433 |
> |
if (nproc > PMAP_MAXPROC) { |
434 |
> |
nproc = PMAP_MAXPROC; |
435 |
> |
sprintf(errmsg, "too many parallel processes, clamping to " |
436 |
> |
"%d\n", nproc); |
437 |
> |
error(WARNING, errmsg); |
438 |
> |
} |
439 |
> |
break; |
440 |
> |
#endif |
441 |
|
case 't': /* Timer */ |
442 |
|
check(2, "i"); |
443 |
|
photonRepTime = atoi(argv [++i]); |
444 |
|
break; |
445 |
< |
|
445 |
> |
|
446 |
> |
case 'v': /* Verbosity */ |
447 |
> |
check_bool(2, verbose); |
448 |
> |
break; |
449 |
> |
#ifdef EVALDRC_HACK |
450 |
> |
case 'A': /* Angular source file */ |
451 |
> |
check(2,"s"); |
452 |
> |
angsrcfile = argv[++i]; |
453 |
> |
break; |
454 |
> |
#endif |
455 |
|
default: goto badopt; |
456 |
|
} |
457 |
|
} |
491 |
|
error(USER, "no photon maps specified"); |
492 |
|
|
493 |
|
readoct(octname, loadflags, &thescene, NULL); |
494 |
+ |
#ifdef EVALDRC_HACK |
495 |
+ |
if (angsrcfile) |
496 |
+ |
readobj(angsrcfile); /* load angular sources */ |
497 |
+ |
#endif |
498 |
|
nsceneobjs = nobjects; |
499 |
|
|
500 |
|
/* Get sources */ |
503 |
|
/* Do forward pass and build photon maps */ |
504 |
|
if (contribPmap) |
505 |
|
/* Just build contrib pmap, ignore others */ |
506 |
< |
distribPhotonContrib(contribPmap); |
506 |
> |
distribPhotonContrib(contribPmap, nproc); |
507 |
|
else |
508 |
< |
distribPhotons(photonMaps); |
508 |
> |
distribPhotons(photonMaps, nproc); |
509 |
|
|
510 |
|
/* Save photon maps; no idea why GCC needs an explicit cast here... */ |
511 |
|
savePmaps((const PhotonMap**)photonMaps, argc, argv); |