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

Comparing src/util/rsensor.c (file contents):
Revision 2.13 by greg, Wed Oct 16 04:35:50 2013 UTC vs.
Revision 2.25 by greg, Tue Jun 3 21:31:51 2025 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9   */
10  
11   #include "ray.h"
12 + #include "platform.h"
13   #include "source.h"
14 + #include "func.h"
15   #include "view.h"
16   #include "random.h"
17  
18   #define DEGREE          (PI/180.)
19  
20 < #define MAXNT           180     /* maximum number of theta divisions */
20 > #define MAXNT           181     /* maximum number of theta divisions */
21   #define MAXNP           360     /* maximum number of phi divisions */
22  
21 extern char     *progname;      /* global argv[0] */
23   extern int      nowarn;         /* don't report warnings? */
24  
25                                  /* current sensor's perspective */
# Line 26 | Line 27 | VIEW           ourview =  {VT_ANG,{0.,0.,0.},{0.,0.,1.},{1.,0.,
27                                  1.,180.,180.,0.,0.,0.,0.,
28                                  {0.,0.,0.},{0.,0.,0.},0.,0.};
29  
30 < unsigned long   nsamps = 10000; /* desired number of initial samples */
30 < unsigned long   nssamps = 9000; /* number of super-samples */
30 > long            nsamps = 10000; /* desired number of initial samples */
31   int             ndsamps = 32;   /* number of direct samples */
32   int             nprocs = 1;     /* number of rendering processes */
33  
# Line 59 | Line 59 | print_defaults()               /* print out default parameters */
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); */
62          printf("-dn %-9d\t\t\t# direct number of samples\n", ndsamps);
63          printf("-vp %f %f %f\t# view point\n",
64                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
# Line 77 | Line 76 | quit(ec)                       /* make sure exit is called */
76   int     ec;
77   {
78          if (ray_pnprocs > 0)    /* close children if any */
79 <                ray_pclose(0);          
79 >                ray_pclose(0);
80 >        else if (ray_pnprocs < 0)
81 >                _exit(ec);      /* avoid flush in child */
82          exit(ec);
83   }
84  
# Line 91 | Line 92 | main(
92          int     doheader = 1;
93          int     optwarn = 0;
94          int     i, rval;
95 <
96 <        progname = argv[0];
95 >                                /* set global progname */
96 >        fixargv0(argv[0]);
97                                  /* set up rendering defaults */
98          rand_samp = 1;
99          dstrsrc = 0.65;
# Line 100 | Line 101 | main(
101          directrelay = 3;
102          ambounce = 1;
103          maxdepth = -10;
104 +                                /* initialize calcomp routines */
105 +        initfunc();
106                                  /* get options from command line */
107          for (i = 1; i < argc; i++) {
108                  while ((rval = expandarg(&argc, &argv, i)) > 0)
# Line 129 | Line 132 | main(
132                  if (argv[i][1] == 'r') {        /* sampling options */
133                          if (argv[i][2] == 'd')
134                                  nsamps = atol(argv[++i]);
132                        else if (argv[i][2] == 's')
133                                nssamps = atol(argv[++i]);
135                          else {
136                                  sprintf(errmsg, "bad option at '%s'", argv[i]);
137                                  error(USER, errmsg);
# Line 209 | Line 210 | load_sensor(
210   {
211          int     warnedneg;
212          char    linebuf[8192];
213 +        int     last_pos_val = 0;
214          int     nelem = 1000;
215          float   *sarr = (float *)malloc(sizeof(float)*nelem);
216          FILE    *fp;
# Line 236 | Line 238 | load_sensor(
238                  cp = fskip(cp);
239                  if (cp == NULL)
240                          break;
241 <                if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]) {
241 >                if (ntp[1] > 1 && sarr[ntp[1]+1] <= sarr[ntp[1]]+FTINY) {
242                          sprintf(errmsg,
243                  "Phi values not monotinically increasing in sensor file '%s'",
244                                          sfile);
# Line 262 | Line 264 | load_sensor(
264                          cp = fskip(cp);
265                          if (cp == NULL)
266                                  break;
267 <                        if (i && sarr[i] < .0) {
267 >                        if (sarr[i] < .0) {
268                                  if (!warnedneg++) {
269                                          sprintf(errmsg,
270                  "Negative value(s) in sensor file '%s' (ignored)\n", sfile);
271                                          error(WARNING, errmsg);
272                                  }
273                                  sarr[i] = .0;
274 <                        }
274 >                        } else if (sarr[i] > FTINY && i > ntp[0]*(ntp[1]+1))
275 >                                last_pos_val = i;
276                          ++i;
277                  }
278 <                if (i == ntp[0]*(ntp[1]+1))
278 >                if (i == ntp[0]*(ntp[1]+1))     /* empty line? */
279                          break;
280                  if (ntp[0] > 1 && sarr[ntp[0]*(ntp[1]+1)] <=
281                                          sarr[(ntp[0]-1)*(ntp[1]+1)]) {
# Line 288 | Line 291 | load_sensor(
291                          error(USER, errmsg);
292                  }
293          }
294 <        nelem = i;
294 >                                                /* truncate zero region */
295 >        ntp[0] = (last_pos_val + ntp[1])/(ntp[1]+1) - 1;
296 >        nelem = (ntp[0]+1)*(ntp[1]+1);
297          fclose(fp);
298          errmsg[0] = '\0';                       /* sanity checks */
299 <        if (ntp[0] <= 0)
300 <                sprintf(errmsg, "no data in sensor file '%s'", sfile);
299 >        if (!last_pos_val)
300 >                sprintf(errmsg, "no positive sensor values in file '%s'", sfile);
301          else if (fabs(sarr[ntp[1]+1]) > FTINY)
302                  sprintf(errmsg, "minimum theta must be 0 in sensor file '%s'",
303                                  sfile);
304          else if (fabs(sarr[1]) > FTINY)
305                  sprintf(errmsg, "minimum phi must be 0 in sensor file '%s'",
306                                  sfile);
307 <        else if (sarr[ntp[1]] <= FTINY)
307 >        else if (sarr[ntp[1]] < 270.-FTINY)
308                  sprintf(errmsg,
309 <                        "maximum phi must be positive in sensor file '%s'",
309 >                        "maximum phi must be 270 or greater in sensor file '%s'",
310                                  sfile);
311 <        else if (sarr[ntp[0]*(ntp[1]+1)] <= FTINY)
311 >        else if (sarr[ntp[1]] >= 360.-FTINY)
312                  sprintf(errmsg,
313 <                        "maximum theta must be positive in sensor file '%s'",
313 >                        "maximum phi must be less than 360 in sensor file '%s'",
314                                  sfile);
315          if (errmsg[0])
316                  error(USER, errmsg);
# Line 318 | Line 323 | init_ptable(
323          char    *sfile
324   )
325   {
326 <        int     samptot = nsamps;
326 >        long    samptot = nsamps;
327          float   *rowp, *rowp1;
328          double  rowsum[MAXNT], rowomega[MAXNT];
329          double  thdiv[MAXNT+1], phdiv[MAXNP+1];
# Line 366 | Line 371 | init_ptable(
371          psize = PI*tsize/maxtheta;
372          if (sntp[0]*sntp[1] < samptot)  /* don't overdo resolution */
373                  samptot = sntp[0]*sntp[1];
374 <        ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5);
374 >        ntheta = (int)(sqrt((double)samptot*tsize/psize)*sntp[0]/sntp[1]) + 1;
375          if (ntheta > MAXNT)
376                  ntheta = MAXNT;
377          nphi = samptot/ntheta;
# Line 398 | Line 403 | init_ptable(
403                  tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) +
404                                                  frac*cos(thdiv[t+1]) );
405                                  /* offset b/c sensor values are centered */
406 <                if ((t < sntp[0]-1) & (frac >= 0.5)) {
407 <                        if ((frac -= 0.5) < 0)
403 <                                frac = 0;
406 >                if ((t < sntp[0]-1) & (!t | (frac >= 0.5))) {
407 >                        frac -= 0.5;
408                  } else {
409                          frac += 0.5;
410                          --t;
# Line 425 | Line 429 | init_ptable(
429                  }
430                  pvals[i*(nphi+1) + nphi] = phdiv[sntp[1]];
431          }
432 +                                                /* duplicate final row */
433 +        memcpy(pvals+ntheta*(nphi+1), pvals+(ntheta-1)*(nphi+1),
434 +                                sizeof(*pvals)*(nphi+1));
435          tvals[0] = .0f;
436          tvals[ntheta] = (float)tsize;
437   }
# Line 516 | Line 523 | comp_sensor(
523                                  ndsamps > 0 ? 1 : 0;
524          char    *err;
525          int     nt, np;
526 <        COLOR   vsum;
526 >        SCOLOR  vsum;
527          RAY     rr;
528          double  sf;
529          int     i, j;
# Line 530 | Line 537 | comp_sensor(
537                                                  /* assign probability table */
538          init_ptable(sfile);
539                                                  /* stratified MC sampling */
540 <        setcolor(vsum, .0f, .0f, .0f);
540 >        scolorblack(vsum);
541          nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5);
542          np = nsamps/nt;
543          sf = gscale/nsamps;
# Line 546 | Line 553 | comp_sensor(
553                          }
554                          rr.rmax = .0;
555                          rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL);
556 <                        scalecolor(rr.rcoef, sf);
556 >                        scalescolor(rr.rcoef, sf);
557                          if (ray_pqueue(&rr) == 1)
558 <                                addcolor(vsum, rr.rcol);
558 >                                saddscolor(vsum, rr.rcol);
559                  }
560                                                  /* remaining rays pure MC */
561          for (i = nsamps - nt*np; i-- > 0; ) {
# Line 562 | Line 569 | comp_sensor(
569                  }
570                  rr.rmax = .0;
571                  rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL);
572 <                scalecolor(rr.rcoef, sf);
572 >                scalescolor(rr.rcoef, sf);
573                  if (ray_pqueue(&rr) == 1)
574 <                        addcolor(vsum, rr.rcol);
574 >                        saddscolor(vsum, rr.rcol);
575          }
576          if (!ray_pnprocs)                       /* just printing rays */
577                  return;
578                                                  /* scale partial result */
579 <        scalecolor(vsum, sf);
579 >        scalescolor(vsum, sf);
580                                                  /* add direct component */
581          for (i = ndirs; i-- > 0; ) {
582                  SRCINDEX        si;
# Line 579 | Line 586 | comp_sensor(
586                          if (sf <= FTINY)
587                                  continue;
588                          sf *= si.dom/ndirs;
589 <                        scalecolor(rr.rcoef, sf);
589 >                        scalescolor(rr.rcoef, sf);
590                          if (ray_pqueue(&rr) == 1) {
591 <                                multcolor(rr.rcol, rr.rcoef);
592 <                                addcolor(vsum, rr.rcol);
591 >                                smultscolor(rr.rcol, rr.rcoef);
592 >                                saddscolor(vsum, rr.rcol);
593                          }
594                  }
595          }
596 <                                                /* finish our calculation */
597 <        while (ray_presult(&rr, 0) > 0) {
598 <                multcolor(rr.rcol, rr.rcoef);
592 <                addcolor(vsum, rr.rcol);
596 >        while (ray_presult(&rr, 0) > 0) {       /* finish our calculation */
597 >                smultscolor(rr.rcol, rr.rcoef);
598 >                saddscolor(vsum, rr.rcol);
599          }
600 <                                                /* print our result */
601 <        printf("%.4e %.4e %.4e\n", colval(vsum,RED),
602 <                                colval(vsum,GRN), colval(vsum,BLU));
600 >        for (i = 0; i < NCSAMP; i++)            /* print our result */
601 >                printf(" %.4e", vsum[i]);
602 >        fputc('\n', stdout);
603   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines