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.13 by schorsch, Mon Jul 21 22:30:19 2003 UTC vs.
Revision 2.24 by greg, Fri Aug 22 17:39:26 2008 UTC

# Line 16 | Line 16 | static const char      RCSid[] = "$Id$";
16   #include  "random.h"
17  
18   #ifndef WFLUSH
19 < #ifdef SPEED
20 < #define WFLUSH          (5*SPEED)
21 < #else
22 < #define WFLUSH          100             /* flush after this many rays */
19 > #define WFLUSH          64              /* flush after this many rays */
20   #endif
24 #endif
21  
22   #ifdef  SMLFLT
23   #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
# Line 29 | Line 25 | static const char      RCSid[] = "$Id$";
25   #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
26   #endif
27  
28 + static unsigned long  niflush;          /* flushes since newimage() */
29  
30   int
31 < getrect(s, r)                           /* get a box */
32 < char  *s;
33 < register RECT  *r;
31 > getrect(                                /* get a box */
32 >        char  *s,
33 >        RECT  *r
34 > )
35   {
36          int  x0, y0, x1, y1;
37  
# Line 78 | Line 76 | register RECT  *r;
76  
77  
78   int
79 < getinterest(s, direc, vec, mp)          /* get area of interest */
80 < char  *s;
81 < int  direc;
82 < FVECT  vec;
83 < double  *mp;
79 > getinterest(            /* get area of interest */
80 >        char  *s,
81 >        int  direc,
82 >        FVECT  vec,
83 >        double  *mp
84 > )
85   {
86          int  x, y;
87          RAY  thisray;
88 <        register int  i;
88 >        int  i;
89  
90          if (sscanf(s, "%lf", mp) != 1)
91                  *mp = 1.0;
# Line 108 | Line 107 | double  *mp;
107                          return(-1);
108                  }
109                  if (!direc || ourview.type == VT_PAR) {
110 <                        rayorigin(&thisray, NULL, PRIMARY, 1.0);
110 >                        rayorigin(&thisray, PRIMARY, NULL, NULL);
111                          if (!localhit(&thisray, &thescene)) {
112                                  error(COMMAND, "not a local object");
113                                  return(-1);
# Line 122 | Line 121 | double  *mp;
121                                  VCOPY(vec, thisray.rdir);
122                  else
123                          VCOPY(vec, thisray.rop);
124 <        } else if (direc)
125 <                        for (i = 0; i < 3; i++)
126 <                                vec[i] -= ourview.vp[i];
124 >        } else if (direc) {
125 >                for (i = 0; i < 3; i++)
126 >                        vec[i] -= ourview.vp[i];
127 >                if (normalize(vec) == 0.0) {
128 >                        error(COMMAND, "point at view origin");
129 >                        return(-1);
130 >                }
131 >        }
132          return(0);
133   }
134  
135  
136   float *         /* keep consistent with COLOR typedef */
137 < greyof(col)                             /* convert color to greyscale */
138 < register COLOR  col;
137 > greyof(                         /* convert color to greyscale */
138 >        COLOR  col
139 > )
140   {
141          static COLOR  gcol;
142          double  b;
# Line 142 | Line 147 | register COLOR  col;
147   }
148  
149  
150 < void
151 < paint(p, xmin, ymin, xmax, ymax)        /* compute and paint a rectangle */
152 < register PNODE  *p;
153 < int  xmin, ymin, xmax, ymax;
150 > int
151 > paint(                  /* compute and paint a rectangle */
152 >        PNODE  *p
153 > )
154   {
155 +        extern int  ray_pnprocs;
156          static unsigned long  lastflush = 0;
157          static RAY  thisray;
158 +        int     flushintvl;
159          double  h, v;
160  
161 <        if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
162 <                p->x = xmin;
163 <                p->y = ymin;
161 >        if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */
162 >                p->x = p->xmin;
163 >                p->y = p->ymin;
164                  setcolor(p->v, 0.0, 0.0, 0.0);
165 <                return;
165 >                return(0);
166          }
167                                                  /* jitter ray direction */
168 <        h = xmin + (xmax-xmin)*frandom();
169 <        v = ymin + (ymax-ymin)*frandom();
168 >        p->x = h = p->xmin + (p->xmax-p->xmin)*frandom();
169 >        p->y = v = p->ymin + (p->ymax-p->ymin)*frandom();
170          
171          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
172                          h/hresolu, v/vresolu)) < -FTINY) {
173                  setcolor(thisray.rcol, 0.0, 0.0, 0.0);
174          } else {
175 <                rayorigin(&thisray, NULL, PRIMARY, 1.0);
176 <                samplendx++;
177 <                rayvalue(&thisray);
175 >                int  rval;
176 >                rayorigin(&thisray, PRIMARY, NULL, NULL);
177 >                thisray.rno = (unsigned long)p;
178 >                rval = ray_pqueue(&thisray);
179 >                if (!rval)
180 >                        return(0);
181 >                if (rval < 0)
182 >                        return(-1);
183 >                p = (PNODE *)thisray.rno;
184          }
185  
173        p->x = h;
174        p->y = v;
186          copycolor(p->v, thisray.rcol);
187          scalecolor(p->v, exposure);
188  
189 <        (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
189 >        (*dev->paintr)(greyscale?greyof(p->v):p->v,
190 >                        p->xmin, p->ymin, p->xmax, p->ymax);
191  
192 <        if (dev->flush != NULL && nrays - lastflush >= WFLUSH) {
193 <                lastflush = nrays;
192 >        if (ambounce <= 0)                      /* shall we check for input? */
193 >                flushintvl = ray_pnprocs*WFLUSH;
194 >        else if (niflush < WFLUSH)
195 >                flushintvl = ray_pnprocs*niflush/(ambounce+1);
196 >        else
197 >                flushintvl = ray_pnprocs*WFLUSH/(ambounce+1);
198 >
199 >        if (dev->flush != NULL && raynum - lastflush >= flushintvl) {
200 >                lastflush = raynum;
201                  (*dev->flush)();
202 +                niflush++;
203          }
204 +        return(1);
205   }
206  
207  
208 + int
209 + waitrays(void)                                  /* finish up pending rays */
210 + {
211 +        int     nwaited = 0;
212 +        int     rval;
213 +        RAY     raydone;
214 +        
215 +        while ((rval = ray_presult(&raydone, 0)) > 0) {
216 +                PNODE  *p = (PNODE *)raydone.rno;
217 +                copycolor(p->v, raydone.rcol);
218 +                scalecolor(p->v, exposure);
219 +                (*dev->paintr)(greyscale?greyof(p->v):p->v,
220 +                                p->xmin, p->ymin, p->xmax, p->ymax);
221 +                nwaited++;
222 +        }
223 +        if (rval < 0)
224 +                return(-1);
225 +        return(nwaited);
226 + }
227 +
228 +
229   void
230 < newimage()                              /* start a new image */
230 > newimage(                                       /* start a new image */
231 >        char *s
232 > )
233   {
234 +        int     newnp;
235 +                                                /* change in nproc? */
236 +        if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) {
237 +                if (!newparam) {
238 +                        if (newnp < nproc)
239 +                                ray_pclose(nproc - newnp);
240 +                        else
241 +                                ray_popen(newnp - nproc);
242 +                }
243 +                nproc = newnp;
244 +        }
245                                                  /* free old image */
246          freepkids(&ptrunk);
192                                                /* save reserve memory */
193        fillreserves();
247                                                  /* compute resolution */
248          hresolu = dev->xsiz;
249          vresolu = dev->ysiz;
250          normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu);
251 <        pframe.l = pframe.d = 0;
252 <        pframe.r = hresolu; pframe.u = vresolu;
251 >        ptrunk.xmin = ptrunk.ymin = pframe.l = pframe.d = 0;
252 >        ptrunk.xmax = pframe.r = hresolu;
253 >        ptrunk.ymax = pframe.u = vresolu;
254          pdepth = 0;
255                                                  /* clear device */
256          (*dev->clear)(hresolu, vresolu);
257 <                                                /* get first value */
258 <        paint(&ptrunk, 0, 0, hresolu, vresolu);
257 >
258 >        if (newparam) {                         /* (re)start rendering procs */
259 >                ray_pclose(0);
260 >                ray_popen(nproc);
261 >                newparam = 0;
262 >        }
263 >        niflush = 0;                            /* get first value */
264 >        paint(&ptrunk);
265   }
266  
267  
268   void
269 < redraw()                                /* redraw the image */
269 > redraw(void)                            /* redraw the image */
270   {
271          (*dev->clear)(hresolu, vresolu);
272          (*dev->comout)("redrawing...\n");
# Line 216 | Line 276 | redraw()                               /* redraw the image */
276  
277  
278   void
279 < repaint(xmin, ymin, xmax, ymax)                 /* repaint a region */
280 < int  xmin, ymin, xmax, ymax;
279 > repaint(                                /* repaint a region */
280 >        int  xmin,
281 >        int  ymin,
282 >        int  xmax,
283 >        int  ymax
284 > )
285   {
286          RECT  reg;
287  
288          reg.l = xmin; reg.r = xmax;
289          reg.d = ymin; reg.u = ymax;
290  
291 <        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &reg);
291 >        paintrect(&ptrunk, &reg);
292   }
293  
294  
295   void
296 < paintrect(p, xmin, ymin, xmax, ymax, r)         /* paint picture rectangle */
297 < register PNODE  *p;
298 < int  xmin, ymin, xmax, ymax;
299 < register RECT  *r;
296 > paintrect(                              /* paint picture rectangle */
297 >        PNODE  *p,
298 >        RECT  *r
299 > )
300   {
301          int  mx, my;
302  
303 <        if (xmax - xmin <= 0 || ymax - ymin <= 0)
303 >        if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0)
304                  return;
305  
306          if (p->kid == NULL) {
307                  (*dev->paintr)(greyscale?greyof(p->v):p->v,
308 <                                xmin, ymin, xmax, ymax);        /* do this */
308 >                        p->xmin, p->ymin, p->xmax, p->ymax);    /* do this */
309                  return;
310          }
311 <        mx = (xmin + xmax) >> 1;                                /* do kids */
312 <        my = (ymin + ymax) >> 1;
311 >        mx = (p->xmin + p->xmax) >> 1;                          /* do kids */
312 >        my = (p->ymin + p->ymax) >> 1;
313          if (mx > r->l) {
314                  if (my > r->d)
315 <                        paintrect(p->kid+DL, xmin, ymin, mx, my, r);
315 >                        paintrect(p->kid+DL, r);
316                  if (my < r->u)
317 <                        paintrect(p->kid+UL, xmin, my, mx, ymax, r);
317 >                        paintrect(p->kid+UL, r);
318          }
319          if (mx < r->r) {
320                  if (my > r->d)
321 <                        paintrect(p->kid+DR, mx, ymin, xmax, my, r);
321 >                        paintrect(p->kid+DR, r);
322                  if (my < r->u)
323 <                        paintrect(p->kid+UR, mx, my, xmax, ymax, r);
323 >                        paintrect(p->kid+UR, r);
324          }
325   }
326  
327  
328   PNODE *
329 < findrect(x, y, p, r, pd)                /* find a rectangle */
330 < int  x, y;
331 < register PNODE  *p;
332 < register RECT  *r;
333 < int  pd;
329 > findrect(                               /* find a rectangle */
330 >        int  x,
331 >        int  y,
332 >        PNODE  *p,
333 >        int  pd
334 > )
335   {
336          int  mx, my;
337  
338          while (p->kid != NULL && pd--) {
339  
340 <                mx = (r->l + r->r) >> 1;
341 <                my = (r->d + r->u) >> 1;
340 >                mx = (p->xmin + p->xmax) >> 1;
341 >                my = (p->ymin + p->ymax) >> 1;
342  
343                  if (x < mx) {
279                        r->r = mx;
344                          if (y < my) {
281                                r->u = my;
345                                  p = p->kid+DL;
346                          } else {
284                                r->d = my;
347                                  p = p->kid+UL;
348                          }
349                  } else {
288                        r->l = mx;
350                          if (y < my) {
290                                r->u = my;
351                                  p = p->kid+DR;
352                          } else {
293                                r->d = my;
353                                  p = p->kid+UR;
354                          }
355                  }
# Line 300 | Line 359 | int  pd;
359  
360  
361   void
362 < scalepict(p, sf)                        /* scale picture values */
363 < register PNODE  *p;
364 < double  sf;
362 > scalepict(                              /* scale picture values */
363 >        PNODE  *p,
364 >        double  sf
365 > )
366   {
367          scalecolor(p->v, sf);           /* do this node */
368  
# Line 317 | Line 377 | double  sf;
377  
378  
379   void
380 < getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */
381 < int  yoff;
382 < register COLR  *scan;
383 < register PNODE  *p;
384 < int  xsiz, ysiz;
380 > getpictcolrs(                           /* get scanline from picture */
381 >        int  yoff,
382 >        COLR  *scan,
383 >        PNODE  *p,
384 >        int  xsiz,
385 >        int  ysiz
386 > )
387   {
388 <        register int  mx;
388 >        int  mx;
389          int  my;
390  
391          if (p->kid == NULL) {                   /* do this node */
# Line 348 | Line 410 | int  xsiz, ysiz;
410  
411  
412   void
413 < freepkids(p)                            /* free pnode's children */
414 < register PNODE  *p;
413 > freepkids(                              /* free pnode's children */
414 >        PNODE  *p
415 > )
416   {
417          if (p->kid == NULL)
418                  return;
# Line 363 | Line 426 | register PNODE  *p;
426  
427  
428   void
429 < newview(vp)                             /* change viewing parameters */
430 < register VIEW  *vp;
429 > newview(                                        /* change viewing parameters */
430 >        VIEW  *vp
431 > )
432   {
433          char  *err;
434  
# Line 374 | Line 438 | register VIEW  *vp;
438          } else if (memcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
439                  oldview = ourview;
440                  ourview = *vp;
441 <                newimage();
441 >                newimage(NULL);
442          }
443   }
444  
445  
446   void
447 < moveview(angle, elev, mag, vc)                  /* move viewpoint */
448 < double  angle, elev, mag;
449 < FVECT  vc;
447 > moveview(                                       /* move viewpoint */
448 >        double  angle,
449 >        double  elev,
450 >        double  mag,
451 >        FVECT  vc
452 > )
453   {
454          double  d;
455          FVECT  v1;
456 <        VIEW  nv;
457 <        register int  i;
456 >        VIEW  nv = ourview;
457 >        int  i;
458  
392        VCOPY(nv.vup, ourview.vup);
393        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
459          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
460          if (elev != 0.0) {
461                  fcross(v1, ourview.vup, nv.vdir);
462                  normalize(v1);
463                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
464          }
465 <        if ((nv.type = ourview.type) == VT_PAR) {
466 <                nv.horiz = ourview.horiz / mag;
467 <                nv.vert = ourview.vert / mag;
465 >        if (nv.type == VT_PAR) {
466 >                nv.horiz /= mag;
467 >                nv.vert /= mag;
468                  d = 0.0;                        /* don't move closer */
469                  for (i = 0; i < 3; i++)
470                          d += (vc[i] - ourview.vp[i])*ourview.vdir[i];
406                nv.vfore = ourview.vfore;
407                nv.vaft = ourview.vaft;
471          } else {
409                nv.horiz = ourview.horiz;
410                nv.vert = ourview.vert;
472                  d = sqrt(dist2(ourview.vp, vc)) / mag;
473 <                if ((nv.vfore = ourview.vfore) > FTINY) {
473 >                if (nv.vfore > FTINY) {
474                          nv.vfore += d - d*mag;
475                          if (nv.vfore < 0.0) nv.vfore = 0.0;
476                  }
477 <                if ((nv.vaft = ourview.vaft) > FTINY) {
477 >                if (nv.vaft > FTINY) {
478                          nv.vaft += d - d*mag;
479                          if (nv.vaft <= nv.vfore) nv.vaft = 0.0;
480                  }
481 +                nv.vdist /= mag;
482          }
483          for (i = 0; i < 3; i++)
484                  nv.vp[i] = vc[i] - d*nv.vdir[i];
# Line 425 | Line 487 | FVECT  vc;
487  
488  
489   void
490 < pcopy(p1, p2)                           /* copy paint node p1 into p2 */
491 < register PNODE  *p1, *p2;
490 > pcopy(                                  /* copy paint node p1 into p2 */
491 >        PNODE  *p1,
492 >        PNODE  *p2
493 > )
494   {
495          copycolor(p2->v, p1->v);
496          p2->x = p1->x;
# Line 435 | Line 499 | register PNODE  *p1, *p2;
499  
500  
501   void
502 < zoomview(vp, zf)                        /* zoom in or out */
503 < register VIEW  *vp;
504 < double  zf;
502 > zoomview(                               /* zoom in or out */
503 >        VIEW  *vp,
504 >        double  zf
505 > )
506   {
507          switch (vp->type) {
508          case VT_PAR:                            /* parallel view */
# Line 451 | Line 516 | double  zf;
516                  vp->vert /= zf;
517                  if (vp->vert > 360.)
518                          vp->vert = 360.;
519 +                return;
520 +        case VT_PLS:                            /* planisphere fisheye */
521 +                vp->horiz = sin((PI/180./2.)*vp->horiz) /
522 +                                (1.0 + cos((PI/180./2.)*vp->horiz)) / zf;
523 +                vp->horiz *= vp->horiz;
524 +                vp->horiz = (2.*180./PI)*acos((1. - vp->horiz) /
525 +                                                (1. + vp->horiz));
526 +                vp->vert = sin((PI/180./2.)*vp->vert) /
527 +                                (1.0 + cos((PI/180./2.)*vp->vert)) / zf;
528 +                vp->vert *= vp->vert;
529 +                vp->vert = (2.*180./PI)*acos((1. - vp->vert) /
530 +                                                (1. + vp->vert));
531                  return;
532          case VT_CYL:                            /* cylindrical panorama */
533                  vp->horiz /= zf;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines