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

Comparing ray/src/common/mesh.c (file contents):
Revision 2.22 by greg, Wed Dec 15 17:27:52 2010 UTC vs.
Revision 2.26 by greg, Tue Nov 6 17:12:35 2012 UTC

# Line 30 | Line 30 | typedef struct {
30  
31   static MESH     *mlist = NULL;          /* list of loaded meshes */
32  
33 static lut_keycmpf_t cvcmp;
34 static lut_hashf_t cvhash;
33  
36
34   static unsigned long
35 < cvhash(p)                               /* hash an encoded vertex */
39 < /* MCVERT       *cvp; */
40 < const void      *p;
35 > cvhash(const char *p)                   /* hash an encoded vertex */
36   {
37          const MCVERT    *cvp = (const MCVERT *)p;
38          unsigned long   hval;
# Line 54 | Line 49 | const void     *p;
49  
50  
51   static int
52 < cvcmp(vv1, vv2)                         /* compare encoded vertices */
58 < /* register MCVERT      *v1, *v2; */
59 < const void      *vv1, *vv2;
52 > cvcmp(const char *vv1, const char *vv2)         /* compare encoded vertices */
53   {
54 <        const MCVERT    *v1 = vv1, *v2 = vv2;
54 >        const MCVERT    *v1 = (const MCVERT *)vv1, *v2 = (const MCVERT *)vv2;
55          if (v1->fl != v2->fl)
56                  return(1);
57          if (v1->xyz[0] != v2->xyz[0])
# Line 80 | Line 73 | const void     *vv1, *vv2;
73  
74  
75   MESH *
76 < getmesh(mname, flags)                   /* get new mesh data reference */
77 < char    *mname;
78 < int     flags;
76 > getmesh(                                /* get new mesh data reference */
77 >        char    *mname,
78 >        int     flags
79 > )
80   {
81          char  *pathname;
82 <        register MESH  *ms;
82 >        MESH  *ms;
83  
84          flags &= IO_LEGAL;
85          for (ms = mlist; ms != NULL; ms = ms->next)
# Line 115 | Line 109 | int    flags;
109  
110  
111   MESHINST *
112 < getmeshinst(o, flags)                   /* create mesh instance */
113 < OBJREC  *o;
114 < int     flags;
112 > getmeshinst(                            /* create mesh instance */
113 >        OBJREC  *o,
114 >        int     flags
115 > )
116   {
117 <        register MESHINST  *ins;
117 >        MESHINST  *ins;
118  
119          flags &= IO_LEGAL;
120          if ((ins = (MESHINST *)o->os) == NULL) {
# Line 148 | Line 143 | int    flags;
143  
144  
145   int
146 < getmeshtrivid(tvid, mo, mp, ti)         /* get triangle vertex ID's */
147 < int32   tvid[3];
148 < OBJECT  *mo;
149 < MESH    *mp;
155 < OBJECT  ti;
146 > nextmeshtri(                            /* get next triangle ID */
147 >        OBJECT *tip,
148 >        MESH *mp
149 > )
150   {
151 +        int             pn;
152 +        MESHPATCH       *pp;
153 +
154 +        pn = ++(*tip) >> 10;                    /* next triangle (OVOID init) */
155 +        while (pn < mp->npatches) {
156 +                pp = &mp->patch[pn];
157 +                if (!(*tip & 0x200)) {          /* local triangle? */
158 +                        if ((*tip & 0x1ff) < pp->ntris)
159 +                                return(1);
160 +                        *tip &= ~0x1ff;         /* move on to single-joiners */
161 +                        *tip |= 0x200;
162 +                }
163 +                if (!(*tip & 0x100)) {          /* single joiner? */
164 +                        if ((*tip & 0xff) < pp->nj1tris)
165 +                                return(1);
166 +                        *tip &= ~0xff;          /* move on to double-joiners */
167 +                        *tip |= 0x100;
168 +                }
169 +                if ((*tip & 0xff) < pp->nj2tris)
170 +                        return(1);
171 +                *tip = ++pn << 10;              /* first in next patch */
172 +        }
173 +        return(0);                              /* out of patches */
174 + }
175 +
176 + int
177 + getmeshtrivid(                          /* get triangle vertex ID's */
178 +        int32   tvid[3],
179 +        OBJECT  *mo,
180 +        MESH    *mp,
181 +        OBJECT  ti
182 + )
183 + {
184          int             pn = ti >> 10;
185          MESHPATCH       *pp;
186  
# Line 209 | Line 236 | OBJECT ti;
236  
237  
238   int
239 < getmeshvert(vp, mp, vid, what)  /* get triangle vertex from ID */
240 < MESHVERT        *vp;
241 < MESH            *mp;
242 < int32           vid;
243 < int             what;
239 > getmeshvert(                            /* get triangle vertex from ID */
240 >        MESHVERT        *vp,
241 >        MESH            *mp,
242 >        int32           vid,
243 >        int             what
244 > )
245   {
246          int             pn = vid >> 8;
247          MESHPATCH       *pp;
248          double          vres;
249 <        register int    i;
249 >        int     i;
250          
251          vp->fl = 0;
252          if (pn >= mp->npatches)
# Line 253 | Line 281 | int            what;
281  
282  
283   OBJREC *
284 < getmeshpseudo(mp, mo)           /* get mesh pseudo object for material */
285 < MESH    *mp;
286 < OBJECT  mo;
284 > getmeshpseudo(                  /* get mesh pseudo object for material */
285 >        MESH    *mp,
286 >        OBJECT  mo
287 > )
288   {
289          if (mo < mp->mat0 || mo >= mp->mat0 + mp->nmats)
290                  error(INTERNAL, "modifier out of range in getmeshpseudo");
291          if (mp->pseudo == NULL) {
292 <                register int    i;
292 >                int     i;
293                  mp->pseudo = (OBJREC *)calloc(mp->nmats, sizeof(OBJREC));
294                  if (mp->pseudo == NULL)
295                          error(SYSTEM, "out of memory in getmeshpseudo");
# Line 275 | Line 304 | OBJECT mo;
304  
305  
306   int
307 < getmeshtri(tv, mo, mp, ti, wha) /* get triangle vertices */
308 < MESHVERT        tv[3];
309 < OBJECT          *mo;
310 < MESH            *mp;
311 < OBJECT          ti;
312 < int             wha;
307 > getmeshtri(                     /* get triangle vertices */
308 >        MESHVERT        tv[3],
309 >        OBJECT          *mo,
310 >        MESH            *mp,
311 >        OBJECT          ti,
312 >        int             wha
313 > )
314   {
315          int32   tvid[3];
316  
# Line 296 | Line 326 | int            wha;
326  
327  
328   int32
329 < addmeshvert(mp, vp)             /* find/add a mesh vertex */
330 < register MESH   *mp;
331 < MESHVERT        *vp;
329 > addmeshvert(                    /* find/add a mesh vertex */
330 >        MESH    *mp,
331 >        MESHVERT        *vp
332 > )
333   {
334          LUENT           *lvp;
335          MCVERT          cv;
336 <        register int    i;
336 >        int     i;
337  
338          if (!(vp->fl & MT_V))
339                  return(-1);
# Line 345 | Line 376 | MESHVERT       *vp;
376                  memcpy((void *)lvp->key, (void *)&cv, sizeof(MCVERT));
377          }
378          if (lvp->data == NULL) {        /* new vertex */
379 <                register MESHPATCH      *pp;
379 >                MESHPATCH       *pp;
380                  if (mp->npatches <= 0) {
381                          mp->patch = (MESHPATCH *)calloc(MPATCHBLKSIZ,
382                                          sizeof(MESHPATCH));
# Line 402 | Line 433 | nomem:
433  
434  
435   OBJECT
436 < addmeshtri(mp, tv, mo)          /* add a new mesh triangle */
437 < MESH            *mp;
438 < MESHVERT        tv[3];
439 < OBJECT          mo;
436 > addmeshtri(                     /* add a new mesh triangle */
437 >        MESH            *mp,
438 >        MESHVERT        tv[3],
439 >        OBJECT          mo
440 > )
441   {
442          int32                   vid[3], t;
443          int                     pn[3], i;
444 <        register MESHPATCH      *pp;
444 >        MESHPATCH       *pp;
445  
446          if (!(tv[0].fl & tv[1].fl & tv[2].fl & MT_V))
447                  return(OVOID);
# Line 499 | Line 531 | nomem:
531  
532  
533   char *
534 < checkmesh(mp)                           /* validate mesh data */
503 < register MESH   *mp;
534 > checkmesh(MESH *mp)                     /* validate mesh data */
535   {
536          static char     embuf[128];
537          int             nouvbounds = 1;
538 <        register int    i;
538 >        int     i;
539                                          /* basic checks */
540          if (mp == NULL)
541                  return("NULL mesh pointer");
# Line 544 | Line 575 | register MESH  *mp;
575                  if (mp->npatches <= 0)
576                          error(WARNING, "no patches in mesh");
577                  for (i = 0; i < mp->npatches; i++) {
578 <                        register MESHPATCH      *pp = &mp->patch[i];
578 >                        MESHPATCH       *pp = &mp->patch[i];
579                          if (pp->nverts <= 0)
580                                  error(WARNING, "no vertices in patch");
581                          else {
# Line 566 | Line 597 | register MESH  *mp;
597  
598  
599   static void
600 < tallyoctree(ot, ecp, lcp, ocp)  /* tally octree size */
601 < OCTREE  ot;
602 < int     *ecp, *lcp, *ocp;
600 > tallyoctree(                    /* tally octree size */
601 >        OCTREE  ot,
602 >        int     *ecp,
603 >        int     *lcp,
604 >        int     *ocp
605 > )
606   {
607          int     i;
608  
# Line 589 | Line 623 | int    *ecp, *lcp, *ocp;
623  
624  
625   void
626 < printmeshstats(ms, fp)          /* print out mesh statistics */
627 < MESH    *ms;
628 < FILE    *fp;
626 > printmeshstats(                 /* print out mesh statistics */
627 >        MESH    *ms,
628 >        FILE    *fp
629 > )
630   {
631          int     lfcnt=0, lecnt=0, locnt=0;
632          int     vcnt=0, ncnt=0, uvcnt=0;
# Line 601 | Line 636 | FILE   *fp;
636          
637          tallyoctree(ms->mcube.cutree, &lecnt, &lfcnt, &locnt);
638          for (i = 0; i < ms->npatches; i++) {
639 <                register MESHPATCH      *pp = &ms->patch[i];
639 >                MESHPATCH       *pp = &ms->patch[i];
640                  vcnt += pp->nverts;
641                  if (pp->norm != NULL) {
642                          for (j = pp->nverts; j--; )
# Line 643 | Line 678 | FILE   *fp;
678  
679  
680   void
681 < freemesh(ms)                    /* free mesh data */
647 < register MESH   *ms;
681 > freemesh(MESH *ms)              /* free mesh data */
682   {
683          MESH    mhead;
684          MESH    *msp;
# Line 672 | Line 706 | register MESH  *ms;
706          octfree(ms->mcube.cutree);
707          lu_done(&ms->lut);
708          if (ms->npatches > 0) {
709 <                register MESHPATCH      *pp = ms->patch + ms->npatches;
709 >                MESHPATCH       *pp = ms->patch + ms->npatches;
710                  while (pp-- > ms->patch) {
711                          if (pp->j2tri != NULL)
712                                  free((void *)pp->j2tri);
# Line 696 | Line 730 | register MESH  *ms;
730  
731  
732   void
733 < freemeshinst(o)                 /* free mesh instance */
700 < OBJREC  *o;
733 > freemeshinst(OBJREC *o)         /* free mesh instance */
734   {
735          if (o->os == NULL)
736                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines