Back to index

radiance  4R0+20100331
Classes | Defines | Functions | Variables
ranimove.h File Reference
#include "ray.h"
#include "view.h"
#include "vars.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ObjMove

Defines

#define BASENAME   0 /* output image base name */
#define END   1 /* number of animation frames */
#define EXPOSURE   2 /* how to compute exposure */
#define HIGHQ   3 /* high quality setting */
#define LOWQ   4 /* low quality setting */
#define MBLUR   5 /* motion blur parameter */
#define MOVE   6 /* object movement */
#define OCONV   7 /* oconv options */
#define OCTREEF   8 /* octree file name */
#define RATE   9 /* frame rate (fps) */
#define RESOLUTION   10 /* desired final resolution */
#define RIF   11 /* rad input file */
#define VIEWFILE   12 /* animation frame views */
#define NV_INIT   13 /* number of variables */
#define VV_INIT
#define ANOVAL   0 /* unevaluated pixel */
#define ALOWQ   1 /* single low-quality sample */
#define AHIGHQ   2 /* single high-quality sample */
#define AMIN   3 /* start of error lookup table */
#define ADISTANT   255 /* ray went off to infinity */
#define CSF_SMN   (1./0.82) /* 1/avg_tracking_efficacy */
#define outbuffer   cprev /* used to hold final output */
#define wbuffer   zprev /* used for final filtering */
#define fndx(x, y)   ((y)*hres + (x))
#define MO_UNK   -32768 /* unknown motion value */
#define FOV_DEG   1.0 /* foveal radius (degrees) */
#define LOG_E1   (-0.0233) /* ln(0.977) */
#define errorf(i)   exp(LOG_E1*((i)-AMIN))
#define errori(e)   (int)(log(e)*(1./LOG_E1) + (AMIN+.5))
#define NSAMPOK   5 /* samples enough for error estimation */
#define NPINTERP   4 /* number of pixels to interpolate */
#define ATIDIFF   7 /* error difference for time extrapolation */

Functions

void init_frame (void)
void filter_frame (void)
void send_frame (void)
void free_frame (void)
void write_map (float *mp, char *fn)
void sample_pos (double hv[2], int x, int y, int sn)
void comp_frame_error (void)
int getclosest (int *iarr, int nc, int x, int y)
int getambcolor (COLOR clr, int obj)
double sample_wt (int xo, int yo)
double estimaterr (COLOR cs, COLOR cs2, int ns, int ns0)
double comperr (int *neigh, int nc, int ns0)
int refine_first ()
void conspicuity (void)
int refine_frame (int pass)
double getTime (void)
double obj_prio (OBJECT obj)
int getmove (OBJECT obj)
char * getoctspec (int n)
double expspec_val (char *s)
char * getexp (int n)
VIEWgetview (int n)

Variables

int silent
int quickstart
int nprocs
int rtperfrm
double ndthresh
int ndtset
int fbeg
int fend
int fcur
char lorendoptf []
RAYPARAMS lorendparams
char hirendoptf []
RAYPARAMS hirendparams
RAYPARAMScurparams
int twolevels
double mblur
double rate
char objtmpf []
struct ObjMoveobj_move
int haveprio
int gargc
char ** gargv
double acctab [256]
int hres
int vres
double pixaspect
VIEW vw
COLORcbuffer
float * zbuffer
OBJECTobuffer
short * xmbuffer
short * ymbuffer
BYTEabuffer
BYTEsbuffer
VIEW vwprev
COLORcprev
float * zprev
OBJECToprev
BYTEaprev
float * cerrmap
int cerrzero
COLORval2map
double frm_stop
double hlsmax

Class Documentation

struct ObjMove

Definition at line 63 of file ranimove.h.

Class Members
MAT4 bxfm
int cfm
double cprio
MAT4 cxfm
char name
int parent
double prio
char prio_file
char spec
char xf_file
MAT4 xfm
char xfs

Define Documentation

#define ADISTANT   255 /* ray went off to infinity */

Definition at line 120 of file ranimove.h.

#define AHIGHQ   2 /* single high-quality sample */

Definition at line 118 of file ranimove.h.

#define ALOWQ   1 /* single low-quality sample */

Definition at line 117 of file ranimove.h.

#define AMIN   3 /* start of error lookup table */

Definition at line 119 of file ranimove.h.

#define ANOVAL   0 /* unevaluated pixel */

Definition at line 116 of file ranimove.h.

#define ATIDIFF   7 /* error difference for time extrapolation */

Definition at line 169 of file ranimove.h.

#define BASENAME   0 /* output image base name */

Definition at line 31 of file ranimove.h.

#define CSF_SMN   (1./0.82) /* 1/avg_tracking_efficacy */

Definition at line 150 of file ranimove.h.

#define END   1 /* number of animation frames */

Definition at line 32 of file ranimove.h.

#define errorf (   i)    exp(LOG_E1*((i)-AMIN))

Definition at line 162 of file ranimove.h.

#define errori (   e)    (int)(log(e)*(1./LOG_E1) + (AMIN+.5))

Definition at line 163 of file ranimove.h.

#define EXPOSURE   2 /* how to compute exposure */

Definition at line 33 of file ranimove.h.

#define fndx (   x,
 
)    ((y)*hres + (x))

Definition at line 155 of file ranimove.h.

#define FOV_DEG   1.0 /* foveal radius (degrees) */

Definition at line 159 of file ranimove.h.

#define HIGHQ   3 /* high quality setting */

Definition at line 34 of file ranimove.h.

#define LOG_E1   (-0.0233) /* ln(0.977) */

Definition at line 161 of file ranimove.h.

#define LOWQ   4 /* low quality setting */

Definition at line 35 of file ranimove.h.

#define MBLUR   5 /* motion blur parameter */

Definition at line 36 of file ranimove.h.

#define MO_UNK   -32768 /* unknown motion value */

Definition at line 157 of file ranimove.h.

#define MOVE   6 /* object movement */

Definition at line 37 of file ranimove.h.

#define NPINTERP   4 /* number of pixels to interpolate */

Definition at line 167 of file ranimove.h.

#define NSAMPOK   5 /* samples enough for error estimation */

Definition at line 165 of file ranimove.h.

#define NV_INIT   13 /* number of variables */

Definition at line 45 of file ranimove.h.

#define OCONV   7 /* oconv options */

Definition at line 38 of file ranimove.h.

#define OCTREEF   8 /* octree file name */

Definition at line 39 of file ranimove.h.

#define outbuffer   cprev /* used to hold final output */

Definition at line 152 of file ranimove.h.

#define RATE   9 /* frame rate (fps) */

Definition at line 40 of file ranimove.h.

#define RESOLUTION   10 /* desired final resolution */

Definition at line 41 of file ranimove.h.

#define RIF   11 /* rad input file */

Definition at line 42 of file ranimove.h.

#define VIEWFILE   12 /* animation frame views */

Definition at line 43 of file ranimove.h.

#define VV_INIT
Value:
{ \
              {"BASENAME",  3,     0,     NULL,  onevalue}, \
              {"END",              3,     0,     NULL,  intvalue}, \
              {"EXPOSURE",  3,     0,     NULL,  onevalue}, \
              {"highq",     2,     0,     NULL,  catvalues}, \
              {"lowq",      2,     0,     NULL,  catvalues}, \
              {"MBLUR",     2,     0,     NULL,  fltvalue}, \
              {"move",      2,     0,     NULL,  NULL}, \
              {"oconv",     2,     0,     NULL,  catvalues}, \
              {"OCTREE",    3,     0,     NULL,  onevalue}, \
              {"RATE",      2,     0,     NULL,  fltvalue}, \
              {"RESOLUTION",       3,     0,     NULL,  onevalue}, \
              {"RIF",              3,     0,     NULL,  onevalue}, \
              {"VIEWFILE",  2,     0,     NULL,  onevalue} \
       }

Definition at line 47 of file ranimove.h.

#define wbuffer   zprev /* used for final filtering */

Definition at line 153 of file ranimove.h.


Function Documentation

void comp_frame_error ( void  )

Definition at line 581 of file ranimove1.c.

{
       BYTE   *edone = NULL;
       COLOR  objamb;
       double eest;
       int    neigh[NSAMPOK];
       int    nc;
       int    x, y, i;
       register int  n;

       if (!silent) {
              printf("\tComputing error map\n");
              fflush(stdout);
       }
       if (acctab[0] <= FTINY)            /* initialize accuracy table */
              for (i = 256; i--; )
                     acctab[i] = errorf(i);
                                   /* estimate sample error */
       if (!curparams->ambounce && hirendparams.ambounce) {
              /*
               * Our error estimate for the initial value is based
               * on the assumption that most of it comes from the
               * lack of an interreflection calculation.  The relative
               * error should be less than the ambient value divided
               * by the returned ray value -- we take half of this.
               */
              edone = (BYTE *)calloc(hres*vres, sizeof(BYTE));
              for (y = vres; y--; )
                  for (x = hres; x--; ) {
                     n = fndx(x, y);
                     if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
                            continue;
                     if (!getambcolor(objamb, obuffer[n]))
                            continue;
                     multcolor(objamb, ambval);
                     if ((eest = bright(cbuffer[n])) <= FTINY)
                            continue;
                     eest = bright(objamb) / eest;
                     if (eest > 1.)       /* should we report this? */
                            continue;
                     eest *= 0.50; /* use 50% ambient error */
                     i = errori(eest);
                     if (i < AMIN) i = AMIN;
                     else if (i >= ADISTANT/2) i = ADISTANT/2-1;
                     abuffer[n] = i;
                     edone[n] = 1;
                  }
       }
                                   /* final statistical estimate */
       for (y = vres; y--; )
           for (x = hres; x--; ) {
              n = fndx(x, y);
              if (abuffer[n] == ADISTANT)
                     continue;     /* don't update these */
              if (edone != NULL && edone[n])
                     continue;     /* already done this */
              if (sbuffer[n] >= 255) {
                     abuffer[n] = ADISTANT;
                     continue;     /* can't take any more */
              }
              nc = getclosest(neigh, NSAMPOK, x, y);
              if (nc <= 0) {
                     abuffer[n] = ANOVAL;
                     continue;     /* no clue what to do for him */
              }
              i = errori(comperr(neigh, nc, sbuffer[n]));
              if (i < AMIN) i = AMIN;
              else if (i >= ADISTANT) i = ADISTANT-1;
              abuffer[n] = i;
                                   /* can't be better than closest */
              if (i < abuffer[neigh[0]] && abuffer[neigh[0]] >= AMIN)
                     abuffer[n] = abuffer[neigh[0]];
           }
       if (edone != NULL)
              free((void *)edone);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double comperr ( int *  neigh,
int  nc,
int  ns0 
)

Definition at line 545 of file ranimove1.c.

{
       COLOR  csum, csum2;
       COLOR  ctmp;
       int    i;
       int    ns;
       register int  n;
                                   /* add together samples */
       setcolor(csum, 0., 0., 0.);
       setcolor(csum2, 0., 0., 0.);
       for (i = 0, ns = 0; (i < nc) & (ns < NSAMPOK); i++) {
              n = neigh[i];
              addcolor(csum, cbuffer[n]);
              if (val2map != NULL) {
                     addcolor(csum2, val2map[n]);
                     ns += sbuffer[n];
                     continue;
              }
              if (sbuffer[n] != 1)
                     error(CONSISTENCY, "bad count in comperr");
              setcolor(ctmp,
                     colval(cbuffer[n],RED)*colval(cbuffer[n],RED),
                     colval(cbuffer[n],GRN)*colval(cbuffer[n],GRN),
                     colval(cbuffer[n],BLU)*colval(cbuffer[n],BLU));
              addcolor(csum2, ctmp);
              ns++;
       }
       return(estimaterr(csum, csum2, ns, ns0));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void conspicuity ( void  )

Definition at line 314 of file ranimove2.c.

{
       int    fhres, fvres;
       int    fx, fy;
                                   /* reuse previous z-buffer */
       cerrmap = (float *)zprev;
       memset((void *)cerrmap, '\0', sizeof(float)*hres*vres);
       cerrzero = 1;
                                   /* compute base pixel frequency */
       pixel_deg = .5*(hres/vw.horiz + vres/vw.vert);
                                   /* compute foveal resolution */
       fhres = vw.horiz/FOV_DEG + 0.5;
       if (fhres <= 0) fhres = 1;
       else if (fhres > hres) fhres = hres;
       fvres = vw.vert/FOV_DEG + 0.5;
       if (fvres <= 0) fvres = 1;
       else if (fvres > vres) fvres = vres;
       fhsiz = hres/fhres;
       fvsiz = vres/fvres;
                                   /* call our foveal subroutine */
       for (fy = fvres; fy--; )
              for (fx = fhres; fx--; )
                     subconspicuity(hres*fx/fhres, vres*fy/fvres,
                                   hres*(fx+1)/fhres, vres*(fy+1)/fvres,
                                   NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double estimaterr ( COLOR  cs,
COLOR  cs2,
int  ns,
int  ns0 
)

Definition at line 519 of file ranimove1.c.

{
       double d, d2, brt;

       if (ns <= 1 || (brt = bright(cs)/ns) < 1e-14)
              return(1.0);
                                   /* use largest of RGB std. dev. */
       d2 = colval(cs2,RED) - colval(cs,RED)*colval(cs,RED)/ns;
       d = colval(cs2,GRN) - colval(cs,GRN)*colval(cs,GRN)/ns;
       if (d > d2) d2 = d;
       d = colval(cs2,BLU) - colval(cs,BLU)*colval(cs,BLU)/ns;
       if (d > d2) d2 = d;
                                   /* use s.d. if <= 1 central sample */
       if (ns0 <= 1)
              return(sqrt(d2/(ns-1))/brt);
                                   /* use s.d./sqrt(ns0) otherwise */
       return(sqrt(d2/((ns-1)*ns0))/brt);
}

Here is the caller graph for this function:

double expspec_val ( char *  s)

Definition at line 595 of file ranimove.c.

{
       double expval;

       if (s == NULL || !*s)
              return(1.0);

       expval = atof(s);
       if ((s[0] == '+') | (s[0] == '-'))
              return(pow(2.0, expval));
       return(expval);
}

Here is the caller graph for this function:

void filter_frame ( void  )

Definition at line 717 of file ranimove1.c.

{
       double expval = expspec_val(getexp(fcur));
       int    x, y;
       int    neigh[NPINTERP];
       int    nc;
       COLOR  cval;
       double w, wsum;
       register int  n;

#if 0
       /* XXX TEMPORARY!! */
       conspicuity();
       write_map(cerrmap, "outcmap.pic");
       {
              float  *ebuf = (float *)malloc(sizeof(float)*hres*vres);
              for (n = hres*vres; n--; )
                     ebuf[n] = acctab[abuffer[n]];
              write_map(ebuf, "outerr.pic");
              free((void *)ebuf);
       }
#endif

       if (!silent) {
              printf("\tFiltering frame\n");
              fflush(stdout);
       }
                                   /* normalize samples */
       for (y = vres; y--; )
           for (x = hres; x--; ) {
              n = fndx(x, y);
              if (sbuffer[n] <= 1)
                     continue;
              w = 1.0/(double)sbuffer[n];
              scalecolor(cbuffer[n], w);
           }
                                   /* interpolate samples */
       for (y = vres; y--; )
           for (x = hres; x--; ) {
              n = fndx(x, y);
              if (sbuffer[n])
                     continue;
              nc = getclosest(neigh, NPINTERP, x, y);
              setcolor(cbuffer[n], 0., 0., 0.);
              if (nc <= 0) {              /* no acceptable neighbors */
                     if (y < vres-1)
                            nc = fndx(x, y+1);
                     else if (x < hres-1)
                            nc = fndx(x+1, y);
                     else
                            continue;
                     copycolor(cbuffer[n], cbuffer[nc]);
                     continue;
              }
              wsum = 0.;
              while (nc-- > 0) {
                     copycolor(cval, cbuffer[neigh[nc]]);
                     w = sample_wt((neigh[nc]%hres) - x,
                                   (neigh[nc]/hres) - y);
                     scalecolor(cval, w);
                     addcolor(cbuffer[n], cval);
                     wsum += w;
              }
              w = 1.0/wsum;
              scalecolor(cbuffer[n], w);
           }
                                   /* motion blur if requested */
       if (mblur > .02) {
              int    xs, ys, xl, yl;
              int    rise, run;
              long   rise2, run2;
              int    n2;
              int    cnt;
                                   /* sum in motion streaks */
              memset(outbuffer, '\0', sizeof(COLOR)*hres*vres);
              memset(wbuffer, '\0', sizeof(float)*hres*vres);
              for (y = vres; y--; )
                  for (x = hres; x--; ) {
                     n = fndx(x, y);
                     if (xmbuffer[n] == MO_UNK) {
                            run = rise = 0;
                     } else {
                            run = (int)(mblur*xmbuffer[n]);
                            rise = (int)(mblur*ymbuffer[n]);
                     }
                     if (!(run | rise)) {
                            addcolor(outbuffer[n], cbuffer[n]);
                            wbuffer[n] += 1.;
                            continue;
                     }
                     xl = x - run/4;
                     yl = y - rise/4;
                     if (run < 0) { xs = -1; run = -run; }
                     else xs = 1;
                     if (rise < 0) { ys = -1; rise = -rise; }
                     else ys = 1;
                     rise2 = run2 = 0L;
                     if (rise > run) {
                            cnt = rise + 1;
                            w = 1./cnt;
                            copycolor(cval, cbuffer[n]);
                            scalecolor(cval, w);
                            while (cnt)
                                   if (rise2 >= run2) {
                                          if ((xl >= 0) & (xl < hres) &
                                              (yl >= 0) & (yl < vres)) {
                                                 n2 = fndx(xl, yl);
                                                 addcolor(outbuffer[n2],
                                                               cval);
                                                 wbuffer[n2] += w;
                                          }
                                          yl += ys;
                                          run2 += run;
                                          cnt--;
                                   } else {
                                          xl += xs;
                                          rise2 += rise;
                                   }
                     } else {
                            cnt = run + 1;
                            w = 1./cnt;
                            copycolor(cval, cbuffer[n]);
                            scalecolor(cval, w);
                            while (cnt)
                                   if (run2 >= rise2) {
                                          if ((xl >= 0) & (xl < hres) &
                                              (yl >= 0) & (yl < vres)) {
                                                 n2 = fndx(xl, yl);
                                                 addcolor(outbuffer[n2],
                                                               cval);
                                                 wbuffer[n2] += w;
                                          }
                                          xl += xs;
                                          rise2 += rise;
                                          cnt--;
                                   } else {
                                          yl += ys;
                                          run2 += run;
                                   }
                     }
                  }
                                   /* compute final results */
              for (y = vres; y--; )
                  for (x = hres; x--; ) {
                     n = fndx(x, y);
                     if (wbuffer[n] <= FTINY)
                            continue;
                     w = 1./wbuffer[n];
                     scalecolor(outbuffer[n], w);
                  }
       } else
              for (n = hres*vres; n--; )
                     copycolor(outbuffer[n], cbuffer[n]);
       /*
          for (n = hres*vres; n--; )
                 if (!sbuffer[n])
                        setcolor(outbuffer[n], 0., 0., 0.);
        */
       /* adjust exposure */
       if ((expval < 0.99) | (expval > 1.01))
              for (n = hres*vres; n--; )
                     scalecolor(outbuffer[n], expval);
#if 0
       {
              float  *sbuf = (float *)malloc(sizeof(float)*hres*vres);
              char   fnm[256];
              sprintf(fnm, vval(BASENAME), fcur);
              strcat(fnm, "_outsamp.pic");
              for (n = hres*vres; n--; )
                     sbuf[n] = (float)sbuffer[n];
              write_map(sbuf, fnm);
              free((void *)sbuf);
       }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void free_frame ( void  )

Definition at line 948 of file ranimove1.c.

{
       if (cbuffer == NULL)
              return;
       free((void *)cbuffer); cbuffer = NULL;
       free((void *)zbuffer); zbuffer = NULL;
       free((void *)obuffer); obuffer = NULL;
       free((void *)xmbuffer); xmbuffer = NULL;
       free((void *)ymbuffer); ymbuffer = NULL;
       free((void *)cprev); cprev = NULL;
       free((void *)zprev); zprev = NULL;
       free((void *)oprev); oprev = NULL;
       cerrmap = NULL;
       val2map = NULL;
       hres = vres = 0;
       vw.type = vwprev.type = 0;
       frm_stop = 0;
}

Here is the caller graph for this function:

int getambcolor ( COLOR  clr,
int  obj 
)

Definition at line 448 of file ranimove1.c.

{
       register OBJREC      *op;

       if (obj == OVOID)
              return(0);
       op = objptr(obj);
       if ((op->otype == OBJ_INSTANCE) & (op->omod == OVOID))
              return(0);
                                   /* search for material */
       do {
              if (op->omod == OVOID || ofun[op->otype].flags & T_X)
                     return(0);
              op = objptr(op->omod);
       } while (!ismaterial(op->otype));
       /*
        * Since this routine is called to compute the difference
        * from rendering with and without interreflections,
        * we don't want to return colors for materials that are
        * explicitly excluded from the HQ ambient calculation.
        */
       if (hirendparams.ambincl >= 0) {
              int    i;
              char   *lv;
              for (i = 0; (lv = rpambmod(&hirendparams,i)) != NULL; i++)
                     if (lv[0] == op->oname[0] &&
                                   !strcmp(lv+1, op->oname+1))
                            break;
              if ((lv != NULL) != hirendparams.ambincl)
                     return(0);
       }
       switch (op->otype) {
       case MAT_PLASTIC:
       case MAT_METAL:
       case MAT_PLASTIC2:
       case MAT_METAL2:
       case MAT_PFUNC:
       case MAT_MFUNC:
       case MAT_PDATA:
       case MAT_MDATA:
       case MAT_TRANS:
       case MAT_TRANS2:
       case MAT_TFUNC:
       case MAT_TDATA:
              if (op->oargs.nfargs < 3)
                     return(0);
              setcolor(clr, op->oargs.farg[0], op->oargs.farg[1],
                            op->oargs.farg[2]);
              return(1);
       case MAT_BRTDF:
              if (op->oargs.nfargs < 6)
                     return(0);
              setcolor(clr, op->oargs.farg[0]+op->oargs.farg[3],
                            op->oargs.farg[1]+op->oargs.farg[4],
                            op->oargs.farg[2]+op->oargs.farg[5]);
              scalecolor(clr, 0.5);
              return(1);
       case MAT_LIGHT:
       case MAT_GLOW:
       case MAT_ILLUM:
              setcolor(clr, 0., 0., 0.);
              return(1);
       }
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int getclosest ( int *  iarr,
int  nc,
int  x,
int  y 
)

Definition at line 234 of file ranimove1.c.

{
#define       NSCHECK              ((2*SAMPDIST+1)*(2*SAMPDIST+1))
       static int    hro, vro;
       static int    ioffs[NSCHECK];
       OBJECT myobj;
       int    i0, nf;
       register int  i, j;
                                   /* get our object number */
       myobj = obuffer[fndx(x, y)];
                                   /* special case for borders */
       if ((x < SAMPDIST) | (x >= hres-SAMPDIST) |
                     (y < SAMPDIST) | (y >= vres-SAMPDIST)) {
              int    tndx[NSCHECK][2];
              nf = 0;
              for (j = y - SAMPDIST; j <= y + SAMPDIST; j++) {
                  if (j >= vres) break;
                  if (j < 0) j = 0;
                  for (i = x - SAMPDIST; i <= x + SAMPDIST; i++) {
                     if (i >= hres) break;
                     if (i < 0) i = 0;
                     i0 = fndx(i, j);
                     if (!sbuffer[i0])
                            continue;
                     if ((myobj != OVOID) & (obuffer[i0] != myobj))
                            continue;
                     tndx[nf][0] = (i-x)*(i-x) + (j-y)*(j-y);
                     tndx[nf][1] = i0;
                     nf++;
                  }
              }
              qsort((void *)tndx, nf, 2*sizeof(int), offset_cmp);
              if (nf > nc)
                     nf = nc;
              for (i = nf; i--; )
                     iarr[i] = tndx[i][1];
              return(nf);
       }
                                   /* initialize offset array */
       if ((hres != hro) | (vres != vro)) {
              int    toffs[NSCHECK][2];
              i0 = fndx(SAMPDIST, SAMPDIST);
              nf = 0;
              for (i = 0; i <= 2*SAMPDIST; i++)
                  for (j = 0; j <= 2*SAMPDIST; j++) {
                     toffs[nf][0] = (i-SAMPDIST)*(i-SAMPDIST) +
                                   (j-SAMPDIST)*(j-SAMPDIST);
                     toffs[nf][1] = fndx(i, j) - i0;
                     nf++;
                  }
              qsort((void *)toffs, nf, 2*sizeof(int), offset_cmp);
              for (i = NSCHECK; i--; )
                     ioffs[i] = toffs[i][1];
              hro = hres;
              vro = vres;
       }
                                   /* find up to nc neighbors */
       i0 = fndx(x, y);
       for (j = 0, nf = 0; (j < NSCHECK) & (nf < nc); j++) {
              i = i0 + ioffs[j];
              if (sbuffer[i] && (myobj == OVOID) | (obuffer[i] == myobj))
                     iarr[nf++] = i;
       }
                                   /* return number found */
       return(nf);
#undef NSCHECK
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* getexp ( int  n)

Definition at line 536 of file ranimove.c.

{
       extern char   *fskip();
       static char   expval[32];
       static FILE   *expfp = NULL;
       static int    curfrm = 0;
       register char *cp;

       if (n == 0) {                      /* signal to close file */
              if (expfp != NULL) {
                     fclose(expfp);
                     expfp = NULL;
              }
              return(NULL);
       }
       if (!vdef(EXPOSURE))               /* no setting (auto) */
              return(NULL);
       if (isflt(vval(EXPOSURE)))         /* always the same */
              return(vval(EXPOSURE));
       if (expfp == NULL) {               /* open exposure file */
              if ((expfp = fopen(vval(EXPOSURE), "r")) == NULL) {
                     sprintf(errmsg, "cannot open exposure file \"%s\"",
                                   vval(EXPOSURE));
                     error(SYSTEM, errmsg);
              }
              curfrm = 0;
       }
       if (curfrm > n) {                  /* rewind if necessary */
              rewind(expfp);
              curfrm = 0;
       }
       while (n > curfrm) {               /* read to line */
              if (fgets(expval, sizeof(expval), expfp) == NULL) {
                     sprintf(errmsg, "%s: too few exposures",
                                   vval(EXPOSURE));
                     error(USER, errmsg);
              }
              if (strlen(expval) == sizeof(expval)-1)
                     goto formerr;
              curfrm++;
       }
       cp = fskip(expval);                /* check format */
       if (cp != NULL)
              while (isspace(*cp))
                     *cp++ = '\0';
       if (cp == NULL || *cp)
              goto formerr;
       return(expval);                           /* return value */
formerr:
       sprintf(errmsg, "%s: exposure format error on line %d",
                     vval(EXPOSURE), curfrm);
       error(USER, errmsg);
       return NULL; /* pro forma return */
}

Here is the call graph for this function:

int getmove ( OBJECT  obj)

Definition at line 809 of file ranimove.c.

{
       static int    lasti;
       static OBJECT lasto = OVOID;
       char   *onm, *objnm;
       int    len, len2;
       register int  i;

       if (obj == OVOID)
              return(-1);
       if (obj == lasto)
              return(lasti);
                                   /* look for matching object */
       onm = objptr(obj)->oname;
       for (i = vdef(MOVE); i--; ) {
              objnm = obj_move[i].name;
              len = strlen(objnm);
              if (!strncmp(onm, objnm, len)) {
                     if ((obj_move[i].parent < 0) & (onm[len] == '.'))
                            break;
                     objnm = getobjname(&obj_move[i]) + len;
                     len2 = strlen(objnm);
                     if (!strncmp(onm+len, objnm, len2) && onm[len+len2] == '.')
                            break;
              }
       }
       lasto = obj;                /* cache what we found */
       return(lasti = i);
}

Here is the call graph for this function:

char* getoctspec ( int  n)

Definition at line 612 of file ranimove.c.

{
       static char   combuf[1024];
       int           cfm = 0;
       int    uses_inline;
       FILE   *fp;
       int    i;
                                   /* is octree static? */
       if (!vdef(MOVE))
              return(vval(OCTREEF));
                                   /* done already */
       if (n == cfm)
              return(combuf);
                                   /* else create object file */
       strcpy(objtmpf, "movinobj.rad");
       fp = fopen(objtmpf, "w");
       if (fp == NULL) {
              sprintf(errmsg, "cannot write to moving objects file '%s'",
                            objtmpf);
              error(SYSTEM, errmsg);
       }
       uses_inline = 0;
       for (i = 0; i < vdef(MOVE); i++) {
              int    inlc = (obj_move[i].spec[0] == '!');
              if (!obj_move[i].spec[0])
                     continue;
              if (inlc)
                     fprintf(fp, "%s %d \\\n\t| xform",
                                   obj_move[i].spec, n);
              else
                     fputs("!xform", fp);
              fprintf(fp, " -n %s", getobjname(&obj_move[i]));
              fputs(getxf(&obj_move[i], n), fp);
              if (!inlc)
                     fprintf(fp, " %s\n", obj_move[i].spec);
              else
                     fputc('\n', fp);
              uses_inline |= inlc;
       }
       if (fclose(fp) == EOF)
              error(SYSTEM, "error writing moving objects file");
       if (uses_inline)
              sprintf(combuf, "!oconv %s -f -i '%s' %s",
                            vdef(OCONV) ? vval(OCONV) : "",
                            vval(OCTREEF), objtmpf);
       else
              sprintf(combuf, "!xform -f %s | oconv -f -i '%s' -",
                            objtmpf, vval(OCTREEF));
       return(combuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double getTime ( void  )

Definition at line 856 of file ranimove.c.

{
       struct timeval       time_now;
                                   /* return CPU time if one process */
       if (nprocs == 1)
              return((double)clock()*(1.0/(double)CLOCKS_PER_SEC));
                                   /* otherwise, return wall time */
       gettimeofday(&time_now, NULL);
       return((double)time_now.tv_sec + 1e-6*(double)time_now.tv_usec);
}

Here is the caller graph for this function:

VIEW* getview ( int  n)

Definition at line 472 of file ranimove.c.

{
       static FILE   *viewfp = NULL;             /* view file pointer */
       static int    viewnum = 0;         /* current view number */
       static VIEW   curview = STDVIEW;   /* current view */
       char   linebuf[256];

       if (n == 0) {               /* signal to close file and clean up */
              if (viewfp != NULL) {
                     fclose(viewfp);
                     viewfp = NULL;
                     viewnum = 0;
                     curview = stdview;
              }
              return(NULL);
       }
       if (viewfp == NULL) {                     /* open file */
              if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
                     perror(vval(VIEWFILE));
                     quit(1);
              }
       } else if (n > 0 && n < viewnum) { /* rewind file */
              if (viewnum == 1 && feof(viewfp))
                     return(&curview);           /* just one view */
              if (fseek(viewfp, 0L, 0) == EOF) {
                     perror(vval(VIEWFILE));
                     quit(1);
              }
              curview = stdview;
              viewnum = 0;
       }
       if (n < 0) {                       /* get next view */
              register int  c = getc(viewfp);
              if (c == EOF)
                     return(NULL);               /* that's it */
              ungetc(c, viewfp);
              n = viewnum + 1;
       }
       while (n > viewnum) {              /* scan to desired view */
              if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
                     return(viewnum==1 ? &curview : (VIEW *)NULL);
              if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
                     viewnum++;
       }
       return(&curview);           /* return it */
}

Here is the call graph for this function:

void init_frame ( void  )

Definition at line 660 of file ranimove1.c.

{
       int    restart;
                                   /* allocate/swap buffers */
       next_frame();
                                   /* check rendering status */
       restart = (!nobjects || vdef(MOVE));
       if (!restart && curparams != &lorendparams && nprocs > 1)
              restart = -1;
                                   /* post low quality parameters */
       if (curparams != &lorendparams)
              ray_restore(curparams = &lorendparams);
       if (restart > 0) {          /* load new octree */
              char   *oct = getoctspec(fcur);
              if (oct == NULL) {
                     sprintf(errmsg, "cannot get scene for frame %d", fcur);
                     error(USER, errmsg);
              }
              if (!silent) {
                     printf("\tLoading octree...");
                     fflush(stdout);
              }
              if (nprocs > 1)
                     ray_pinit(oct, nprocs);
              else
                     ray_init(oct);
       } else if (restart < 0) {   /* update children */
              if (!silent) {
                     printf("\tRestarting %d processes...", nprocs);
                     fflush(stdout);
              }
              ray_pclose(0);
              ray_popen(nprocs);
       }
       if (restart && !silent)
              printf("done\n");
                                   /* sample frame buffer */
       init_frame_sample();
                                   /* initialize frame error */
       comp_frame_error();
#if 0
{
       float  *ebuf = (float *)malloc(sizeof(float)*hres*vres);
       char   fnm[256];
       register int  n;
       for (n = hres*vres; n--; )
              ebuf[n] = acctab[abuffer[n]];
       sprintf(fnm, vval(BASENAME), fcur);
       strcat(fnm, "_inerr.pic");
       write_map(ebuf, fnm);
       free((void *)ebuf);
}
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

double obj_prio ( OBJECT  obj)

Definition at line 843 of file ranimove.c.

{
       int    moi;
       
       if (obj == OVOID || (moi = getmove(obj)) < 0)
              return(1.0);
       return(obj_move[moi].cprio);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int refine_first ( )

Definition at line 30 of file ranimove2.c.

{
       int    *esamp = (int *)zprev;      /* OK to reuse */
       int    hl_erri = errori(HL_ERR);
       int    nextra = 0;
       int    x, y, xp, yp;
       int    neigh;
       register int  n, np;

       if (sizeof(int) < sizeof(*zprev))
              error(CONSISTENCY, "code error in refine_first");
       if (!silent) {
              printf("\tFirst refinement pass...");
              fflush(stdout);
       }
       memset((void *)esamp, '\0', sizeof(int)*hres*vres);
       /*
        * In our initial pass, we look for lower error pixels from
        * the same objects in the previous frame, and copy them here.
        */
       for (y = vres; y--; )
           for (x = hres; x--; ) {
              n = fndx(x, y);
              if (obuffer[n] == OVOID)
                     continue;
              if (xmbuffer[n] == MO_UNK)
                     continue;
              xp = x + xmbuffer[n];
              if ((xp < 0) | (xp >= hres))
                     continue;
              yp = y + ymbuffer[n];
              if ((yp < 0) | (yp >= vres))
                     continue;
              np = fndx(xp, yp);
                                   /* make sure we hit same object */
              if (oprev[np] != obuffer[n])
                     continue;
                                   /* is previous frame error lower? */
              if (aprev[np] < AMIN + ATIDIFF)
                     continue;
              if (aprev[np] <= abuffer[n] + ATIDIFF)
                     continue;
                                   /* shadow & highlight detection */
              if (abuffer[n] > hl_erri &&
                            getclosest(&neigh, 1, x, y) &&
                            bigdiff(cbuffer[neigh], cprev[np],
                                   HL_ERR*(.9+.2*frandom())))
                     continue;
              abuffer[n] = aprev[np] - ATIDIFF;
              copycolor(cbuffer[n], cprev[np]);
              esamp[n] = 1;        /* record extrapolated sample */
              nextra++;
           }
       for (n = hres*vres; n--; )  /* update sample counts */
              if (esamp[n])
                     sbuffer[n] = 1;
       if (!silent)
              printf("extrapolated %d pixels\n", nextra);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int refine_frame ( int  pass)

Definition at line 490 of file ranimove2.c.

{
       static double rtime_used = 0;
       static long   ray_cnt = 0;
       static double ctime_used = 0;
       static int    csp_cnt = 0;
       int    timed = (fcur > fbeg) | (pass > 0) | (quickstart);
       double time_start, rtime_start, time_done;
       struct AmbSum myAmbSum;
       long   rays_todo, nr;
       register int  n;
                                   /* IBR refinement? */
       if ((pass == 0) & (fcur > fbeg))
              return(refine_first());
                                   /* any time left? */
       time_start = getTime();
       if (timed) {
              if (time_start >= frm_stop)
                     goto nomore;
              if (csp_cnt > 0 && time_start + ctime_used/csp_cnt >= frm_stop)
                     goto nomore;
       }
       asump = NULL;               /* use resampling to update ambval? */
       if (!curparams->ambounce && hirendparams.ambounce) {
              myAmbSum.diffsum[RED] =
              myAmbSum.diffsum[GRN] =
              myAmbSum.diffsum[BLU] = 0;
              myAmbSum.nsamps = 0;
              asump = &myAmbSum;
       }
                                   /* initialize value-squared map */
       if (val2map == NULL) {
              val2map = cprev;     /* OK to reuse at this point */
              n = (asump == NULL) ? hres*vres : 0;
              while (n--)
                     if (sbuffer[n])
                            setcolor(val2map[n],
                            colval(cbuffer[n],RED)*colval(cbuffer[n],RED),
                            colval(cbuffer[n],GRN)*colval(cbuffer[n],GRN),
                            colval(cbuffer[n],BLU)*colval(cbuffer[n],BLU));
                     else
                            setcolor(val2map[n], 0., 0., 0.);
       }
                                   /* compute conspicuity */
       if (!silent) {
              printf("\tComputing conspicuity map\n");
              fflush(stdout);
       }
       conspicuity();
       csp_cnt++;
#if 0
if (pass == 1) {
       char   fnm[256];
       sprintf(fnm, vval(BASENAME), fcur);
       strcat(fnm, "_incmap.pic");
       write_map(cerrmap, fnm);
}
#endif
                                   /* get ray start time */
       rtime_start = getTime();
       ctime_used += rtime_start - time_start;
       if (timed && rtime_start >= frm_stop)
              return(0);           /* error done but out of time */
       if (rtime_used <= FTINY) {
              if (quickstart)
                     rays_todo = 1000;
              else
                     rays_todo = hres*vres;
       } else {
              rays_todo = (long)((frm_stop - rtime_start) *
                                   ray_cnt / rtime_used);
              if (rays_todo < 1000)
                     return(0);    /* let's call it a frame */
       }
                                   /* set higher rendering quality */
       if (twolevels && curparams != &hirendparams) {
              ray_restore(curparams = &hirendparams);
              if (nprocs > 1) {    /* need to update children */
                     if (!silent) {
                            printf("\tRestarting %d processes\n", nprocs);
                            fflush(stdout);
                     }
                     ray_pclose(0);
                     ray_popen(nprocs);
              }
       }
                                   /* compute refinement rays */
       if (!silent) {
              printf("\tRefinement pass %d...",
                            pass+1); /*, rays_todo); */
              fflush(stdout);
       }
       if (asump != NULL)          /* flag low-quality samples */
              for (n = hres*vres; n--; )
                     if (sbuffer[n])
                            abuffer[n] = ALOWQ;
                                   /* trace those rays */
       nr = refine_rays(rays_todo);
       if (!silent)
              printf("traced %ld HQ rays\n", nr);
       if (nr <= 0)
              return(0);
                                   /* update timing stats */
       while (ray_cnt >= 1L<<20) {
              ray_cnt >>= 1;
              rtime_used *= .5;
       }
       ray_cnt += nr;
       time_done = getTime();
       rtime_used += time_done - rtime_start;
       if (!timed && time_done > frm_stop)
              frm_stop = time_done;
                                   /* update ambient value */
       if (asump != NULL && asump->nsamps >= 1000) {
              double sf = 1./(double)asump->nsamps;
              for (n = 3; n--; ) {
                     asump->diffsum[n] *= sf;
                     asump->diffsum[n] += colval(lorendparams.ambval,n);
                     if (asump->diffsum[n] < 0) asump->diffsum[n] = 0;
              }
              setcolor(lorendparams.ambval,
                            asump->diffsum[RED],
                            asump->diffsum[GRN],
                            asump->diffsum[BLU]);
              if (!silent)
                     printf("\tUpdated parameter: -av %f %f %f\n",
                                   asump->diffsum[RED],
                                   asump->diffsum[GRN],
                                   asump->diffsum[BLU]);
              asump = NULL;
       }
       return(1);
nomore:
                                   /* make sure error map is updated */
       if ((fcur == fbeg) | (pass > 1))
              comp_frame_error();
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sample_pos ( double  hv[2],
int  x,
int  y,
int  sn 
)

Definition at line 183 of file ranimove1.c.

{
       int    hl[2];

       hl[0] = x; hl[1] = y;
       multisamp(hv, 2, urand(ilhash(hl,2) + sn));
       hv[0] = ((double)x + hv[0]) / (double)hres;
       hv[1] = ((double)y + hv[1]) / (double)vres;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double sample_wt ( int  xo,
int  yo 
)

Definition at line 200 of file ranimove1.c.

{
       static double etab[400];
       /* we can't use the name rad2 here, for some reason Visual C
          thinks that is a constant (compiler bug?) */
       int    rad_2 = xo*xo + yo*yo;
       int    i;

       if (etab[0] <= FTINY)              /* initialize exponent table */
              for (i = 400; i--; )
                     etab[i] = exp(-0.1*i);

                                   /* look up Gaussian */
       i = (int)((10.*3./(double)SAMPDIST2)*rad_2 + .5);
       if (i >= 400)
              return(0.0);
       return(etab[i]);
}

Here is the caller graph for this function:

void send_frame ( void  )

Definition at line 895 of file ranimove1.c.

{
       char   pfname[1024];
       double d;
       FILE   *fp;
       int    y;
                                   /* open output picture */
       sprintf(pfname, vval(BASENAME), fcur);
       strcat(pfname, ".hdr");
       fp = fopen(pfname, "w");
       if (fp == NULL) {
              sprintf(errmsg, "cannot open output frame \"%s\"", pfname);
              error(SYSTEM, errmsg);
       }
       SET_FILE_BINARY(fp);
       if (!silent) {
              printf("\tWriting to \"%s\"\n", pfname);
              fflush(stdout);
       }
                                   /* write header */
       newheader("RADIANCE", fp);
       printargs(gargc, gargv, fp);
       fprintf(fp, "SOFTWARE= %s\n", VersionID);
       fprintf(fp, "FRAME=%d\n", fcur);
       fputnow(fp);
       fputs(VIEWSTR, fp); fprintview(&vw, fp); fputc('\n', fp);
       d = expspec_val(getexp(fcur));
       if ((d < 0.99) | (d > 1.01))
              fputexpos(d, fp);
       d = viewaspect(&vw) * hres / vres;
       if ((d < 0.99) | (d > 1.01))
              fputaspect(d, fp);
       fputformat(COLRFMT, fp);
       fputc('\n', fp);            /* end header */
       fprtresolu(hres, vres, fp);
       if (fflush(fp) == EOF)
              goto writerr;
#if (PIXSTANDARD != (YMAJOR|YDECR))
       error(CONSISTENCY, "bad code in send_frame");
#endif
       for (y = vres; y--; )              /* write scanlines */
              if (fwritescan(outbuffer+y*hres, hres, fp) < 0)
                     goto writerr;
       if (fclose(fp) == EOF)
              goto writerr;
       return;                            /* all is well */
writerr:
       sprintf(errmsg, "error writing frame \"%s\"", pfname);
       error(SYSTEM, errmsg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_map ( float *  mp,
char *  fn 
)

Here is the caller graph for this function:


Variable Documentation

Definition at line 33 of file ranimove1.c.

double acctab[256]

Definition at line 22 of file ranimove1.c.

Definition at line 40 of file ranimove1.c.

Definition at line 28 of file ranimove1.c.

float* cerrmap

Definition at line 42 of file ranimove1.c.

int cerrzero

Definition at line 22 of file ranimove2.c.

Definition at line 37 of file ranimove1.c.

Definition at line 50 of file ranimove.c.

int fbeg

Definition at line 42 of file ranimove.c.

int fcur

Definition at line 44 of file ranimove.c.

int fend

Definition at line 43 of file ranimove.c.

double frm_stop

Definition at line 45 of file ranimove1.c.

int gargc

Definition at line 127 of file ies2rad.c.

char** gargv

Definition at line 128 of file ies2rad.c.

int haveprio

Definition at line 60 of file ranimove.c.

char hirendoptf[]

Definition at line 48 of file ranimove.c.

Definition at line 49 of file ranimove.c.

double hlsmax

Definition at line 47 of file ranimove1.c.

int hres

Definition at line 30 of file rhpict.c.

char lorendoptf[]

Definition at line 46 of file ranimove.c.

Definition at line 47 of file ranimove.c.

double mblur

Definition at line 66 of file rpict.c.

double ndthresh

Definition at line 39 of file ranimove.c.

int ndtset

Definition at line 40 of file ranimove.c.

int nprocs

Definition at line 22 of file rholo2l.c.

struct ObjMove* obj_move

Definition at line 58 of file ranimove.c.

char objtmpf[]

Definition at line 56 of file ranimove.c.

Definition at line 30 of file ranimove1.c.

Definition at line 39 of file ranimove1.c.

double pixaspect

Definition at line 23 of file rhpict.c.

Definition at line 33 of file ranimove.c.

double rate

Definition at line 54 of file ranimove.c.

int rtperfrm

Definition at line 37 of file ranimove.c.

Definition at line 34 of file ranimove1.c.

int silent

Definition at line 80 of file glrad.c.

int twolevels

Definition at line 51 of file ranimove.c.

Definition at line 43 of file ranimove1.c.

int vres

Definition at line 30 of file rhpict.c.

Definition at line 27 of file ranimove1.c.

Definition at line 36 of file ranimove1.c.

short* xmbuffer

Definition at line 31 of file ranimove1.c.

short* ymbuffer

Definition at line 32 of file ranimove1.c.

float* zbuffer

Definition at line 29 of file ranimove1.c.

float* zprev

Definition at line 38 of file ranimove1.c.