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.1 by greg, Thu Feb 2 10:41:39 1989 UTC vs.
Revision 2.7 by greg, Thu Dec 22 11:46:19 1994 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 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include  "ray.h"
14  
15 + #include  "octree.h"
16 +
17   #include  "rpaint.h"
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;
39 + {
40 +        int  x0, y0, x1, y1;
41 +
42 +        if (*s && !strncmp(s, "all", strlen(s))) {
43 +                r->l = r->d = 0;
44 +                r->r = hresolu;
45 +                r->u = vresolu;
46 +                return(0);
47 +        }
48 +        if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) {
49 +                if (dev->getcur == NULL)
50 +                        return(-1);
51 +                (*dev->comout)("Pick first corner\n");
52 +                if ((*dev->getcur)(&x0, &y0) == ABORT)
53 +                        return(-1);
54 +                (*dev->comout)("Pick second corner\n");
55 +                if ((*dev->getcur)(&x1, &y1) == ABORT)
56 +                        return(-1);
57 +        }
58 +        if (x0 < x1) {
59 +                r->l = x0;
60 +                r->r = x1;
61 +        } else {
62 +                r->l = x1;
63 +                r->r = x0;
64 +        }
65 +        if (y0 < y1) {
66 +                r->d = y0;
67 +                r->u = y1;
68 +        } else {
69 +                r->d = y1;
70 +                r->u = y0;
71 +        }
72 +        if (r->l < 0) r->l = 0;
73 +        if (r->d < 0) r->d = 0;
74 +        if (r->r > hresolu) r->r = hresolu;
75 +        if (r->u > vresolu) r->u = vresolu;
76 +        if (r->l > r->r) r->l = r->r;
77 +        if (r->d > r->u) r->d = r->u;
78 +        return(0);
79 + }
80 +
81 +
82 + getinterest(s, direc, vec, mp)          /* get area of interest */
83 + char  *s;
84 + int  direc;
85 + FVECT  vec;
86 + double  *mp;
87 + {
88 +        int  x, y;
89 +        RAY  thisray;
90 +        register int  i;
91 +
92 +        if (sscanf(s, "%lf", mp) != 1)
93 +                *mp = 1.0;
94 +        else if (*mp < -FTINY)          /* negative zoom is reduction */
95 +                *mp = -1.0 / *mp;
96 +        else if (*mp <= FTINY) {        /* too small */
97 +                error(COMMAND, "illegal magnification");
98 +                return(-1);
99 +        }
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 +                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)) {
114 +                                error(COMMAND, "not a local object");
115 +                                return(-1);
116 +                        }
117 +                }
118 +                if (direc)
119 +                        if (ourview.type == VT_PAR)
120 +                                for (i = 0; i < 3; i++)
121 +                                        vec[i] = thisray.rop[i] - ourview.vp[i];
122 +                        else
123 +                                VCOPY(vec, thisray.rdir);
124 +                else
125 +                        VCOPY(vec, thisray.rop);
126 +        } else if (direc)
127 +                        for (i = 0; i < 3; i++)
128 +                                vec[i] -= ourview.vp[i];
129 +        return(0);
130 + }
131 +
132 +
133   float *         /* keep consistent with COLOR typedef */
134   greyof(col)                             /* convert color to greyscale */
135   register COLOR  col;
# Line 34 | 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;
39        register int  i;
154  
155          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
156                  p->x = xmin;
# Line 45 | Line 159 | int  xmin, ymin, xmax, ymax;
159                  return;
160          }
161                                                  /* jitter ray direction */
162 <        p->x = h = xmin + (xmax-xmin)*frandom();
163 <        p->y = v = ymin + (ymax-ymin)*frandom();
162 >        h = xmin + (xmax-xmin)*frandom();
163 >        v = ymin + (ymax-ymin)*frandom();
164          
165 <        rayview(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 <        
55 <        rayvalue(&thisray);
56 <
174 >        p->x = h;
175 >        p->y = v;
176          copycolor(p->v, thisray.rcol);
58
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 66 | Line 189 | newimage()                             /* start a new image */
189   {
190                                                  /* free old image */
191          freepkids(&ptrunk);
192 <                                                /* set up frame */
193 <        if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz)
194 <                error(USER, "resolution mismatch");
192 >                                                /* save reserve memory */
193 >        fillreserves();
194 >                                                /* compute resolution */
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 = ourview.hresolu; pframe.u = ourview.vresolu;
199 >        pframe.r = hresolu; pframe.u = vresolu;
200          pdepth = 0;
201                                                  /* clear device */
202 <        (*dev->clear)(ourview.hresolu, ourview.vresolu);
202 >        (*dev->clear)(hresolu, vresolu);
203                                                  /* get first value */
204 <        paint(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu);
204 >        paint(&ptrunk, 0, 0, hresolu, vresolu);
205   }
206  
207  
208   redraw()                                /* redraw the image */
209   {
210 <        (*dev->clear)(ourview.hresolu, ourview.vresolu);
210 >        (*dev->clear)(hresolu, vresolu);
211          (*dev->comout)("redrawing...\n");
212 <        repaint(0, 0, ourview.hresolu, ourview.vresolu);
212 >        repaint(0, 0, hresolu, vresolu);
213          (*dev->comout)("\n");
214   }
215  
# Line 96 | Line 222 | int  xmin, ymin, xmax, ymax;
222          reg.l = xmin; reg.r = xmax;
223          reg.d = ymin; reg.u = ymax;
224  
225 <        paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, &reg);
225 >        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &reg);
226   }
227  
228  
# Line 107 | Line 233 | register RECT  *r;
233   {
234          int  mx, my;
235  
110        if (dev->inpready)
111                return;                         /* break for input */
112
236          if (xmax - xmin <= 0 || ymax - ymin <= 0)
237                  return;
238  
# Line 247 | Line 370 | register VIEW  *vp;
370   {
371          char  *err;
372  
373 <        if (vp->hresolu > dev->xsiz || vp->vresolu > dev->ysiz) {
251 <                error(COMMAND, "view not set - resolution mismatch");
252 <        } else if ((err = setview(vp)) != NULL) {
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 <                bcopy(&ourview, &oldview, sizeof(VIEW));
378 <                bcopy(vp, &ourview, sizeof(VIEW));
376 >        } else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
377 >                copystruct(&oldview, &ourview);
378 >                copystruct(&ourview, vp);
379                  newimage();
380          }
381   }
382  
383  
384 < moveview(angle, mag, vc)                        /* move viewpoint */
385 < double  angle, mag;
384 > moveview(angle, elev, mag, vc)                  /* move viewpoint */
385 > double  angle, elev, mag;
386   FVECT  vc;
387   {
267        extern double  sqrt(), dist2();
388          double  d;
389 +        FVECT  v1;
390          VIEW  nv;
391          register int  i;
392  
393          VCOPY(nv.vup, ourview.vup);
394 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
394 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
395          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
396 <        d = sqrt(dist2(ourview.vp, vc)) / mag;
397 <        for (i = 0; i < 3; i++)
398 <                nv.vp[i] = vc[i] - d*nv.vdir[i];
396 >        if (elev != 0.0) {
397 >                fcross(v1, ourview.vup, nv.vdir);
398 >                normalize(v1);
399 >                spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
400 >        }
401          if ((nv.type = ourview.type) == VT_PAR) {
402                  nv.horiz = ourview.horiz / mag;
403                  nv.vert = ourview.vert / mag;
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 +                nv.vfore = ourview.vfore + d - d*mag;
414 +                if (nv.vfore < 0.0) nv.vfore = 0.0;
415 +                nv.vaft = ourview.vaft + d - d*mag;
416 +                if (nv.vaft < nv.vfore) nv.vaft = 0.0;
417          }
418 +        for (i = 0; i < 3; i++)
419 +                nv.vp[i] = vc[i] - d*nv.vdir[i];
420          newview(&nv);
421   }
422  
423  
424 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
425 < FVECT  vres, vorig, vnorm;
426 < double  theta;
424 > zoomview(vp, zf)                        /* zoom in our out */
425 > register VIEW  *vp;
426 > double  zf;
427   {
428 <        extern double  sin(), cos();
429 <        double  sint, cost, dotp;
430 <        FVECT  vperp;
431 <        register int  i;
432 <        
298 <        if (theta == 0.0) {
299 <                VCOPY(vres, vorig);
428 >        switch (vp->type) {
429 >        case VT_PAR:                            /* parallel view */
430 >        case VT_ANG:                            /* angular fisheye */
431 >                vp->horiz /= zf;
432 >                vp->vert /= zf;
433                  return;
434 +        case VT_PER:                            /* perspective view */
435 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
436 +                                (PI/180./2.);
437 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
438 +                                (PI/180./2.);
439 +                return;
440 +        case VT_HEM:                            /* hemispherical fisheye */
441 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
442 +                if (vp->horiz >= 1.0-FTINY)
443 +                        vp->horiz = 180.;
444 +                else
445 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
446 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
447 +                if (vp->vert >= 1.0-FTINY)
448 +                        vp->vert = 180.;
449 +                else
450 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
451 +                return;
452          }
302        sint = sin(theta);
303        cost = cos(theta);
304        dotp = DOT(vorig, vnorm);
305        fcross(vperp, vnorm, vorig);
306        for (i = 0; i < 3; i++)
307                vres[i] = vnorm[i]*dotp*(1.-cost) +
308                                vorig[i]*cost + vperp[i]*sint;
453   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines