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.23 by greg, Thu Aug 21 16:13:00 2008 UTC vs.
Revision 2.29 by greg, Tue Sep 16 18:35:56 2008 UTC

# Line 16 | Line 16 | static const char      RCSid[] = "$Id$";
16   #include  "random.h"
17  
18   #ifndef WFLUSH
19 < #define WFLUSH          64              /* flush after this many rays */
19 > #define WFLUSH          64              /* flush after this many primary rays */
20   #endif
21 + #ifndef WFLUSH1
22 + #define WFLUSH1         512             /* or this many total rays */
23 + #endif
24  
25 +
26   #ifdef  SMLFLT
27   #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
28   #else
29   #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
30   #endif
31  
32 < static int  niflush;                    /* flushes since newimage() */
32 > static unsigned long  niflush;          /* flushes since newimage() */
33  
34   int
35   getrect(                                /* get a box */
# Line 146 | Line 150 | greyof(                                /* convert color to greyscale */
150          return(gcol);
151   }
152  
153 + static void
154 + recolor(                                        /* recolor the given node */
155 +        PNODE *p
156 + )
157 + {
158 +        while (p->kid != NULL) {                /* need to propogate down */
159 +                int  mx = (p->xmin + p->xmax) >> 1;
160 +                int  my = (p->ymin + p->ymax) >> 1;
161 +                int  ki;
162 +                if (p->x >= mx)
163 +                        ki = (p->y >= my) ? UR : DR;
164 +                else
165 +                        ki = (p->y >= my) ? UL : DL;
166 +                pcopy(p, p->kid+ki);
167 +                p = p->kid + ki;
168 +        }
169  
170 +        (*dev->paintr)(greyscale?greyof(p->v):p->v,
171 +                        p->xmin, p->ymin, p->xmax, p->ymax);
172 + }
173 +
174   int
175   paint(                  /* compute and paint a rectangle */
176          PNODE  *p
177   )
178   {
155        extern int  ray_pnprocs;
156        static unsigned long  lastflush = 0;
179          static RAY  thisray;
180          double  h, v;
181  
182 <        if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */
182 >        if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) {      /* empty */
183                  p->x = p->xmin;
184                  p->y = p->ymin;
185                  setcolor(p->v, 0.0, 0.0, 0.0);
# Line 170 | Line 192 | paint(                 /* compute and paint a rectangle */
192          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
193                          h/hresolu, v/vresolu)) < -FTINY) {
194                  setcolor(thisray.rcol, 0.0, 0.0, 0.0);
195 <        } else {
196 <                int  rval;
195 >        } else if (nproc == 1) {                /* immediate mode */
196 >                ray_trace(&thisray);
197 >        } else {                                /* queuing mode */
198 >                int     rval;
199                  rayorigin(&thisray, PRIMARY, NULL, NULL);
200                  thisray.rno = (unsigned long)p;
201                  rval = ray_pqueue(&thisray);
# Line 185 | Line 209 | paint(                 /* compute and paint a rectangle */
209          copycolor(p->v, thisray.rcol);
210          scalecolor(p->v, exposure);
211  
212 <        (*dev->paintr)(greyscale?greyof(p->v):p->v,
189 <                        p->xmin, p->ymin, p->xmax, p->ymax);
212 >        recolor(p);                             /* paint it */
213  
214 <        if (dev->flush != NULL && raynum - lastflush >= ray_pnprocs *
215 <                        (ambounce > 0 && niflush < WFLUSH ? niflush : WFLUSH)) {
216 <                lastflush = raynum;
217 <                (*dev->flush)();
218 <                niflush++;
214 >        if (dev->flush != NULL) {               /* shall we check for input? */
215 >                static unsigned long    lastflush = 0;
216 >                unsigned long           counter = raynum;
217 >                int                     flushintvl;
218 >                if (nproc == 1) {
219 >                        counter = nrays;
220 >                        flushintvl = WFLUSH1;
221 >                } else if (ambounce == 0)
222 >                        flushintvl = nproc*WFLUSH;
223 >                else if (niflush < WFLUSH)
224 >                        flushintvl = nproc*niflush/(ambounce+1);
225 >                else
226 >                        flushintvl = nproc*WFLUSH/(ambounce+1);
227 >
228 >                if (counter - lastflush >= flushintvl) {
229 >                        lastflush = counter;
230 >                        (*dev->flush)();
231 >                        niflush++;
232 >                }
233          }
234          return(1);
235   }
236  
237  
238   int
239 < waitrays(void)                          /* finish up pending rays */
239 > waitrays(void)                                  /* finish up pending rays */
240   {
241          int     nwaited = 0;
242          int     rval;
243          RAY     raydone;
244 <        
244 >
245 >        if (nproc == 1)                         /* immediate mode? */
246 >                return(0);
247          while ((rval = ray_presult(&raydone, 0)) > 0) {
248                  PNODE  *p = (PNODE *)raydone.rno;
249                  copycolor(p->v, raydone.rcol);
250                  scalecolor(p->v, exposure);
251 <                (*dev->paintr)(greyscale?greyof(p->v):p->v,
213 <                                p->xmin, p->ymin, p->xmax, p->ymax);
251 >                recolor(p);
252                  nwaited++;
253          }
254          if (rval < 0)
# Line 224 | Line 262 | newimage(                                      /* start a new image */
262          char *s
263   )
264   {
265 <        int     newnp;
265 >        extern int      ray_pnprocs;
266 >        int             newnp;
267                                                  /* change in nproc? */
268          if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) {
269                  if (!newparam) {
270 <                        if (newnp < nproc)
270 >                        if (nproc == 1)
271 >                                nproc = 0;      /* actually running */
272 >                        if (newnp == 1)
273 >                                ray_pclose(0);
274 >                        else if (newnp < nproc)
275                                  ray_pclose(nproc - newnp);
276                          else
277                                  ray_popen(newnp - nproc);
# Line 249 | Line 292 | newimage(                                      /* start a new image */
292          (*dev->clear)(hresolu, vresolu);
293  
294          if (newparam) {                         /* (re)start rendering procs */
295 <                ray_pclose(0);
296 <                ray_popen(nproc);
295 >                if (ray_pnprocs > 0)
296 >                        ray_pclose(0);
297 >                if (nproc > 1)
298 >                        ray_popen(nproc);
299                  newparam = 0;
300          }
301          niflush = 0;                            /* get first value */
# Line 348 | Line 393 | findrect(                              /* find a rectangle */
393                  }
394          }
395          return(p);
396 + }
397 +
398 +
399 + void
400 + compavg(                                /* recompute averages */
401 +        PNODE   *p
402 + )
403 + {
404 +        int     i, navg;
405 +        
406 +        if (p->kid == NULL)
407 +                return;
408 +
409 +        setcolor(p->v, .0, .0, .0);
410 +        navg = 0;
411 +        for (i = 0; i < 4; i++) {
412 +                if (p->kid[i].xmin >= p->kid[i].xmax) continue;
413 +                if (p->kid[i].ymin >= p->kid[i].ymax) continue;
414 +                compavg(p->kid+i);
415 +                addcolor(p->v, p->kid[i].v);
416 +                navg++;
417 +        }
418 +        if (navg > 1)
419 +                scalecolor(p->v, 1./navg);
420   }
421  
422  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines