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.21 by greg, Tue Mar 11 02:21:47 2008 UTC vs.
Revision 2.22 by greg, Thu Aug 21 07:05:59 2008 UTC

# Line 16 | Line 16 | static const char      RCSid[] = "$Id$";
16   #include  "random.h"
17  
18   #ifndef WFLUSH
19 < #define WFLUSH          2048            /* flush after this many rays */
19 > #define WFLUSH          64              /* flush after this many rays */
20   #endif
21  
22   #ifdef  SMLFLT
# Line 27 | Line 27 | static const char      RCSid[] = "$Id$";
27  
28  
29   int
30 < getrect(s, r)                           /* get a box */
31 < char  *s;
32 < register RECT  *r;
30 > getrect(                                /* get a box */
31 >        char  *s,
32 >        RECT  *r
33 > )
34   {
35          int  x0, y0, x1, y1;
36  
# Line 74 | Line 75 | register RECT  *r;
75  
76  
77   int
78 < getinterest(s, direc, vec, mp)          /* get area of interest */
79 < char  *s;
80 < int  direc;
81 < FVECT  vec;
82 < double  *mp;
78 > getinterest(            /* get area of interest */
79 >        char  *s,
80 >        int  direc,
81 >        FVECT  vec,
82 >        double  *mp
83 > )
84   {
85          int  x, y;
86          RAY  thisray;
87 <        register int  i;
87 >        int  i;
88  
89          if (sscanf(s, "%lf", mp) != 1)
90                  *mp = 1.0;
# Line 131 | Line 133 | double  *mp;
133  
134  
135   float *         /* keep consistent with COLOR typedef */
136 < greyof(col)                             /* convert color to greyscale */
137 < register COLOR  col;
136 > greyof(                         /* convert color to greyscale */
137 >        COLOR  col
138 > )
139   {
140          static COLOR  gcol;
141          double  b;
# Line 143 | Line 146 | register COLOR  col;
146   }
147  
148  
149 < void
150 < paint(p, xmin, ymin, xmax, ymax)        /* compute and paint a rectangle */
151 < register PNODE  *p;
152 < int  xmin, ymin, xmax, ymax;
149 > int
150 > paint(                  /* compute and paint a rectangle */
151 >        PNODE  *p
152 > )
153   {
154 +        extern int  ray_pnprocs;
155          static unsigned long  lastflush = 0;
156          static RAY  thisray;
157          double  h, v;
158  
159 <        if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
160 <                p->x = xmin;
161 <                p->y = ymin;
159 >        if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */
160 >                p->x = p->xmin;
161 >                p->y = p->ymin;
162                  setcolor(p->v, 0.0, 0.0, 0.0);
163 <                return;
163 >                return(0);
164          }
165                                                  /* jitter ray direction */
166 <        h = xmin + (xmax-xmin)*frandom();
167 <        v = ymin + (ymax-ymin)*frandom();
166 >        p->x = h = p->xmin + (p->xmax-p->xmin)*frandom();
167 >        p->y = v = p->ymin + (p->ymax-p->ymin)*frandom();
168          
169          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
170                          h/hresolu, v/vresolu)) < -FTINY) {
171                  setcolor(thisray.rcol, 0.0, 0.0, 0.0);
172          } else {
173 +                int  rval;
174                  rayorigin(&thisray, PRIMARY, NULL, NULL);
175 <                samplendx++;
176 <                rayvalue(&thisray);
175 >                thisray.rno = (unsigned long)p;
176 >                rval = ray_pqueue(&thisray);
177 >                if (!rval)
178 >                        return(0);
179 >                if (rval < 0)
180 >                        return(-1);
181 >                p = (PNODE *)thisray.rno;
182          }
183  
174        p->x = h;
175        p->y = v;
184          copycolor(p->v, thisray.rcol);
185          scalecolor(p->v, exposure);
186  
187 <        (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
187 >        (*dev->paintr)(greyscale?greyof(p->v):p->v, p->xmin, p->ymin, p->xmax, p->ymax);
188  
189 <        if (dev->flush != NULL && nrays - lastflush >= WFLUSH) {
190 <                lastflush = nrays;
189 >        if (dev->flush != NULL && raynum - lastflush >= WFLUSH*ray_pnprocs) {
190 >                lastflush = raynum;
191                  (*dev->flush)();
192          }
193 +        return(1);
194   }
195  
196  
197 + int
198 + waitrays(void)                          /* finish up pending rays */
199 + {
200 +        int     nwaited = 0;
201 +        int     rval;
202 +        RAY     raydone;
203 +        
204 +        while ((rval = ray_presult(&raydone, 0)) > 0) {
205 +                PNODE  *p = (PNODE *)raydone.rno;
206 +                copycolor(p->v, raydone.rcol);
207 +                scalecolor(p->v, exposure);
208 +                (*dev->paintr)(greyscale?greyof(p->v):p->v,
209 +                                p->xmin, p->ymin, p->xmax, p->ymax);
210 +                nwaited++;
211 +        }
212 +        if (rval < 0)
213 +                return(-1);
214 +        return(nwaited);
215 + }
216 +
217 +
218   void
219 < newimage()                              /* start a new image */
219 > newimage(                                       /* start a new image */
220 >        char *s
221 > )
222   {
223 +        int     newnp;
224 +                                                /* change in nproc? */
225 +        if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) {
226 +                if (!newparam) {
227 +                        if (newnp < nproc)
228 +                                ray_pclose(nproc - newnp);
229 +                        else
230 +                                ray_popen(newnp - nproc);
231 +                }
232 +                nproc = newnp;
233 +        }
234                                                  /* free old image */
235          freepkids(&ptrunk);
193                                                /* save reserve memory */
194        fillreserves();
236                                                  /* compute resolution */
237          hresolu = dev->xsiz;
238          vresolu = dev->ysiz;
239          normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu);
240 <        pframe.l = pframe.d = 0;
241 <        pframe.r = hresolu; pframe.u = vresolu;
240 >        ptrunk.xmin = ptrunk.ymin = pframe.l = pframe.d = 0;
241 >        ptrunk.xmax = pframe.r = hresolu;
242 >        ptrunk.ymax = pframe.u = vresolu;
243          pdepth = 0;
244                                                  /* clear device */
245          (*dev->clear)(hresolu, vresolu);
246 +
247 +        if (newparam) {                         /* (re)start rendering procs */
248 +                ray_pclose(0);
249 +                ray_popen(nproc);
250 +                newparam = 0;
251 +        }
252                                                  /* get first value */
253 <        paint(&ptrunk, 0, 0, hresolu, vresolu);
253 >        paint(&ptrunk);
254   }
255  
256  
257   void
258 < redraw()                                /* redraw the image */
258 > redraw(void)                            /* redraw the image */
259   {
260          (*dev->clear)(hresolu, vresolu);
261          (*dev->comout)("redrawing...\n");
# Line 217 | Line 265 | redraw()                               /* redraw the image */
265  
266  
267   void
268 < repaint(xmin, ymin, xmax, ymax)                 /* repaint a region */
269 < int  xmin, ymin, xmax, ymax;
268 > repaint(                                /* repaint a region */
269 >        int  xmin,
270 >        int  ymin,
271 >        int  xmax,
272 >        int  ymax
273 > )
274   {
275          RECT  reg;
276  
277          reg.l = xmin; reg.r = xmax;
278          reg.d = ymin; reg.u = ymax;
279  
280 <        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &reg);
280 >        paintrect(&ptrunk, &reg);
281   }
282  
283  
284   void
285 < paintrect(p, xmin, ymin, xmax, ymax, r)         /* paint picture rectangle */
286 < register PNODE  *p;
287 < int  xmin, ymin, xmax, ymax;
288 < register RECT  *r;
285 > paintrect(                              /* paint picture rectangle */
286 >        PNODE  *p,
287 >        RECT  *r
288 > )
289   {
290          int  mx, my;
291  
292 <        if (xmax - xmin <= 0 || ymax - ymin <= 0)
292 >        if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0)
293                  return;
294  
295          if (p->kid == NULL) {
296                  (*dev->paintr)(greyscale?greyof(p->v):p->v,
297 <                                xmin, ymin, xmax, ymax);        /* do this */
297 >                        p->xmin, p->ymin, p->xmax, p->ymax);    /* do this */
298                  return;
299          }
300 <        mx = (xmin + xmax) >> 1;                                /* do kids */
301 <        my = (ymin + ymax) >> 1;
300 >        mx = (p->xmin + p->xmax) >> 1;                          /* do kids */
301 >        my = (p->ymin + p->ymax) >> 1;
302          if (mx > r->l) {
303                  if (my > r->d)
304 <                        paintrect(p->kid+DL, xmin, ymin, mx, my, r);
304 >                        paintrect(p->kid+DL, r);
305                  if (my < r->u)
306 <                        paintrect(p->kid+UL, xmin, my, mx, ymax, r);
306 >                        paintrect(p->kid+UL, r);
307          }
308          if (mx < r->r) {
309                  if (my > r->d)
310 <                        paintrect(p->kid+DR, mx, ymin, xmax, my, r);
310 >                        paintrect(p->kid+DR, r);
311                  if (my < r->u)
312 <                        paintrect(p->kid+UR, mx, my, xmax, ymax, r);
312 >                        paintrect(p->kid+UR, r);
313          }
314   }
315  
316  
317   PNODE *
318 < findrect(x, y, p, r, pd)                /* find a rectangle */
319 < int  x, y;
320 < register PNODE  *p;
321 < register RECT  *r;
322 < int  pd;
318 > findrect(                               /* find a rectangle */
319 >        int  x,
320 >        int  y,
321 >        PNODE  *p,
322 >        int  pd
323 > )
324   {
325          int  mx, my;
326  
327          while (p->kid != NULL && pd--) {
328  
329 <                mx = (r->l + r->r) >> 1;
330 <                my = (r->d + r->u) >> 1;
329 >                mx = (p->xmin + p->xmax) >> 1;
330 >                my = (p->ymin + p->ymax) >> 1;
331  
332                  if (x < mx) {
280                        r->r = mx;
333                          if (y < my) {
282                                r->u = my;
334                                  p = p->kid+DL;
335                          } else {
285                                r->d = my;
336                                  p = p->kid+UL;
337                          }
338                  } else {
289                        r->l = mx;
339                          if (y < my) {
291                                r->u = my;
340                                  p = p->kid+DR;
341                          } else {
294                                r->d = my;
342                                  p = p->kid+UR;
343                          }
344                  }
# Line 301 | Line 348 | int  pd;
348  
349  
350   void
351 < scalepict(p, sf)                        /* scale picture values */
352 < register PNODE  *p;
353 < double  sf;
351 > scalepict(                              /* scale picture values */
352 >        PNODE  *p,
353 >        double  sf
354 > )
355   {
356          scalecolor(p->v, sf);           /* do this node */
357  
# Line 318 | Line 366 | double  sf;
366  
367  
368   void
369 < getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */
370 < int  yoff;
371 < register COLR  *scan;
372 < register PNODE  *p;
373 < int  xsiz, ysiz;
369 > getpictcolrs(                           /* get scanline from picture */
370 >        int  yoff,
371 >        COLR  *scan,
372 >        PNODE  *p,
373 >        int  xsiz,
374 >        int  ysiz
375 > )
376   {
377 <        register int  mx;
377 >        int  mx;
378          int  my;
379  
380          if (p->kid == NULL) {                   /* do this node */
# Line 349 | Line 399 | int  xsiz, ysiz;
399  
400  
401   void
402 < freepkids(p)                            /* free pnode's children */
403 < register PNODE  *p;
402 > freepkids(                              /* free pnode's children */
403 >        PNODE  *p
404 > )
405   {
406          if (p->kid == NULL)
407                  return;
# Line 364 | Line 415 | register PNODE  *p;
415  
416  
417   void
418 < newview(vp)                             /* change viewing parameters */
419 < register VIEW  *vp;
418 > newview(                                        /* change viewing parameters */
419 >        VIEW  *vp
420 > )
421   {
422          char  *err;
423  
# Line 375 | Line 427 | register VIEW  *vp;
427          } else if (memcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
428                  oldview = ourview;
429                  ourview = *vp;
430 <                newimage();
430 >                newimage(NULL);
431          }
432   }
433  
434  
435   void
436 < moveview(angle, elev, mag, vc)                  /* move viewpoint */
437 < double  angle, elev, mag;
438 < FVECT  vc;
436 > moveview(                                       /* move viewpoint */
437 >        double  angle,
438 >        double  elev,
439 >        double  mag,
440 >        FVECT  vc
441 > )
442   {
443          double  d;
444          FVECT  v1;
445          VIEW  nv = ourview;
446 <        register int  i;
446 >        int  i;
447  
448          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
449          if (elev != 0.0) {
# Line 421 | Line 476 | FVECT  vc;
476  
477  
478   void
479 < pcopy(p1, p2)                           /* copy paint node p1 into p2 */
480 < register PNODE  *p1, *p2;
479 > pcopy(                                  /* copy paint node p1 into p2 */
480 >        PNODE  *p1,
481 >        PNODE  *p2
482 > )
483   {
484          copycolor(p2->v, p1->v);
485          p2->x = p1->x;
# Line 431 | Line 488 | register PNODE  *p1, *p2;
488  
489  
490   void
491 < zoomview(vp, zf)                        /* zoom in or out */
492 < register VIEW  *vp;
493 < double  zf;
491 > zoomview(                               /* zoom in or out */
492 >        VIEW  *vp,
493 >        double  zf
494 > )
495   {
496          switch (vp->type) {
497          case VT_PAR:                            /* parallel view */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines