Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77999511
pmapio.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 17, 18:33
Size
5 KB
Mime Type
text/x-c
Expires
Mon, Aug 19, 18:33 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19964469
Attached To
R10977 RADIANCE Photon Map
pmapio.c
View Options
#ifndef lint
static const char RCSid[] = "$Id: pmapio.c,v 2.13 2021/02/18 17:08:50 rschregle Exp $";
#endif
/*
=========================================================================
Photon map portable file I/O
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
(c) Fraunhofer Institute for Solar Energy Systems,
supported by the German Research Foundation
(DFG LU-204/10-2, "Fassadenintegrierte Regelsysteme FARESYS")
(c) Lucerne University of Applied Sciences and Arts,
supported by the Swiss National Science Foundation
(SNSF #147053, "Daylight Redirecting Components",
SNSF #179067, "Light Fields for Spatio-Temporal Glare Assessment")
=========================================================================
$Id: pmapio.c,v 2.13 2021/02/18 17:08:50 rschregle Exp $
*/
#include "pmapio.h"
#include "pmapdiag.h"
#include "resolu.h"
void savePhotonMap (const PhotonMap *pmap, const char *fname,
int argc, char **argv
)
{
unsigned long i, j;
FILE *file;
if (!pmap || !pmap -> numPhotons || !validPmapType(pmap -> type)) {
error(INTERNAL, "attempt to save empty or invalid photon map");
return;
}
if (verbose) {
sprintf(errmsg, "Saving %s (%ld photons)\n",
fname, pmap -> numPhotons
);
eputs(errmsg);
fflush(stderr);
}
if (!(file = fopen(fname, "wb"))) {
sprintf(errmsg, "can't open photon map file %s", fname);
error(SYSTEM, errmsg);
}
/* Write header */
newheader("RADIANCE", file);
/* Write command line */
printargs(argc, argv, file);
/* Include statistics in info text */
fprintf(file,
"NumPhotons\t= %ld\n"
"AvgFlux\t\t= [%.2e, %.2e, %.2e]\n"
"Bbox\t\t= [%.3f, %.3f, %.3f] [%.3f, %.3f, %.3f]\n"
"CoG\t\t= [%.3f, %.3f, %.3f]\n"
"MaxDist^2\t= %.3f\n",
pmap -> numPhotons,
pmap -> photonFlux [0], pmap -> photonFlux [1], pmap -> photonFlux [2],
pmap -> minPos [0], pmap -> minPos [1], pmap -> minPos [2],
pmap -> maxPos [0], pmap -> maxPos [1], pmap -> maxPos [2],
pmap -> CoG [0], pmap -> CoG [1], pmap -> CoG [2],
pmap -> CoGdist
);
/* Write format, including human-readable file version */
fputformat((char *)pmapFormat [pmap -> type], file);
fprintf(file, "VERSION=%s\n", PMAP_FILEVER);
/* Empty line = end of header */
putc('\n', file);
/* Write machine-readable file format version */
putstr(PMAP_FILEVER, file);
/* Write number of photons as fixed size, which possibly results in
* padding of MSB with 0 on some platforms. Unlike sizeof() however,
* this ensures portability since this value may span 32 or 64 bits
* depending on platform. */
putint(pmap -> numPhotons, PMAP_LONGSIZE, file);
/* Write average photon flux */
for (j = 0; j < 3; j++)
putflt(pmap -> photonFlux [j], file);
/* Write max and min photon positions */
for (j = 0; j < 3; j++) {
putflt(pmap -> minPos [j], file);
putflt(pmap -> maxPos [j], file);
}
/* Write centre of gravity */
for (j = 0; j < 3; j++)
putflt(pmap -> CoG [j], file);
/* Write avg distance to centre of gravity */
putflt(pmap -> CoGdist, file);
/* Save photon storage */
#ifdef PMAP_OOC
if (OOC_SavePhotons(pmap, file)) {
#else
if (kdT_SavePhotons(pmap, file)) {
#endif
sprintf(errmsg, "error writing photon map file %s", fname);
error(SYSTEM, errmsg);
}
fclose(file);
}
PhotonMapType loadPhotonMap (PhotonMap *pmap, const char *fname)
{
PhotonMapType ptype = PMAP_TYPE_NONE;
char format [MAXFMTLEN];
unsigned long i, j;
FILE *file;
if (!pmap)
return PMAP_TYPE_NONE;
if ((file = fopen(fname, "rb")) == NULL) {
sprintf(errmsg, "can't open photon map file %s", fname);
error(SYSTEM, errmsg);
}
/* Get format string */
strcpy(format, PMAP_FORMAT_GLOB);
if (checkheader(file, format, NULL) != 1) {
sprintf(errmsg, "photon map file %s has an unknown format", fname);
error(USER, errmsg);
}
/* Identify photon map type from format string */
for (ptype = 0;
ptype < NUM_PMAP_TYPES && strcmp(pmapFormat [ptype], format);
ptype++
);
if (!validPmapType(ptype)) {
sprintf(errmsg, "file %s contains an unknown photon map type", fname);
error(USER, errmsg);
}
initPhotonMap(pmap, ptype);
/* Get file format version and check for compatibility */
if (strcmp(getstr(format, file), PMAP_FILEVER))
error(USER, "incompatible photon map file format");
/* Get number of photons as fixed size, which possibly results in
* padding of MSB with 0 on some platforms. Unlike sizeof() however,
* this ensures portability since this value may span 32 or 64 bits
* depending on platform. */
pmap -> numPhotons = getint(PMAP_LONGSIZE, file);
/* Get average photon flux */
for (j = 0; j < 3; j++)
pmap -> photonFlux [j] = getflt(file);
/* Get max and min photon positions */
for (j = 0; j < 3; j++) {
pmap -> minPos [j] = getflt(file);
pmap -> maxPos [j] = getflt(file);
}
/* Get centre of gravity */
for (j = 0; j < 3; j++)
pmap -> CoG [j] = getflt(file);
/* Get avg distance to centre of gravity */
pmap -> CoGdist = getflt(file);
/* Load photon storage */
#ifdef PMAP_OOC
if (OOC_LoadPhotons(pmap, file)) {
#else
if (kdT_LoadPhotons(pmap, file)) {
#endif
sprintf(errmsg, "error reading photon map file %s", fname);
error(SYSTEM, errmsg);
}
fclose(file);
return ptype;
}
Event Timeline
Log In to Comment