Back to index

radiance  4R0+20100331
Defines | Functions | Variables
m_mist.c File Reference
#include "copyright.h"
#include <string.h>
#include "ray.h"
#include "source.h"
#include "rtotypes.h"

Go to the source code of this file.

Defines

#define MAXSLIST   32 /* maximum sources to check */
#define RELAYDELIM   '>' /* relay delimiter character */

Functions

static int inslist (int *sl, int n)
static int srcmatch (SRCREC *sp, char *id)
static void add2slist (RAY *r, int *sl)
static int inslist (register int *sl, register int n)
static int srcmatch (register SRCREC *sp, register char *id)
static void add2slist (register RAY *r, register int *sl)
int m_mist (OBJREC *m, register RAY *r)

Variables

static const char RCSid [] = "$Id: m_mist.c,v 2.17 2005/04/19 01:15:06 greg Exp $"

Define Documentation

#define MAXSLIST   32 /* maximum sources to check */

Definition at line 49 of file m_mist.c.

#define RELAYDELIM   '>' /* relay delimiter character */

Definition at line 52 of file m_mist.c.


Function Documentation

static void add2slist ( RAY r,
int *  sl 
) [static]

Here is the caller graph for this function:

static void add2slist ( register RAY r,
register int *  sl 
) [static]

Definition at line 97 of file m_mist.c.

{
       static int  slspare[MAXSLIST+1];   /* in case of emergence */
       register int  i;

       if (sl == NULL || sl[0] == 0)             /* nothing to add */
              return;
       if (r->slights == NULL)
              (r->slights = slspare)[0] = 0;     /* just once per ray path */
       for (i = sl[0]; i > 0; i--)
              if (!inslist(r->slights, sl[i])) {
                     if (r->slights[0] >= MAXSLIST)
                            error(INTERNAL,
                                   "scattering source list overflow");
                     r->slights[++r->slights[0]] = sl[i];
              }
}

Here is the call graph for this function:

static int inslist ( int *  sl,
int  n 
) [static]

Here is the caller graph for this function:

static int inslist ( register int *  sl,
register int  n 
) [static]

Definition at line 60 of file m_mist.c.

{
       register int  i;

       for (i = sl[0]; i > 0; i--)
              if (sl[i] == n)
                     return(i);
       return(0);
}
int m_mist ( OBJREC m,
register RAY r 
)

Definition at line 120 of file m_mist.c.

{
       RAY  p;
       int  *myslist = NULL;
       int  newslist[MAXSLIST+1];
       COLOR  mext;
       double  re, ge, be;
       register int  i, j;
                                   /* check arguments */
       if (m->oargs.nfargs > 7)
              objerror(m, USER, "bad arguments");
                                   /* get source indices */
       if (m->oargs.nsargs > 0 && (myslist = (int *)m->os) == NULL) {
              if (m->oargs.nsargs > MAXSLIST)
                     objerror(m, INTERNAL, "too many sources in list");
              myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int));
              if (myslist == NULL)
                     goto memerr;
              myslist[0] = 0;                    /* size is first in list */
              for (j = 0; j < m->oargs.nsargs; j++) {
                     i = nsources;        /* look up each source id */
                     while (i--)
                            if (srcmatch(source+i, m->oargs.sarg[j]))
                                   break;
                     if (i < 0) {
                            sprintf(errmsg, "unknown source \"%s\"",
                                          m->oargs.sarg[j]);
                            objerror(m, WARNING, errmsg);
                     } else if (inslist(myslist, i)) {
                            sprintf(errmsg, "duplicate source \"%s\"",
                                          m->oargs.sarg[j]);
                            objerror(m, WARNING, errmsg);
                     } else
                            myslist[++myslist[0]] = i;
              }
              m->os = (char *)myslist;
       }
       if (m->oargs.nfargs > 2) {         /* compute extinction */
              setcolor(mext, m->oargs.farg[0], m->oargs.farg[1],
                            m->oargs.farg[2]);
              raytexture(r, m->omod);                   /* get modifiers */
              multcolor(mext, r->pcol);
       } else
              setcolor(mext, 0., 0., 0.);
                                          /* start transmitted ray */
       if (rayorigin(&p, TRANS, r, NULL) < 0)
              return(1);
       VCOPY(p.rdir, r->rdir);
       p.slights = newslist;
       if (r->slights != NULL)                   /* copy old list if one */
              for (j = r->slights[0]; j >= 0; j--)
                     p.slights[j] = r->slights[j];
       else
              p.slights[0] = 0;
       if (r->rod > 0.) {                 /* entering ray */
              addcolor(p.cext, mext);
              if (m->oargs.nfargs > 5)
                     setcolor(p.albedo, m->oargs.farg[3],
                                   m->oargs.farg[4], m->oargs.farg[5]);
              if (m->oargs.nfargs > 6)
                     p.gecc = m->oargs.farg[6];
              add2slist(&p, myslist);                   /* add to list */
       } else {                           /* leaving ray */
              if (myslist != NULL) {                    /* delete from list */
                     for (j = myslist[0]; j > 0; j--)
                            if ( (i = inslist(p.slights, myslist[j])) )
                                   p.slights[i] = -1;
                     for (i = 0, j = 1; j <= p.slights[0]; j++)
                            if (p.slights[j] != -1)
                                   p.slights[++i] = p.slights[j];
                     if (p.slights[0] - i < myslist[0]) {      /* fix old */
                            addcolor(r->cext, mext);
                            if (m->oargs.nfargs > 5)
                                   setcolor(r->albedo, m->oargs.farg[3],
                                   m->oargs.farg[4], m->oargs.farg[5]);
                            if (m->oargs.nfargs > 6)
                                   r->gecc = m->oargs.farg[6];
                            add2slist(r, myslist);
                     }
                     p.slights[0] = i;
              }
              if ((re = colval(r->cext,RED) - colval(mext,RED)) <
                            colval(cextinction,RED))
                     re = colval(cextinction,RED);
              if ((ge = colval(r->cext,GRN) - colval(mext,GRN)) <
                            colval(cextinction,GRN))
                     ge = colval(cextinction,GRN);
              if ((be = colval(r->cext,BLU) - colval(mext,BLU)) <
                            colval(cextinction,BLU))
                     be = colval(cextinction,BLU);
              setcolor(p.cext, re, ge, be);
              if (m->oargs.nfargs > 5)
                     copycolor(p.albedo, salbedo);
              if (m->oargs.nfargs > 6)
                     p.gecc = seccg;
       }
       rayvalue(&p);                      /* calls rayparticipate() */
       copycolor(r->rcol, p.rcol);        /* return value */
       r->rt = r->rot + p.rt;
       return(1);
memerr:
       error(SYSTEM, "out of memory in m_mist");
       return 0; /* pro forma return */
}

Here is the call graph for this function:

static int srcmatch ( SRCREC sp,
char *  id 
) [static]

Here is the caller graph for this function:

static int srcmatch ( register SRCREC sp,
register char *  id 
) [static]

Definition at line 75 of file m_mist.c.

{
       register char  *cp;
                                          /* check for relay sources */
       while ((cp = strchr(id, RELAYDELIM)) != NULL) {
              if (!(sp->sflags & SVIRTUAL) || sp->so == NULL)
                     return(0);
              if (strncmp(id, sp->so->oname, cp-id) || sp->so->oname[cp-id])
                     return(0);
              id = cp + 1;                       /* relay to next */
              sp = source + sp->sa.sv.sn;
       }
       if (sp->sflags & SVIRTUAL || sp->so == NULL)
              return(0);
       return(!strcmp(id, sp->so->oname));
}

Here is the call graph for this function:


Variable Documentation

const char RCSid[] = "$Id: m_mist.c,v 2.17 2005/04/19 01:15:06 greg Exp $" [static]

Definition at line 2 of file m_mist.c.