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

Comparing ray/src/cv/bsdf2ttree.c (file contents):
Revision 2.13 by greg, Sat Mar 23 02:21:14 2013 UTC vs.
Revision 2.17 by greg, Fri Aug 2 20:56:19 2013 UTC

# Line 20 | Line 20 | char                   *progname;
20   double                  pctcull = 90.;
21                                  /* sampling order */
22   int                     samp_order = 6;
23 +                                /* super-sampling threshold */
24 + const double            ssamp_thresh = 0.35;
25 +                                /* number of super-samples */
26 + const int               nssamp = 100;
27  
28   /* Output XML prologue to stdout */
29   static void
# Line 90 | Line 94 | xml_epilogue(void)
94          puts("</WindowElement>");
95   }
96  
97 + /* Compute absolute relative difference */
98 + static double
99 + abs_diff(double v1, double v0)
100 + {
101 +        if ((v0 < 0) | (v1 < 0))
102 +                return(.0);
103 +        v1 = (v1-v0)*2./(v0+v1+.0001);
104 +        if (v1 < 0)
105 +                return(-v1);
106 +        return(v1);
107 + }
108 +
109   /* Interpolate and output isotropic BSDF data */
110   static void
111   eval_isotropic(char *funame)
112   {
113          const int       sqres = 1<<samp_order;
114          FILE            *ofp = NULL;
115 +        int             assignD = 0;
116          char            cmd[128];
117          int             ix, ox, oy;
118          double          iovec[6];
119          float           bsdf;
120 < #if DEBUG
104 <        fprintf(stderr, "Writing isotropic order %d ", samp_order);
105 <        if (pctcull >= 0) fprintf(stderr, "data with %.1f%% culling\n", pctcull);
106 <        else fputs("raw data\n", stderr);
107 < #endif
120 >
121          data_prologue();                        /* begin output */
122          if (pctcull >= 0) {
123                  sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d",
# Line 119 | Line 132 | eval_isotropic(char *funame)
132                  SET_FILE_BINARY(ofp);
133          } else
134                  fputs("{\n", stdout);
135 +                                                /* need to assign Dx, Dy, Dz? */
136 +        if (funame != NULL)
137 +                assignD = (fundefined(funame) < 6);
138                                                  /* run through directions */
139          for (ix = 0; ix < sqres/2; ix++) {
140                  RBFNODE *rbf = NULL;
141 <                iovec[0] = (ix+.5)/sqres - 1.;
141 >                iovec[0] = 2.*(ix+.5)/sqres - 1.;
142                  iovec[1] = .0;
143                  iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]);
144                  if (funame == NULL)
145                          rbf = advect_rbf(iovec);
146 <                for (ox = 0; ox < sqres; ox++)
146 >                for (ox = 0; ox < sqres; ox++) {
147 >                    float       last_bsdf = -1;
148                      for (oy = 0; oy < sqres; oy++) {
149                          SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
150                          iovec[5] = output_orient *
151                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
152                          if (funame == NULL)
153 <                                bsdf = eval_rbfrep(rbf, iovec+3) *
153 >                            bsdf = eval_rbfrep(rbf, iovec+3) *
154                                                  output_orient/iovec[5];
155 <                        else
156 <                                bsdf = funvalue(funame, 6, iovec);
155 >                        else {
156 >                            double      ssa[3], ssvec[6], sum;
157 >                            int         ssi;
158 >                            if (assignD) {
159 >                                varset("Dx", '=', -iovec[3]);
160 >                                varset("Dy", '=', -iovec[4]);
161 >                                varset("Dz", '=', -iovec[5]);
162 >                                ++eclock;
163 >                            }
164 >                            bsdf = funvalue(funame, 6, iovec);
165 >                            if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
166 >                                sum = 0;        /* super-sample voxel */
167 >                                for (ssi = nssamp; ssi--; ) {
168 >                                    SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp);
169 >                                    ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.;
170 >                                    ssvec[1] = .0;
171 >                                    ssvec[2] = input_orient *
172 >                                                sqrt(1. - ssvec[0]*ssvec[0]);
173 >                                    SDsquare2disk(ssvec+3, (ox+ssa[1])/sqres,
174 >                                                (oy+ssa[2])/sqres);
175 >                                    ssvec[5] = output_orient *
176 >                                                sqrt(1. - ssvec[3]*ssvec[3] -
177 >                                                        ssvec[4]*ssvec[4]);
178 >                                    if (assignD) {
179 >                                        varset("Dx", '=', -iovec[3]);
180 >                                        varset("Dy", '=', -iovec[4]);
181 >                                        varset("Dz", '=', -iovec[5]);
182 >                                        ++eclock;
183 >                                    }
184 >                                    sum += funvalue(funame, 6, ssvec);
185 >                                }
186 >                                bsdf = sum/nssamp;
187 >                            }
188 >                        }
189                          if (pctcull >= 0)
190                                  fwrite(&bsdf, sizeof(bsdf), 1, ofp);
191                          else
192                                  printf("\t%.3e\n", bsdf);
193 +                        last_bsdf = bsdf;
194                      }
195 +                }
196                  if (rbf != NULL)
197                          free(rbf);
198          }
# Line 165 | Line 216 | eval_anisotropic(char *funame)
216   {
217          const int       sqres = 1<<samp_order;
218          FILE            *ofp = NULL;
219 +        int             assignD = 0;
220          char            cmd[128];
221          int             ix, iy, ox, oy;
222          double          iovec[6];
223          float           bsdf;
224 < #if DEBUG
173 <        fprintf(stderr, "Writing anisotropic order %d ", samp_order);
174 <        if (pctcull >= 0) fprintf(stderr, "data with %.1f%% culling\n", pctcull);
175 <        else fputs("raw data\n", stderr);
176 < #endif
224 >
225          data_prologue();                        /* begin output */
226          if (pctcull >= 0) {
227                  sprintf(cmd, "rttree_reduce -h -a -ff -r 4 -t %f -g %d",
# Line 187 | Line 235 | eval_anisotropic(char *funame)
235                  }
236          } else
237                  fputs("{\n", stdout);
238 +                                                /* need to assign Dx, Dy, Dz? */
239 +        if (funame != NULL)
240 +                assignD = (fundefined(funame) < 6);
241                                                  /* run through directions */
242          for (ix = 0; ix < sqres; ix++)
243              for (iy = 0; iy < sqres; iy++) {
244                  RBFNODE *rbf = NULL;            /* Klems reversal */
245 <                SDsquare2disk(iovec, (ix+.5)/sqres, (iy+.5)/sqres);
195 <                iovec[0] = -iovec[0]; iovec[1] = -iovec[1];
245 >                SDsquare2disk(iovec, 1.-(ix+.5)/sqres, 1.-(iy+.5)/sqres);
246                  iovec[2] = input_orient *
247                                  sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]);
248                  if (funame == NULL)
249                          rbf = advect_rbf(iovec);
250 <                for (ox = 0; ox < sqres; ox++)
250 >                for (ox = 0; ox < sqres; ox++) {
251 >                    float       last_bsdf = -1;
252                      for (oy = 0; oy < sqres; oy++) {
253                          SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
254                          iovec[5] = output_orient *
255                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
256                          if (funame == NULL)
257 <                                bsdf = eval_rbfrep(rbf, iovec+3) *
257 >                            bsdf = eval_rbfrep(rbf, iovec+3) *
258                                                  output_orient/iovec[5];
259 <                        else
260 <                                bsdf = funvalue(funame, 6, iovec);
259 >                        else {
260 >                            double      ssa[4], ssvec[6], sum;
261 >                            int         ssi;
262 >                            if (assignD) {
263 >                                varset("Dx", '=', -iovec[3]);
264 >                                varset("Dy", '=', -iovec[4]);
265 >                                varset("Dz", '=', -iovec[5]);
266 >                                ++eclock;
267 >                            }
268 >                            bsdf = funvalue(funame, 6, iovec);
269 >                            if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
270 >                                sum = 0;        /* super-sample voxel */
271 >                                for (ssi = nssamp; ssi--; ) {
272 >                                    SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp);
273 >                                    SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres,
274 >                                                1.-(iy+ssa[1])/sqres);
275 >                                    ssvec[2] = output_orient *
276 >                                                sqrt(1. - ssvec[0]*ssvec[0] -
277 >                                                        ssvec[1]*ssvec[1]);
278 >                                    SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres,
279 >                                                (oy+ssa[3])/sqres);
280 >                                    ssvec[5] = output_orient *
281 >                                                sqrt(1. - ssvec[3]*ssvec[3] -
282 >                                                        ssvec[4]*ssvec[4]);
283 >                                    if (assignD) {
284 >                                        varset("Dx", '=', -iovec[3]);
285 >                                        varset("Dy", '=', -iovec[4]);
286 >                                        varset("Dz", '=', -iovec[5]);
287 >                                        ++eclock;
288 >                                    }
289 >                                    sum += funvalue(funame, 6, ssvec);
290 >                                }
291 >                                bsdf = sum/nssamp;
292 >                            }
293 >                        }
294                          if (pctcull >= 0)
295                                  fwrite(&bsdf, sizeof(bsdf), 1, ofp);
296                          else
297                                  printf("\t%.3e\n", bsdf);
298 +                        last_bsdf = bsdf;
299                      }
300 +                }
301                  if (rbf != NULL)
302                          free(rbf);
303              }
# Line 276 | Line 362 | main(int argc, char *argv[])
362          if (single_plane_incident >= 0) {       /* function-based BSDF? */
363                  void    (*evf)(char *s) = single_plane_incident ?
364                                  &eval_isotropic : &eval_anisotropic;
365 <                if (i != argc-1 || fundefined(argv[i]) != 6) {
365 >                if (i != argc-1 || fundefined(argv[i]) < 3) {
366                          fprintf(stderr,
367          "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n",
368                                          progname);
369 +                        fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n",
370 +                                        progname);
371                          goto userr;
372                  }
373 +                ++eclock;
374                  xml_prologue(argc, argv);       /* start XML output */
375                  if (dofwd) {
376                          input_orient = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines