ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_mist.c
(Generate patch)

Comparing ray/src/rt/m_mist.c (file contents):
Revision 2.1 by greg, Fri Dec 8 21:27:10 1995 UTC vs.
Revision 2.2 by greg, Sat Dec 9 09:40:42 1995 UTC

# Line 43 | Line 43 | static char SCCSid[] = "$SunId$ LBL";
43   *  scattering.  A value approaching 1 indicates strong forward scattering.
44   */
45  
46 #define MAXSLIST        32              /* maximum sources to check */
46   #define RELAYDELIM      '>'             /* relay delimiter character */
47  
48   extern COLOR  cextinction;              /* global coefficient of extinction */
# Line 66 | Line 65 | register int  n;
65  
66  
67   static int
68 < srcmatch(sn, id)        /* check for an id match on a light source */
69 < register int  sn;
70 < char  *id;
68 > srcmatch(sp, id)        /* check for an id match on a light source */
69 > register SRCREC  *sp;
70 > register char  *id;
71   {
72          extern char  *index();
73          register char  *cp;
74 < again:
75 <        if (source[sn].so == NULL)              /* just in case */
76 <                return(0);
78 <        if ((cp = index(id, RELAYDELIM)) != NULL) {     /* relay source */
79 <                if (!(source[sn].sflags & SVIRTUAL))
74 >                                                /* check for relay sources */
75 >        while ((cp = index(id, RELAYDELIM)) != NULL) {
76 >                if (!(sp->sflags & SVIRTUAL) || sp->so == NULL)
77                          return(0);
78 <                *cp = '\0';
82 <                if (strcmp(id, source[sn].so->oname)) {
83 <                        *cp = RELAYDELIM;
78 >                if (strncmp(id, sp->so->oname, cp-id) || sp->so->oname[cp-id])
79                          return(0);
80 <                }
81 <                *cp = RELAYDELIM;
87 <                id = cp + 1;                            /* recurse */
88 <                sn = source[sn].sa.sv.sn;
89 <                goto again;
80 >                id = cp + 1;                            /* relay to next */
81 >                sp = source + sp->sa.sv.sn;
82          }
83 <        if (source[sn].sflags & SVIRTUAL)
83 >        if (sp->sflags & SVIRTUAL || sp->so == NULL)
84                  return(0);
85 <        return(!strcmp(id, source[sn].so->oname));
85 >        return(!strcmp(id, sp->so->oname));
86   }
87  
88  
89 + static
90 + add2slist(r, sl)        /* add source list to ray's */
91 + register RAY  *r;
92 + register int  *sl;
93 + {
94 +        static int  slspare[MAXSLIST+1];        /* in case of emergence */
95 +        register int  i;
96 +
97 +        if (sl == NULL || sl[0] == 0)           /* nothing to add */
98 +                return;
99 +        if (r->slights == NULL)
100 +                (r->slights = slspare)[0] = 0;  /* just once per ray path */
101 +        for (i = sl[0]; i > 0; i--)
102 +                if (!inslist(r->slights, sl[i])) {
103 +                        if (r->slights[0] >= MAXSLIST)
104 +                                error(USER, "scattering source list overflow");
105 +                        r->slights[++r->slights[0]] = sl[i];
106 +                }
107 + }
108 +
109 +
110   m_mist(m, r)            /* process a ray entering or leaving some mist */
111   OBJREC  *m;
112   register RAY  *r;
# Line 107 | Line 120 | register RAY  *r;
120                                          /* check arguments */
121          if (m->oargs.nfargs > 5)
122                  objerror(m, USER, "bad arguments");
110        if (m->oargs.nsargs > MAXSLIST)
111                objerror(m, USER, "too many sources in list");
123                                          /* get source indices */
124          if (m->oargs.nsargs > 0 && (myslist = (int *)m->os) == NULL) {
125 +                if (m->oargs.nsargs > MAXSLIST)
126 +                        objerror(m, USER, "too many sources in list");
127                  myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int));
128                  if (myslist == NULL)
129                          goto memerr;
130 <                myslist[0] = m->oargs.nsargs;   /* size is first in set */
131 <                for (j = myslist[0]; j > 0; j--) {
130 >                myslist[0] = 0;                 /* size is first in list */
131 >                for (j = 0; j < m->oargs.nsargs; j++) {
132                          i = nsources;           /* look up each source id */
133                          while (i--)
134 <                                if (srcmatch(i, m->oargs.sarg[j-1]))
134 >                                if (srcmatch(source+i, m->oargs.sarg[j]))
135                                          break;
136                          if (i < 0) {
137                                  sprintf(errmsg, "unknown source \"%s\"",
138 <                                                m->oargs.sarg[j-1]);
138 >                                                m->oargs.sarg[j]);
139                                  objerror(m, WARNING, errmsg);
140 +                        } else if (inslist(myslist, i)) {
141 +                                sprintf(errmsg, "duplicate source \"%s\"",
142 +                                                m->oargs.sarg[j]);
143 +                                objerror(m, WARNING, errmsg);
144                          } else
145 <                                myslist[j] = i;
145 >                                myslist[++myslist[0]] = i;
146                  }
147                  m->os = (char *)myslist;
148          }
# Line 141 | Line 158 | register RAY  *r;
158                  return(1);
159          VCOPY(p.rdir, r->rdir);
160          p.slights = newslist;
161 <        if (r->slights != NULL)
161 >        if (r->slights != NULL)                 /* copy old list if one */
162                  for (j = r->slights[0]; j >= 0; j--)
163                          p.slights[j] = r->slights[j];
164          else
# Line 152 | Line 169 | register RAY  *r;
169                          p.albedo = m->oargs.farg[3];
170                  if (m->oargs.nfargs > 4)
171                          p.gecc = m->oargs.farg[4];
172 <                if (myslist != NULL)                    /* add to list */
156 <                        for (j = myslist[0]; j > 0; j--)
157 <                                if (!inslist(p.slights, myslist[j])) {
158 <                                        if (p.slights[0] >= MAXSLIST)
159 <                                                error(USER,
160 <                                        "scattering source list overflow");
161 <                                        p.slights[++p.slights[0]] = myslist[j];
162 <                                }
172 >                add2slist(&p, myslist);                 /* add to list */
173          } else {                                /* leaving ray */
174 +                if (myslist != NULL) {                  /* delete from list */
175 +                        for (j = myslist[0]; j > 0; j--)
176 +                                if (i = inslist(p.slights, myslist[j]))
177 +                                        p.slights[i] = -1;
178 +                        for (i = 0, j = 1; j <= p.slights[0]; j++)
179 +                                if (p.slights[j] != -1)
180 +                                        p.slights[++i] = p.slights[j];
181 +                        if (p.slights[0] - i < myslist[0]) {    /* fix old */
182 +                                addcolor(r->cext, mext);
183 +                                if (m->oargs.nfargs > 3)
184 +                                        r->albedo = m->oargs.farg[3];
185 +                                if (m->oargs.nfargs > 4)
186 +                                        r->gecc = m->oargs.farg[4];
187 +                                add2slist(r, myslist);
188 +                        }
189 +                        p.slights[0] = i;
190 +                }
191                  re = colval(r->cext,RED) - colval(mext,RED);
192                  ge = colval(r->cext,GRN) - colval(mext,GRN);
193                  be = colval(r->cext,BLU) - colval(mext,BLU);
# Line 171 | Line 198 | register RAY  *r;
198                          p.albedo = salbedo;
199                  if (m->oargs.nfargs > 4)
200                          p.gecc = seccg;
174                if (myslist != NULL) {                  /* delete from list */
175                        for (j = myslist[0]; j > 0; j--)
176                                if (i = inslist(p.slights, myslist[j]))
177                                        p.slights[i] = -1;
178                        for (i = 0, j = 1; j <= p.slights[0]; j++)
179                                if (p.slights[j] != -1)
180                                        p.slights[++i] = p.slights[j];
181                        p.slights[0] = i;
182                }
201          }
202          rayvalue(&p);                           /* calls rayparticipate() */
203          copycolor(r->rcol, p.rcol);             /* return value */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines