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.14 by greg, Tue Feb 27 09:51:00 1990 UTC vs.
Revision 2.10 by greg, Sat Feb 22 02:07:29 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 + /* ====================================================================
11 + * The Radiance Software License, Version 1.0
12 + *
13 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 + *
16 + * Redistribution and use in source and binary forms, with or without
17 + * modification, are permitted provided that the following conditions
18 + * are met:
19 + *
20 + * 1. Redistributions of source code must retain the above copyright
21 + *         notice, this list of conditions and the following disclaimer.
22 + *
23 + * 2. Redistributions in binary form must reproduce the above copyright
24 + *       notice, this list of conditions and the following disclaimer in
25 + *       the documentation and/or other materials provided with the
26 + *       distribution.
27 + *
28 + * 3. The end-user documentation included with the redistribution,
29 + *           if any, must include the following acknowledgment:
30 + *             "This product includes Radiance software
31 + *                 (http://radsite.lbl.gov/)
32 + *                 developed by the Lawrence Berkeley National Laboratory
33 + *               (http://www.lbl.gov/)."
34 + *       Alternately, this acknowledgment may appear in the software itself,
35 + *       if and wherever such third-party acknowledgments normally appear.
36 + *
37 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 + *       and "The Regents of the University of California" must
39 + *       not be used to endorse or promote products derived from this
40 + *       software without prior written permission. For written
41 + *       permission, please contact [email protected].
42 + *
43 + * 5. Products derived from this software may not be called "Radiance",
44 + *       nor may "Radiance" appear in their name, without prior written
45 + *       permission of Lawrence Berkeley National Laboratory.
46 + *
47 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 + * SUCH DAMAGE.
59 + * ====================================================================
60 + *
61 + * This software consists of voluntary contributions made by many
62 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 + * information on Lawrence Berkeley National Laboratory, please see
64 + * <http://www.lbl.gov/>.
65 + */
66 +
67   #include  "ray.h"
68  
15 #include  "octree.h"
16
69   #include  "rpaint.h"
70  
71   #include  "random.h"
72  
73   #ifndef WFLUSH
74 < #define WFLUSH          30              /* flush after this many rays */
74 > #ifdef SPEED
75 > #define WFLUSH          (5*SPEED)
76 > #else
77 > #define WFLUSH          100             /* flush after this many rays */
78   #endif
79 + #endif
80  
81 + #ifdef  SMLFLT
82 + #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
83 + #else
84 + #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
85 + #endif
86  
87 +
88 + int
89   getrect(s, r)                           /* get a box */
90   char  *s;
91   register RECT  *r;
# Line 69 | Line 132 | register RECT  *r;
132   }
133  
134  
135 + int
136   getinterest(s, direc, vec, mp)          /* get area of interest */
137   char  *s;
138   int  direc;
# Line 87 | Line 151 | double  *mp;
151                  error(COMMAND, "illegal magnification");
152                  return(-1);
153          }
154 <        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
154 >        if (!sscanvec(sskip(s), vec)) {
155                  if (dev->getcur == NULL)
156                          return(-1);
157                  (*dev->comout)("Pick view center\n");
158                  if ((*dev->getcur)(&x, &y) == ABORT)
159                          return(-1);
160 <                viewray(thisray.rorg, thisray.rdir, &ourview,
161 <                                (x+.5)/hresolu, (y+.5)/vresolu);
160 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
161 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
162 >                        error(COMMAND, "not on image");
163 >                        return(-1);
164 >                }
165                  if (!direc || ourview.type == VT_PAR) {
166                          rayorigin(&thisray, NULL, PRIMARY, 1.0);
167                          if (!localhit(&thisray, &thescene)) {
# Line 130 | Line 197 | register COLOR  col;
197   }
198  
199  
200 + void
201   paint(p, xmin, ymin, xmax, ymax)        /* compute and paint a rectangle */
202   register PNODE  *p;
203   int  xmin, ymin, xmax, ymax;
204   {
205 <        extern long  nrays;
138 <        static long  lastflush = 0;
205 >        static unsigned long  lastflush = 0;
206          static RAY  thisray;
207          double  h, v;
141        register int  i;
208  
209          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
210                  p->x = xmin;
# Line 147 | Line 213 | int  xmin, ymin, xmax, ymax;
213                  return;
214          }
215                                                  /* jitter ray direction */
216 <        p->x = h = xmin + (xmax-xmin)*frandom();
217 <        h /= hresolu;
152 <        p->y = v = ymin + (ymax-ymin)*frandom();
153 <        v /= vresolu;
216 >        h = xmin + (xmax-xmin)*frandom();
217 >        v = ymin + (ymax-ymin)*frandom();
218          
219 <        viewray(thisray.rorg, thisray.rdir, &ourview, h, v);
219 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
220 >                        h/hresolu, v/vresolu)) < -FTINY) {
221 >                setcolor(thisray.rcol, 0.0, 0.0, 0.0);
222 >        } else {
223 >                rayorigin(&thisray, NULL, PRIMARY, 1.0);
224 >                samplendx++;
225 >                rayvalue(&thisray);
226 >        }
227  
228 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
229 <        
159 <        rayvalue(&thisray);
160 <
228 >        p->x = h;
229 >        p->y = v;
230          copycolor(p->v, thisray.rcol);
162
231          scalecolor(p->v, exposure);
232  
233          (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
# Line 171 | Line 239 | int  xmin, ymin, xmax, ymax;
239   }
240  
241  
242 + void
243   newimage()                              /* start a new image */
244   {
245                                                  /* free old image */
246          freepkids(&ptrunk);
247 +                                                /* save reserve memory */
248 +        fillreserves();
249                                                  /* compute resolution */
250          hresolu = dev->xsiz;
251          vresolu = dev->ysiz;
# Line 189 | Line 260 | newimage()                             /* start a new image */
260   }
261  
262  
263 + void
264   redraw()                                /* redraw the image */
265   {
266          (*dev->clear)(hresolu, vresolu);
# Line 198 | Line 270 | redraw()                               /* redraw the image */
270   }
271  
272  
273 + void
274   repaint(xmin, ymin, xmax, ymax)                 /* repaint a region */
275   int  xmin, ymin, xmax, ymax;
276   {
# Line 210 | Line 283 | int  xmin, ymin, xmax, ymax;
283   }
284  
285  
286 + void
287   paintrect(p, xmin, ymin, xmax, ymax, r)         /* paint picture rectangle */
288   register PNODE  *p;
289   int  xmin, ymin, xmax, ymax;
# Line 280 | Line 354 | int  pd;
354   }
355  
356  
357 + void
358   scalepict(p, sf)                        /* scale picture values */
359   register PNODE  *p;
360   double  sf;
# Line 296 | Line 371 | double  sf;
371   }
372  
373  
374 + void
375   getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */
376   int  yoff;
377   register COLR  *scan;
# Line 326 | Line 402 | int  xsiz, ysiz;
402   }
403  
404  
405 < 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 <
405 > void
406   freepkids(p)                            /* free pnode's children */
407   register PNODE  *p;
408   {
# Line 344 | Line 412 | register PNODE  *p;
412          freepkids(p->kid+DR);
413          freepkids(p->kid+UL);
414          freepkids(p->kid+UR);
415 <        free((char *)p->kid);
415 >        free((void *)p->kid);
416          p->kid = NULL;
417   }
418  
419  
420 + void
421   newview(vp)                             /* change viewing parameters */
422   register VIEW  *vp;
423   {
# Line 365 | Line 434 | register VIEW  *vp;
434   }
435  
436  
437 + void
438   moveview(angle, elev, mag, vc)                  /* move viewpoint */
439   double  angle, elev, mag;
440   FVECT  vc;
441   {
372        extern double  sqrt(), dist2();
442          double  d;
443          FVECT  v1;
444          VIEW  nv;
# Line 389 | Line 458 | FVECT  vc;
458                  d = 0.0;                        /* don't move closer */
459                  for (i = 0; i < 3; i++)
460                          d += (vc[i] - ourview.vp[i])*ourview.vdir[i];
461 +                nv.vfore = ourview.vfore;
462 +                nv.vaft = ourview.vaft;
463          } else {
464                  nv.horiz = ourview.horiz;
465                  nv.vert = ourview.vert;
466                  d = sqrt(dist2(ourview.vp, vc)) / mag;
467 +                if ((nv.vfore = ourview.vfore) > FTINY) {
468 +                        nv.vfore += d - d*mag;
469 +                        if (nv.vfore < 0.0) nv.vfore = 0.0;
470 +                }
471 +                if ((nv.vaft = ourview.vaft) > FTINY) {
472 +                        nv.vaft += d - d*mag;
473 +                        if (nv.vaft <= nv.vfore) nv.vaft = 0.0;
474 +                }
475          }
476          for (i = 0; i < 3; i++)
477                  nv.vp[i] = vc[i] - d*nv.vdir[i];
# Line 400 | Line 479 | FVECT  vc;
479   }
480  
481  
482 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
483 < FVECT  vres, vorig, vnorm;
484 < double  theta;
482 > void
483 > pcopy(p1, p2)                           /* copy paint node p1 into p2 */
484 > register PNODE  *p1, *p2;
485   {
486 <        extern double  sin(), cos();
487 <        double  sint, cost, dotp;
488 <        FVECT  vperp;
489 <        register int  i;
490 <        
491 <        if (theta == 0.0) {
492 <                VCOPY(vres, vorig);
486 >        copycolor(p2->v, p1->v);
487 >        p2->x = p1->x;
488 >        p2->y = p1->y;
489 > }
490 >
491 >
492 > void
493 > zoomview(vp, zf)                        /* zoom in or out */
494 > register VIEW  *vp;
495 > double  zf;
496 > {
497 >        switch (vp->type) {
498 >        case VT_PAR:                            /* parallel view */
499 >                vp->horiz /= zf;
500 >                vp->vert /= zf;
501                  return;
502 +        case VT_ANG:                            /* angular fisheye */
503 +                vp->horiz /= zf;
504 +                if (vp->horiz > 360.)
505 +                        vp->horiz = 360.;
506 +                vp->vert /= zf;
507 +                if (vp->vert > 360.)
508 +                        vp->vert = 360.;
509 +                return;
510 +        case VT_CYL:                            /* cylindrical panorama */
511 +                vp->horiz /= zf;
512 +                if (vp->horiz > 360.)
513 +                        vp->horiz = 360.;
514 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / (PI/180./2.);
515 +                return;
516 +        case VT_PER:                            /* perspective view */
517 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
518 +                                (PI/180./2.);
519 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
520 +                                (PI/180./2.);
521 +                return;
522 +        case VT_HEM:                            /* hemispherical fisheye */
523 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
524 +                if (vp->horiz >= 1.0-FTINY)
525 +                        vp->horiz = 180.;
526 +                else
527 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
528 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
529 +                if (vp->vert >= 1.0-FTINY)
530 +                        vp->vert = 180.;
531 +                else
532 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
533 +                return;
534          }
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;
535   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines