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.15 by greg, Thu Mar 8 10:28:29 1990 UTC vs.
Revision 2.11 by greg, Tue Feb 25 02:47:23 2003 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 "copyright.h"
11 +
12   #include  "ray.h"
13  
15 #include  "octree.h"
16
14   #include  "rpaint.h"
15  
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 130 | Line 142 | register COLOR  col;
142   }
143  
144  
145 + void
146   paint(p, xmin, ymin, xmax, ymax)        /* compute and paint a rectangle */
147   register PNODE  *p;
148   int  xmin, ymin, xmax, ymax;
149   {
150 <        extern long  nrays;
138 <        static long  lastflush = 0;
150 >        static unsigned long  lastflush = 0;
151          static RAY  thisray;
152          double  h, v;
141        register int  i;
153  
154          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
155                  p->x = xmin;
# Line 150 | Line 161 | int  xmin, ymin, xmax, ymax;
161          h = xmin + (xmax-xmin)*frandom();
162          v = ymin + (ymax-ymin)*frandom();
163          
164 <        viewray(thisray.rorg, thisray.rdir, &ourview, h/hresolu, v/vresolu);
165 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
166 <        rayvalue(&thisray);
164 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
165 >                        h/hresolu, v/vresolu)) < -FTINY) {
166 >                setcolor(thisray.rcol, 0.0, 0.0, 0.0);
167 >        } else {
168 >                rayorigin(&thisray, NULL, PRIMARY, 1.0);
169 >                samplendx++;
170 >                rayvalue(&thisray);
171 >        }
172  
173          p->x = h;
174          p->y = v;
# Line 168 | Line 184 | int  xmin, ymin, xmax, ymax;
184   }
185  
186  
187 + void
188   newimage()                              /* start a new image */
189   {
190                                                  /* free old image */
191          freepkids(&ptrunk);
192 +                                                /* save reserve memory */
193 +        fillreserves();
194                                                  /* compute resolution */
195          hresolu = dev->xsiz;
196          vresolu = dev->ysiz;
# Line 186 | Line 205 | newimage()                             /* start a new image */
205   }
206  
207  
208 + void
209   redraw()                                /* redraw the image */
210   {
211          (*dev->clear)(hresolu, vresolu);
# Line 195 | Line 215 | redraw()                               /* redraw the image */
215   }
216  
217  
218 + void
219   repaint(xmin, ymin, xmax, ymax)                 /* repaint a region */
220   int  xmin, ymin, xmax, ymax;
221   {
# Line 207 | Line 228 | int  xmin, ymin, xmax, ymax;
228   }
229  
230  
231 + void
232   paintrect(p, xmin, ymin, xmax, ymax, r)         /* paint picture rectangle */
233   register PNODE  *p;
234   int  xmin, ymin, xmax, ymax;
# Line 277 | Line 299 | int  pd;
299   }
300  
301  
302 + void
303   scalepict(p, sf)                        /* scale picture values */
304   register PNODE  *p;
305   double  sf;
# Line 293 | Line 316 | double  sf;
316   }
317  
318  
319 + void
320   getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */
321   int  yoff;
322   register COLR  *scan;
# Line 323 | Line 347 | int  xsiz, ysiz;
347   }
348  
349  
350 < pcopy(p1, p2)                           /* copy paint node p1 into p2 */
327 < register PNODE  *p1, *p2;
328 < {
329 <        copycolor(p2->v, p1->v);
330 <        p2->x = p1->x;
331 <        p2->y = p1->y;
332 < }
333 <
334 <
350 > void
351   freepkids(p)                            /* free pnode's children */
352   register PNODE  *p;
353   {
# Line 341 | Line 357 | register PNODE  *p;
357          freepkids(p->kid+DR);
358          freepkids(p->kid+UL);
359          freepkids(p->kid+UR);
360 <        free((char *)p->kid);
360 >        free((void *)p->kid);
361          p->kid = NULL;
362   }
363  
364  
365 + void
366   newview(vp)                             /* change viewing parameters */
367   register VIEW  *vp;
368   {
# Line 362 | Line 379 | register VIEW  *vp;
379   }
380  
381  
382 + void
383   moveview(angle, elev, mag, vc)                  /* move viewpoint */
384   double  angle, elev, mag;
385   FVECT  vc;
386   {
369        extern double  sqrt(), dist2();
387          double  d;
388          FVECT  v1;
389          VIEW  nv;
# Line 386 | Line 403 | FVECT  vc;
403                  d = 0.0;                        /* don't move closer */
404                  for (i = 0; i < 3; i++)
405                          d += (vc[i] - ourview.vp[i])*ourview.vdir[i];
406 +                nv.vfore = ourview.vfore;
407 +                nv.vaft = ourview.vaft;
408          } else {
409                  nv.horiz = ourview.horiz;
410                  nv.vert = ourview.vert;
411                  d = sqrt(dist2(ourview.vp, vc)) / mag;
412 +                if ((nv.vfore = ourview.vfore) > FTINY) {
413 +                        nv.vfore += d - d*mag;
414 +                        if (nv.vfore < 0.0) nv.vfore = 0.0;
415 +                }
416 +                if ((nv.vaft = ourview.vaft) > FTINY) {
417 +                        nv.vaft += d - d*mag;
418 +                        if (nv.vaft <= nv.vfore) nv.vaft = 0.0;
419 +                }
420          }
421          for (i = 0; i < 3; i++)
422                  nv.vp[i] = vc[i] - d*nv.vdir[i];
# Line 397 | Line 424 | FVECT  vc;
424   }
425  
426  
427 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
428 < FVECT  vres, vorig, vnorm;
429 < double  theta;
427 > void
428 > pcopy(p1, p2)                           /* copy paint node p1 into p2 */
429 > register PNODE  *p1, *p2;
430   {
431 <        extern double  sin(), cos();
432 <        double  sint, cost, dotp;
433 <        FVECT  vperp;
434 <        register int  i;
435 <        
436 <        if (theta == 0.0) {
437 <                VCOPY(vres, vorig);
431 >        copycolor(p2->v, p1->v);
432 >        p2->x = p1->x;
433 >        p2->y = p1->y;
434 > }
435 >
436 >
437 > void
438 > zoomview(vp, zf)                        /* zoom in or out */
439 > register VIEW  *vp;
440 > double  zf;
441 > {
442 >        switch (vp->type) {
443 >        case VT_PAR:                            /* parallel view */
444 >                vp->horiz /= zf;
445 >                vp->vert /= zf;
446                  return;
447 +        case VT_ANG:                            /* angular fisheye */
448 +                vp->horiz /= zf;
449 +                if (vp->horiz > 360.)
450 +                        vp->horiz = 360.;
451 +                vp->vert /= zf;
452 +                if (vp->vert > 360.)
453 +                        vp->vert = 360.;
454 +                return;
455 +        case VT_CYL:                            /* cylindrical panorama */
456 +                vp->horiz /= zf;
457 +                if (vp->horiz > 360.)
458 +                        vp->horiz = 360.;
459 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / (PI/180./2.);
460 +                return;
461 +        case VT_PER:                            /* perspective view */
462 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
463 +                                (PI/180./2.);
464 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
465 +                                (PI/180./2.);
466 +                return;
467 +        case VT_HEM:                            /* hemispherical fisheye */
468 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
469 +                if (vp->horiz >= 1.0-FTINY)
470 +                        vp->horiz = 180.;
471 +                else
472 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
473 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
474 +                if (vp->vert >= 1.0-FTINY)
475 +                        vp->vert = 180.;
476 +                else
477 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
478 +                return;
479          }
413        sint = sin(theta);
414        cost = cos(theta);
415        dotp = DOT(vorig, vnorm);
416        fcross(vperp, vnorm, vorig);
417        for (i = 0; i < 3; i++)
418                vres[i] = vnorm[i]*dotp*(1.-cost) +
419                                vorig[i]*cost + vperp[i]*sint;
480   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines