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

Comparing ray/src/rt/rv3.c (file contents):
Revision 2.25 by greg, Thu Aug 28 23:50:39 2008 UTC vs.
Revision 2.42 by greg, Thu Nov 8 00:54:07 2018 UTC

# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
13  
14   #include  "ray.h"
15   #include  "rpaint.h"
16 + #include  "otypes.h"
17 + #include  "otspecial.h"
18   #include  "random.h"
19  
20   #ifndef WFLUSH
21 < #define WFLUSH          64              /* flush after this many rays */
21 > #define WFLUSH          64              /* flush after this many primary rays */
22   #endif
23 + #ifndef WFLUSH1
24 + #define WFLUSH1         512             /* or this many total rays */
25 + #endif
26  
27 +
28   #ifdef  SMLFLT
29   #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
30   #else
31   #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
32   #endif
33  
34 < static unsigned long  niflush;          /* flushes since newimage() */
34 > extern int      ray_pnprocs;
35  
36 + static RNUMBER  niflush;                /* flushes since newimage() */
37 +
38   int
39   getrect(                                /* get a box */
40          char  *s,
# Line 108 | Line 116 | getinterest(           /* get area of interest */
116                  }
117                  if (!direc || ourview.type == VT_PAR) {
118                          rayorigin(&thisray, PRIMARY, NULL, NULL);
119 <                        if (!localhit(&thisray, &thescene)) {
119 >                        while (localhit(&thisray, &thescene)) {
120 >                                OBJREC  *m = findmaterial(thisray.ro);
121 >                                if (m != NULL && !istransp(m->otype) &&
122 >                                                !isBSDFproxy(m) &&
123 >                                                (thisray.clipset == NULL ||
124 >                                                        !inset(thisray.clipset,
125 >                                                            thisray.ro->omod)))
126 >                                        break;          /* found something */
127 >                                VCOPY(thisray.rorg, thisray.rop);
128 >                                rayclear(&thisray);     /* skip invisible */
129 >                        }
130 >                        if ((thisray.ro == NULL) | (thisray.ro == &Aftplane)) {
131                                  error(COMMAND, "not a local object");
132                                  return(-1);
133                          }
# Line 133 | Line 152 | getinterest(           /* get area of interest */
152   }
153  
154  
155 < float *         /* keep consistent with COLOR typedef */
155 > COLORV *
156   greyof(                         /* convert color to greyscale */
157          COLOR  col
158   )
# Line 146 | Line 165 | greyof(                                /* convert color to greyscale */
165          return(gcol);
166   }
167  
168 + static void
169 + recolor(                                        /* recolor the given node */
170 +        PNODE *p
171 + )
172 + {
173 +        while (p->kid != NULL) {                /* need to propogate down */
174 +                int  mx = (p->xmin + p->xmax) >> 1;
175 +                int  my = (p->ymin + p->ymax) >> 1;
176 +                int  ki;
177 +                if (p->x >= mx)
178 +                        ki = (p->y >= my) ? UR : DR;
179 +                else
180 +                        ki = (p->y >= my) ? UL : DL;
181 +                pcopy(p, p->kid+ki);
182 +                p = p->kid + ki;
183 +        }
184  
185 +        (*dev->paintr)(greyscale?greyof(p->v):p->v,
186 +                        p->xmin, p->ymin, p->xmax, p->ymax);
187 + }
188 +
189   int
190   paint(                  /* compute and paint a rectangle */
191          PNODE  *p
192   )
193   {
155        extern int  ray_pnprocs;
156        static unsigned long  lastflush = 0;
194          static RAY  thisray;
158        int     flushintvl;
195          double  h, v;
196  
197 <        if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */
197 >        if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) {      /* empty */
198                  p->x = p->xmin;
199                  p->y = p->ymin;
200                  setcolor(p->v, 0.0, 0.0, 0.0);
# Line 171 | Line 207 | paint(                 /* compute and paint a rectangle */
207          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
208                          h/hresolu, v/vresolu)) < -FTINY) {
209                  setcolor(thisray.rcol, 0.0, 0.0, 0.0);
210 <        } else {
211 <                int  rval;
210 >        } else if (!ray_pnprocs) {              /* immediate mode */
211 >                ray_trace(&thisray);
212 >        } else {                                /* queuing mode */
213 >                int     rval;
214                  rayorigin(&thisray, PRIMARY, NULL, NULL);
215 <                thisray.rno = (unsigned long)p;
215 >                thisray.rno = (RNUMBER)p;
216                  rval = ray_pqueue(&thisray);
217                  if (!rval)
218                          return(0);
219                  if (rval < 0)
220                          return(-1);
221 +                                                /* get node for returned ray */
222                  p = (PNODE *)thisray.rno;
223          }
224  
225          copycolor(p->v, thisray.rcol);
226          scalecolor(p->v, exposure);
227  
228 <        while (p->kid != NULL) {                /* need to propogate down */
229 <                int  mx = (p->xmin + p->xmax) >> 1;
230 <                int  my = (p->ymin + p->ymax) >> 1;
231 <                int  ki;
232 <                if (p->x >= mx)
233 <                        ki = (p->y >= my) ? UR : DR;
228 >        recolor(p);                             /* paint it */
229 >
230 >        if (dev->flush != NULL) {               /* shall we check for input? */
231 >                static RNUMBER  lastflush = 0;
232 >                RNUMBER         counter = raynum;
233 >                int             flushintvl;
234 >                if (!ray_pnprocs) {
235 >                        counter = nrays;
236 >                        flushintvl = WFLUSH1;
237 >                } else if (ambounce == 0)
238 >                        flushintvl = ray_pnprocs*WFLUSH;
239 >                else if (niflush < WFLUSH)
240 >                        flushintvl = ray_pnprocs*niflush/(ambounce*(ambounce>0)+1);
241                  else
242 <                        ki = (p->y >= my) ? UL : DL;
243 <                pcopy(p, p->kid+ki);
244 <                p = p->kid + ki;
199 <        }
242 >                        flushintvl = ray_pnprocs*WFLUSH/(ambounce*(ambounce>0)+1);
243 >                if (lastflush > counter)
244 >                        lastflush = 0;          /* counter wrapped */
245  
246 <        (*dev->paintr)(greyscale?greyof(p->v):p->v,
247 <                        p->xmin, p->ymin, p->xmax, p->ymax);
248 <
249 <        if (ambounce <= 0)                      /* shall we check for input? */
250 <                flushintvl = ray_pnprocs*WFLUSH;
206 <        else if (niflush < WFLUSH)
207 <                flushintvl = ray_pnprocs*niflush/(ambounce+1);
208 <        else
209 <                flushintvl = ray_pnprocs*WFLUSH/(ambounce+1);
210 <
211 <        if (dev->flush != NULL && raynum - lastflush >= flushintvl) {
212 <                lastflush = raynum;
213 <                (*dev->flush)();
214 <                niflush++;
246 >                if (counter - lastflush >= flushintvl) {
247 >                        lastflush = counter;
248 >                        (*dev->flush)();
249 >                        niflush++;
250 >                }
251          }
252          return(1);
253   }
# Line 223 | Line 259 | waitrays(void)                                 /* finish up pending rays */
259          int     nwaited = 0;
260          int     rval;
261          RAY     raydone;
262 <        
262 >
263 >        if (!ray_pnprocs)                       /* immediate mode? */
264 >                return(0);
265          while ((rval = ray_presult(&raydone, 0)) > 0) {
266                  PNODE  *p = (PNODE *)raydone.rno;
267                  copycolor(p->v, raydone.rcol);
268                  scalecolor(p->v, exposure);
269 <                (*dev->paintr)(greyscale?greyof(p->v):p->v,
232 <                                p->xmin, p->ymin, p->xmax, p->ymax);
269 >                recolor(p);
270                  nwaited++;
271          }
272          if (rval < 0)
# Line 243 | Line 280 | newimage(                                      /* start a new image */
280          char *s
281   )
282   {
283 <        int     newnp;
284 <                                                /* change in nproc? */
285 <        if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) {
286 <                if (!newparam) {
250 <                        if (newnp < nproc)
251 <                                ray_pclose(nproc - newnp);
252 <                        else
253 <                                ray_popen(newnp - nproc);
254 <                }
255 <                nproc = newnp;
256 <        }
283 >        int             newnp = 0;
284 >                                                /* # rendering procs arg? */
285 >        if (s != NULL)
286 >                sscanf(s, "%d", &newnp);
287                                                  /* free old image */
288          freepkids(&ptrunk);
289                                                  /* compute resolution */
# Line 268 | Line 298 | newimage(                                      /* start a new image */
298          (*dev->clear)(hresolu, vresolu);
299  
300          if (newparam) {                         /* (re)start rendering procs */
301 <                ray_pclose(0);
302 <                ray_popen(nproc);
301 >                if (ray_pnprocs)
302 >                        ray_pclose(0);          /* should already be closed */
303 >                if (newnp > 0)
304 >                        nproc = newnp;
305 >                if (nproc > 1)
306 >                        ray_popen(nproc);
307                  newparam = 0;
308 +        } else if ((newnp > 0) & (newnp != nproc)) {
309 +                if (newnp == 1)                 /* change # rendering procs */
310 +                        ray_pclose(0);
311 +                else if (newnp < ray_pnprocs)
312 +                        ray_pclose(ray_pnprocs - newnp);
313 +                else
314 +                        ray_popen(newnp - ray_pnprocs);
315 +                nproc = newnp;
316          }
317          niflush = 0;                            /* get first value */
318          paint(&ptrunk);
# Line 371 | Line 413 | findrect(                              /* find a rectangle */
413  
414  
415   void
416 + compavg(                                /* recompute averages */
417 +        PNODE   *p
418 + )
419 + {
420 +        int     i, navg;
421 +        
422 +        if (p->kid == NULL)
423 +                return;
424 +
425 +        setcolor(p->v, .0, .0, .0);
426 +        navg = 0;
427 +        for (i = 0; i < 4; i++) {
428 +                if (p->kid[i].xmin >= p->kid[i].xmax) continue;
429 +                if (p->kid[i].ymin >= p->kid[i].ymax) continue;
430 +                compavg(p->kid+i);
431 +                addcolor(p->v, p->kid[i].v);
432 +                navg++;
433 +        }
434 +        if (navg > 1)
435 +                scalecolor(p->v, 1./navg);
436 + }
437 +
438 +
439 + void
440   scalepict(                              /* scale picture values */
441          PNODE  *p,
442          double  sf
# Line 464 | Line 530 | moveview(                                      /* move viewpoint */
530   )
531   {
532          double  d;
467        FVECT  v1;
533          VIEW  nv = ourview;
534          int  i;
535  
536          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
537 <        if (elev != 0.0) {
538 <                fcross(v1, ourview.vup, nv.vdir);
539 <                normalize(v1);
475 <                spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
476 <        }
537 >        if (elev != 0.0)
538 >                geodesic(nv.vdir, nv.vdir, nv.vup, elev*(-PI/180.), GEOD_RAD);
539 >
540          if (nv.type == VT_PAR) {
541                  nv.horiz /= mag;
542                  nv.vert /= mag;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines