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.9 by greg, Mon Jan 8 13:38:09 1990 UTC vs.
Revision 2.8 by greg, Wed Jan 25 16:08:57 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1994 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "random.h"
20  
21 + #ifndef WFLUSH
22 + #ifdef SPEED
23 + #define WFLUSH          (5*SPEED)
24 + #else
25 + #define WFLUSH          100             /* flush after this many rays */
26 + #endif
27 + #endif
28  
29 + #ifdef  SMLFLT
30 + #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
31 + #else
32 + #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
33 + #endif
34 +
35 +
36   getrect(s, r)                           /* get a box */
37   char  *s;
38   register RECT  *r;
# Line 83 | Line 97 | double  *mp;
97                  error(COMMAND, "illegal magnification");
98                  return(-1);
99          }
100 <        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
100 >        if (!sscanvec(sskip(s), vec)) {
101                  if (dev->getcur == NULL)
102                          return(-1);
103                  (*dev->comout)("Pick view center\n");
104                  if ((*dev->getcur)(&x, &y) == ABORT)
105                          return(-1);
106 <                viewray(thisray.rorg, thisray.rdir, &ourview,
107 <                                (x+.5)/hresolu, (y+.5)/vresolu);
106 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
107 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
108 >                        error(COMMAND, "not on image");
109 >                        return(-1);
110 >                }
111                  if (!direc || ourview.type == VT_PAR) {
112                          rayorigin(&thisray, NULL, PRIMARY, 1.0);
113                          if (!localhit(&thisray, &thescene)) {
# Line 130 | Line 147 | paint(p, xmin, ymin, xmax, ymax)       /* compute and paint
147   register PNODE  *p;
148   int  xmin, ymin, xmax, ymax;
149   {
150 +        extern unsigned long  nrays;
151 +        static unsigned long  lastflush = 0;
152          static RAY  thisray;
153          double  h, v;
135        register int  i;
154  
155          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
156                  p->x = xmin;
# Line 141 | Line 159 | int  xmin, ymin, xmax, ymax;
159                  return;
160          }
161                                                  /* jitter ray direction */
162 <        p->x = h = xmin + (xmax-xmin)*frandom();
163 <        h /= hresolu;
146 <        p->y = v = ymin + (ymax-ymin)*frandom();
147 <        v /= vresolu;
162 >        h = xmin + (xmax-xmin)*frandom();
163 >        v = ymin + (ymax-ymin)*frandom();
164          
165 <        viewray(thisray.rorg, thisray.rdir, &ourview, h, v);
165 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
166 >                        h/hresolu, v/vresolu)) < -FTINY) {
167 >                setcolor(thisray.rcol, 0.0, 0.0, 0.0);
168 >        } else {
169 >                rayorigin(&thisray, NULL, PRIMARY, 1.0);
170 >                samplendx++;
171 >                rayvalue(&thisray);
172 >        }
173  
174 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
175 <        
153 <        rayvalue(&thisray);
154 <
174 >        p->x = h;
175 >        p->y = v;
176          copycolor(p->v, thisray.rcol);
156
177          scalecolor(p->v, exposure);
178  
179          (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
180 +
181 +        if (dev->flush != NULL && nrays - lastflush >= WFLUSH) {
182 +                lastflush = nrays;
183 +                (*dev->flush)();
184 +        }
185   }
186  
187  
# Line 164 | Line 189 | newimage()                             /* start a new image */
189   {
190                                                  /* free old image */
191          freepkids(&ptrunk);
192 +                                                /* save reserve memory */
193 +        fillreserves();
194                                                  /* compute resolution */
195 <        if (viewaspect(&ourview)*dev->xsiz > dev->pixaspect*dev->ysiz) {
196 <                vresolu = dev->ysiz;
197 <                hresolu = vresolu/viewaspect(&ourview)*dev->pixaspect;
171 <        } else {
172 <                hresolu = dev->xsiz;
173 <                vresolu = hresolu*viewaspect(&ourview)/dev->pixaspect;
174 <        }
195 >        hresolu = dev->xsiz;
196 >        vresolu = dev->ysiz;
197 >        normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu);
198          pframe.l = pframe.d = 0;
199          pframe.r = hresolu; pframe.u = vresolu;
200          pdepth = 0;
# Line 350 | Line 373 | register VIEW  *vp;
373          if ((err = setview(vp)) != NULL) {
374                  sprintf(errmsg, "view not set - %s", err);
375                  error(COMMAND, errmsg);
376 <        } else if (bcmp(vp, &ourview, sizeof(VIEW))) {
377 <                copyview(&oldview, &ourview);
378 <                copyview(&ourview, vp);
379 <                newimage();             /* newimage() calls with vp=&ourview! */
376 >        } else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
377 >                copystruct(&oldview, &ourview);
378 >                copystruct(&ourview, vp);
379 >                newimage();
380          }
381   }
382  
# Line 362 | Line 385 | moveview(angle, elev, mag, vc)                 /* move viewpoint */
385   double  angle, elev, mag;
386   FVECT  vc;
387   {
365        extern double  sqrt(), dist2();
388          double  d;
389          FVECT  v1;
390          VIEW  nv;
# Line 382 | Line 404 | FVECT  vc;
404                  d = 0.0;                        /* don't move closer */
405                  for (i = 0; i < 3; i++)
406                          d += (vc[i] - ourview.vp[i])*ourview.vdir[i];
407 +                nv.vfore = ourview.vfore;
408 +                nv.vaft = ourview.vaft;
409          } else {
410                  nv.horiz = ourview.horiz;
411                  nv.vert = ourview.vert;
412                  d = sqrt(dist2(ourview.vp, vc)) / mag;
413 +                if ((nv.vfore = ourview.vfore) > FTINY) {
414 +                        nv.vfore += d - d*mag;
415 +                        if (nv.vfore < 0.0) nv.vfore = 0.0;
416 +                }
417 +                if ((nv.vaft = ourview.vaft) > FTINY) {
418 +                        nv.vaft += d - d*mag;
419 +                        if (nv.vaft <= nv.vfore) nv.vaft = 0.0;
420 +                }
421          }
422          for (i = 0; i < 3; i++)
423                  nv.vp[i] = vc[i] - d*nv.vdir[i];
# Line 393 | Line 425 | FVECT  vc;
425   }
426  
427  
428 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
429 < FVECT  vres, vorig, vnorm;
430 < double  theta;
428 > zoomview(vp, zf)                        /* zoom in our out */
429 > register VIEW  *vp;
430 > double  zf;
431   {
432 <        extern double  sin(), cos();
433 <        double  sint, cost, dotp;
434 <        FVECT  vperp;
435 <        register int  i;
436 <        
405 <        if (theta == 0.0) {
406 <                VCOPY(vres, vorig);
432 >        switch (vp->type) {
433 >        case VT_PAR:                            /* parallel view */
434 >        case VT_ANG:                            /* angular fisheye */
435 >                vp->horiz /= zf;
436 >                vp->vert /= zf;
437                  return;
438 +        case VT_PER:                            /* perspective view */
439 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
440 +                                (PI/180./2.);
441 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
442 +                                (PI/180./2.);
443 +                return;
444 +        case VT_HEM:                            /* hemispherical fisheye */
445 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
446 +                if (vp->horiz >= 1.0-FTINY)
447 +                        vp->horiz = 180.;
448 +                else
449 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
450 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
451 +                if (vp->vert >= 1.0-FTINY)
452 +                        vp->vert = 180.;
453 +                else
454 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
455 +                return;
456          }
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;
457   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines