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.12 by rschregle, Wed Nov 21 19:30:59 2018 UTC vs.
Revision 2.13 by rschregle, Thu Jan 10 17:32:39 2019 UTC

# Line 25 | Line 25 | static const char RCSid[] = "$Id$";
25   #include "random.h"
26   #include "math.h"
27  
28 #define PMAPDUMP_REC "$Revision$"  
28  
30
29   /* Defaults */
30   /*    Sphere radius as fraction of avg. intersphere dist */
31   /*    Relative scale for sphere radius (fudge factor) */
# Line 43 | Line 41 | typedef struct {
41   } RadianceDef;
42  
43  
44 + /* We use %e for the material def to preserve precision when outputting
45 +   photon flux */
46   const RadianceDef radDefs [] = {
47 <   {  "void plastic mat.global\n0\n0\n5 %f %f %f 0 0\n",
47 >   {  "void glow mat.global\n0\n0\n4 %e %e %e 0\n",
48        "mat.global sphere obj.global\n0\n0\n4 %g %g %g %g\n"
49     },
50 <   {  "void plastic mat.pglobal\n0\n0\n5 %f %f %f 0 0\n",
51 <      "mat.pglobal sphere obj.global\n0\n0\n4 %g %g %g %g\n"
50 >   {  "void glow mat.pglobal\n0\n0\n4 %e %e %e 0\n",
51 >      "mat.pglobal sphere obj.pglobal\n0\n0\n4 %g %g %g %g\n"
52     },
53 <   {  "void plastic mat.caustic\n0\n0\n5 %f %f %f 0 0\n",
53 >   {  "void glow mat.caustic\n0\n0\n4 %e %e %e 0\n",
54        "mat.caustic sphere obj.caustic\n0\n0\n4 %g %g %g %g\n"
55     },
56 <   {  "void plastic mat.volume\n0\n0\n5 %f %f %f 0 0\n",
56 >   {  "void glow mat.volume\n0\n0\n4 %e %e %e 0\n",
57        "mat.volume sphere obj.volume\n0\n0\n4 %g %g %g %g\n"
58     },
59 <   {  "void plastic mat.direct\n0\n0\n5 %f %f %f 0 0\n",
59 >   {  "void glow mat.direct\n0\n0\n4 %e %e %e 0\n",
60        "mat.direct sphere obj.direct\n0\n0\n4 %g %g %g %g\n"
61     },
62 <   {  "void plastic mat.contrib\n0\n0\n5 %f %f %f 0 0\n",
62 >   {  "void glow mat.contrib\n0\n0\n4 %e %e %e 0\n",
63        "mat.contrib sphere obj.contrib\n0\n0\n4 %g %g %g %g\n"
64     }
65   };
# Line 71 | Line 71 | const RadianceDef radDefs [] = {
71                                            direct         = magenta
72                                            contrib        = yellow */
73   const COLOR colDefs [] = {
74 <   {0, 0, 1}, {0, 1, 1}, {1, 0, 0}, {0, 1, 0}, {1, 0, 1}, {1, 1, 0}
74 >   {0.25, 0.25, 2}, {0.1, 1, 1}, {1, 0.1, 0.1},
75 >   {0.1, 1, 0.1}, {1, 0.1, 1}, {1, 1, 0.1}
76   };
77  
78  
# Line 79 | Line 80 | int main (int argc, char** argv)
80   {
81     char           format [MAXFMTLEN];
82     RREAL          rad, radScale = RADSCALE, extent, dumpRatio;
83 <   unsigned       arg, j, ptype, dim;
83 >   unsigned       arg, j, ptype, dim, fluxCol = 0;
84     long           numSpheres = NSPHERES;
85     COLOR          customCol = {0, 0, 0};
86     FILE           *pmapFile;
# Line 89 | Line 90 | int main (int argc, char** argv)
90   #ifdef PMAP_OOC
91     char           leafFname [1024];
92   #endif
93 <  
93 >
94 >   int setBool(char *str, int pos, int *var)
95 >   {
96 >      switch ((str) [pos]) {
97 >         case '\0':
98 >            *var = !*var;
99 >            break;
100 >         case 'y': case 'Y': case 't': case 'T': case '+': case '1':
101 >            *var = 1;
102 >            break;
103 >         case 'n': case 'N': case 'f': case 'F': case '-': case '0':
104 >            *var = 0;
105 >            break;
106 >         default:
107 >            return 0;
108 >      }
109 >      
110 >      return 1;
111 >   }
112 >
113     if (argc < 2) {
114        puts("Dump photon maps as RADIANCE scene description\n");
115        printf("Usage: %s "
116 <             "[-r radscale1] [-n nspheres1] [-c rcol1 gcol1 bcol1] pmap1 "
117 <             "[-r radscale2] [-n nspheres2] [-c rcol2 gcol2 bcol2] pmap2 "
116 >             "[-r radscale1] [-n nspheres1] [-f | -c rcol1 gcol1 bcol1] pmap1 "
117 >             "[-r radscale2] [-n nspheres2] [-f | -c rcol2 gcol2 bcol2] pmap2 "
118               "...\n", argv [0]);
119        return 1;
120     }
# Line 114 | Line 134 | int main (int argc, char** argv)
134                 break;
135                
136              case 'c':
137 +               if (fluxCol)
138 +                  error(USER, "-f and -c are mutually exclusive");
139 +              
140 +               if (badarg(argc - arg - 1, &argv [arg + 1], "fff"))
141 +                  error(USER, "invalid RGB colour");
142 +                                
143                 for (j = 0; j < 3; j++)
144 <                  if ((customCol [j] = atof(argv [++arg])) <= 0)
119 <                     error(USER, "invalid RGB colour");
144 >                  customCol [j] = atof(argv [++arg]);
145                 break;
146                
147 +            case 'f':
148 +               if (intens(customCol) > 0)
149 +                  error(USER, "-f and -c are mutually exclusive");
150 +                  
151 +               if (!setBool(argv [arg], 2, &fluxCol))
152 +                  error(USER, "invalid option syntax at -f");
153 +               break;
154 +              
155              default:
156                 sprintf(errmsg, "unknown option %s", argv [arg]);
157                 error(USER, errmsg);
# Line 127 | Line 160 | int main (int argc, char** argv)
160          
161           continue;
162        }
163 <      
163 >
164        /* Dump photon map */
165        if (!(pmapFile = fopen(argv [arg], "rb"))) {
166           sprintf(errmsg, "can't open %s", argv [arg]);
167           error(SYSTEM, errmsg);
168        }
169 <        
169 >
170        /* Get format string */
171        strcpy(format, PMAP_FORMAT_GLOB);
172        if (checkheader(pmapFile, format, NULL) != 1) {
# Line 141 | Line 174 | int main (int argc, char** argv)
174                   argv [arg], format);
175           error(USER, errmsg);
176        }
177 <      
177 >
178        /* Identify photon map type from format string */
179        for (ptype = 0;
180             ptype < NUM_PMAP_TYPES && strcmp(pmapFormat [ptype], format);
181             ptype++);
182 <      
182 >
183        if (!validPmapType(ptype)) {
184           sprintf(errmsg, "file %s contains an unknown photon map type",
185                  argv [arg]);
# Line 156 | Line 189 | int main (int argc, char** argv)
189        /* Get file format version and check for compatibility */
190        if (strcmp(getstr(format, pmapFile), PMAP_FILEVER))      
191           error(USER, "incompatible photon map file format");
192 <        
192 >
193        /* Dump command line as comment */
194        fputs("# ", stdout);
195        printargs(argc, argv, stdout);
196        fputc('\n', stdout);
197 +
198 +      /* Dump common material def if constant for all photons,
199 +         i.e. independent of individual flux */
200 +      if (!fluxCol) {
201 +         if (intens(customCol) > 0)
202 +            printf(radDefs [ptype].mat,
203 +                   customCol [0], customCol [1], customCol [2]);
204 +         else
205 +            printf(radDefs [ptype].mat, colDefs [ptype][0],
206 +                   colDefs [ptype][1], colDefs [ptype][2]);
207 +         fputc('\n', stdout);
208 +      }
209        
165      /* Dump material def */
166      if (intens(customCol) > 0)
167         printf(radDefs [ptype].mat,
168                customCol [0], customCol [1], customCol [2]);
169      else
170         printf(radDefs [ptype].mat,
171                colDefs [ptype][0], colDefs [ptype][1], colDefs [ptype][2]);
172      fputc('\n', stdout);
173      
210        /* Get number of photons */
211        pm.numPhotons = getint(sizeof(pm.numPhotons), pmapFile);
212 <      
212 >
213        /* Skip avg photon flux */
214        for (j = 0; j < 3; j++)
215           getflt(pmapFile);
216 <      
216 >
217        /* Get distribution extent (min & max photon positions) */
218        for (j = 0; j < 3; j++) {
219           pm.minPos [j] = getflt(pmapFile);
# Line 215 | Line 251 | int main (int argc, char** argv)
251   #ifdef PMAP_PRIMARYDIR
252           /* Skip primary incident dir */
253           getint(sizeof(pri.dir), pmapFile);        
254 < #endif        
255 < #ifdef PMAP_PRIMARYPOS        
254 > #endif
255 > #ifdef PMAP_PRIMARYPOS
256           /* Skip primary hitpoint */
257           for (j = 0; j < 3; j++)
258              getflt(pmapFile);
# Line 238 | Line 274 | int main (int argc, char** argv)
274        /* Load photons */      
275        while (pm.numPhotons-- > 0) {
276   #ifdef PMAP_OOC
277 <         /* Get entire photon record
277 >         /* Get entire photon record from ooC octree leaf file
278              !!! OOC PMAP FILES CURRENTLY DON'T USE PORTABLE I/O !!! */
279           if (!fread(&p, sizeof(p), 1, pmapFile)) {
280              sprintf(errmsg, "error reading OOC leaf file %s", leafFname);
281              error(SYSTEM, errmsg);
282           }
283 < #else        
284 <         /* Get photon position */            
283 > #else /* kd-tree */
284 >         /* Get photon position */
285           for (j = 0; j < 3; j++)
286              p.pos [j] = getflt(pmapFile);
287 < #endif
288 <         /* Dump photon probabilistically acc. to target sphere count */
253 <         if (frandom() <= dumpRatio) {
254 <            printf(radDefs [ptype].obj, p.pos [0], p.pos [1], p.pos [2], rad);
255 <            fputc('\n', stdout);
256 <         }
257 <        
258 < #ifndef PMAP_OOC
259 <         /* Skip photon normal and flux */
287 >
288 >         /* Get photon normal (currently not used) */
289           for (j = 0; j < 3; j++)
290 <            getint(sizeof(p.norm [j]), pmapFile);
291 <            
292 < #ifdef PMAP_FLOAT_FLUX
290 >            p.norm [j] = getint(1, pmapFile);
291 >
292 >         /* Get photon flux */
293 >   #ifdef PMAP_FLOAT_FLUX
294           for (j = 0; j < 3; j++)
295 <            getflt(pmapFile);
296 < #else      
295 >            p.flux [j] = getflt(pmapFile);
296 >   #else
297           for (j = 0; j < 4; j++)
298 <            getint(1, pmapFile);
299 < #endif
298 >            p.flux [j] = getint(1, pmapFile);
299 >   #endif
300  
301           /* Skip primary ray index */
302           getint(sizeof(p.primary), pmapFile);
# Line 274 | Line 304 | int main (int argc, char** argv)
304           /* Skip flags */
305           getint(sizeof(p.flags), pmapFile);
306   #endif
307 <        
307 >
308 >         /* Dump photon probabilistically acc. to target sphere count */
309 >         if (frandom() <= dumpRatio) {
310 >            if (fluxCol) {
311 >               /* Dump individual material def per photon acc. to flux */
312 >               getPhotonFlux(&p, customCol);
313 >               printf(radDefs [ptype].mat,
314 >                      customCol [0], customCol [1], customCol [2]);
315 >               fputc('\n', stdout);
316 >            }
317 >            
318 >            printf(radDefs [ptype].obj, p.pos [0], p.pos [1], p.pos [2], rad);
319 >            fputc('\n', stdout);
320 >         }
321 >              
322           if (ferror(pmapFile) || feof(pmapFile)) {
323              sprintf(errmsg, "error reading %s", argv [arg]);
324              error(USER, errmsg);
# Line 287 | Line 331 | int main (int argc, char** argv)
331        radScale = RADSCALE;
332        numSpheres = NSPHERES;
333        customCol [0] = customCol [1] = customCol [2] = 0;
334 +      fluxCol = 0;
335     }
336    
337     return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines