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

Comparing ray/src/util/ranimove1.c (file contents):
Revision 3.6 by schorsch, Sun Jul 27 22:12:03 2003 UTC vs.
Revision 3.13 by greg, Thu Apr 17 14:44:25 2008 UTC

# Line 4 | Line 4 | static const char      RCSid[] = "$Id$";
4   /*
5   *  ranimove1.c
6   *
7 < *  Basic frame rendering routines for ranimate(1).
7 > *  Basic frame rendering routines for ranimove(1).
8   *
9   *  Created by Gregory Ward on Wed Jan 08 2003.
10   */
# Line 16 | Line 16 | static const char      RCSid[] = "$Id$";
16   #include "platform.h"
17   #include "ranimove.h"
18   #include "otypes.h"
19 + #include "source.h"
20   #include "random.h"
21  
22   double          acctab[256];    /* accuracy value table */
# Line 46 | Line 47 | double         frm_stop;       /* when to stop rendering this frame
47   double          hlsmax;         /* maximum high-level saliency this frame */
48  
49  
50 < void
51 < write_map(mp, fn)               /* write out float map (debugging) */
52 < float   *mp;
53 < char    *fn;
50 > static void next_frame(void);
51 > static int sample_here(int      x, int  y);
52 > static int offset_cmp(const void        *p1, const void *p2);
53 > static void setmotion(int       n, FVECT        wpos);
54 > static void init_frame_sample(void);
55 >
56 >
57 > extern void
58 > write_map(              /* write out float map (debugging) */
59 >        float   *mp,
60 >        char    *fn
61 > )
62   {
63          FILE    *fp = fopen(fn, "w");
64          COLOR   scanbuf[2048];
# Line 73 | Line 82 | char   *fn;
82  
83  
84   static void
85 < next_frame()                    /* prepare next frame buffer */
85 > next_frame(void)                        /* prepare next frame buffer */
86   {
87          VIEW    *fv;
88          char    *err;
# Line 155 | Line 164 | next_frame()                   /* prepare next frame buffer */
164  
165  
166   static int
167 < sample_here(x, y)               /* 4x4 quincunx sample at this pixel? */
168 < register int    x, y;
167 > sample_here(            /* 4x4 quincunx sample at this pixel? */
168 >        register int    x,
169 >        register int    y
170 > )
171   {
172          if (y & 0x1)            /* every other row has samples */
173                  return(0);
# Line 166 | Line 177 | register int   x, y;
177   }
178  
179  
180 < void
181 < sample_pos(hv, x, y, sn)        /* compute jittered sample position */
182 < double  hv[2];
183 < int     x, y;
184 < int     sn;
180 > extern void
181 > sample_pos(     /* compute jittered sample position */
182 >        double  hv[2],
183 >        int     x,
184 >        int     y,
185 >        int     sn
186 > )
187   {
188          int     hl[2];
189  
# Line 181 | Line 194 | int    sn;
194   }
195  
196  
197 < double
198 < sample_wt(xo, yo)               /* compute interpolant sample weight */
199 < int     xo, yo;
197 > extern double
198 > sample_wt(              /* compute interpolant sample weight */
199 >        int     xo,
200 >        int yo
201 > )
202   {
203          static double   etab[400];
204 <        int     rad2 = xo*xo + yo*yo;
204 >        /* we can't use the name rad2 here, for some reason Visual C
205 >           thinks that is a constant (compiler bug?) */
206 >        int     rad_2 = xo*xo + yo*yo;
207          int     i;
208  
209          if (etab[0] <= FTINY)           /* initialize exponent table */
# Line 194 | Line 211 | int    xo, yo;
211                          etab[i] = exp(-0.1*i);
212  
213                                          /* look up Gaussian */
214 <        i = (int)((10.*3./(double)SAMPDIST2)*rad2 + .5);
214 >        i = (int)((10.*3./(double)SAMPDIST2)*rad_2 + .5);
215          if (i >= 400)
216                  return(0.0);
217          return(etab[i]);
# Line 202 | Line 219 | int    xo, yo;
219  
220  
221   static int
222 < offset_cmp(p1, p2)              /* compare offset distances */
223 < const void      *p1, *p2;
222 > offset_cmp(             /* compare offset distances */
223 >        const void      *p1,
224 >        const void      *p2
225 > )
226   {
227          return(*(const int *)p1 - *(const int *)p2);
228   }
229  
230  
231 < int
232 < getclosest(iarr, nc, x, y)      /* get nc closest neighbors on same object */
233 < int     *iarr;
234 < int     nc;
235 < int     x, y;
231 > extern int
232 > getclosest(     /* get nc closest neighbors on same object */
233 >        int     *iarr,
234 >        int     nc,
235 >        int     x,
236 >        int     y
237 > )
238   {
239   #define NSCHECK         ((2*SAMPDIST+1)*(2*SAMPDIST+1))
240          static int      hro, vro;
# Line 283 | Line 304 | int    x, y;
304  
305  
306   static void
307 < setmotion(n, wpos)              /* compute motion vector for this pixel */
308 < register int    n;
309 < FVECT   wpos;
307 > setmotion(              /* compute motion vector for this pixel */
308 >                register int    n,
309 >                FVECT   wpos
310 > )
311   {
312          FVECT   ovp;
291        MAT4    xfm;
292        double  d;
313          int     moi;
314          int     xp, yp;
315                                          /* ID object and update maximum HLS */
# Line 320 | Line 340 | FVECT  wpos;
340  
341  
342   static void
343 < init_frame_sample()             /* sample our initial frame */
343 > init_frame_sample(void)         /* sample our initial frame */
344   {
345          RAY     ir;
346          int     x, y;
# Line 347 | Line 367 | init_frame_sample()            /* sample our initial frame */
367                          continue;
368                  }
369                  if (!sample_here(x, y)) {       /* just cast */
370 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
370 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
371                          if (!localhit(&ir, &thescene)) {
372                                  if (ir.ro != &Aftplane)
373                                          sourcehit(&ir);
# Line 365 | Line 385 | init_frame_sample()            /* sample our initial frame */
385                  }
386                  if (nprocs > 1) {               /* get sample */
387                          int     rval;
388 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
388 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
389                          ir.rno = n;
390                          rval = ray_pqueue(&ir);
391                          if (!rval)
# Line 422 | Line 442 | init_frame_sample()            /* sample our initial frame */
442   }
443  
444  
445 < int
446 < getambcolor(clr, obj)           /* get ambient color for object if we can */
447 < COLOR   clr;
448 < int     obj;
445 > extern int
446 > getambcolor(            /* get ambient color for object if we can */
447 >                COLOR   clr,
448 >                int     obj
449 > )
450   {
451          register OBJREC *op;
452  
# Line 492 | Line 513 | int    obj;
513   }
514  
515  
516 < double
517 < estimaterr(cs, cs2, ns, ns0)    /* estimate relative error from samples */
518 < COLOR   cs, cs2;
519 < int     ns;
516 > extern double
517 > estimaterr(             /* estimate relative error from samples */
518 >                COLOR   cs,
519 >                COLOR   cs2,
520 >                int     ns,
521 >                int ns0
522 > )
523   {
524          double  d, d2, brt;
525  
# Line 515 | Line 539 | int    ns;
539   }
540  
541  
542 < double
543 < comperr(neigh, nc, ns0)         /* estimate relative error in neighborhood */
544 < int     *neigh;
545 < int     nc;
546 < int     ns0;
542 > extern double
543 > comperr(                /* estimate relative error in neighborhood */
544 >                int     *neigh,
545 >                int     nc,
546 >                int     ns0
547 > )
548   {
549          COLOR   csum, csum2;
550          COLOR   ctmp;
# Line 550 | Line 575 | int    ns0;
575   }
576  
577  
578 < void
579 < comp_frame_error()              /* initialize frame error values */
578 > extern void
579 > comp_frame_error(void)          /* initialize frame error values */
580   {
581          BYTE    *edone = NULL;
582          COLOR   objamb;
583          double  eest;
584          int     neigh[NSAMPOK];
585          int     nc;
586 <        int     x, y, i, j;
586 >        int     x, y, i;
587          register int    n;
588  
589          if (!silent) {
# Line 629 | Line 654 | comp_frame_error()             /* initialize frame error values *
654   }
655  
656  
657 < void
658 < init_frame()                    /* render base (low quality) frame */
657 > extern void
658 > init_frame(void)                        /* render base (low quality) frame */
659   {
660          int     restart;
636
661                                          /* allocate/swap buffers */
662          next_frame();
663                                          /* check rendering status */
# Line 642 | Line 666 | init_frame()                   /* render base (low quality) frame */
666                  restart = -1;
667          if (restart > 0) {
668                  if (nprocs > 1)
669 <                        ray_pdone(1);
669 >                        ray_pdone(0);
670                  else
671 <                        ray_done(1);
671 >                        ray_done(0);
672          }
673                                          /* post low quality parameters */
674          if (curparams != &lorendparams)
# Line 692 | Line 716 | return;
716   }
717  
718  
719 < void
720 < filter_frame()                  /* interpolation, motion-blur, and exposure */
719 > extern void
720 > filter_frame(void)                      /* interpolation, motion-blur, and exposure */
721   {
722          double  expval = expspec_val(getexp(fcur));
723          int     x, y;
# Line 704 | Line 728 | filter_frame()                 /* interpolation, motion-blur, and ex
728          register int    n;
729  
730   #if 0
731 < /* XXX TEMPORARY!! */
732 < conspicuity();
733 < write_map(cerrmap, "outcmap.pic");
734 < {
735 <        float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
736 <        for (n = hres*vres; n--; )
737 <                ebuf[n] = acctab[abuffer[n]];
738 <        write_map(ebuf, "outerr.pic");
739 <        free((void *)ebuf);
740 < }
731 >        /* XXX TEMPORARY!! */
732 >        conspicuity();
733 >        write_map(cerrmap, "outcmap.pic");
734 >        {
735 >                float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
736 >                for (n = hres*vres; n--; )
737 >                        ebuf[n] = acctab[abuffer[n]];
738 >                write_map(ebuf, "outerr.pic");
739 >                free((void *)ebuf);
740 >        }
741   #endif
742  
743          if (!silent) {
# Line 737 | Line 761 | write_map(cerrmap, "outcmap.pic");
761                          continue;
762                  nc = getclosest(neigh, NPINTERP, x, y);
763                  setcolor(cbuffer[n], 0., 0., 0.);
764 +                if (nc <= 0) {          /* no acceptable neighbors */
765 +                        if (y < vres-1)
766 +                                nc = fndx(x, y+1);
767 +                        else if (x < hres-1)
768 +                                nc = fndx(x+1, y);
769 +                        else
770 +                                continue;
771 +                        copycolor(cbuffer[n], cbuffer[nc]);
772 +                        continue;
773 +                }
774                  wsum = 0.;
775                  while (nc-- > 0) {
776                          copycolor(cval, cbuffer[neigh[nc]]);
# Line 746 | Line 780 | write_map(cerrmap, "outcmap.pic");
780                          addcolor(cbuffer[n], cval);
781                          wsum += w;
782                  }
783 <                if (wsum > FTINY) {
784 <                        w = 1.0/wsum;
751 <                        scalecolor(cbuffer[n], w);
752 <                }
783 >                w = 1.0/wsum;
784 >                scalecolor(cbuffer[n], w);
785              }
786                                          /* motion blur if requested */
787          if (mblur > .02) {
756                int     len;
788                  int     xs, ys, xl, yl;
789                  int     rise, run;
790                  long    rise2, run2;
# Line 791 | Line 822 | write_map(cerrmap, "outcmap.pic");
822                                  while (cnt)
823                                          if (rise2 >= run2) {
824                                                  if ((xl >= 0) & (xl < hres) &
825 <                                                        (yl >= 0) & (yl < vres)) {
825 >                                                    (yl >= 0) & (yl < vres)) {
826                                                          n2 = fndx(xl, yl);
827                                                          addcolor(outbuffer[n2],
828                                                                          cval);
# Line 812 | Line 843 | write_map(cerrmap, "outcmap.pic");
843                                  while (cnt)
844                                          if (run2 >= rise2) {
845                                                  if ((xl >= 0) & (xl < hres) &
846 <                                                        (yl >= 0) & (yl < vres)) {
846 >                                                    (yl >= 0) & (yl < vres)) {
847                                                          n2 = fndx(xl, yl);
848                                                          addcolor(outbuffer[n2],
849                                                                          cval);
# Line 839 | Line 870 | write_map(cerrmap, "outcmap.pic");
870          } else
871                  for (n = hres*vres; n--; )
872                          copycolor(outbuffer[n], cbuffer[n]);
873 < /*
874 < for (n = hres*vres; n--; )
875 <        if (!sbuffer[n])
876 <                setcolor(outbuffer[n], 0., 0., 0.);
877 < */
878 <                                /* adjust exposure */
873 >        /*
874 >           for (n = hres*vres; n--; )
875 >                   if (!sbuffer[n])
876 >                           setcolor(outbuffer[n], 0., 0., 0.);
877 >         */
878 >        /* adjust exposure */
879          if ((expval < 0.99) | (expval > 1.01))
880                  for (n = hres*vres; n--; )
881                          scalecolor(outbuffer[n], expval);
882 < return;
883 < {
884 <        float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
885 <        char    fnm[256];
886 <        sprintf(fnm, vval(BASENAME), fcur);
887 <        strcat(fnm, "_outsamp.pic");
888 <        for (n = hres*vres; n--; )
889 <                sbuf[n] = (float)sbuffer[n];
890 <        write_map(sbuf, fnm);
891 <        free((void *)sbuf);
882 > #if 0
883 >        {
884 >                float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
885 >                char    fnm[256];
886 >                sprintf(fnm, vval(BASENAME), fcur);
887 >                strcat(fnm, "_outsamp.pic");
888 >                for (n = hres*vres; n--; )
889 >                        sbuf[n] = (float)sbuffer[n];
890 >                write_map(sbuf, fnm);
891 >                free((void *)sbuf);
892 >        }
893 > #endif
894   }
862 }
895  
896  
897 < void
898 < send_frame()                    /* send frame to destination */
897 > extern void
898 > send_frame(void)                        /* send frame to destination */
899   {
900          char    pfname[1024];
901          double  d;
# Line 915 | Line 947 | writerr:
947   }
948  
949  
950 < void
951 < free_frame()                    /* free frame allocation */
950 > extern void
951 > free_frame(void)                        /* free frame allocation */
952   {
953          if (cbuffer == NULL)
954                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines