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 1.20 by greg, Tue May 21 17:41:19 1991 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 +
26   getrect(s, r)                           /* get a box */
27   char  *s;
28   register RECT  *r;
# Line 27 | Line 31 | register RECT  *r;
31  
32          if (*s && !strncmp(s, "all", strlen(s))) {
33                  r->l = r->d = 0;
34 <                r->r = ourview.hresolu;
35 <                r->u = ourview.vresolu;
34 >                r->r = hresolu;
35 >                r->u = vresolu;
36                  return(0);
37          }
38          if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) {
# Line 57 | Line 61 | register RECT  *r;
61          }
62          if (r->l < 0) r->l = 0;
63          if (r->d < 0) r->d = 0;
64 <        if (r->r > ourview.hresolu) r->r = ourview.hresolu;
65 <        if (r->u > ourview.vresolu) r->u = ourview.vresolu;
64 >        if (r->r > hresolu) r->r = hresolu;
65 >        if (r->u > vresolu) r->u = vresolu;
66          if (r->l > r->r) r->l = r->r;
67          if (r->d > r->u) r->d = r->u;
68          return(0);
# Line 89 | Line 93 | double  *mp;
93                  (*dev->comout)("Pick view center\n");
94                  if ((*dev->getcur)(&x, &y) == ABORT)
95                          return(-1);
96 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
96 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
97 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
98 >                        error(COMMAND, "not on image");
99 >                        return(-1);
100 >                }
101                  if (!direc || ourview.type == VT_PAR) {
102                          rayorigin(&thisray, NULL, PRIMARY, 1.0);
103                          if (!localhit(&thisray, &thescene)) {
# Line 129 | Line 137 | paint(p, xmin, ymin, xmax, ymax)       /* compute and paint
137   register PNODE  *p;
138   int  xmin, ymin, xmax, ymax;
139   {
140 +        extern long  nrays;
141 +        static long  lastflush = 0;
142          static RAY  thisray;
143          double  h, v;
134        register int  i;
144  
145          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
146                  p->x = xmin;
# Line 140 | Line 149 | int  xmin, ymin, xmax, ymax;
149                  return;
150          }
151                                                  /* jitter ray direction */
152 <        p->x = h = xmin + (xmax-xmin)*frandom();
153 <        p->y = v = ymin + (ymax-ymin)*frandom();
152 >        h = xmin + (xmax-xmin)*frandom();
153 >        v = ymin + (ymax-ymin)*frandom();
154          
155 <        rayview(thisray.rorg, thisray.rdir, &ourview, h, v);
155 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
156 >                        h/hresolu, v/vresolu) < 0) {
157 >                setcolor(thisray.rcol, 0.0, 0.0, 0.0);
158 >        } else {
159 >                rayorigin(&thisray, NULL, PRIMARY, 1.0);
160 >                samplendx++;
161 >                rayvalue(&thisray);
162 >        }
163  
164 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
165 <        
150 <        rayvalue(&thisray);
151 <
164 >        p->x = h;
165 >        p->y = v;
166          copycolor(p->v, thisray.rcol);
153
167          scalecolor(p->v, exposure);
168  
169          (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
170 +
171 +        if (dev->flush != NULL && nrays - lastflush >= WFLUSH) {
172 +                lastflush = nrays;
173 +                (*dev->flush)();
174 +        }
175   }
176  
177  
# Line 161 | Line 179 | newimage()                             /* start a new image */
179   {
180                                                  /* free old image */
181          freepkids(&ptrunk);
182 <                                                /* set up frame */
183 <        if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz)
184 <                newview(&ourview);              /* beware recursive loop! */
182 >                                                /* save reserve memory */
183 >        fillreserves();
184 >                                                /* compute resolution */
185 >        hresolu = dev->xsiz;
186 >        vresolu = dev->ysiz;
187 >        normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu);
188          pframe.l = pframe.d = 0;
189 <        pframe.r = ourview.hresolu; pframe.u = ourview.vresolu;
189 >        pframe.r = hresolu; pframe.u = vresolu;
190          pdepth = 0;
191                                                  /* clear device */
192 <        (*dev->clear)(ourview.hresolu, ourview.vresolu);
192 >        (*dev->clear)(hresolu, vresolu);
193                                                  /* get first value */
194 <        paint(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu);
194 >        paint(&ptrunk, 0, 0, hresolu, vresolu);
195   }
196  
197  
198   redraw()                                /* redraw the image */
199   {
200 <        (*dev->clear)(ourview.hresolu, ourview.vresolu);
200 >        (*dev->clear)(hresolu, vresolu);
201          (*dev->comout)("redrawing...\n");
202 <        repaint(0, 0, ourview.hresolu, ourview.vresolu);
202 >        repaint(0, 0, hresolu, vresolu);
203          (*dev->comout)("\n");
204   }
205  
# Line 191 | Line 212 | int  xmin, ymin, xmax, ymax;
212          reg.l = xmin; reg.r = xmax;
213          reg.d = ymin; reg.u = ymax;
214  
215 <        paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, &reg);
215 >        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &reg);
216   }
217  
218  
# Line 339 | Line 360 | register VIEW  *vp;
360   {
361          char  *err;
362  
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                }
363          if ((err = setview(vp)) != NULL) {
364                  sprintf(errmsg, "view not set - %s", err);
365                  error(COMMAND, errmsg);
366 <        } else if (bcmp(vp, &ourview, sizeof(VIEW))) {
367 <                bcopy(&ourview, &oldview, sizeof(VIEW));
368 <                bcopy(vp, &ourview, sizeof(VIEW));
369 <                newimage();             /* newimage() calls with vp=&ourview! */
366 >        } else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
367 >                copystruct(&oldview, &ourview);
368 >                copystruct(&ourview, vp);
369 >                newimage();
370          }
371   }
372  
# Line 369 | Line 382 | FVECT  vc;
382          register int  i;
383  
384          VCOPY(nv.vup, ourview.vup);
385 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
385 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
386          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
387          if (elev != 0.0) {
388                  fcross(v1, ourview.vup, nv.vdir);
# Line 393 | Line 406 | FVECT  vc;
406   }
407  
408  
409 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
410 < FVECT  vres, vorig, vnorm;
411 < double  theta;
409 > zoomview(vp, zf)                        /* zoom in our out */
410 > register VIEW  *vp;
411 > double  zf;
412   {
413 <        extern double  sin(), cos();
414 <        double  sint, cost, dotp;
415 <        FVECT  vperp;
416 <        register int  i;
417 <        
405 <        if (theta == 0.0) {
406 <                VCOPY(vres, vorig);
413 >        switch (vp->type) {
414 >        case VT_PAR:                            /* parallel view */
415 >        case VT_ANG:                            /* angular fisheye */
416 >                vp->horiz /= zf;
417 >                vp->vert /= zf;
418                  return;
419 +        case VT_PER:                            /* perspective view */
420 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
421 +                                (PI/180./2.);
422 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
423 +                                (PI/180./2.);
424 +                return;
425 +        case VT_HEM:                            /* hemispherical fisheye */
426 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
427 +                if (vp->horiz >= 1.0-FTINY)
428 +                        vp->horiz = 180.;
429 +                else
430 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
431 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
432 +                if (vp->vert >= 1.0-FTINY)
433 +                        vp->vert = 180.;
434 +                else
435 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
436 +                return;
437          }
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;
438   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines