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.13 by greg, Thu Feb 22 11:46:15 1990 UTC vs.
Revision 2.14 by greg, Tue Jan 18 00:33:16 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1987 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  rv3.c - miscellaneous routines for rview.
6   *
7 < *     5/11/87
7 > *  External symbols declared in rpaint.h
8   */
9  
10 < #include  "ray.h"
10 > #include "copyright.h"
11  
12 < #include  "octree.h"
12 > #include <string.h>
13  
14 + #include  "ray.h"
15   #include  "rpaint.h"
18
16   #include  "random.h"
17  
18   #ifndef WFLUSH
19 < #define WFLUSH          30              /* flush after this many rays */
19 > #ifdef SPEED
20 > #define WFLUSH          (5*SPEED)
21 > #else
22 > #define WFLUSH          100             /* flush after this many rays */
23   #endif
24 + #endif
25  
26 + #ifdef  SMLFLT
27 + #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
28 + #else
29 + #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
30 + #endif
31  
32 +
33 + int
34   getrect(s, r)                           /* get a box */
35   char  *s;
36   register RECT  *r;
# Line 69 | Line 77 | register RECT  *r;
77   }
78  
79  
80 + int
81   getinterest(s, direc, vec, mp)          /* get area of interest */
82   char  *s;
83   int  direc;
# Line 87 | Line 96 | double  *mp;
96                  error(COMMAND, "illegal magnification");
97                  return(-1);
98          }
99 <        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
99 >        if (!sscanvec(sskip(s), vec)) {
100                  if (dev->getcur == NULL)
101                          return(-1);
102                  (*dev->comout)("Pick view center\n");
103                  if ((*dev->getcur)(&x, &y) == ABORT)
104                          return(-1);
105 <                viewray(thisray.rorg, thisray.rdir, &ourview,
106 <                                (x+.5)/hresolu, (y+.5)/vresolu);
105 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
106 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
107 >                        error(COMMAND, "not on image");
108 >                        return(-1);
109 >                }
110                  if (!direc || ourview.type == VT_PAR) {
111                          rayorigin(&thisray, NULL, PRIMARY, 1.0);
112                          if (!localhit(&thisray, &thescene)) {
# Line 113 | Line 125 | double  *mp;
125          } else if (direc)
126                          for (i = 0; i < 3; i++)
127                                  vec[i] -= ourview.vp[i];
128 +        if (normalize(vec) == 0.0)
129 +                return(-1);
130          return(0);
131   }
132  
# Line 130 | Line 144 | register COLOR  col;
144   }
145  
146  
147 + void
148   paint(p, xmin, ymin, xmax, ymax)        /* compute and paint a rectangle */
149   register PNODE  *p;
150   int  xmin, ymin, xmax, ymax;
151   {
152 <        extern long  nrays;
138 <        static long  lastflush = 0;
152 >        static unsigned long  lastflush = 0;
153          static RAY  thisray;
154          double  h, v;
141        register int  i;
155  
156          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
157                  p->x = xmin;
# Line 147 | Line 160 | int  xmin, ymin, xmax, ymax;
160                  return;
161          }
162                                                  /* jitter ray direction */
163 <        p->x = h = xmin + (xmax-xmin)*frandom();
164 <        h /= hresolu;
152 <        p->y = v = ymin + (ymax-ymin)*frandom();
153 <        v /= vresolu;
163 >        h = xmin + (xmax-xmin)*frandom();
164 >        v = ymin + (ymax-ymin)*frandom();
165          
166 <        viewray(thisray.rorg, thisray.rdir, &ourview, h, v);
166 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
167 >                        h/hresolu, v/vresolu)) < -FTINY) {
168 >                setcolor(thisray.rcol, 0.0, 0.0, 0.0);
169 >        } else {
170 >                rayorigin(&thisray, NULL, PRIMARY, 1.0);
171 >                samplendx++;
172 >                rayvalue(&thisray);
173 >        }
174  
175 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
176 <        
159 <        rayvalue(&thisray);
160 <
175 >        p->x = h;
176 >        p->y = v;
177          copycolor(p->v, thisray.rcol);
162
178          scalecolor(p->v, exposure);
179  
180          (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
# Line 171 | Line 186 | int  xmin, ymin, xmax, ymax;
186   }
187  
188  
189 + void
190   newimage()                              /* start a new image */
191   {
192                                                  /* free old image */
193          freepkids(&ptrunk);
194 +                                                /* save reserve memory */
195 +        fillreserves();
196                                                  /* compute resolution */
197          hresolu = dev->xsiz;
198          vresolu = dev->ysiz;
# Line 189 | Line 207 | newimage()                             /* start a new image */
207   }
208  
209  
210 + void
211   redraw()                                /* redraw the image */
212   {
213          (*dev->clear)(hresolu, vresolu);
# Line 198 | Line 217 | redraw()                               /* redraw the image */
217   }
218  
219  
220 + void
221   repaint(xmin, ymin, xmax, ymax)                 /* repaint a region */
222   int  xmin, ymin, xmax, ymax;
223   {
# Line 210 | Line 230 | int  xmin, ymin, xmax, ymax;
230   }
231  
232  
233 + void
234   paintrect(p, xmin, ymin, xmax, ymax, r)         /* paint picture rectangle */
235   register PNODE  *p;
236   int  xmin, ymin, xmax, ymax;
# Line 280 | Line 301 | int  pd;
301   }
302  
303  
304 + void
305   scalepict(p, sf)                        /* scale picture values */
306   register PNODE  *p;
307   double  sf;
# Line 296 | Line 318 | double  sf;
318   }
319  
320  
321 + void
322   getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */
323   int  yoff;
324   register COLR  *scan;
# Line 326 | Line 349 | int  xsiz, ysiz;
349   }
350  
351  
352 < pcopy(p1, p2)                           /* copy paint node p1 into p2 */
330 < register PNODE  *p1, *p2;
331 < {
332 <        copycolor(p2->v, p1->v);
333 <        p2->x = p1->x;
334 <        p2->y = p1->y;
335 < }
336 <
337 <
352 > void
353   freepkids(p)                            /* free pnode's children */
354   register PNODE  *p;
355   {
# Line 344 | Line 359 | register PNODE  *p;
359          freepkids(p->kid+DR);
360          freepkids(p->kid+UL);
361          freepkids(p->kid+UR);
362 <        free((char *)p->kid);
362 >        free((void *)p->kid);
363          p->kid = NULL;
364   }
365  
366  
367 + void
368   newview(vp)                             /* change viewing parameters */
369   register VIEW  *vp;
370   {
# Line 357 | 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((char *)vp, (char *)&ourview, sizeof(VIEW))) {
377 <                copystruct(&oldview, &ourview);
378 <                copystruct(&ourview, vp);
379 <                newimage();             /* newimage() calls with vp=&ourview! */
376 >        } else if (memcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
377 >                oldview = ourview;
378 >                ourview = *vp;
379 >                newimage();
380          }
381   }
382  
383  
384 + void
385   moveview(angle, elev, mag, vc)                  /* move viewpoint */
386   double  angle, elev, mag;
387   FVECT  vc;
388   {
372        extern double  sqrt(), dist2();
389          double  d;
390          FVECT  v1;
391 <        VIEW  nv;
391 >        VIEW  nv = ourview;
392          register int  i;
393  
378        VCOPY(nv.vup, ourview.vup);
379        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
394          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
395          if (elev != 0.0) {
396                  fcross(v1, ourview.vup, nv.vdir);
# Line 390 | Line 404 | FVECT  vc;
404                  for (i = 0; i < 3; i++)
405                          d += (vc[i] - ourview.vp[i])*ourview.vdir[i];
406          } else {
393                nv.horiz = ourview.horiz;
394                nv.vert = ourview.vert;
407                  d = sqrt(dist2(ourview.vp, vc)) / mag;
408 +                if ((nv.vfore = ourview.vfore) > FTINY) {
409 +                        nv.vfore += d - d*mag;
410 +                        if (nv.vfore < 0.0) nv.vfore = 0.0;
411 +                }
412 +                if ((nv.vaft = ourview.vaft) > FTINY) {
413 +                        nv.vaft += d - d*mag;
414 +                        if (nv.vaft <= nv.vfore) nv.vaft = 0.0;
415 +                }
416          }
417          for (i = 0; i < 3; i++)
418                  nv.vp[i] = vc[i] - d*nv.vdir[i];
# Line 400 | Line 420 | FVECT  vc;
420   }
421  
422  
423 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
424 < FVECT  vres, vorig, vnorm;
425 < double  theta;
423 > void
424 > pcopy(p1, p2)                           /* copy paint node p1 into p2 */
425 > register PNODE  *p1, *p2;
426   {
427 <        extern double  sin(), cos();
428 <        double  sint, cost, dotp;
429 <        FVECT  vperp;
430 <        register int  i;
431 <        
432 <        if (theta == 0.0) {
433 <                VCOPY(vres, vorig);
427 >        copycolor(p2->v, p1->v);
428 >        p2->x = p1->x;
429 >        p2->y = p1->y;
430 > }
431 >
432 >
433 > void
434 > zoomview(vp, zf)                        /* zoom in or out */
435 > register VIEW  *vp;
436 > double  zf;
437 > {
438 >        switch (vp->type) {
439 >        case VT_PAR:                            /* parallel view */
440 >                vp->horiz /= zf;
441 >                vp->vert /= zf;
442                  return;
443 +        case VT_ANG:                            /* angular fisheye */
444 +                vp->horiz /= zf;
445 +                if (vp->horiz > 360.)
446 +                        vp->horiz = 360.;
447 +                vp->vert /= zf;
448 +                if (vp->vert > 360.)
449 +                        vp->vert = 360.;
450 +                return;
451 +        case VT_CYL:                            /* cylindrical panorama */
452 +                vp->horiz /= zf;
453 +                if (vp->horiz > 360.)
454 +                        vp->horiz = 360.;
455 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / (PI/180./2.);
456 +                return;
457 +        case VT_PER:                            /* perspective view */
458 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
459 +                                (PI/180./2.);
460 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
461 +                                (PI/180./2.);
462 +                return;
463 +        case VT_HEM:                            /* hemispherical fisheye */
464 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
465 +                if (vp->horiz >= 1.0-FTINY)
466 +                        vp->horiz = 180.;
467 +                else
468 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
469 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
470 +                if (vp->vert >= 1.0-FTINY)
471 +                        vp->vert = 180.;
472 +                else
473 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
474 +                return;
475          }
416        sint = sin(theta);
417        cost = cos(theta);
418        dotp = DOT(vorig, vnorm);
419        fcross(vperp, vnorm, vorig);
420        for (i = 0; i < 3; i++)
421                vres[i] = vnorm[i]*dotp*(1.-cost) +
422                                vorig[i]*cost + vperp[i]*sint;
476   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines