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.7 by rschregle, Tue May 17 17:39:47 2016 UTC vs.
Revision 2.12 by rschregle, Wed Nov 21 19:30:59 2018 UTC

# Line 42 | Line 42 | typedef struct {
42     char *mat, *obj;
43   } RadianceDef;
44  
45  
45  
47 /* Colour code is as follows:    global         = blue
48                                 precomp global = cyan
49                                 caustic        = red
50                                 volume         = green
51                                 direct         = magenta
52                                 contrib        = yellow */  
46   const RadianceDef radDefs [] = {
47 <   {  "void plastic mat.global\n0\n0\n5 0 0 1 0 0\n",
47 >   {  "void plastic mat.global\n0\n0\n5 %f %f %f 0 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 0 1 1 0 0\n",
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"
52     },
53 <   {  "void plastic mat.caustic\n0\n0\n5 1 0 0 0 0\n",
53 >   {  "void plastic mat.caustic\n0\n0\n5 %f %f %f 0 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 0 1 0 0 0\n",
56 >   {  "void plastic mat.volume\n0\n0\n5 %f %f %f 0 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 1 0 1 0 0\n",
59 >   {  "void plastic mat.direct\n0\n0\n5 %f %f %f 0 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 1 1 0 0 0\n",
62 >   {  "void plastic mat.contrib\n0\n0\n5 %f %f %f 0 0\n",
63        "mat.contrib sphere obj.contrib\n0\n0\n4 %g %g %g %g\n"
64     }
65   };
66  
67 + /* Default colour codes are as follows:   global         = blue
68 +                                          precomp global = cyan
69 +                                          caustic        = red
70 +                                          volume         = green
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}
75 + };
76  
77  
78   int main (int argc, char** argv)
79   {
80 <   char           format [128];
81 <   RREAL          rad, radScale = RADSCALE, vol, dumpRatio;
82 <   unsigned       arg, j, ptype;
80 >   char           format [MAXFMTLEN];
81 >   RREAL          rad, radScale = RADSCALE, extent, dumpRatio;
82 >   unsigned       arg, j, ptype, dim;
83     long           numSpheres = NSPHERES;
84 +   COLOR          customCol = {0, 0, 0};
85     FILE           *pmapFile;
86     PhotonMap      pm;
87     PhotonPrimary  pri;
# Line 89 | Line 92 | int main (int argc, char** argv)
92    
93     if (argc < 2) {
94        puts("Dump photon maps as RADIANCE scene description\n");
95 <      printf("Usage: %s [-r radscale1] [-n nspheres1] pmap1 "
96 <             "[-r radscale2] [-n nspheres2] pmap2 ...\n", argv [0]);
95 >      printf("Usage: %s "
96 >             "[-r radscale1] [-n nspheres1] [-c rcol1 gcol1 bcol1] pmap1 "
97 >             "[-r radscale2] [-n nspheres2] [-c rcol2 gcol2 bcol2] pmap2 "
98 >             "...\n", argv [0]);
99        return 1;
100     }
101    
# Line 108 | Line 113 | int main (int argc, char** argv)
113                    error(USER, "invalid number of spheres");
114                 break;
115                
116 +            case 'c':
117 +               for (j = 0; j < 3; j++)
118 +                  if ((customCol [j] = atof(argv [++arg])) <= 0)
119 +                     error(USER, "invalid RGB colour");
120 +               break;
121 +              
122              default:
123                 sprintf(errmsg, "unknown option %s", argv [arg]);
124                 error(USER, errmsg);
# Line 151 | Line 162 | int main (int argc, char** argv)
162        printargs(argc, argv, stdout);
163        fputc('\n', stdout);
164        
165 <      /* Dump material def */  
166 <      fputs(radDefs [ptype].mat, stdout);
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        
174        /* Get number of photons */
# Line 172 | Line 188 | int main (int argc, char** argv)
188        for (j = 0; j < 4; j++)
189           getflt(pmapFile);
190        
191 <      /* Sphere radius based on avg intersphere dist
192 <         (= sphere distrib density ^-1/3) */
193 <      vol = (pm.maxPos [0] - pm.minPos [0]) * (pm.maxPos [1] - pm.minPos [1]) *
194 <            (pm.maxPos [2] - pm.minPos [2]);
195 <      rad = radScale * RADCOEFF * pow(vol / numSpheres, 1./3.);
191 >      /* Sphere radius based on avg intersphere dist depending on
192 >         whether the distribution occupies a 1D line (!), a 2D plane,
193 >         or 3D volume (= sphere distrib density ^-1/d, where d is the
194 >         dimensionality of the distribution) */
195 >      for (j = 0, extent = 1.0, dim = 0; j < 3; j++) {
196 >         rad = pm.maxPos [j] - pm.minPos [j];
197 >        
198 >         if (rad > FTINY) {
199 >            dim++;
200 >            extent *= rad;
201 >         }
202 >      }
203 >
204 >      rad = radScale * RADCOEFF * pow(extent / numSpheres, 1./dim);
205        
206        /* Photon dump probability to satisfy target sphere count */
207        dumpRatio = numSpheres < pm.numPhotons
# Line 185 | Line 210 | int main (int argc, char** argv)
210        /* Skip primary rays */
211        pm.numPrimary = getint(sizeof(pm.numPrimary), pmapFile);
212        while (pm.numPrimary-- > 0) {
213 <         getint(sizeof(pri.srcIdx) + sizeof(pri.dir), pmapFile);
213 >         /* Skip source index & incident dir */
214 >         getint(sizeof(pri.srcIdx), pmapFile);
215 > #ifdef PMAP_PRIMARYDIR
216 >         /* Skip primary incident dir */
217 >         getint(sizeof(pri.dir), pmapFile);        
218 > #endif        
219 > #ifdef PMAP_PRIMARYPOS        
220 >         /* Skip primary hitpoint */
221           for (j = 0; j < 3; j++)
222              getflt(pmapFile);
223 + #endif
224        }
225  
226   #ifdef PMAP_OOC
# Line 253 | Line 286 | int main (int argc, char** argv)
286        /* Reset defaults for next dump */
287        radScale = RADSCALE;
288        numSpheres = NSPHERES;
289 +      customCol [0] = customCol [1] = customCol [2] = 0;
290     }
291    
292     return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines