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

Comparing ray/src/util/rsensor.c (file contents):
Revision 2.1 by greg, Thu Feb 21 01:22:06 2008 UTC vs.
Revision 2.5 by greg, Fri Apr 11 22:06:04 2008 UTC

# Line 22 | Line 22 | extern char    *progname;      /* global argv[0] */
22   extern int      nowarn;         /* don't report warnings? */
23  
24                                  /* current sensor's perspective */
25 < VIEW            ourview = STDVIEW;
25 > VIEW            ourview =  {VT_ANG,{0.,0.,0.},{0.,0.,1.},{1.,0.,0.},
26 >                                1.,180.,180.,0.,0.,0.,0.,
27 >                                {0.,0.,0.},{0.,0.,0.},0.,0.};
28  
29   unsigned long   nsamps = 10000; /* desired number of initial samples */
30   unsigned long   nssamps = 9000; /* number of super-samples */
31 < int             ndsamps = 16;   /* number of direct samples */
31 > int             ndsamps = 32;   /* number of direct samples */
32   int             nprocs = 1;     /* number of rendering processes */
33  
34   float           *sensor = NULL; /* current sensor data */
# Line 38 | Line 40 | int            ntheta = 0;     /* polar angle divisions */
40   int             nphi = 0;       /* azimuthal angle divisions */
41   double          gscale = 1.;    /* global scaling value */
42  
43 + #define s_theta(t)      sensor[(t+1)*(sntp[1]+1)]
44 + #define s_phi(p)        sensor[(p)+1]
45 + #define s_val(t,p)      sensor[(p)+1+(t+1)*(sntp[1]+1)]
46 +
47   static void     comp_sensor(char *sfile);
48  
49   static void
50 < print_defaults()
50 > over_options()                  /* overriding options */
51   {
52 +        directvis = (ndsamps <= 0);
53 +        do_irrad = 0;
54 + }
55 +
56 + static void
57 + print_defaults()                /* print out default parameters */
58 + {
59 +        over_options();
60          printf("-n %-9d\t\t\t# number of processes\n", nprocs);
61          printf("-rd %-9ld\t\t\t# ray directions\n", nsamps);
62          /* printf("-rs %-9ld\t\t\t# ray super-samples\n", nssamps); */
# Line 64 | Line 78 | main(
78   )
79   {
80          int     doheader = 1;
81 +        int     optwarn = 0;
82          int     i, rval;
83  
84          progname = argv[0];
85                                  /* set up rendering defaults */
86 <        dstrsrc = 0.25;
86 >        rand_samp = 1;
87 >        dstrsrc = 0.5;
88 >        srcsizerat = 0.1;
89          directrelay = 3;
90          ambounce = 1;
91 <                                /* just asking defaults? */
75 <        if (argc == 2 && !strcmp(argv[1], "-defaults")) {
76 <                print_defaults();
77 <                return(0);
78 <        }
79 <                                /* check octree */
80 <        if (argc < 2 || argv[argc-1][0] == '-')
81 <                error(USER, "missing octree argument");
91 >        maxdepth = -10;
92                                  /* get options from command line */
93 <        for (i = 1; i < argc-1; i++) {
93 >        for (i = 1; i < argc; i++) {
94                  while ((rval = expandarg(&argc, &argv, i)) > 0)
95                          ;
96                  if (rval < 0) {
97                          sprintf(errmsg, "cannot expand '%s'", argv[i]);
98                          error(SYSTEM, errmsg);
99                  }
100 <                if (argv[i][0] != '-') {        /* process a sensor file */
100 >                if (argv[i][0] != '-') {
101 >                        if (i >= argc-1)
102 >                                break;          /* final octree argument */
103                          if (!ray_pnprocs) {
104 <                                                /* overriding options */
93 <                                directvis = (ndsamps <= 0);
94 <                                do_irrad = 0;
104 >                                over_options();
105                                  if (doheader) { /* print header */
106                                          printargs(argc, argv, stdout);
107                                          fputformat("ascii", stdout);
# Line 100 | Line 110 | main(
110                                                  /* start process(es) */
111                                  ray_pinit(argv[argc-1], nprocs);
112                          }
113 <                        comp_sensor(argv[i]);
113 >                        comp_sensor(argv[i]);   /* process a sensor file */
114                          continue;
115                  }
116                  if (argv[i][1] == 'r') {        /* sampling options */
# Line 143 | Line 153 | main(
153                          sprintf(errmsg, "bad view option at '%s'", argv[i]);
154                          error(USER, errmsg);
155                  }
156 <                if (!strcmp(argv[i], "-w")) {   /* turn off warnings */
157 <                        nowarn = 1;
156 >                if (!strcmp(argv[i], "-w")) {   /* toggle warnings */
157 >                        nowarn = !nowarn;
158                          continue;
159                  }
160                  if (ray_pnprocs) {
161 <                        error(WARNING,
161 >                        if (!optwarn++)
162 >                                error(WARNING,
163                          "rendering options should appear before first sensor");
164                  } else if (!strcmp(argv[i], "-defaults")) {
165                          print_defaults();
# Line 171 | Line 182 | main(
182                  }
183                  i += rval;
184          }
185 +        if (!ray_pnprocs)
186 +                error(USER, i<argc ? "missing sensor file" : "missing octree");
187          quit(0);
188   }
189  
# Line 282 | Line 295 | init_ptable(
295          if (pvals != NULL)
296                  free((void *)pvals);
297          if (sfile == NULL || !*sfile) {
298 +                sensor = NULL;
299 +                sntp[0] = sntp[1] = 0;
300                  pvals = NULL;
301                  ntheta = nphi = 0;
302                  return;
# Line 299 | Line 314 | init_ptable(
314                  error(INTERNAL, errmsg);
315          }
316                                          /* compute boundary angles */
317 <        maxtheta = 1.5f*sensor[sntp[0]*(sntp[1]+1)] -
303 <                        0.5f*sensor[sntp[0]*sntp[1]];
317 >        maxtheta = 1.5f*s_theta(sntp[0]-1) - 0.5f*s_theta(sntp[0]-2);
318          thdiv[0] = .0;
319          for (t = 1; t < sntp[0]; t++)
320 <                thdiv[t] = DEGREE/2.*(sensor[t*(sntp[1]+1)] +
307 <                                        sensor[(t+1)*(sntp[1]+1)]);
320 >                thdiv[t] = DEGREE/2.*(s_theta(t-1) + s_theta(t));
321          thdiv[sntp[0]] = maxtheta*DEGREE;
322          phdiv[0] = .0;
323          for (p = 1; p < sntp[1]; p++)
324 <                phdiv[p] = DEGREE/2.*(sensor[p] + sensor[p+1]);
324 >                phdiv[p] = DEGREE/2.*(s_phi(p-1) + s_phi(p));
325          phdiv[sntp[1]] = 2.*PI;
326                                          /* size our table */
327          tsize = 1. - cos(maxtheta*DEGREE);
328 <        psize = PI*tsize/maxtheta;
328 >        psize = PI*tsize/(maxtheta*DEGREE);
329          if (sntp[0]*sntp[1] < samptot)  /* don't overdo resolution */
330                  samptot = sntp[0]*sntp[1];
331 <        ntheta = (int)(sqrt(samptot*tsize/psize) + 0.5);
331 >        ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5);
332          if (ntheta > MAXNT)
333                  ntheta = MAXNT;
334          nphi = samptot/ntheta;
# Line 324 | Line 337 | init_ptable(
337                  error(SYSTEM, "out of memory in init_ptable()");
338          gscale = .0;                    /* compute our inverse table */
339          for (i = 0; i < sntp[0]; i++) {
340 <                rowp = sensor + (i+1)*(sntp[1]+1) + 1;
340 >                rowp = &s_val(i,0);
341                  rowsum[i] = 0.;
342                  for (j = 0; j < sntp[1]; j++)
343                          rowsum[i] += *rowp++;
# Line 332 | Line 345 | init_ptable(
345                  rowomega[i] *= 2.*PI / (double)sntp[1];
346                  gscale += rowsum[i] * rowomega[i];
347          }
348 <        tvals[0] = .0f;
336 <        for (i = 1; i < ntheta; i++) {
348 >        for (i = 0; i < ntheta; i++) {
349                  prob = (double)i / (double)ntheta;
350                  for (t = 0; t < sntp[0]; t++)
351                          if ((prob -= rowsum[t]*rowomega[t]/gscale) <= .0)
# Line 343 | Line 355 | init_ptable(
355                  frac = 1. + prob/(rowsum[t]*rowomega[t]/gscale);
356                  tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) +
357                                                  frac*cos(thdiv[t+1]) );
358 +                                /* offset b/c sensor values are centered */
359 +                if (t <= 0 || frac > 0.5)
360 +                        frac -= 0.5;
361 +                else if (t >= sntp[0]-1 || frac < 0.5) {
362 +                        frac += 0.5;
363 +                        --t;
364 +                }
365                  pvals[i*(nphi+1)] = .0f;
366                  for (j = 1; j < nphi; j++) {
367                          prob = (double)j / (double)nphi;
368 <                        rowp = sensor + t*(sntp[1]+1) + 1;
369 <                        rowp1 = rowp + sntp[1]+1;
368 >                        rowp = &s_val(t,0);
369 >                        rowp1 = &s_val(t+1,0);
370                          for (p = 0; p < sntp[1]; p++) {
371 <                                if ((prob -= (1.-frac)*rowp[p]/rowsum[t-1] +
372 <                                                frac*rowp1[p]/rowsum[t]) <= .0)
371 >                                if ((prob -= (1.-frac)*rowp[p]/rowsum[t] +
372 >                                            frac*rowp1[p]/rowsum[t+1]) <= .0)
373                                          break;
374                                  if (p >= sntp[1])
375                                          error(INTERNAL,
376                                              "code error 2 in init_ptable()");
377 <                                frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t-1]
378 <                                                + frac*rowp1[p]/rowsum[t]);
377 >                                frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t]
378 >                                                + frac*rowp1[p]/rowsum[t+1]);
379                                  pvals[i*(nphi+1) + j] = (1.-frac1)*phdiv[p] +
380                                                          frac1*phdiv[p+1];
381                          }
382                  }
383                  pvals[i*(nphi+1) + nphi] = (float)(2.*PI);
384          }
385 +        tvals[0] = .0f;
386          tvals[ntheta] = (float)tsize;
387   }
388  
# Line 418 | Line 438 | sens_val(
438          t = (int)(theta/maxtheta * sntp[0]);
439          p = (int)(phi*(1./360.) * sntp[1]);
440                          /* hack for non-uniform sensor grid */
441 <        while (t+1 < sntp[0] && theta >= sensor[(t+2)*(sntp[1]+1)])
441 >        while (t+1 < sntp[0] && theta >= s_theta(t+1))
442                  ++t;
443 <        while (t-1 >= 0 && theta < sensor[t*(sntp[1]+1)])
443 >        while (t-1 >= 0 && theta <= s_theta(t-1))
444                  --t;
445 <        while (p+1 < sntp[1] && phi >= sensor[p+2])
445 >        while (p+1 < sntp[1] && phi >= s_phi(p+1))
446                  ++p;
447 <        while (p-1 >= 0 && phi < sensor[p])
447 >        while (p-1 >= 0 && phi <= s_phi(p-1))
448                  --p;
449 <        return(sensor[t*(sntp[1]+1) + p + 1]);
449 >        return(s_val(t,p));
450   }
451  
452   /* Compute sensor output */
# Line 455 | Line 475 | comp_sensor(
475          setcolor(vsum, .0f, .0f, .0f);
476          nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5);
477          np = nsamps/nt;
458        VCOPY(rr.rorg, ourview.vp);
459        rr.rmax = .0;
478          for (i = 0; i < nt; i++)
479 <                for (j =0; j < np; j++) {
480 <                        get_direc(rr.rdir, (i+frandom())/nt,
481 <                                        (j + frandom())/np);
479 >                for (j = 0; j < np; j++) {
480 >                        VCOPY(rr.rorg, ourview.vp);
481 >                        get_direc(rr.rdir, (i+frandom())/nt, (j+frandom())/np);
482 >                        if (ourview.vfore > FTINY)
483 >                                VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore);
484 >                        rr.rmax = .0;
485                          rayorigin(&rr, PRIMARY, NULL, NULL);
486                          if (ray_pqueue(&rr) == 1)
487                                  addcolor(vsum, rr.rcol);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines