ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambient.c
(Generate patch)

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.55 by greg, Mon Oct 20 16:01:55 2003 UTC vs.
Revision 2.56 by schorsch, Tue Mar 30 16:13:00 2004 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
14   #include  "platform.h"
15   #include  "ray.h"
16   #include  "otypes.h"
17 + #include  "resolu.h"
18   #include  "ambient.h"
19   #include  "random.h"
20  
# Line 75 | Line 76 | static long  lastpos = -1;             /* last flush position */
76   #define  newambval()    (AMBVAL *)malloc(sizeof(AMBVAL))
77   #define  freeav(av)     free((void *)av);
78  
79 < static void  initambfile(), avsave(), avinsert(), sortambvals(), unloadatree();
80 < static int  avlmemi();
81 < static AMBVAL  *avstore();
79 > static void initambfile(int creat);
80 > static void avsave(AMBVAL *av);
81 > static AMBVAL *avstore(AMBVAL  *aval);
82 > static AMBTREE *newambtree(void);
83 > static void freeambtree(AMBTREE  *atp);
84 >
85 > typedef void unloadtf_t(void *);
86 > static unloadtf_t avinsert;
87 > static unloadtf_t av2list;
88 > static void unloadatree(AMBTREE  *at, unloadtf_t *f);
89 >
90 > static int aposcmp(const void *avp1, const void *avp2);
91 > static int avlmemi(AMBVAL *avaddr);
92 > static void sortambvals(int always);
93 >
94   #ifdef  F_SETLKW
95 < static void  aflock();
95 > static void aflock(int  typ);
96   #endif
97  
98  
99 < void
100 < setambres(ar)                           /* set ambient resolution */
101 < int  ar;
99 > extern void
100 > setambres(                              /* set ambient resolution */
101 >        int  ar
102 > )
103   {
104          ambres = ar < 0 ? 0 : ar;               /* may be done already */
105                                                  /* set min & max radii */
# Line 105 | Line 119 | int  ar;
119   }
120  
121  
122 < void
123 < setambacc(newa)                         /* set ambient accuracy */
124 < double  newa;
122 > extern void
123 > setambacc(                              /* set ambient accuracy */
124 >        double  newa
125 > )
126   {
127          double  ambdiff;
128  
# Line 119 | Line 134 | double  newa;
134   }
135  
136  
137 < void
138 < setambient()                            /* initialize calculation */
137 > extern void
138 > setambient(void)                                /* initialize calculation */
139   {
140          int     readonly = 0;
141          long  pos, flen;
# Line 180 | Line 195 | setambient()                           /* initialize calculation */
195   }
196  
197  
198 < void
199 < ambdone()                       /* close ambient file and free memory */
198 > extern void
199 > ambdone(void)                   /* close ambient file and free memory */
200   {
201          if (ambfp != NULL) {            /* close ambient file */
202                  ambsync();
# Line 206 | Line 221 | ambdone()                      /* close ambient file and free memory */
221   }
222  
223  
224 < void
225 < ambnotify(obj)                  /* record new modifier */
226 < OBJECT  obj;
224 > extern void
225 > ambnotify(                      /* record new modifier */
226 >        OBJECT  obj
227 > )
228   {
229          static int  hitlimit = 0;
230          register OBJREC  *o;
# Line 235 | Line 251 | OBJECT obj;
251   }
252  
253  
254 < void
255 < ambient(acol, r, nrm)           /* compute ambient component for ray */
256 < COLOR  acol;
257 < register RAY  *r;
258 < FVECT  nrm;
254 > extern void
255 > ambient(                /* compute ambient component for ray */
256 >        COLOR  acol,
257 >        register RAY  *r,
258 >        FVECT  nrm
259 > )
260   {
261          static int  rdepth = 0;                 /* ambient recursion */
262          double  d, l;
# Line 295 | Line 312 | dumbamb:                                       /* return global value */
312   }
313  
314  
315 < double
316 < sumambient(acol, r, rn, al, at, c0, s)  /* get interpolated ambient value */
317 < COLOR  acol;
318 < register RAY  *r;
319 < FVECT  rn;
320 < int  al;
321 < AMBTREE  *at;
322 < FVECT  c0;
323 < double  s;
315 > extern double
316 > sumambient(     /* get interpolated ambient value */
317 >        COLOR  acol,
318 >        register RAY  *r,
319 >        FVECT  rn,
320 >        int  al,
321 >        AMBTREE  *at,
322 >        FVECT  c0,
323 >        double  s
324 > )
325   {
326          double  d, e1, e2, wt, wsum;
327          COLOR  ct;
# Line 408 | Line 426 | double s;
426   }
427  
428  
429 < double
430 < makeambient(acol, r, rn, al)    /* make a new ambient value */
431 < COLOR  acol;
432 < register RAY  *r;
433 < FVECT  rn;
434 < int  al;
429 > extern double
430 > makeambient(    /* make a new ambient value */
431 >        COLOR  acol,
432 >        register RAY  *r,
433 >        FVECT  rn,
434 >        int  al
435 > )
436   {
437          AMBVAL  amb;
438          FVECT   gp, gd;
# Line 440 | Line 459 | int  al;
459   }
460  
461  
462 < void
463 < extambient(cr, ap, pv, nv)              /* extrapolate value at pv, nv */
464 < COLOR  cr;
465 < register AMBVAL  *ap;
466 < FVECT  pv, nv;
462 > extern void
463 > extambient(             /* extrapolate value at pv, nv */
464 >        COLOR  cr,
465 >        register AMBVAL  *ap,
466 >        FVECT  pv,
467 >        FVECT  nv
468 > )
469   {
470          FVECT  v1;
471          register int  i;
# Line 467 | Line 488 | FVECT  pv, nv;
488  
489  
490   static void
491 < initambfile(creat)              /* initialize ambient file */
492 < int  creat;
491 > initambfile(            /* initialize ambient file */
492 >        int  creat
493 > )
494   {
495          extern char  *progname, *octname;
496          static char  *mybuf = NULL;
# Line 503 | Line 525 | int  creat;
525  
526  
527   static void
528 < avsave(av)                              /* insert and save an ambient value */
529 < AMBVAL  *av;
528 > avsave(                         /* insert and save an ambient value */
529 >        AMBVAL  *av
530 > )
531   {
532          avinsert(avstore(av));
533          if (ambfp == NULL)
# Line 521 | Line 544 | writerr:
544  
545  
546   static AMBVAL *
547 < avstore(aval)                           /* allocate memory and store aval */
548 < register AMBVAL  *aval;
547 > avstore(                                /* allocate memory and store aval */
548 >        register AMBVAL  *aval
549 > )
550   {
551          register AMBVAL  *av;
552          double  d;
# Line 548 | Line 572 | static AMBTREE  *atfreelist = NULL;    /* free ambient tr
572  
573  
574   static AMBTREE *
575 < newambtree()                            /* allocate 8 ambient tree structs */
575 > newambtree(void)                                /* allocate 8 ambient tree structs */
576   {
577          register AMBTREE  *atp, *upperlim;
578  
# Line 570 | Line 594 | newambtree()                           /* allocate 8 ambient tree structs */
594  
595  
596   static void
597 < freeambtree(atp)                        /* free 8 ambient tree structs */
598 < AMBTREE  *atp;
597 > freeambtree(                    /* free 8 ambient tree structs */
598 >        AMBTREE  *atp
599 > )
600   {
601          atp->kid = atfreelist;
602          atfreelist = atp;
# Line 579 | Line 604 | AMBTREE  *atp;
604  
605  
606   static void
607 < avinsert(av)                            /* insert ambient value in our tree */
608 < register AMBVAL  *av;
607 > avinsert(                               /* insert ambient value in our tree */
608 >        void *av
609 > )
610   {
611          register AMBTREE  *at;
612          register AMBVAL  *ap;
# Line 590 | Line 616 | register AMBVAL         *av;
616          int  branch;
617          register int  i;
618  
619 <        if (av->rad <= FTINY)
619 >        if (((AMBVAL*)av)->rad <= FTINY)
620                  error(CONSISTENCY, "zero ambient radius in avinsert");
621          at = &atrunk;
622          VCOPY(ck0, thescene.cuorg);
623          s = thescene.cusize;
624 <        while (s*(OCTSCALE/2) > av->rad*ambacc) {
624 >        while (s*(OCTSCALE/2) > ((AMBVAL*)av)->rad*ambacc) {
625                  if (at->kid == NULL)
626                          if ((at->kid = newambtree()) == NULL)
627                                  error(SYSTEM, "out of memory in avinsert");
628                  s *= 0.5;
629                  branch = 0;
630                  for (i = 0; i < 3; i++)
631 <                        if (av->pos[i] > ck0[i] + s) {
631 >                        if (((AMBVAL*)av)->pos[i] > ck0[i] + s) {
632                                  ck0[i] += s;
633                                  branch |= 1 << i;
634                          }
# Line 610 | Line 636 | register AMBVAL         *av;
636          }
637          avh.next = at->alist;           /* order by increasing level */
638          for (ap = &avh; ap->next != NULL; ap = ap->next)
639 <                if (ap->next->lvl >= av->lvl)
639 >                if (ap->next->lvl >= ((AMBVAL*)av)->lvl)
640                          break;
641 <        av->next = ap->next;
642 <        ap->next = av;
641 >        ((AMBVAL*)av)->next = ap->next;
642 >        ap->next = (AMBVAL*)av;
643          at->alist = avh.next;
644   }
645  
646  
647   static void
648 < unloadatree(at, f)                      /* unload an ambient value tree */
649 < register AMBTREE  *at;
650 < void    (*f)();
648 > unloadatree(                    /* unload an ambient value tree */
649 >        register AMBTREE  *at,
650 >        unloadtf_t *f
651 > )
652   {
653          register AMBVAL  *av;
654          register int  i;
# Line 646 | Line 673 | static struct avl {
673   static AMBVAL   **avlist2;              /* memory positions for sorting */
674   static int      i_avlist;               /* index for lists */
675  
676 + static int alatcmp(const void *av1, const void *av2);
677  
678 < static int
679 < av2list(av)
680 < register AMBVAL *av;
678 > static void
679 > av2list(
680 >        void *av
681 > )
682   {
683   #ifdef DEBUG
684          if (i_avlist >= nambvals)
685                  error(CONSISTENCY, "too many ambient values in av2list1");
686   #endif
687 <        avlist1[i_avlist].p = avlist2[i_avlist] = av;
688 <        avlist1[i_avlist++].t = av->latick;
687 >        avlist1[i_avlist].p = avlist2[i_avlist] = (AMBVAL*)av;
688 >        avlist1[i_avlist++].t = ((AMBVAL*)av)->latick;
689   }
690  
691  
692   static int
693 < alatcmp(av1, av2)                       /* compare ambient values for MRA */
694 < struct avl      *av1, *av2;
693 > alatcmp(                        /* compare ambient values for MRA */
694 >        const void *av1,
695 >        const void *av2
696 > )
697   {
698 <        register long  lc = av2->t - av1->t;
698 >        register long  lc = ((struct avl *)av2)->t - ((struct avl *)av1)->t;
699          return(lc<0 ? -1 : lc>0 ? 1 : 0);
700   }
701  
# Line 676 | Line 707 | struct avl     *av1, *av2;
707   * assumes pointers differ by exact struct size increments.
708   */
709   static int
710 < aposcmp(avp1, avp2)                     /* compare ambient value positions */
711 < const void      *avp1, *avp2;
710 > aposcmp(                        /* compare ambient value positions */
711 >        const void      *avp1,
712 >        const void      *avp2
713 > )
714   {
715          register long   diff = *(char * const *)avp1 - *(char * const *)avp2;
716          if (diff < 0)
# Line 687 | Line 720 | const void     *avp1, *avp2;
720  
721   #if 1
722   static int
723 < avlmemi(avaddr)                         /* find list position from address */
724 < AMBVAL  *avaddr;
723 > avlmemi(                                /* find list position from address */
724 >        AMBVAL  *avaddr
725 > )
726   {
727          register AMBVAL  **avlpp;
728  
# Line 705 | Line 739 | AMBVAL *avaddr;
739  
740  
741   static void
742 < sortambvals(always)                     /* resort ambient values */
743 < int     always;
742 > sortambvals(                    /* resort ambient values */
743 >        int     always
744 > )
745   {
746          AMBTREE  oldatrunk;
747          AMBVAL  tav, *tap, *pnext;
# Line 804 | Line 839 | int    always;
839   #ifdef  F_SETLKW
840  
841   static void
842 < aflock(typ)                     /* lock/unlock ambient file */
843 < int  typ;
842 > aflock(                 /* lock/unlock ambient file */
843 >        int  typ
844 > )
845   {
846          static struct flock  fls;       /* static so initialized to zeroes */
847  
# Line 815 | Line 851 | int  typ;
851   }
852  
853  
854 < int
855 < ambsync()                       /* synchronize ambient file */
854 > extern int
855 > ambsync(void)                   /* synchronize ambient file */
856   {
857          long  flen;
858          AMBVAL  avs;
# Line 872 | Line 908 | syncend:
908          return(n);
909   seekerr:
910          error(SYSTEM, "seek failed in ambsync");
911 +        return -1; /* pro forma return */
912   }
913  
914   #else
915  
916 < int
917 < ambsync()                       /* flush ambient file */
916 > extern int
917 > ambsync(void)                   /* flush ambient file */
918   {
919          if (nunflshed == 0)
920                  return(0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines