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.14 by greg, Thu Apr 17 14:49:59 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 > #if 0
58 > extern void
59 > write_map(              /* write out float map (debugging) */
60 >        float   *mp,
61 >        char    *fn
62 > )
63   {
64          FILE    *fp = fopen(fn, "w");
65          COLOR   scanbuf[2048];
# Line 70 | Line 80 | char   *fn;
80          }
81          fclose(fp);
82   }
83 + #endif
84  
85  
86   static void
87 < next_frame()                    /* prepare next frame buffer */
87 > next_frame(void)                        /* prepare next frame buffer */
88   {
89          VIEW    *fv;
90          char    *err;
# Line 155 | Line 166 | next_frame()                   /* prepare next frame buffer */
166  
167  
168   static int
169 < sample_here(x, y)               /* 4x4 quincunx sample at this pixel? */
170 < register int    x, y;
169 > sample_here(            /* 4x4 quincunx sample at this pixel? */
170 >        register int    x,
171 >        register int    y
172 > )
173   {
174          if (y & 0x1)            /* every other row has samples */
175                  return(0);
# Line 166 | Line 179 | register int   x, y;
179   }
180  
181  
182 < void
183 < sample_pos(hv, x, y, sn)        /* compute jittered sample position */
184 < double  hv[2];
185 < int     x, y;
186 < int     sn;
182 > extern void
183 > sample_pos(     /* compute jittered sample position */
184 >        double  hv[2],
185 >        int     x,
186 >        int     y,
187 >        int     sn
188 > )
189   {
190          int     hl[2];
191  
# Line 181 | Line 196 | int    sn;
196   }
197  
198  
199 < double
200 < sample_wt(xo, yo)               /* compute interpolant sample weight */
201 < int     xo, yo;
199 > extern double
200 > sample_wt(              /* compute interpolant sample weight */
201 >        int     xo,
202 >        int yo
203 > )
204   {
205          static double   etab[400];
206 <        int     rad2 = xo*xo + yo*yo;
206 >        /* we can't use the name rad2 here, for some reason Visual C
207 >           thinks that is a constant (compiler bug?) */
208 >        int     rad_2 = xo*xo + yo*yo;
209          int     i;
210  
211          if (etab[0] <= FTINY)           /* initialize exponent table */
# Line 194 | Line 213 | int    xo, yo;
213                          etab[i] = exp(-0.1*i);
214  
215                                          /* look up Gaussian */
216 <        i = (int)((10.*3./(double)SAMPDIST2)*rad2 + .5);
216 >        i = (int)((10.*3./(double)SAMPDIST2)*rad_2 + .5);
217          if (i >= 400)
218                  return(0.0);
219          return(etab[i]);
# Line 202 | Line 221 | int    xo, yo;
221  
222  
223   static int
224 < offset_cmp(p1, p2)              /* compare offset distances */
225 < const void      *p1, *p2;
224 > offset_cmp(             /* compare offset distances */
225 >        const void      *p1,
226 >        const void      *p2
227 > )
228   {
229          return(*(const int *)p1 - *(const int *)p2);
230   }
231  
232  
233 < int
234 < getclosest(iarr, nc, x, y)      /* get nc closest neighbors on same object */
235 < int     *iarr;
236 < int     nc;
237 < int     x, y;
233 > extern int
234 > getclosest(     /* get nc closest neighbors on same object */
235 >        int     *iarr,
236 >        int     nc,
237 >        int     x,
238 >        int     y
239 > )
240   {
241   #define NSCHECK         ((2*SAMPDIST+1)*(2*SAMPDIST+1))
242          static int      hro, vro;
# Line 283 | Line 306 | int    x, y;
306  
307  
308   static void
309 < setmotion(n, wpos)              /* compute motion vector for this pixel */
310 < register int    n;
311 < FVECT   wpos;
309 > setmotion(              /* compute motion vector for this pixel */
310 >                register int    n,
311 >                FVECT   wpos
312 > )
313   {
314          FVECT   ovp;
291        MAT4    xfm;
292        double  d;
315          int     moi;
316          int     xp, yp;
317                                          /* ID object and update maximum HLS */
# Line 320 | Line 342 | FVECT  wpos;
342  
343  
344   static void
345 < init_frame_sample()             /* sample our initial frame */
345 > init_frame_sample(void)         /* sample our initial frame */
346   {
347          RAY     ir;
348          int     x, y;
# Line 347 | Line 369 | init_frame_sample()            /* sample our initial frame */
369                          continue;
370                  }
371                  if (!sample_here(x, y)) {       /* just cast */
372 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
372 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
373                          if (!localhit(&ir, &thescene)) {
374                                  if (ir.ro != &Aftplane)
375                                          sourcehit(&ir);
# Line 365 | Line 387 | init_frame_sample()            /* sample our initial frame */
387                  }
388                  if (nprocs > 1) {               /* get sample */
389                          int     rval;
390 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
390 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
391                          ir.rno = n;
392                          rval = ray_pqueue(&ir);
393                          if (!rval)
# Line 422 | Line 444 | init_frame_sample()            /* sample our initial frame */
444   }
445  
446  
447 < int
448 < getambcolor(clr, obj)           /* get ambient color for object if we can */
449 < COLOR   clr;
450 < int     obj;
447 > extern int
448 > getambcolor(            /* get ambient color for object if we can */
449 >                COLOR   clr,
450 >                int     obj
451 > )
452   {
453          register OBJREC *op;
454  
# Line 492 | Line 515 | int    obj;
515   }
516  
517  
518 < double
519 < estimaterr(cs, cs2, ns, ns0)    /* estimate relative error from samples */
520 < COLOR   cs, cs2;
521 < int     ns;
518 > extern double
519 > estimaterr(             /* estimate relative error from samples */
520 >                COLOR   cs,
521 >                COLOR   cs2,
522 >                int     ns,
523 >                int ns0
524 > )
525   {
526          double  d, d2, brt;
527  
# Line 515 | Line 541 | int    ns;
541   }
542  
543  
544 < double
545 < comperr(neigh, nc, ns0)         /* estimate relative error in neighborhood */
546 < int     *neigh;
547 < int     nc;
548 < int     ns0;
544 > extern double
545 > comperr(                /* estimate relative error in neighborhood */
546 >                int     *neigh,
547 >                int     nc,
548 >                int     ns0
549 > )
550   {
551          COLOR   csum, csum2;
552          COLOR   ctmp;
# Line 550 | Line 577 | int    ns0;
577   }
578  
579  
580 < void
581 < comp_frame_error()              /* initialize frame error values */
580 > extern void
581 > comp_frame_error(void)          /* initialize frame error values */
582   {
583          BYTE    *edone = NULL;
584          COLOR   objamb;
585          double  eest;
586          int     neigh[NSAMPOK];
587          int     nc;
588 <        int     x, y, i, j;
588 >        int     x, y, i;
589          register int    n;
590  
591          if (!silent) {
# Line 629 | Line 656 | comp_frame_error()             /* initialize frame error values *
656   }
657  
658  
659 < void
660 < init_frame()                    /* render base (low quality) frame */
659 > extern void
660 > init_frame(void)                        /* render base (low quality) frame */
661   {
662          int     restart;
636
663                                          /* allocate/swap buffers */
664          next_frame();
665                                          /* check rendering status */
666          restart = (!nobjects || vdef(MOVE));
667          if (!restart && curparams != &lorendparams && nprocs > 1)
668                  restart = -1;
643        if (restart > 0) {
644                if (nprocs > 1)
645                        ray_pdone(1);
646                else
647                        ray_done(1);
648        }
669                                          /* post low quality parameters */
670          if (curparams != &lorendparams)
671                  ray_restore(curparams = &lorendparams);
# Line 677 | Line 697 | init_frame()                   /* render base (low quality) frame */
697          init_frame_sample();
698                                          /* initialize frame error */
699          comp_frame_error();
700 < return;
700 > #if 0
701   {
702          float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
703          char    fnm[256];
# Line 689 | Line 709 | return;
709          write_map(ebuf, fnm);
710          free((void *)ebuf);
711   }
712 + #endif
713   }
714  
715  
716 < void
717 < filter_frame()                  /* interpolation, motion-blur, and exposure */
716 > extern void
717 > filter_frame(void)                      /* interpolation, motion-blur, and exposure */
718   {
719          double  expval = expspec_val(getexp(fcur));
720          int     x, y;
# Line 704 | Line 725 | filter_frame()                 /* interpolation, motion-blur, and ex
725          register int    n;
726  
727   #if 0
728 < /* XXX TEMPORARY!! */
729 < conspicuity();
730 < write_map(cerrmap, "outcmap.pic");
731 < {
732 <        float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
733 <        for (n = hres*vres; n--; )
734 <                ebuf[n] = acctab[abuffer[n]];
735 <        write_map(ebuf, "outerr.pic");
736 <        free((void *)ebuf);
737 < }
728 >        /* XXX TEMPORARY!! */
729 >        conspicuity();
730 >        write_map(cerrmap, "outcmap.pic");
731 >        {
732 >                float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
733 >                for (n = hres*vres; n--; )
734 >                        ebuf[n] = acctab[abuffer[n]];
735 >                write_map(ebuf, "outerr.pic");
736 >                free((void *)ebuf);
737 >        }
738   #endif
739  
740          if (!silent) {
# Line 737 | Line 758 | write_map(cerrmap, "outcmap.pic");
758                          continue;
759                  nc = getclosest(neigh, NPINTERP, x, y);
760                  setcolor(cbuffer[n], 0., 0., 0.);
761 +                if (nc <= 0) {          /* no acceptable neighbors */
762 +                        if (y < vres-1)
763 +                                nc = fndx(x, y+1);
764 +                        else if (x < hres-1)
765 +                                nc = fndx(x+1, y);
766 +                        else
767 +                                continue;
768 +                        copycolor(cbuffer[n], cbuffer[nc]);
769 +                        continue;
770 +                }
771                  wsum = 0.;
772                  while (nc-- > 0) {
773                          copycolor(cval, cbuffer[neigh[nc]]);
# Line 746 | Line 777 | write_map(cerrmap, "outcmap.pic");
777                          addcolor(cbuffer[n], cval);
778                          wsum += w;
779                  }
780 <                if (wsum > FTINY) {
781 <                        w = 1.0/wsum;
751 <                        scalecolor(cbuffer[n], w);
752 <                }
780 >                w = 1.0/wsum;
781 >                scalecolor(cbuffer[n], w);
782              }
783                                          /* motion blur if requested */
784          if (mblur > .02) {
756                int     len;
785                  int     xs, ys, xl, yl;
786                  int     rise, run;
787                  long    rise2, run2;
# Line 791 | Line 819 | write_map(cerrmap, "outcmap.pic");
819                                  while (cnt)
820                                          if (rise2 >= run2) {
821                                                  if ((xl >= 0) & (xl < hres) &
822 <                                                        (yl >= 0) & (yl < vres)) {
822 >                                                    (yl >= 0) & (yl < vres)) {
823                                                          n2 = fndx(xl, yl);
824                                                          addcolor(outbuffer[n2],
825                                                                          cval);
# Line 812 | Line 840 | write_map(cerrmap, "outcmap.pic");
840                                  while (cnt)
841                                          if (run2 >= rise2) {
842                                                  if ((xl >= 0) & (xl < hres) &
843 <                                                        (yl >= 0) & (yl < vres)) {
843 >                                                    (yl >= 0) & (yl < vres)) {
844                                                          n2 = fndx(xl, yl);
845                                                          addcolor(outbuffer[n2],
846                                                                          cval);
# Line 839 | Line 867 | write_map(cerrmap, "outcmap.pic");
867          } else
868                  for (n = hres*vres; n--; )
869                          copycolor(outbuffer[n], cbuffer[n]);
870 < /*
871 < for (n = hres*vres; n--; )
872 <        if (!sbuffer[n])
873 <                setcolor(outbuffer[n], 0., 0., 0.);
874 < */
875 <                                /* adjust exposure */
870 >        /*
871 >           for (n = hres*vres; n--; )
872 >                   if (!sbuffer[n])
873 >                           setcolor(outbuffer[n], 0., 0., 0.);
874 >         */
875 >        /* adjust exposure */
876          if ((expval < 0.99) | (expval > 1.01))
877                  for (n = hres*vres; n--; )
878                          scalecolor(outbuffer[n], expval);
879 < return;
880 < {
881 <        float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
882 <        char    fnm[256];
883 <        sprintf(fnm, vval(BASENAME), fcur);
884 <        strcat(fnm, "_outsamp.pic");
885 <        for (n = hres*vres; n--; )
886 <                sbuf[n] = (float)sbuffer[n];
887 <        write_map(sbuf, fnm);
888 <        free((void *)sbuf);
879 > #if 0
880 >        {
881 >                float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
882 >                char    fnm[256];
883 >                sprintf(fnm, vval(BASENAME), fcur);
884 >                strcat(fnm, "_outsamp.pic");
885 >                for (n = hres*vres; n--; )
886 >                        sbuf[n] = (float)sbuffer[n];
887 >                write_map(sbuf, fnm);
888 >                free((void *)sbuf);
889 >        }
890 > #endif
891   }
862 }
892  
893  
894 < void
895 < send_frame()                    /* send frame to destination */
894 > extern void
895 > send_frame(void)                        /* send frame to destination */
896   {
897          char    pfname[1024];
898          double  d;
# Line 915 | Line 944 | writerr:
944   }
945  
946  
947 < void
948 < free_frame()                    /* free frame allocation */
947 > extern void
948 > free_frame(void)                        /* free frame allocation */
949   {
950          if (cbuffer == NULL)
951                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines