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

Comparing ray/src/gen/mkillum2.c (file contents):
Revision 1.12 by greg, Fri Aug 23 12:30:33 1991 UTC vs.
Revision 2.11 by schorsch, Mon Jun 30 14:59:11 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines to do the actual calculation for mkillum
6   */
7  
8 < #include  "mkillum.h"
8 > #include <string.h>
9  
10 + #include  "mkillum.h"
11   #include  "face.h"
14
12   #include  "cone.h"
16
13   #include  "random.h"
14  
15  
# Line 26 | Line 22 | char  *nm;
22          sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"",
23                          nm, ofun[ob->otype].funame, ob->oname);
24          error(WARNING, errmsg);
25 <        if (!(il->flags & IL_LIGHT))
30 <                printobj(il->altmat, ob);
25 >        printobj(il->altmat, ob);
26   }
27  
28  
# Line 67 | Line 62 | char  *nm;
62          distarr = (float *)calloc(n, 3*sizeof(float));
63          if (distarr == NULL)
64                  error(SYSTEM, "out of memory in o_face");
65 <        mkaxes(u, v, fa->norm);
65 >                                /* take first edge longer than sqrt(area) */
66 >        for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) {
67 >                u[0] = VERTEX(fa,i)[0] - VERTEX(fa,j)[0];
68 >                u[1] = VERTEX(fa,i)[1] - VERTEX(fa,j)[1];
69 >                u[2] = VERTEX(fa,i)[2] - VERTEX(fa,j)[2];
70 >                if ((r1 = DOT(u,u)) >= fa->area-FTINY)
71 >                        break;
72 >        }
73 >        if (i < fa->nv) {       /* got one! -- let's align our axes */
74 >                r2 = 1.0/sqrt(r1);
75 >                u[0] *= r2; u[1] *= r2; u[2] *= r2;
76 >                fcross(v, fa->norm, u);
77 >        } else                  /* oh well, we'll just have to wing it */
78 >                mkaxes(u, v, fa->norm);
79 >                                /* now, find limits in (u,v) coordinates */
80          ur[0] = vr[0] = FHUGE;
81          ur[1] = vr[1] = -FHUGE;
82          for (i = 0; i < fa->nv; i++) {
# Line 88 | Line 97 | char  *nm;
97                      h = ilhash(dim, 3) + i;
98                      multisamp(sp, 2, urand(h));
99                      r1 = (dim[1] + sp[0])/nalt;
100 <                    r2 = (dim[2] + sp[1])/nazi;
100 >                    r2 = (dim[2] + sp[1] - .5)/nazi;
101                      flatdir(dn, r1, r2);
102                      for (j = 0; j < 3; j++)
103                          dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j];
# Line 105 | Line 114 | char  *nm;
114                          objerror(ob, WARNING, "bad aspect");
115                          rt->nrays = 0;
116                          freeface(ob);
117 <                        free((char *)distarr);
117 >                        free((void *)distarr);
118                          o_default(ob, il, rt, nm);
119                          return;
120                      }
# Line 120 | Line 129 | char  *nm;
129                  if (il->sampdens > 0)
130                          flatout(il, distarr, nalt, nazi, u, v, fa->norm);
131                  illumout(il, ob);
132 <        } else if (!(il->flags & IL_LIGHT))
132 >        } else
133                  printobj(il->altmat, ob);
134                                  /* clean up */
135          freeface(ob);
136 <        free((char *)distarr);
136 >        free((void *)distarr);
137   #undef MAXMISS
138   }
139  
# Line 150 | Line 159 | char  *nm;
159                  nalt = nazi = 1;
160          else {
161                  n = 4.*PI * il->sampdens;
162 <                nalt = sqrt(n/PI) + .5;
163 <                nazi = PI*nalt + .5;
162 >                nalt = sqrt(2./PI*n) + .5;
163 >                nazi = PI/2.*nalt + .5;
164          }
165          n = nalt*nazi;
166          distarr = (float *)calloc(n, 3*sizeof(float));
# Line 166 | Line 175 | char  *nm;
175                      multisamp(sp, 4, urand(ilhash(dim,3)+i));
176                                          /* random direction */
177                      r1 = (dim[1] + sp[0])/nalt;
178 <                    r2 = (dim[2] + sp[1])/nazi;
178 >                    r2 = (dim[2] + sp[1] - .5)/nazi;
179                      rounddir(dir, r1, r2);
180                                          /* random location */
181                      mkaxes(u, v, dir);          /* yuck! */
# Line 191 | Line 200 | char  *nm;
200                  else
201                          objerror(ob, WARNING, "diffuse distribution");
202                  illumout(il, ob);
203 <        } else if (!(il->flags & IL_LIGHT))
203 >        } else
204                  printobj(il->altmat, ob);
205                                  /* clean up */
206 <        free((char *)distarr);
206 >        free((void *)distarr);
207   }
208  
209  
# Line 236 | Line 245 | char  *nm;
245                      multisamp(sp, 4, urand(ilhash(dim,3)+i));
246                                          /* random direction */
247                      r1 = (dim[1] + sp[0])/nalt;
248 <                    r2 = (dim[2] + sp[1])/nalt;
248 >                    r2 = (dim[2] + sp[1] - .5)/nazi;
249                      flatdir(dn, r1, r2);
250                      for (j = 0; j < 3; j++)
251                          dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j];
# Line 247 | Line 256 | char  *nm;
256                      r1 = r3*cos(r2);
257                      r2 = r3*sin(r2);
258                      for (j = 0; j < 3; j++)
259 <                        org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] +
259 >                        org[j] = CO_P0(co)[j] + r1*u[j] + r2*v[j] +
260                                          .001*co->ad[j];
261  
262                                          /* send sample */
# Line 259 | Line 268 | char  *nm;
268                  if (il->sampdens > 0)
269                          flatout(il, distarr, nalt, nazi, u, v, co->ad);
270                  illumout(il, ob);
271 <        } else if (!(il->flags & IL_LIGHT))
271 >        } else
272                  printobj(il->altmat, ob);
273                                  /* clean up */
274          freecone(ob);
275 <        free((char *)distarr);
275 >        free((void *)distarr);
276   }
277  
278  
# Line 290 | Line 299 | register struct rtproc  *rt;
299  
300          if (rt->nrays <= 0)
301                  return;
302 <        bzero(rt->buf+6*rt->nrays, 6*sizeof(float));
303 <        if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf,
304 <                        3*sizeof(float)*rt->nrays,
302 >        memset(rt->buf+6*rt->nrays, '\0', 6*sizeof(float));
303 >        errno = 0;
304 >        if ( process(&(rt->pd), (char *)rt->buf, (char *)rt->buf,
305 >                        3*sizeof(float)*(rt->nrays+1),
306                          6*sizeof(float)*(rt->nrays+1)) <
307 <                        3*sizeof(float)*rt->nrays )
307 >                        3*sizeof(float)*(rt->nrays+1) )
308                  error(SYSTEM, "error reading from rtrace process");
309          i = rt->nrays;
310          while (i--) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines