3 |
|
#endif |
4 |
|
|
5 |
|
/* |
6 |
< |
====================================================================== |
7 |
< |
Photon map file I/O |
6 |
> |
======================================================================= |
7 |
> |
Photon map portable file I/O |
8 |
|
|
9 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
10 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
11 |
+ |
supported by the German Research Foundation |
12 |
+ |
(DFG LU-204/10-2, "Fassadenintegrierte Regelsysteme FARESYS") |
13 |
|
(c) Lucerne University of Applied Sciences and Arts, |
14 |
< |
supported by the Swiss National Science Foundation (SNSF, #147053) |
15 |
< |
====================================================================== |
14 |
> |
supported by the Swiss National Science Foundation |
15 |
> |
(SNSF #147053, "Daylight Redirecting Components", |
16 |
> |
SNSF #179067, "Light Fields for Spatio-Temporal Glare Assessment") |
17 |
> |
======================================================================= |
18 |
|
|
19 |
|
$Id$ |
20 |
|
*/ |
38 |
|
return; |
39 |
|
} |
40 |
|
|
41 |
< |
if (photonRepTime) { |
41 |
> |
if (verbose) { |
42 |
|
if (pmap -> numPrimary) |
43 |
< |
sprintf(errmsg, "Saving %s (%ld photons, %d primaries)...\n", |
43 |
> |
sprintf(errmsg, "Saving %s (%ld photons, %d primaries)\n", |
44 |
|
fname, pmap -> numPhotons, pmap -> numPrimary); |
45 |
< |
else sprintf(errmsg, "Saving %s (%ld photons)...\n", fname, |
45 |
> |
else sprintf(errmsg, "Saving %s (%ld photons)\n", fname, |
46 |
|
pmap -> numPhotons); |
47 |
|
|
48 |
|
eputs(errmsg); |
61 |
|
printargs(argc, argv, file); |
62 |
|
|
63 |
|
/* Include statistics in info text */ |
64 |
< |
fprintf(file, "NumPhotons\t= %ld\n" |
65 |
< |
"AvgFlux\t\t= [%.2e, %.2e, %.2e]\n" |
66 |
< |
"Bbox\t\t= [%.3f, %.3f, %.3f] [%.3f, %.3f, %.3f]\n" |
67 |
< |
"CoG\t\t= [%.3f, %.3f, %.3f]\n" |
68 |
< |
"MaxDist^2\t= %.3f\n", |
69 |
< |
pmap -> numPhotons, pmap -> photonFlux [0], |
70 |
< |
pmap -> photonFlux [1], pmap -> photonFlux [2], |
71 |
< |
pmap -> minPos [0], pmap -> minPos [1], pmap -> minPos [2], |
72 |
< |
pmap -> maxPos [0], pmap -> maxPos [1], pmap -> maxPos [2], |
73 |
< |
pmap -> CoG [0], pmap -> CoG [1], pmap -> CoG [2], |
74 |
< |
pmap -> CoGdist); |
64 |
> |
fprintf( |
65 |
> |
file, |
66 |
> |
"NumPhotons\t= %ld\n" |
67 |
> |
"AvgFlux\t\t= [%.2e, %.2e, %.2e]\n" |
68 |
> |
"Bbox\t\t= [%.3f, %.3f, %.3f] [%.3f, %.3f, %.3f]\n" |
69 |
> |
"CoG\t\t= [%.3f, %.3f, %.3f]\n" |
70 |
> |
"MaxDist^2\t= %.3f\n", |
71 |
> |
pmap -> numPhotons, |
72 |
> |
pmap -> photonFlux [0], pmap -> photonFlux [1], pmap -> photonFlux [2], |
73 |
> |
pmap -> minPos [0], pmap -> minPos [1], pmap -> minPos [2], |
74 |
> |
pmap -> maxPos [0], pmap -> maxPos [1], pmap -> maxPos [2], |
75 |
> |
pmap -> CoG [0], pmap -> CoG [1], pmap -> CoG [2], |
76 |
> |
pmap -> CoGdist |
77 |
> |
); |
78 |
|
|
79 |
|
if (pmap -> primaries) |
80 |
|
fprintf(file, "%d primary rays\n", pmap -> numPrimary); |
81 |
|
|
82 |
< |
/* Write format */ |
82 |
> |
/* Write format, including human-readable file version */ |
83 |
|
fputformat((char*)pmapFormat [pmap -> type], file); |
84 |
|
fprintf(file, "VERSION=%s\n", PMAP_FILEVER); |
85 |
|
|
86 |
|
/* Empty line = end of header */ |
87 |
|
putc('\n', file); |
88 |
|
|
89 |
< |
/* Write file format version */ |
89 |
> |
/* Write machine-readable file format version */ |
90 |
|
putstr(PMAP_FILEVER, file); |
91 |
|
|
92 |
< |
/* Write number of photons */ |
93 |
< |
putint(pmap -> numPhotons, sizeof(pmap -> numPhotons), file); |
92 |
> |
/* Write number of photons as fixed size, which possibly results in |
93 |
> |
* padding of MSB with 0 on some platforms. Unlike sizeof() however, |
94 |
> |
* this ensures portability since this value may span 32 or 64 bits |
95 |
> |
* depending on platform. */ |
96 |
> |
putint(pmap -> numPhotons, PMAP_LONGSIZE, file); |
97 |
|
|
98 |
|
/* Write average photon flux */ |
99 |
|
for (j = 0; j < 3; j++) |
120 |
|
PhotonPrimary *prim = pmap -> primaries + i; |
121 |
|
|
122 |
|
putint(prim -> srcIdx, sizeof(prim -> srcIdx), file); |
123 |
+ |
#ifdef PMAP_PRIMARYDIR |
124 |
|
putint(prim -> dir, sizeof(prim -> dir), file); |
125 |
+ |
#endif |
126 |
|
#ifdef PMAP_PRIMARYPOS |
127 |
|
for (j = 0; j < 3; j++) |
128 |
|
putflt(prim -> pos [j], file); |
151 |
|
PhotonMapType loadPhotonMap (PhotonMap *pmap, const char *fname) |
152 |
|
{ |
153 |
|
PhotonMapType ptype = PMAP_TYPE_NONE; |
154 |
< |
char format [128]; |
154 |
> |
char format [MAXFMTLEN]; |
155 |
|
unsigned long i, j; |
156 |
|
FILE *file; |
157 |
|
|
187 |
|
if (strcmp(getstr(format, file), PMAP_FILEVER)) |
188 |
|
error(USER, "incompatible photon map file format"); |
189 |
|
|
190 |
< |
/* Get number of photons */ |
191 |
< |
pmap -> numPhotons = getint(sizeof(pmap -> numPhotons), file); |
190 |
> |
/* Get number of photons as fixed size, which possibly results in |
191 |
> |
* padding of MSB with 0 on some platforms. Unlike sizeof() however, |
192 |
> |
* this ensures portability since this value may span 32 or 64 bits |
193 |
> |
* depending on platform. */ |
194 |
> |
pmap -> numPhotons = getint(PMAP_LONGSIZE, file); |
195 |
|
|
196 |
|
/* Get average photon flux */ |
197 |
|
for (j = 0; j < 3; j++) |
222 |
|
PhotonPrimary *prim = pmap -> primaries + i; |
223 |
|
|
224 |
|
prim -> srcIdx = getint(sizeof(prim -> srcIdx), file); |
225 |
< |
|
225 |
> |
#ifdef PMAP_PRIMARYDIR |
226 |
|
prim -> dir = getint(sizeof(prim -> dir), file); |
227 |
+ |
#endif |
228 |
|
#ifdef PMAP_PRIMARYPOS |
229 |
|
for (j = 0; j < 3; j++) |
230 |
|
prim -> pos [j] = getflt(file); |