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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines