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.16 by greg, Wed May 15 17:29:30 2013 UTC vs.
Revision 2.24 by greg, Sat Mar 8 01:05:00 2014 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
11   #include <stdio.h>
12   #include <stdlib.h>
13   #include <math.h>
14 + #include "random.h"
15   #include "platform.h"
16 + #include "rtprocess.h"
17   #include "calcomp.h"
18   #include "bsdfrep.h"
19                                  /* global argv[0] */
# Line 24 | Line 26 | int                    samp_order = 6;
26   const double            ssamp_thresh = 0.35;
27                                  /* number of super-samples */
28   const int               nssamp = 100;
29 +                                /* limit on number of RBF lobes */
30 + static int              lobe_lim = 15000;
31  
32   /* Output XML prologue to stdout */
33   static void
# Line 42 | Line 46 | xml_prologue(int ac, char *av[])
46          puts("<Optical>");
47          puts("<Layer>");
48          puts("\t<Material>");
49 <        puts("\t\t<Name>Name</Name>");
50 <        puts("\t\t<Manufacturer>Manufacturer</Manufacturer>");
49 >        printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown");
50 >        printf("\t\t<Manufacturer>%s</Manufacturer>\n",
51 >                        bsdf_manuf[0] ? bsdf_manuf : "Unknown");
52          puts("\t\t<DeviceType>Other</DeviceType>");
53          puts("\t</Material>");
54          puts("\t<DataDefinition>");
# Line 112 | Line 117 | eval_isotropic(char *funame)
117   {
118          const int       sqres = 1<<samp_order;
119          FILE            *ofp = NULL;
120 +        int             assignD = 0;
121          char            cmd[128];
122          int             ix, ox, oy;
123          double          iovec[6];
# Line 119 | Line 125 | eval_isotropic(char *funame)
125  
126          data_prologue();                        /* begin output */
127          if (pctcull >= 0) {
128 <                sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d",
128 >                sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d",
129                                  pctcull, samp_order);
130                  fflush(stdout);
131                  ofp = popen(cmd, "w");
# Line 131 | Line 137 | eval_isotropic(char *funame)
137                  SET_FILE_BINARY(ofp);
138          } else
139                  fputs("{\n", stdout);
140 +                                                /* need to assign Dx, Dy, Dz? */
141 +        if (funame != NULL)
142 +                assignD = (fundefined(funame) < 6);
143                                                  /* run through directions */
144          for (ix = 0; ix < sqres/2; ix++) {
145                  RBFNODE *rbf = NULL;
# Line 138 | Line 147 | eval_isotropic(char *funame)
147                  iovec[1] = .0;
148                  iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]);
149                  if (funame == NULL)
150 <                        rbf = advect_rbf(iovec);
150 >                        rbf = advect_rbf(iovec, lobe_lim);
151                  for (ox = 0; ox < sqres; ox++) {
152                      float       last_bsdf = -1;
153                      for (oy = 0; oy < sqres; oy++) {
# Line 151 | Line 160 | eval_isotropic(char *funame)
160                          else {
161                              double      ssa[3], ssvec[6], sum;
162                              int         ssi;
163 +                            if (assignD) {
164 +                                varset("Dx", '=', -iovec[3]);
165 +                                varset("Dy", '=', -iovec[4]);
166 +                                varset("Dz", '=', -iovec[5]);
167 +                                ++eclock;
168 +                            }
169                              bsdf = funvalue(funame, 6, iovec);
170                              if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
171                                  sum = 0;        /* super-sample voxel */
172                                  for (ssi = nssamp; ssi--; ) {
173 <                                    SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp);
173 >                                    SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp);
174                                      ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.;
175                                      ssvec[1] = .0;
176                                      ssvec[2] = input_orient *
# Line 165 | Line 180 | eval_isotropic(char *funame)
180                                      ssvec[5] = output_orient *
181                                                  sqrt(1. - ssvec[3]*ssvec[3] -
182                                                          ssvec[4]*ssvec[4]);
183 +                                    if (assignD) {
184 +                                        varset("Dx", '=', -iovec[3]);
185 +                                        varset("Dy", '=', -iovec[4]);
186 +                                        varset("Dz", '=', -iovec[5]);
187 +                                        ++eclock;
188 +                                    }
189                                      sum += funvalue(funame, 6, ssvec);
190                                  }
191                                  bsdf = sum/nssamp;
# Line 200 | Line 221 | eval_anisotropic(char *funame)
221   {
222          const int       sqres = 1<<samp_order;
223          FILE            *ofp = NULL;
224 +        int             assignD = 0;
225          char            cmd[128];
226          int             ix, iy, ox, oy;
227          double          iovec[6];
# Line 207 | Line 229 | eval_anisotropic(char *funame)
229  
230          data_prologue();                        /* begin output */
231          if (pctcull >= 0) {
232 <                sprintf(cmd, "rttree_reduce -h -a -ff -r 4 -t %f -g %d",
232 >                sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d",
233 >                                (input_orient>0 ^ output_orient>0) ? "" : " -a",
234                                  pctcull, samp_order);
235                  fflush(stdout);
236                  ofp = popen(cmd, "w");
# Line 218 | Line 241 | eval_anisotropic(char *funame)
241                  }
242          } else
243                  fputs("{\n", stdout);
244 +                                                /* need to assign Dx, Dy, Dz? */
245 +        if (funame != NULL)
246 +                assignD = (fundefined(funame) < 6);
247                                                  /* run through directions */
248          for (ix = 0; ix < sqres; ix++)
249              for (iy = 0; iy < sqres; iy++) {
# Line 226 | Line 252 | eval_anisotropic(char *funame)
252                  iovec[2] = input_orient *
253                                  sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]);
254                  if (funame == NULL)
255 <                        rbf = advect_rbf(iovec);
255 >                        rbf = advect_rbf(iovec, lobe_lim);
256                  for (ox = 0; ox < sqres; ox++) {
257                      float       last_bsdf = -1;
258                      for (oy = 0; oy < sqres; oy++) {
# Line 239 | Line 265 | eval_anisotropic(char *funame)
265                          else {
266                              double      ssa[4], ssvec[6], sum;
267                              int         ssi;
268 +                            if (assignD) {
269 +                                varset("Dx", '=', -iovec[3]);
270 +                                varset("Dy", '=', -iovec[4]);
271 +                                varset("Dz", '=', -iovec[5]);
272 +                                ++eclock;
273 +                            }
274                              bsdf = funvalue(funame, 6, iovec);
275                              if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
276                                  sum = 0;        /* super-sample voxel */
277                                  for (ssi = nssamp; ssi--; ) {
278 <                                    SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp);
278 >                                    SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp);
279                                      SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres,
280                                                  1.-(iy+ssa[1])/sqres);
281                                      ssvec[2] = output_orient *
# Line 254 | Line 286 | eval_anisotropic(char *funame)
286                                      ssvec[5] = output_orient *
287                                                  sqrt(1. - ssvec[3]*ssvec[3] -
288                                                          ssvec[4]*ssvec[4]);
289 +                                    if (assignD) {
290 +                                        varset("Dx", '=', -iovec[3]);
291 +                                        varset("Dy", '=', -iovec[4]);
292 +                                        varset("Dz", '=', -iovec[5]);
293 +                                        ++eclock;
294 +                                    }
295                                      sum += funvalue(funame, 6, ssvec);
296                                  }
297                                  bsdf = sum/nssamp;
# Line 324 | Line 362 | main(int argc, char *argv[])
362                  case 'g':
363                          samp_order = atoi(argv[++i]);
364                          break;
365 +                case 'l':
366 +                        lobe_lim = atoi(argv[++i]);
367 +                        break;
368                  default:
369                          goto userr;
370                  }
371          if (single_plane_incident >= 0) {       /* function-based BSDF? */
372                  void    (*evf)(char *s) = single_plane_incident ?
373                                  &eval_isotropic : &eval_anisotropic;
374 <                if (i != argc-1 || fundefined(argv[i]) != 6) {
374 >                if (i != argc-1 || fundefined(argv[i]) < 3) {
375                          fprintf(stderr,
376          "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n",
377                                          progname);
378 +                        fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n");
379                          goto userr;
380                  }
381 +                ++eclock;
382                  xml_prologue(argc, argv);       /* start XML output */
383                  if (dofwd) {
384                          input_orient = -1;
# Line 388 | Line 431 | main(int argc, char *argv[])
431          return(0);
432   userr:
433          fprintf(stderr,
434 <        "Usage: %s [-g Nlog2][-t pctcull] [bsdf.sir ..] > bsdf.xml\n",
434 >        "Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
435                                  progname);
436          fprintf(stderr,
437          "   or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines