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.5 by schorsch, Mon Jul 21 22:30:19 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 106 | Line 117 | next_frame()                   /* prepare next frame buffer */
117                          pixaspect = 1.;
118                          /* fall through */
119                  case 3:
120 <                        if ((hres > 0 & vres > 0))
120 >                        if ((hres > 0) & (vres > 0))
121                                  break;
122                          /* fall through */
123                  default:
# Line 125 | Line 136 | next_frame()                   /* prepare next frame buffer */
136                  zprev = (float *)malloc(sizeof(float)*hres*vres);
137                  oprev = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres);
138                  aprev = (BYTE *)malloc(sizeof(BYTE)*hres*vres);
139 <                if ((cbuffer==NULL | zbuffer==NULL | obuffer==NULL |
140 <                                xmbuffer==NULL | ymbuffer==NULL |
141 <                                abuffer==NULL | sbuffer==NULL |
142 <                                cprev==NULL | zprev == NULL |
143 <                                oprev==NULL | aprev==NULL))
139 >                if ((cbuffer==NULL) | (zbuffer==NULL) | (obuffer==NULL) |
140 >                                (xmbuffer==NULL) | (ymbuffer==NULL) |
141 >                                (abuffer==NULL) | (sbuffer==NULL) |
142 >                                (cprev==NULL) | (zprev == NULL) |
143 >                                (oprev==NULL) | (aprev==NULL))
144                          error(SYSTEM, "out of memory in init_frame");
145                  frm_stop = getTime() + rtperfrm;
146          } else {
# 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 224 | Line 247 | int    x, y;
247                                          /* get our object number */
248          myobj = obuffer[fndx(x, y)];
249                                          /* special case for borders */
250 <        if ((x < SAMPDIST | x >= hres-SAMPDIST |
251 <                        y < SAMPDIST | y >= vres-SAMPDIST)) {
250 >        if ((x < SAMPDIST) | (x >= hres-SAMPDIST) |
251 >                        (y < SAMPDIST) | (y >= vres-SAMPDIST)) {
252                  int     tndx[NSCHECK][2];
253                  nf = 0;
254                  for (j = y - SAMPDIST; j <= y + SAMPDIST; j++) {
# Line 237 | Line 260 | int    x, y;
260                          i0 = fndx(i, j);
261                          if (!sbuffer[i0])
262                                  continue;
263 <                        if ((myobj != OVOID & obuffer[i0] != myobj))
263 >                        if ((myobj != OVOID) & (obuffer[i0] != myobj))
264                                  continue;
265                          tndx[nf][0] = (i-x)*(i-x) + (j-y)*(j-y);
266                          tndx[nf][1] = i0;
# Line 252 | Line 275 | int    x, y;
275                  return(nf);
276          }
277                                          /* initialize offset array */
278 <        if ((hres != hro | vres != vro)) {
278 >        if ((hres != hro) | (vres != vro)) {
279                  int     toffs[NSCHECK][2];
280                  i0 = fndx(SAMPDIST, SAMPDIST);
281                  nf = 0;
# Line 271 | Line 294 | int    x, y;
294          }
295                                          /* find up to nc neighbors */
296          i0 = fndx(x, y);
297 <        for (j = 0, nf = 0; (j < NSCHECK & nf < nc); j++) {
297 >        for (j = 0, nf = 0; (j < NSCHECK) & (nf < nc); j++) {
298                  i = i0 + ioffs[j];
299 <                if (sbuffer[i] && (myobj == OVOID | obuffer[i] == myobj))
299 >                if (sbuffer[i] && (myobj == OVOID) | (obuffer[i] == myobj))
300                          iarr[nf++] = i;
301          }
302                                          /* return number found */
# 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 309 | Line 331 | FVECT  wpos;
331          yp = (int)(ovp[1]*vres);
332          xmbuffer[n] = xp - (n % hres);
333          ymbuffer[n] = yp - (n / hres);
334 <        if ((xp < 0 | xp >= hres))
334 >        if ((xp < 0) | (xp >= hres))
335                  return;
336 <        if ((yp < 0 | yp >= vres))
336 >        if ((yp < 0) | (yp >= vres))
337                  return;
338          n = fndx(xp, yp);
339 <        if ((zprev[n] < 0.97*ovp[2] | zprev[n] > 1.03*ovp[2]))
339 >        if ((zprev[n] < 0.97*ovp[2]) | (zprev[n] > 1.03*ovp[2]))
340                  oprev[n] = OVOID;       /* assume it's a bad match */
341   }
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 407 | Line 429 | init_frame_sample()            /* sample our initial frame */
429                  n = fndx(x, y);
430                  if ((obj = obuffer[n]) == OVOID)
431                          continue;
432 <                if ((obuffer[n+1] != OVOID & obuffer[n+1] != obj)) {
432 >                if ((obuffer[n+1] != OVOID) & (obuffer[n+1] != obj)) {
433                          obuffer[n] = OVOID;
434                          obuffer[n+1] = OVOID;
435                  }
436 <                if ((obuffer[n+hres] != OVOID & obuffer[n+hres] != obj)) {
436 >                if ((obuffer[n+hres] != OVOID) & (obuffer[n+hres] != obj)) {
437                          obuffer[n] = OVOID;
438                          obuffer[n+hres] = OVOID;
439                  }
# 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  
455          if (obj == OVOID)
456                  return(0);
457          op = objptr(obj);
458 <        if ((op->otype == OBJ_INSTANCE & op->omod == OVOID))
458 >        if ((op->otype == OBJ_INSTANCE) & (op->omod == OVOID))
459                  return(0);
460                                          /* search for material */
461          do {
# 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 529 | Line 556 | int    ns0;
556                                          /* add together samples */
557          setcolor(csum, 0., 0., 0.);
558          setcolor(csum2, 0., 0., 0.);
559 <        for (i = 0, ns = 0; (i < nc & ns < NSAMPOK); i++) {
559 >        for (i = 0, ns = 0; (i < nc) & (ns < NSAMPOK); i++) {
560                  n = neigh[i];
561                  addcolor(csum, cbuffer[n]);
562                  if (val2map != NULL) {
# 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 581 | Line 608 | comp_frame_error()             /* initialize frame error values *
608                  for (y = vres; y--; )
609                      for (x = hres; x--; ) {
610                          n = fndx(x, y);
611 <                        if ((abuffer[n] != ALOWQ | obuffer[n] == OVOID))
611 >                        if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
612                                  continue;
613                          if (!getambcolor(objamb, obuffer[n]))
614                                  continue;
# 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 790 | Line 818 | write_map(cerrmap, "outcmap.pic");
818                                  scalecolor(cval, w);
819                                  while (cnt)
820                                          if (rise2 >= run2) {
821 <                                                if ((xl >= 0 & xl < hres &
822 <                                                        yl >= 0 & yl < vres)) {
821 >                                                if ((xl >= 0) & (xl < hres) &
822 >                                                    (yl >= 0) & (yl < vres)) {
823                                                          n2 = fndx(xl, yl);
824                                                          addcolor(outbuffer[n2],
825                                                                          cval);
# Line 811 | Line 839 | write_map(cerrmap, "outcmap.pic");
839                                  scalecolor(cval, w);
840                                  while (cnt)
841                                          if (run2 >= rise2) {
842 <                                                if ((xl >= 0 & xl < hres &
843 <                                                        yl >= 0 & yl < vres)) {
842 >                                                if ((xl >= 0) & (xl < hres) &
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 */
876 <        if ((expval < 0.99 | expval > 1.01))
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 890 | Line 919 | send_frame()                   /* send frame to destination */
919          fputnow(fp);
920          fputs(VIEWSTR, fp); fprintview(&vw, fp); fputc('\n', fp);
921          d = expspec_val(getexp(fcur));
922 <        if ((d < 0.99 | d > 1.01))
922 >        if ((d < 0.99) | (d > 1.01))
923                  fputexpos(d, fp);
924          d = viewaspect(&vw) * hres / vres;
925 <        if ((d < 0.99 | d > 1.01))
925 >        if ((d < 0.99) | (d > 1.01))
926                  fputaspect(d, fp);
927          fputformat(COLRFMT, fp);
928          fputc('\n', fp);                /* end header */
# 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