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.7 by greg, Sat Dec 12 19:01:00 2009 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 61 | Line 71 | print_defaults()
71          print_rdefaults();
72   }
73  
74 +
75 + void
76 + quit(ec)                        /* make sure exit is called */
77 + int     ec;
78 + {
79 +        if (ray_pnprocs > 0)    /* close children if any */
80 +                ray_pclose(0);          
81 +        exit(ec);
82 + }
83 +
84 +
85   int
86   main(
87          int     argc,
# Line 68 | Line 89 | main(
89   )
90   {
91          int     doheader = 1;
92 +        int     optwarn = 0;
93          int     i, rval;
94  
95          progname = argv[0];
96                                  /* set up rendering defaults */
97          rand_samp = 1;
98 <        dstrsrc = 0.5;
98 >        dstrsrc = 0.65;
99          srcsizerat = 0.1;
100          directrelay = 3;
101          ambounce = 1;
102          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");
103                                  /* get options from command line */
104 <        for (i = 1; i < argc-1; i++) {
104 >        for (i = 1; i < argc; i++) {
105                  while ((rval = expandarg(&argc, &argv, i)) > 0)
106                          ;
107                  if (rval < 0) {
108                          sprintf(errmsg, "cannot expand '%s'", argv[i]);
109                          error(SYSTEM, errmsg);
110                  }
111 <                if (argv[i][0] != '-') {        /* process a sensor file */
111 >                if (argv[i][0] != '-') {
112 >                        if (i >= argc-1)
113 >                                break;          /* final octree argument */
114                          if (!ray_pnprocs) {
115 <                                                /* overriding options */
100 <                                directvis = (ndsamps <= 0);
101 <                                do_irrad = 0;
115 >                                over_options();
116                                  if (doheader) { /* print header */
117 +                                        newheader("RADIANCE", stdout);
118                                          printargs(argc, argv, stdout);
119                                          fputformat("ascii", stdout);
120                                          putchar('\n');
# Line 107 | Line 122 | main(
122                                                  /* start process(es) */
123                                  ray_pinit(argv[argc-1], nprocs);
124                          }
125 <                        comp_sensor(argv[i]);
125 >                        comp_sensor(argv[i]);   /* process a sensor file */
126                          continue;
127                  }
128                  if (argv[i][1] == 'r') {        /* sampling options */
# Line 150 | Line 165 | main(
165                          sprintf(errmsg, "bad view option at '%s'", argv[i]);
166                          error(USER, errmsg);
167                  }
168 <                if (!strcmp(argv[i], "-w")) {   /* turn off warnings */
169 <                        nowarn = 1;
168 >                if (!strcmp(argv[i], "-w")) {   /* toggle warnings */
169 >                        nowarn = !nowarn;
170                          continue;
171                  }
172                  if (ray_pnprocs) {
173 <                        error(WARNING,
173 >                        if (!optwarn++)
174 >                                error(WARNING,
175                          "rendering options should appear before first sensor");
176                  } else if (!strcmp(argv[i], "-defaults")) {
177                          print_defaults();
# Line 178 | Line 194 | main(
194                  }
195                  i += rval;
196          }
197 +        if (!ray_pnprocs)
198 +                error(USER, i<argc ? "missing sensor file" : "missing octree");
199          quit(0);
200   }
201  
# Line 370 | Line 388 | init_ptable(
388                                              "code error 2 in init_ptable()");
389                                  frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t]
390                                                  + 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                                }
391                                  pvals[i*(nphi+1) + j] = (1.-frac1)*phdiv[p] +
392                                                          frac1*phdiv[p+1];
393                          }
# Line 461 | Line 473 | comp_sensor(
473          int     nt, np;
474          COLOR   vsum;
475          RAY     rr;
476 +        double  sf;
477          int     i, j;
478                                                  /* set view */
479          ourview.type = VT_ANG;
# Line 471 | Line 484 | comp_sensor(
484                  error(USER, err);
485                                                  /* assign probability table */
486          init_ptable(sfile);
487 <                                                /* do Monte Carlo sampling */
487 >                                                /* stratified MC sampling */
488          setcolor(vsum, .0f, .0f, .0f);
489          nt = (int)(sqrt((double)nsamps*ntheta/nphi) + .5);
490          np = nsamps/nt;
491 <        VCOPY(rr.rorg, ourview.vp);
479 <        rr.rmax = .0;
491 >        sf = gscale/nsamps;
492          for (i = 0; i < nt; i++)
493                  for (j = 0; j < np; j++) {
494 +                        VCOPY(rr.rorg, ourview.vp);
495                          get_direc(rr.rdir, (i+frandom())/nt, (j+frandom())/np);
496 +                        if (ourview.vfore > FTINY)
497 +                                VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore);
498 +                        rr.rmax = .0;
499                          rayorigin(&rr, PRIMARY, NULL, NULL);
500 +                        scalecolor(rr.rcoef, sf);
501                          if (ray_pqueue(&rr) == 1)
502                                  addcolor(vsum, rr.rcol);
503                  }
504 <                                                /* finish MC calculation */
505 <        while (ray_presult(&rr, 0) > 0)
506 <                addcolor(vsum, rr.rcol);
507 <        scalecolor(vsum, gscale/(nt*np));
508 <                                                /* compute direct component */
504 >                                                /* remaining rays pure MC */
505 >        for (i = nsamps - nt*np; i-- > 0; ) {
506 >                VCOPY(rr.rorg, ourview.vp);
507 >                get_direc(rr.rdir, frandom(), frandom());
508 >                if (ourview.vfore > FTINY)
509 >                        VSUM(rr.rorg, rr.rorg, rr.rdir, ourview.vfore);
510 >                rr.rmax = .0;
511 >                rayorigin(&rr, PRIMARY, NULL, NULL);
512 >                scalecolor(rr.rcoef, sf);
513 >                if (ray_pqueue(&rr) == 1)
514 >                        addcolor(vsum, rr.rcol);
515 >        }
516 >                                                /* scale partial result */
517 >        scalecolor(vsum, sf);
518 >                                                /* add direct component */
519          for (i = ndirs; i-- > 0; ) {
520                  SRCINDEX        si;
521                  initsrcindex(&si);
522                  while (srcray(&rr, NULL, &si)) {
523 <                        double  d = sens_val(rr.rdir);
524 <                        if (d <= FTINY)
523 >                        sf = sens_val(rr.rdir);
524 >                        if (sf <= FTINY)
525                                  continue;
526 <                        d *= si.dom/ndirs;
527 <                        scalecolor(rr.rcoef, d);
526 >                        sf *= si.dom/ndirs;
527 >                        scalecolor(rr.rcoef, sf);
528                          if (ray_pqueue(&rr) == 1) {
529                                  multcolor(rr.rcol, rr.rcoef);
530                                  addcolor(vsum, rr.rcol);
531                          }
532                  }
533          }
534 <                                                /* finish direct calculation */
534 >                                                /* finish our calculation */
535          while (ray_presult(&rr, 0) > 0) {
536                  multcolor(rr.rcol, rr.rcoef);
537                  addcolor(vsum, rr.rcol);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines