Back to index

radiance  4R0+20100331
Defines | Typedefs | Functions | Variables
rtrace.c File Reference
#include "copyright.h"
#include <time.h>
#include "platform.h"
#include "ray.h"
#include "ambient.h"
#include "source.h"
#include "otypes.h"
#include "resolu.h"
#include "random.h"

Go to the source code of this file.

Defines

#define MAXTSET   8191 /* maximum number in trace set */

Typedefs

typedef void putf_t (double v)
typedef void oputf_t (RAY *r)

Functions

static void setoutput (char *vs)
void tranotify (OBJECT obj)
static void bogusray (void)
static void raycast (RAY *r)
static void rayirrad (RAY *r)
static void rtcompute (FVECT org, FVECT dir, double dmax)
static int printvals (RAY *r)
static int getvec (FVECT vec, int fmt, FILE *fp)
static void tabin (RAY *r)
static void ourtrace (RAY *r)
void quit (int code)
char * formstr (int f)
void rtrace (char *fname, int nproc)
static void trace_sources (void)
static void oputo (RAY *r)
static void oputd (RAY *r)
static void oputv (RAY *r)
static void oputV (RAY *r)
static void oputl (RAY *r)
static void oputL (RAY *r)
static void oputc (RAY *r)
static void oputp (RAY *r)
static void oputN (RAY *r)
static void oputn (RAY *r)
static void oputs (RAY *r)
static void oputw (RAY *r)
static void oputW (RAY *r)
static void oputm (RAY *r)
static void oputM (RAY *r)
static void oputtilde (RAY *r)
static void puta (double v)
static void putd (double v)
static void putf (double v)

Variables

static const char RCSid [] = "$Id: rtrace.c,v 2.63 2009/12/16 03:30:50 greg Exp $"
int inform
int outform
char * outvals
int imm_irrad
int lim_dist
char * tralist []
int traincl
int hresolu
int vresolu
static int castonly = 0
OBJECT traset [MAXTSET+1] = {0}
static RAY thisray
static putf_t puta
static putf_t putd
static putf_t putf
static oputf_t oputo
static oputf_t oputd
static oputf_t oputv
static oputf_t oputV
static oputf_t oputl
static oputf_t oputL
static oputf_t oputc
static oputf_t oputp
static oputf_t oputn
static oputf_t oputN
static oputf_t oputs
static oputf_t oputw
static oputf_t oputW
static oputf_t oputm
static oputf_t oputM
static oputf_t oputtilde
static oputf_tray_out [16]
static oputf_tevery_out [16]
static putf_tputreal

Define Documentation

#define MAXTSET   8191 /* maximum number in trace set */

Definition at line 50 of file rtrace.c.


Typedef Documentation

typedef void oputf_t(RAY *r)

Definition at line 59 of file rtrace.c.

typedef void putf_t(double v)

Definition at line 56 of file rtrace.c.


Function Documentation

static void bogusray ( void  ) [static]

Definition at line 294 of file rtrace.c.

{
       thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
       thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
       thisray.rmax = 0.0;
       rayorigin(&thisray, PRIMARY, NULL, NULL);
       printvals(&thisray);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* formstr ( int  f)

Definition at line 96 of file rtrace.c.

{
       switch (f) {
       case 'a': return("ascii");
       case 'f': return("float");
       case 'd': return("double");
       case 'c': return(COLRFMT);
       }
       return("unknown");
}

Here is the caller graph for this function:

static int getvec ( FVECT  vec,
int  fmt,
FILE *  fp 
) [static]

Definition at line 391 of file rtrace.c.

{
       static float  vf[3];
       static double  vd[3];
       char  buf[32];
       int  i;

       switch (fmt) {
       case 'a':                                 /* ascii */
              for (i = 0; i < 3; i++) {
                     if (fgetword(buf, sizeof(buf), fp) == NULL ||
                                   !isflt(buf))
                            return(-1);
                     vec[i] = atof(buf);
              }
              break;
       case 'f':                                 /* binary float */
              if (fread((char *)vf, sizeof(float), 3, fp) != 3)
                     return(-1);
              VCOPY(vec, vf);
              break;
       case 'd':                                 /* binary double */
              if (fread((char *)vd, sizeof(double), 3, fp) != 3)
                     return(-1);
              VCOPY(vec, vd);
              break;
       default:
              error(CONSISTENCY, "botched input format");
       }
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void oputc ( RAY r) [static]

Definition at line 566 of file rtrace.c.

{
       (*putreal)(r->uv[0]);
       (*putreal)(r->uv[1]);
}
static void oputd ( RAY r) [static]

Definition at line 503 of file rtrace.c.

{
       (*putreal)(r->rdir[0]);
       (*putreal)(r->rdir[1]);
       (*putreal)(r->rdir[2]);
}
static void oputl ( RAY r) [static]

Definition at line 548 of file rtrace.c.

{
       (*putreal)(r->rt);
}
static void oputL ( RAY r) [static]

Definition at line 557 of file rtrace.c.

{
       (*putreal)(r->rot);
}
static void oputm ( RAY r) [static]

Definition at line 666 of file rtrace.c.

{
       if (r->ro != NULL)
              if (r->ro->omod != OVOID)
                     fputs(objptr(r->ro->omod)->oname, stdout);
              else
                     fputs(VOIDID, stdout);
       else
              putchar('*');
       putchar('\t');
}
static void oputM ( RAY r) [static]

Definition at line 682 of file rtrace.c.

{
       OBJREC *mat;

       if (r->ro != NULL) {
              if ((mat = findmaterial(r->ro)) != NULL)
                     fputs(mat->oname, stdout);
              else
                     fputs(VOIDID, stdout);
       } else
              putchar('*');
       putchar('\t');
}

Here is the call graph for this function:

static void oputN ( RAY r) [static]

Definition at line 593 of file rtrace.c.

{
       if (r->rot < FHUGE) {
              (*putreal)(r->ron[0]);
              (*putreal)(r->ron[1]);
              (*putreal)(r->ron[2]);
       } else {
              (*putreal)(0.0);
              (*putreal)(0.0);
              (*putreal)(0.0);
       }
}
static void oputn ( RAY r) [static]

Definition at line 610 of file rtrace.c.

{
       FVECT  pnorm;

       if (r->rot >= FHUGE) {
              (*putreal)(0.0);
              (*putreal)(0.0);
              (*putreal)(0.0);
              return;
       }
       raynormal(pnorm, r);
       (*putreal)(pnorm[0]);
       (*putreal)(pnorm[1]);
       (*putreal)(pnorm[2]);
}

Here is the call graph for this function:

static void oputo ( RAY r) [static]

Definition at line 492 of file rtrace.c.

{
       (*putreal)(r->rorg[0]);
       (*putreal)(r->rorg[1]);
       (*putreal)(r->rorg[2]);
}
static void oputp ( RAY r) [static]

Definition at line 576 of file rtrace.c.

{
       if (r->rot < FHUGE) {
              (*putreal)(r->rop[0]);
              (*putreal)(r->rop[1]);
              (*putreal)(r->rop[2]);
       } else {
              (*putreal)(0.0);
              (*putreal)(0.0);
              (*putreal)(0.0);
       }
}
static void oputs ( RAY r) [static]

Definition at line 630 of file rtrace.c.

{
       if (r->ro != NULL)
              fputs(r->ro->oname, stdout);
       else
              putchar('*');
       putchar('\t');
}
static void oputtilde ( RAY r) [static]

Definition at line 700 of file rtrace.c.

{
       fputs("~\t", stdout);
}
static void oputv ( RAY r) [static]

Definition at line 514 of file rtrace.c.

{
       if (outform == 'c') {
              COLR  cout;
              setcolr(cout, colval(r->rcol,RED),
                            colval(r->rcol,GRN),
                            colval(r->rcol,BLU));
              fwrite((char *)cout, sizeof(cout), 1, stdout);
              return;
       }
       (*putreal)(colval(r->rcol,RED));
       (*putreal)(colval(r->rcol,GRN));
       (*putreal)(colval(r->rcol,BLU));
}

Here is the call graph for this function:

static void oputV ( RAY r) [static]

Definition at line 533 of file rtrace.c.

{
       double contr[3];

       raycontrib(contr, r, PRIMARY);
       multcolor(contr, r->rcol);
       (*putreal)(contr[RED]);
       (*putreal)(contr[GRN]);
       (*putreal)(contr[BLU]);
}

Here is the call graph for this function:

static void oputw ( RAY r) [static]

Definition at line 643 of file rtrace.c.

{
       (*putreal)(r->rweight);
}
static void oputW ( RAY r) [static]

Definition at line 652 of file rtrace.c.

{
       double contr[3];

       raycontrib(contr, r, PRIMARY);
       (*putreal)(contr[RED]);
       (*putreal)(contr[GRN]);
       (*putreal)(contr[BLU]);
}

Here is the call graph for this function:

static void ourtrace ( RAY r) [static]

Definition at line 458 of file rtrace.c.

{
       oputf_t **tp;

       if (every_out[0] == NULL)
              return;
       if (r->ro == NULL) {
              if (traincl == 1)
                     return;
       } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
              return;
       tabin(r);
       for (tp = every_out; *tp != NULL; tp++)
              (**tp)(r);
       if (outform == 'a')
              putchar('\n');
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int printvals ( RAY r) [static]

Definition at line 374 of file rtrace.c.

{
       oputf_t **tp;

       if (ray_out[0] == NULL)
              return(0);
       for (tp = ray_out; *tp != NULL; tp++)
              (**tp)(r);
       if (outform == 'a')
              putchar('\n');
       return(1);
}

Here is the caller graph for this function:

static void puta ( double  v) [static]

Definition at line 709 of file rtrace.c.

{
       printf("%e\t", v);
}
static void putd ( double  v) [static]

Definition at line 718 of file rtrace.c.

{
       fwrite((char *)&v, sizeof(v), 1, stdout);
}
static void putf ( double  v) [static]

Definition at line 726 of file rtrace.c.

{
       float f = v;

       fwrite((char *)&f, sizeof(f), 1, stdout);
}
void quit ( int  code)

Definition at line 79 of file rtrace.c.

{
       if (ray_pnprocs > 0) /* close children if any */
              ray_pclose(0);              
#ifndef  NON_POSIX
       else if (!ray_pnprocs) {
              headclean();  /* delete header file */
              pfclean();    /* clean up persist files */
       }
#endif
       exit(code);
}

Here is the call graph for this function:

static void raycast ( RAY r) [static]

Definition at line 305 of file rtrace.c.

{
       if (!localhit(r, &thescene)) {
              if (r->ro == &Aftplane) {   /* clipped */
                     r->ro = NULL;
                     r->rot = FHUGE;
              } else
                     sourcehit(r);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void rayirrad ( RAY r) [static]

Definition at line 320 of file rtrace.c.

{
       void   (*old_revf)(RAY *) = r->revf;

       r->rot = 1e-5;                     /* pretend we hit surface */
       VSUM(r->rop, r->rorg, r->rdir, r->rot);
       r->ron[0] = -r->rdir[0];
       r->ron[1] = -r->rdir[1];
       r->ron[2] = -r->rdir[2];
       r->rod = 1.0;
                                   /* compute result */
       r->revf = raytrace;
       (*ofun[Lamb.otype].funp)(&Lamb, r);
       r->revf = old_revf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void rtcompute ( FVECT  org,
FVECT  dir,
double  dmax 
) [static]

Definition at line 340 of file rtrace.c.

{
                                   /* set up ray */
       rayorigin(&thisray, PRIMARY, NULL, NULL);
       if (imm_irrad) {
              VSUM(thisray.rorg, org, dir, 1.1e-4);
              thisray.rdir[0] = -dir[0];
              thisray.rdir[1] = -dir[1];
              thisray.rdir[2] = -dir[2];
              thisray.rmax = 0.0;
              thisray.revf = rayirrad;
       } else {
              VCOPY(thisray.rorg, org);
              VCOPY(thisray.rdir, dir);
              thisray.rmax = dmax;
              if (castonly)
                     thisray.revf = raycast;
       }
       if (ray_pnprocs > 1) {             /* multiprocessing FIFO? */
              if (ray_fifo_in(&thisray) < 0)
                     error(USER, "lost children");
              return;
       }
       samplendx++;                /* else do it ourselves */
       rayvalue(&thisray);
       printvals(&thisray);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rtrace ( char *  fname,
int  nproc 
)

Definition at line 111 of file rtrace.c.

{
       unsigned long  vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu
                                         : vresolu;
       long  nextflush = hresolu;
       FILE  *fp;
       double d;
       FVECT  orig, direc;
                                   /* set up input */
       if (fname == NULL)
              fp = stdin;
       else if ((fp = fopen(fname, "r")) == NULL) {
              sprintf(errmsg, "cannot open input file \"%s\"", fname);
              error(SYSTEM, errmsg);
       }
       if (inform != 'a')
              SET_FILE_BINARY(fp);
                                   /* set up output */
       setoutput(outvals);
       if (imm_irrad)
              castonly = 0;
       else if (castonly)
              nproc = 1;           /* don't bother multiprocessing */
       switch (outform) {
       case 'a': putreal = puta; break;
       case 'f': putreal = putf; break;
       case 'd': putreal = putd; break;
       case 'c': 
              if (strcmp(outvals, "v"))
                     error(USER, "color format with value output only");
              break;
       default:
              error(CONSISTENCY, "botched output format");
       }
       if (nproc > 1) {            /* start multiprocessing */
              ray_popen(nproc);
              ray_fifo_out = printvals;
       }
       if (hresolu > 0) {
              if (vresolu > 0)
                     fprtresolu(hresolu, vresolu, stdout);
              fflush(stdout);
       }
                                   /* process file */
       while (getvec(orig, inform, fp) == 0 &&
                     getvec(direc, inform, fp) == 0) {

              d = normalize(direc);
              if (d == 0.0) {                           /* zero ==> flush */
                     if (--nextflush <= 0 || !vcount) {
                            if (nproc > 1 && ray_fifo_flush() < 0)
                                   error(USER, "lost children");
                            bogusray();
                            fflush(stdout);
                            nextflush = hresolu;
                     } else
                            bogusray();
              } else {                           /* compute and print */
                     rtcompute(orig, direc, lim_dist ? d : 0.0);
                                                 /* flush if time */
                     if (!--nextflush) {
                            if (nproc > 1 && ray_fifo_flush() < 0)
                                   error(USER, "lost children");
                            fflush(stdout);
                            nextflush = hresolu;
                     }
              }
              if (ferror(stdout))
                     error(SYSTEM, "write error");
              if (vcount && !--vcount)           /* check for end */
                     break;
       }
       if (nproc > 1) {                          /* clean up children */
              if (ray_fifo_flush() < 0)
                     error(USER, "unable to complete processing");
              ray_pclose(0);
       }
       if (fflush(stdout) < 0)
              error(SYSTEM, "write error");
       if (vcount)
              error(USER, "unexpected EOF on input");
       if (fname != NULL)
              fclose(fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void setoutput ( char *  vs) [static]

Definition at line 211 of file rtrace.c.

{
       oputf_t **table = ray_out;

       castonly = 1;
       while (*vs)
              switch (*vs++) {
              case 'T':                          /* trace sources */
                     if (!*vs) break;
                     trace_sources();
                     /* fall through */
              case 't':                          /* trace */
                     if (!*vs) break;
                     *table = NULL;
                     table = every_out;
                     trace = ourtrace;
                     castonly = 0;
                     break;
              case 'o':                          /* origin */
                     *table++ = oputo;
                     break;
              case 'd':                          /* direction */
                     *table++ = oputd;
                     break;
              case 'v':                          /* value */
                     *table++ = oputv;
                     castonly = 0;
                     break;
              case 'V':                          /* contribution */
                     *table++ = oputV;
                     if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
                            error(WARNING,
                                   "-otV accuracy depends on -aa 0 -as 0");
                     break;
              case 'l':                          /* effective distance */
                     *table++ = oputl;
                     castonly = 0;
                     break;
              case 'c':                          /* local coordinates */
                     *table++ = oputc;
                     break;
              case 'L':                          /* single ray length */
                     *table++ = oputL;
                     break;
              case 'p':                          /* point */
                     *table++ = oputp;
                     break;
              case 'n':                          /* perturbed normal */
                     *table++ = oputn;
                     castonly = 0;
                     break;
              case 'N':                          /* unperturbed normal */
                     *table++ = oputN;
                     break;
              case 's':                          /* surface */
                     *table++ = oputs;
                     break;
              case 'w':                          /* weight */
                     *table++ = oputw;
                     break;
              case 'W':                          /* coefficient */
                     *table++ = oputW;
                     if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
                            error(WARNING,
                                   "-otW accuracy depends on -aa 0 -as 0");
                     break;
              case 'm':                          /* modifier */
                     *table++ = oputm;
                     break;
              case 'M':                          /* material */
                     *table++ = oputM;
                     break;
              case '~':                          /* tilde */
                     *table++ = oputtilde;
                     break;
              }
       *table = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void tabin ( RAY r) [static]

Definition at line 480 of file rtrace.c.

{
       const RAY  *rp;

       for (rp = r->parent; rp != NULL; rp = rp->parent)
              putchar('\t');
}

Here is the caller graph for this function:

static void trace_sources ( void  ) [static]

Definition at line 201 of file rtrace.c.

{
       int    sn;
       
       for (sn = 0; sn < nsources; sn++)
              source[sn].sflags |= SFOLLOW;
}

Here is the caller graph for this function:

void tranotify ( OBJECT  obj)

Definition at line 429 of file rtrace.c.

{
       static int  hitlimit = 0;
       OBJREC  *o = objptr(obj);
       char  **tralp;

       if (obj == OVOID) {         /* starting over */
              traset[0] = 0;
              hitlimit = 0;
              return;
       }
       if (hitlimit || !ismodifier(o->otype))
              return;
       for (tralp = tralist; *tralp != NULL; tralp++)
              if (!strcmp(o->oname, *tralp)) {
                     if (traset[0] >= MAXTSET) {
                            error(WARNING, "too many modifiers in trace list");
                            hitlimit++;
                            return;              /* should this be fatal? */
                     }
                     insertelem(traset, obj);
                     return;
              }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int castonly = 0 [static]

Definition at line 47 of file rtrace.c.

oputf_t * every_out[16] [static]

Definition at line 74 of file rtrace.c.

int hresolu

Definition at line 52 of file pinterp.c.

int imm_irrad

Definition at line 45 of file rtmain.c.

int inform

Definition at line 38 of file rtmain.c.

int lim_dist

Definition at line 46 of file rtmain.c.

oputf_t oputc [static]

Definition at line 60 of file rtrace.c.

oputf_t oputd [static]

Definition at line 60 of file rtrace.c.

oputf_t oputl [static]

Definition at line 60 of file rtrace.c.

oputf_t oputL [static]

Definition at line 60 of file rtrace.c.

oputf_t oputm [static]

Definition at line 60 of file rtrace.c.

oputf_t oputM [static]

Definition at line 60 of file rtrace.c.

oputf_t oputn [static]

Definition at line 60 of file rtrace.c.

oputf_t oputN [static]

Definition at line 60 of file rtrace.c.

oputf_t oputo [static]

Definition at line 60 of file rtrace.c.

oputf_t oputp [static]

Definition at line 60 of file rtrace.c.

oputf_t oputs [static]

Definition at line 60 of file rtrace.c.

oputf_t oputtilde [static]

Definition at line 60 of file rtrace.c.

oputf_t oputv [static]

Definition at line 60 of file rtrace.c.

oputf_t oputV [static]

Definition at line 60 of file rtrace.c.

oputf_t oputW [static]

Definition at line 60 of file rtrace.c.

oputf_t oputw [static]

Definition at line 60 of file rtrace.c.

int outform

Definition at line 39 of file rtmain.c.

char* outvals

Definition at line 40 of file rtmain.c.

putf_t puta [static]

Definition at line 57 of file rtrace.c.

putf_t putd [static]

Definition at line 57 of file rtrace.c.

putf_t putf [static]

Definition at line 57 of file rtrace.c.

putf_t* putreal [static]

Definition at line 75 of file rtrace.c.

oputf_t* ray_out[16] [static]

Definition at line 74 of file rtrace.c.

const char RCSid[] = "$Id: rtrace.c,v 2.63 2009/12/16 03:30:50 greg Exp $" [static]

Definition at line 2 of file rtrace.c.

RAY thisray [static]

Definition at line 54 of file rtrace.c.

int traincl

Definition at line 56 of file rtmain.c.

char* tralist[]

Definition at line 55 of file rtmain.c.

OBJECT traset[MAXTSET+1] = {0}

Definition at line 52 of file rtrace.c.

int vresolu

Definition at line 53 of file pinterp.c.