ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmapdump.c
(Generate patch)

Comparing ray/src/rt/pmapdump.c (file contents):
Revision 2.3 by rschregle, Fri May 8 13:20:23 2015 UTC vs.
Revision 2.7 by rschregle, Tue May 17 17:39:47 2016 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4 +
5   /*
6 <   ==================================================================
6 >   ======================================================================
7     Dump photon maps as RADIANCE scene description to stdout
8  
9     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
10     (c) Fraunhofer Institute for Solar Energy Systems,
11     (c) Lucerne University of Applied Sciences and Arts,
12 <   supported by the Swiss National Science Foundation (SNSF, #147053)
13 <   ==================================================================
12 >       supported by the Swiss National Science Foundation (SNSF, #147053)
13 >   ======================================================================
14    
15     $Id$
16   */
# Line 21 | Line 25
25   #include "random.h"
26   #include "math.h"
27  
28 + #define PMAPDUMP_REC "$Revision$"  
29  
30 +
31   /* Defaults */
32   /*    Sphere radius as fraction of avg. intersphere dist */
33   /*    Relative scale for sphere radius (fudge factor) */
# Line 37 | Line 43 | typedef struct {
43   } RadianceDef;
44  
45    
40 static char header [] = "$Revision$";
46  
42
47   /* Colour code is as follows:    global         = blue
48                                   precomp global = cyan
49                                   caustic        = red
# Line 71 | Line 75 | const RadianceDef radDefs [] = {
75  
76   int main (int argc, char** argv)
77   {
78 <   char format [128];
79 <   RREAL rad, radScale = RADSCALE, vol, dumpRatio;
80 <   FVECT minPos, maxPos;
81 <   unsigned arg, j, ptype;
82 <   long numPhotons, numSpheres = NSPHERES;
83 <   FILE *pmapFile;
84 <   Photon p;
78 >   char           format [128];
79 >   RREAL          rad, radScale = RADSCALE, vol, dumpRatio;
80 >   unsigned       arg, j, ptype;
81 >   long           numSpheres = NSPHERES;
82 >   FILE           *pmapFile;
83 >   PhotonMap      pm;
84 >   PhotonPrimary  pri;
85 >   Photon         p;
86 > #ifdef PMAP_OOC
87 >   char           leafFname [1024];
88 > #endif
89    
90     if (argc < 2) {
91        puts("Dump photon maps as RADIANCE scene description\n");
# Line 125 | Line 133 | int main (int argc, char** argv)
133        
134        /* Identify photon map type from format string */
135        for (ptype = 0;
136 <           strcmp(pmapFormat [ptype], format) && ptype < NUM_PMAP_TYPES;
136 >           ptype < NUM_PMAP_TYPES && strcmp(pmapFormat [ptype], format);
137             ptype++);
138        
139        if (!validPmapType(ptype)) {
# Line 135 | Line 143 | int main (int argc, char** argv)
143        }
144  
145        /* Get file format version and check for compatibility */
146 <      if (getint(sizeof(PMAP_FILEVER), pmapFile) != PMAP_FILEVER)
146 >      if (strcmp(getstr(format, pmapFile), PMAP_FILEVER))      
147           error(USER, "incompatible photon map file format");
148          
149        /* Dump command line as comment */
# Line 147 | Line 155 | int main (int argc, char** argv)
155        fputs(radDefs [ptype].mat, stdout);
156        fputc('\n', stdout);
157        
158 <      /* Get number of photons (is this sizeof() hack portable?) */
159 <      numPhotons = getint(sizeof(((PhotonMap*)NULL) -> heapSize), pmapFile);
158 >      /* Get number of photons */
159 >      pm.numPhotons = getint(sizeof(pm.numPhotons), pmapFile);
160        
161        /* Skip avg photon flux */
162        for (j = 0; j < 3; j++)
# Line 156 | Line 164 | int main (int argc, char** argv)
164        
165        /* Get distribution extent (min & max photon positions) */
166        for (j = 0; j < 3; j++) {
167 <         minPos [j] = getflt(pmapFile);
168 <         maxPos [j] = getflt(pmapFile);
167 >         pm.minPos [j] = getflt(pmapFile);
168 >         pm.maxPos [j] = getflt(pmapFile);
169        }
170        
171        /* Skip centre of gravity, and avg photon dist to it */
# Line 166 | Line 174 | int main (int argc, char** argv)
174        
175        /* Sphere radius based on avg intersphere dist
176           (= sphere distrib density ^-1/3) */
177 <      vol = (maxPos [0] - minPos [0]) * (maxPos [1] - minPos [1]) *
178 <            (maxPos [2] - minPos [2]);
177 >      vol = (pm.maxPos [0] - pm.minPos [0]) * (pm.maxPos [1] - pm.minPos [1]) *
178 >            (pm.maxPos [2] - pm.minPos [2]);
179        rad = radScale * RADCOEFF * pow(vol / numSpheres, 1./3.);
180        
181        /* Photon dump probability to satisfy target sphere count */
182 <      dumpRatio = numSpheres < numPhotons ? (float)numSpheres / numPhotons
183 <                                          : 1;
182 >      dumpRatio = numSpheres < pm.numPhotons
183 >                  ? (float)numSpheres / pm.numPhotons : 1;
184        
185 <      while (numPhotons-- > 0) {
185 >      /* Skip primary rays */
186 >      pm.numPrimary = getint(sizeof(pm.numPrimary), pmapFile);
187 >      while (pm.numPrimary-- > 0) {
188 >         getint(sizeof(pri.srcIdx) + sizeof(pri.dir), pmapFile);
189 >         for (j = 0; j < 3; j++)
190 >            getflt(pmapFile);
191 >      }
192 >
193 > #ifdef PMAP_OOC
194 >      /* Open leaf file with filename derived from pmap, replace pmapFile
195 >       * (which is currently the node file) */
196 >      strncpy(leafFname, argv [arg], 1024);
197 >      strncat(leafFname, PMAP_OOC_LEAFSUFFIX, 1024);
198 >      fclose(pmapFile);
199 >      if (!(pmapFile = fopen(leafFname, "rb"))) {
200 >         sprintf(errmsg, "cannot open leaf file %s", leafFname);
201 >         error(SYSTEM, errmsg);
202 >      }
203 > #endif
204 >            
205 >      /* Load photons */      
206 >      while (pm.numPhotons-- > 0) {
207 > #ifdef PMAP_OOC
208 >         /* Get entire photon record
209 >            !!! OOC PMAP FILES CURRENTLY DON'T USE PORTABLE I/O !!! */
210 >         if (!fread(&p, sizeof(p), 1, pmapFile)) {
211 >            sprintf(errmsg, "error reading OOC leaf file %s", leafFname);
212 >            error(SYSTEM, errmsg);
213 >         }
214 > #else        
215           /* Get photon position */            
216           for (j = 0; j < 3; j++)
217              p.pos [j] = getflt(pmapFile);
218 <
218 > #endif
219           /* Dump photon probabilistically acc. to target sphere count */
220           if (frandom() <= dumpRatio) {
221              printf(radDefs [ptype].obj, p.pos [0], p.pos [1], p.pos [2], rad);
222              fputc('\n', stdout);
223           }
224          
225 + #ifndef PMAP_OOC
226           /* Skip photon normal and flux */
227           for (j = 0; j < 3; j++)
228              getint(sizeof(p.norm [j]), pmapFile);
229              
230 <         #ifdef PMAP_FLOAT_FLUX
231 <            for (j = 0; j < 3; j++)
232 <               getflt(pmapFile);
233 <         #else      
234 <            for (j = 0; j < 4; j++)
235 <               getint(1, pmapFile);
236 <         #endif
230 > #ifdef PMAP_FLOAT_FLUX
231 >         for (j = 0; j < 3; j++)
232 >            getflt(pmapFile);
233 > #else      
234 >         for (j = 0; j < 4; j++)
235 >            getint(1, pmapFile);
236 > #endif
237  
238           /* Skip primary ray index */
239           getint(sizeof(p.primary), pmapFile);
240  
241           /* Skip flags */
242           getint(sizeof(p.flags), pmapFile);
243 + #endif
244          
245 <         if (feof(pmapFile)) {
245 >         if (ferror(pmapFile) || feof(pmapFile)) {
246              sprintf(errmsg, "error reading %s", argv [arg]);
247              error(USER, errmsg);
248           }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines