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 1.8 by greg, Wed Nov 1 16:12:20 1989 UTC vs.
Revision 2.3 by greg, Fri Oct 2 16:19:56 1992 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "random.h"
20  
21 + #ifndef WFLUSH
22 + #define WFLUSH          30              /* flush after this many rays */
23 + #endif
24  
25 + #ifdef  SMLFLT
26 + #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
27 + #else
28 + #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
29 + #endif
30 +
31 +
32   getrect(s, r)                           /* get a box */
33   char  *s;
34   register RECT  *r;
# Line 27 | Line 37 | register RECT  *r;
37  
38          if (*s && !strncmp(s, "all", strlen(s))) {
39                  r->l = r->d = 0;
40 <                r->r = ourview.hresolu;
41 <                r->u = ourview.vresolu;
40 >                r->r = hresolu;
41 >                r->u = vresolu;
42                  return(0);
43          }
44          if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) {
# Line 57 | Line 67 | register RECT  *r;
67          }
68          if (r->l < 0) r->l = 0;
69          if (r->d < 0) r->d = 0;
70 <        if (r->r > ourview.hresolu) r->r = ourview.hresolu;
71 <        if (r->u > ourview.vresolu) r->u = ourview.vresolu;
70 >        if (r->r > hresolu) r->r = hresolu;
71 >        if (r->u > vresolu) r->u = vresolu;
72          if (r->l > r->r) r->l = r->r;
73          if (r->d > r->u) r->d = r->u;
74          return(0);
# Line 83 | Line 93 | double  *mp;
93                  error(COMMAND, "illegal magnification");
94                  return(-1);
95          }
96 <        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
96 >        if (!sscanvec(sskip(s), vec)) {
97                  if (dev->getcur == NULL)
98                          return(-1);
99                  (*dev->comout)("Pick view center\n");
100                  if ((*dev->getcur)(&x, &y) == ABORT)
101                          return(-1);
102 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
102 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
103 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
104 >                        error(COMMAND, "not on image");
105 >                        return(-1);
106 >                }
107                  if (!direc || ourview.type == VT_PAR) {
108                          rayorigin(&thisray, NULL, PRIMARY, 1.0);
109                          if (!localhit(&thisray, &thescene)) {
# Line 129 | Line 143 | paint(p, xmin, ymin, xmax, ymax)       /* compute and paint
143   register PNODE  *p;
144   int  xmin, ymin, xmax, ymax;
145   {
146 +        extern long  nrays;
147 +        static long  lastflush = 0;
148          static RAY  thisray;
149          double  h, v;
134        register int  i;
150  
151          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
152                  p->x = xmin;
# Line 140 | Line 155 | int  xmin, ymin, xmax, ymax;
155                  return;
156          }
157                                                  /* jitter ray direction */
158 <        p->x = h = xmin + (xmax-xmin)*frandom();
159 <        p->y = v = ymin + (ymax-ymin)*frandom();
158 >        h = xmin + (xmax-xmin)*frandom();
159 >        v = ymin + (ymax-ymin)*frandom();
160          
161 <        rayview(thisray.rorg, thisray.rdir, &ourview, h, v);
161 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
162 >                        h/hresolu, v/vresolu) < 0) {
163 >                setcolor(thisray.rcol, 0.0, 0.0, 0.0);
164 >        } else {
165 >                rayorigin(&thisray, NULL, PRIMARY, 1.0);
166 >                samplendx++;
167 >                rayvalue(&thisray);
168 >        }
169  
170 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
171 <        
150 <        rayvalue(&thisray);
151 <
170 >        p->x = h;
171 >        p->y = v;
172          copycolor(p->v, thisray.rcol);
153
173          scalecolor(p->v, exposure);
174  
175          (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
176 +
177 +        if (dev->flush != NULL && nrays - lastflush >= WFLUSH) {
178 +                lastflush = nrays;
179 +                (*dev->flush)();
180 +        }
181   }
182  
183  
# Line 161 | Line 185 | newimage()                             /* start a new image */
185   {
186                                                  /* free old image */
187          freepkids(&ptrunk);
188 <                                                /* set up frame */
189 <        if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz)
190 <                newview(&ourview);              /* beware recursive loop! */
188 >                                                /* save reserve memory */
189 >        fillreserves();
190 >                                                /* compute resolution */
191 >        hresolu = dev->xsiz;
192 >        vresolu = dev->ysiz;
193 >        normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu);
194          pframe.l = pframe.d = 0;
195 <        pframe.r = ourview.hresolu; pframe.u = ourview.vresolu;
195 >        pframe.r = hresolu; pframe.u = vresolu;
196          pdepth = 0;
197                                                  /* clear device */
198 <        (*dev->clear)(ourview.hresolu, ourview.vresolu);
198 >        (*dev->clear)(hresolu, vresolu);
199                                                  /* get first value */
200 <        paint(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu);
200 >        paint(&ptrunk, 0, 0, hresolu, vresolu);
201   }
202  
203  
204   redraw()                                /* redraw the image */
205   {
206 <        (*dev->clear)(ourview.hresolu, ourview.vresolu);
206 >        (*dev->clear)(hresolu, vresolu);
207          (*dev->comout)("redrawing...\n");
208 <        repaint(0, 0, ourview.hresolu, ourview.vresolu);
208 >        repaint(0, 0, hresolu, vresolu);
209          (*dev->comout)("\n");
210   }
211  
# Line 191 | Line 218 | int  xmin, ymin, xmax, ymax;
218          reg.l = xmin; reg.r = xmax;
219          reg.d = ymin; reg.u = ymax;
220  
221 <        paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, &reg);
221 >        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &reg);
222   }
223  
224  
# Line 339 | Line 366 | register VIEW  *vp;
366   {
367          char  *err;
368  
342        if (vp->hresolu > dev->xsiz || vp->vresolu > dev->ysiz) /* shrink */
343                if (vp->vresolu * dev->xsiz < vp->hresolu * dev->ysiz) {
344                        vp->vresolu = dev->xsiz * vp->vresolu / vp->hresolu;
345                        vp->hresolu = dev->xsiz;
346                } else {
347                        vp->hresolu = dev->ysiz * vp->hresolu / vp->vresolu;
348                        vp->vresolu = dev->ysiz;
349                }
369          if ((err = setview(vp)) != NULL) {
370                  sprintf(errmsg, "view not set - %s", err);
371                  error(COMMAND, errmsg);
372 <        } else if (bcmp(vp, &ourview, sizeof(VIEW))) {
373 <                bcopy(&ourview, &oldview, sizeof(VIEW));
374 <                bcopy(vp, &ourview, sizeof(VIEW));
375 <                newimage();             /* newimage() calls with vp=&ourview! */
372 >        } else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
373 >                copystruct(&oldview, &ourview);
374 >                copystruct(&ourview, vp);
375 >                newimage();
376          }
377   }
378  
# Line 362 | Line 381 | moveview(angle, elev, mag, vc)                 /* move viewpoint */
381   double  angle, elev, mag;
382   FVECT  vc;
383   {
365        extern double  sqrt(), dist2();
384          double  d;
385          FVECT  v1;
386          VIEW  nv;
387          register int  i;
388  
389          VCOPY(nv.vup, ourview.vup);
390 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
390 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
391          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
392          if (elev != 0.0) {
393                  fcross(v1, ourview.vup, nv.vdir);
# Line 393 | Line 411 | FVECT  vc;
411   }
412  
413  
414 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
415 < FVECT  vres, vorig, vnorm;
416 < double  theta;
414 > zoomview(vp, zf)                        /* zoom in our out */
415 > register VIEW  *vp;
416 > double  zf;
417   {
418 <        extern double  sin(), cos();
419 <        double  sint, cost, dotp;
420 <        FVECT  vperp;
421 <        register int  i;
422 <        
405 <        if (theta == 0.0) {
406 <                VCOPY(vres, vorig);
418 >        switch (vp->type) {
419 >        case VT_PAR:                            /* parallel view */
420 >        case VT_ANG:                            /* angular fisheye */
421 >                vp->horiz /= zf;
422 >                vp->vert /= zf;
423                  return;
424 +        case VT_PER:                            /* perspective view */
425 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
426 +                                (PI/180./2.);
427 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
428 +                                (PI/180./2.);
429 +                return;
430 +        case VT_HEM:                            /* hemispherical fisheye */
431 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
432 +                if (vp->horiz >= 1.0-FTINY)
433 +                        vp->horiz = 180.;
434 +                else
435 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
436 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
437 +                if (vp->vert >= 1.0-FTINY)
438 +                        vp->vert = 180.;
439 +                else
440 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
441 +                return;
442          }
409        sint = sin(theta);
410        cost = cos(theta);
411        dotp = DOT(vorig, vnorm);
412        fcross(vperp, vnorm, vorig);
413        for (i = 0; i < 3; i++)
414                vres[i] = vnorm[i]*dotp*(1.-cost) +
415                                vorig[i]*cost + vperp[i]*sint;
443   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines