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.2 by greg, Thu Feb 21 20:18:25 2008 UTC vs.
Revision 2.6 by greg, Sat Dec 13 00:44:05 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 */
# Line 45 | Line 47 | double         gscale = 1.;    /* global scaling value */
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 68 | 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          rand_samp = 1;
87 <        dstrsrc = 0.5;
87 >        dstrsrc = 0.65;
88          srcsizerat = 0.1;
89          directrelay = 3;
90          ambounce = 1;
91          maxdepth = -10;
81                                /* just asking defaults? */
82        if (argc == 2 && !strcmp(argv[1], "-defaults")) {
83                print_defaults();
84                return(0);
85        }
86                                /* check octree */
87        if (argc < 2 || argv[argc-1][0] == '-')
88                error(USER, "missing octree argument");
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 */
100 <                                directvis = (ndsamps <= 0);
101 <                                do_irrad = 0;
104 >                                over_options();
105                                  if (doheader) { /* print header */
106 +                                        newheader("RADIANCE", stdout);
107                                          printargs(argc, argv, stdout);
108                                          fputformat("ascii", stdout);
109                                          putchar('\n');
# Line 107 | Line 111 | main(
111                                                  /* start process(es) */
112                                  ray_pinit(argv[argc-1], nprocs);
113                          }
114 <                        comp_sensor(argv[i]);
114 >                        comp_sensor(argv[i]);   /* process a sensor file */
115                          continue;
116                  }
117                  if (argv[i][1] == 'r') {        /* sampling options */
# Line 150 | Line 154 | main(
154                          sprintf(errmsg, "bad view option at '%s'", argv[i]);
155                          error(USER, errmsg);
156                  }
157 <                if (!strcmp(argv[i], "-w")) {   /* turn off warnings */
158 <                        nowarn = 1;
157 >                if (!strcmp(argv[i], "-w")) {   /* toggle warnings */
158 >                        nowarn = !nowarn;
159                          continue;
160                  }
161                  if (ray_pnprocs) {
162 <                        error(WARNING,
162 >                        if (!optwarn++)
163 >                                error(WARNING,
164                          "rendering options should appear before first sensor");
165                  } else if (!strcmp(argv[i], "-defaults")) {
166                          print_defaults();
# Line 178 | Line 183 | main(
183                  }
184                  i += rval;
185          }
186 +        if (!ray_pnprocs)
187 +                error(USER, i<argc ? "missing sensor file" : "missing octree");
188          quit(0);
189   }
190  
# Line 370 | Line 377 | init_ptable(
377                                              "code error 2 in init_ptable()");
378                                  frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t]
379                                                  + frac*rowp1[p]/rowsum[t+1]);
373                                if (p <= 0 || frac1 > 0.5)
374                                        frac1 -= 0.5;
375                                else if (p >= sntp[1]-1 || frac1 < 0.5) {
376                                        frac1 += 0.5;
377                                        --p;
378                                }
380                                  pvals[i*(nphi+1) + j] = (1.-frac1)*phdiv[p] +
381                                                          frac1*phdiv[p+1];
382                          }
# Line 461 | Line 462 | comp_sensor(
462          int     nt, np;
463          COLOR   vsum;
464          RAY     rr;
465 +        double  sf;
466          int     i, j;
467                                                  /* set view */
468          ourview.type = VT_ANG;
# Line 471 | Line 473 | comp_sensor(
473                  error(USER, err);
474                                                  /* assign probability table */
475          init_ptable(sfile);
476 <                                                /* do Monte Carlo sampling */
476 >                                                /* stratified MC sampling */
477          setcolor(vsum, .0f, .0f, .0f);
478          nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5);
479          np = nsamps/nt;
480 <        VCOPY(rr.rorg, ourview.vp);
479 <        rr.rmax = .0;
480 >        sf = gscale/nsamps;
481          for (i = 0; i < nt; i++)
482                  for (j = 0; j < np; j++) {
483 +                        VCOPY(rr.rorg, ourview.vp);
484                          get_direc(rr.rdir, (i+frandom())/nt, (j+frandom())/np);
485 +                        if (ourview.vfore > FTINY)
486 +                                VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore);
487 +                        rr.rmax = .0;
488                          rayorigin(&rr, PRIMARY, NULL, NULL);
489 +                        scalecolor(rr.rcoef, sf);
490                          if (ray_pqueue(&rr) == 1)
491                                  addcolor(vsum, rr.rcol);
492                  }
493 <                                                /* finish MC calculation */
494 <        while (ray_presult(&rr, 0) > 0)
495 <                addcolor(vsum, rr.rcol);
496 <        scalecolor(vsum, gscale/(nt*np));
497 <                                                /* compute direct component */
493 >                                                /* remaining rays pure MC */
494 >        for (i = nsamps - nt*np; i-- > 0; ) {
495 >                VCOPY(rr.rorg, ourview.vp);
496 >                get_direc(rr.rdir, frandom(), frandom());
497 >                if (ourview.vfore > FTINY)
498 >                        VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore);
499 >                rr.rmax = .0;
500 >                rayorigin(&rr, PRIMARY, NULL, NULL);
501 >                scalecolor(rr.rcoef, sf);
502 >                if (ray_pqueue(&rr) == 1)
503 >                        addcolor(vsum, rr.rcol);
504 >        }
505 >                                                /* scale partial result */
506 >        scalecolor(vsum, sf);
507 >                                                /* add direct component */
508          for (i = ndirs; i-- > 0; ) {
509                  SRCINDEX        si;
510                  initsrcindex(&si);
511                  while (srcray(&rr, NULL, &si)) {
512 <                        double  d = sens_val(rr.rdir);
513 <                        if (d <= FTINY)
512 >                        sf = sens_val(rr.rdir);
513 >                        if (sf <= FTINY)
514                                  continue;
515 <                        d *= si.dom/ndirs;
516 <                        scalecolor(rr.rcoef, d);
515 >                        sf *= si.dom/ndirs;
516 >                        scalecolor(rr.rcoef, sf);
517                          if (ray_pqueue(&rr) == 1) {
518                                  multcolor(rr.rcol, rr.rcoef);
519                                  addcolor(vsum, rr.rcol);
520                          }
521                  }
522          }
523 <                                                /* finish direct calculation */
523 >                                                /* finish our calculation */
524          while (ray_presult(&rr, 0) > 0) {
525                  multcolor(rr.rcol, rr.rcoef);
526                  addcolor(vsum, rr.rcol);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines