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 1.19 by greg, Fri May 3 16:12:38 1991 UTC

# 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 + #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;
29 + {
30 +        int  x0, y0, x1, y1;
31 +
32 +        if (*s && !strncmp(s, "all", strlen(s))) {
33 +                r->l = r->d = 0;
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) {
39 +                if (dev->getcur == NULL)
40 +                        return(-1);
41 +                (*dev->comout)("Pick first corner\n");
42 +                if ((*dev->getcur)(&x0, &y0) == ABORT)
43 +                        return(-1);
44 +                (*dev->comout)("Pick second corner\n");
45 +                if ((*dev->getcur)(&x1, &y1) == ABORT)
46 +                        return(-1);
47 +        }
48 +        if (x0 < x1) {
49 +                r->l = x0;
50 +                r->r = x1;
51 +        } else {
52 +                r->l = x1;
53 +                r->r = x0;
54 +        }
55 +        if (y0 < y1) {
56 +                r->d = y0;
57 +                r->u = y1;
58 +        } else {
59 +                r->d = y1;
60 +                r->u = y0;
61 +        }
62 +        if (r->l < 0) r->l = 0;
63 +        if (r->d < 0) r->d = 0;
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);
69 + }
70 +
71 +
72 + getinterest(s, direc, vec, mp)          /* get area of interest */
73 + char  *s;
74 + int  direc;
75 + FVECT  vec;
76 + double  *mp;
77 + {
78 +        int  x, y;
79 +        RAY  thisray;
80 +        register int  i;
81 +
82 +        if (sscanf(s, "%lf", mp) != 1)
83 +                *mp = 1.0;
84 +        else if (*mp < -FTINY)          /* negative zoom is reduction */
85 +                *mp = -1.0 / *mp;
86 +        else if (*mp <= FTINY) {        /* too small */
87 +                error(COMMAND, "illegal magnification");
88 +                return(-1);
89 +        }
90 +        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
91 +                if (dev->getcur == NULL)
92 +                        return(-1);
93 +                (*dev->comout)("Pick view center\n");
94 +                if ((*dev->getcur)(&x, &y) == ABORT)
95 +                        return(-1);
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)) {
104 +                                error(COMMAND, "not a local object");
105 +                                return(-1);
106 +                        }
107 +                }
108 +                if (direc)
109 +                        if (ourview.type == VT_PAR)
110 +                                for (i = 0; i < 3; i++)
111 +                                        vec[i] = thisray.rop[i] - ourview.vp[i];
112 +                        else
113 +                                VCOPY(vec, thisray.rdir);
114 +                else
115 +                        VCOPY(vec, thisray.rop);
116 +        } else if (direc)
117 +                        for (i = 0; i < 3; i++)
118 +                                vec[i] -= ourview.vp[i];
119 +        return(0);
120 + }
121 +
122 +
123   float *         /* keep consistent with COLOR typedef */
124   greyof(col)                             /* convert color to greyscale */
125   register COLOR  col;
# Line 34 | 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;
39        register int  i;
144  
145          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
146                  p->x = xmin;
# Line 45 | 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 >                rayvalue(&thisray);
161 >        }
162  
163 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
164 <        
55 <        rayvalue(&thisray);
56 <
163 >        p->x = h;
164 >        p->y = v;
165          copycolor(p->v, thisray.rcol);
58
166          scalecolor(p->v, exposure);
167  
168          (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
169 +
170 +        if (dev->flush != NULL && nrays - lastflush >= WFLUSH) {
171 +                lastflush = nrays;
172 +                (*dev->flush)();
173 +        }
174   }
175  
176  
# Line 66 | Line 178 | newimage()                             /* start a new image */
178   {
179                                                  /* free old image */
180          freepkids(&ptrunk);
181 <                                                /* set up frame */
182 <        if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz)
183 <                error(USER, "resolution mismatch");
181 >                                                /* save reserve memory */
182 >        fillreserves();
183 >                                                /* compute resolution */
184 >        hresolu = dev->xsiz;
185 >        vresolu = dev->ysiz;
186 >        normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu);
187          pframe.l = pframe.d = 0;
188 <        pframe.r = ourview.hresolu; pframe.u = ourview.vresolu;
188 >        pframe.r = hresolu; pframe.u = vresolu;
189          pdepth = 0;
190                                                  /* clear device */
191 <        (*dev->clear)(ourview.hresolu, ourview.vresolu);
191 >        (*dev->clear)(hresolu, vresolu);
192                                                  /* get first value */
193 <        paint(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu);
193 >        paint(&ptrunk, 0, 0, hresolu, vresolu);
194   }
195  
196  
197   redraw()                                /* redraw the image */
198   {
199 <        (*dev->clear)(ourview.hresolu, ourview.vresolu);
199 >        (*dev->clear)(hresolu, vresolu);
200          (*dev->comout)("redrawing...\n");
201 <        repaint(0, 0, ourview.hresolu, ourview.vresolu);
201 >        repaint(0, 0, hresolu, vresolu);
202          (*dev->comout)("\n");
203   }
204  
# Line 96 | Line 211 | int  xmin, ymin, xmax, ymax;
211          reg.l = xmin; reg.r = xmax;
212          reg.d = ymin; reg.u = ymax;
213  
214 <        paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, &reg);
214 >        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &reg);
215   }
216  
217  
# Line 107 | Line 222 | register RECT  *r;
222   {
223          int  mx, my;
224  
110        if (dev->inpready)
111                return;                         /* break for input */
112
225          if (xmax - xmin <= 0 || ymax - ymin <= 0)
226                  return;
227  
# Line 247 | Line 359 | register VIEW  *vp;
359   {
360          char  *err;
361  
362 <        if (vp->hresolu > dev->xsiz || vp->vresolu > dev->ysiz) {
251 <                error(COMMAND, "view not set - resolution mismatch");
252 <        } else if ((err = setview(vp)) != NULL) {
362 >        if ((err = setview(vp)) != NULL) {
363                  sprintf(errmsg, "view not set - %s", err);
364                  error(COMMAND, errmsg);
365 <        } else if (bcmp(vp, &ourview, sizeof(VIEW))) {
366 <                bcopy(&ourview, &oldview, sizeof(VIEW));
367 <                bcopy(vp, &ourview, sizeof(VIEW));
365 >        } else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
366 >                copystruct(&oldview, &ourview);
367 >                copystruct(&ourview, vp);
368                  newimage();
369          }
370   }
371  
372  
373 < moveview(angle, mag, vc)                        /* move viewpoint */
374 < double  angle, mag;
373 > moveview(angle, elev, mag, vc)                  /* move viewpoint */
374 > double  angle, elev, mag;
375   FVECT  vc;
376   {
377          extern double  sqrt(), dist2();
378          double  d;
379 +        FVECT  v1;
380          VIEW  nv;
381          register int  i;
382  
383          VCOPY(nv.vup, ourview.vup);
384 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
384 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
385          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
386 <        d = sqrt(dist2(ourview.vp, vc)) / mag;
387 <        for (i = 0; i < 3; i++)
388 <                nv.vp[i] = vc[i] - d*nv.vdir[i];
386 >        if (elev != 0.0) {
387 >                fcross(v1, ourview.vup, nv.vdir);
388 >                normalize(v1);
389 >                spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
390 >        }
391          if ((nv.type = ourview.type) == VT_PAR) {
392                  nv.horiz = ourview.horiz / mag;
393                  nv.vert = ourview.vert / mag;
394 +                d = 0.0;                        /* don't move closer */
395 +                for (i = 0; i < 3; i++)
396 +                        d += (vc[i] - ourview.vp[i])*ourview.vdir[i];
397          } else {
398                  nv.horiz = ourview.horiz;
399                  nv.vert = ourview.vert;
400 +                d = sqrt(dist2(ourview.vp, vc)) / mag;
401          }
402 +        for (i = 0; i < 3; i++)
403 +                nv.vp[i] = vc[i] - d*nv.vdir[i];
404          newview(&nv);
405   }
406  
407  
408 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
409 < FVECT  vres, vorig, vnorm;
410 < double  theta;
408 > zoomview(vp, zf)                        /* zoom in our out */
409 > register VIEW  *vp;
410 > double  zf;
411   {
412 <        extern double  sin(), cos();
413 <        double  sint, cost, dotp;
414 <        FVECT  vperp;
415 <        register int  i;
416 <        
298 <        if (theta == 0.0) {
299 <                VCOPY(vres, vorig);
412 >        switch (vp->type) {
413 >        case VT_PAR:                            /* parallel view */
414 >        case VT_ANG:                            /* angular fisheye */
415 >                vp->horiz /= zf;
416 >                vp->vert /= zf;
417                  return;
418 +        case VT_PER:                            /* perspective view */
419 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
420 +                                (PI/180./2.);
421 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
422 +                                (PI/180./2.);
423 +                return;
424 +        case VT_HEM:                            /* hemispherical fisheye */
425 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
426 +                if (vp->horiz >= 1.0-FTINY)
427 +                        vp->horiz = 180.;
428 +                else
429 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
430 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
431 +                if (vp->vert >= 1.0-FTINY)
432 +                        vp->vert = 180.;
433 +                else
434 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
435 +                return;
436          }
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;
437   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines