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.6 by greg, Wed Apr 23 00:52:33 2003 UTC vs.
Revision 2.18 by greg, Tue Mar 16 19:56:27 2004 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   * Mesh support routines
6   */
7  
8 < #include "standard.h"
8 > #include <string.h>
9 >
10 > #include "rtio.h"
11 > #include "rtmath.h"
12 > #include "rterror.h"
13 > #include "paths.h"
14   #include "octree.h"
15   #include "object.h"
16   #include "otypes.h"
# Line 14 | Line 19 | static const char RCSid[] = "$Id$";
19   /* An encoded mesh vertex */
20   typedef struct {
21          int             fl;
22 <        uint4           xyz[3];
23 <        int4            norm;
24 <        uint4           uv[2];
22 >        uint32          xyz[3];
23 >        int32           norm;
24 >        uint32          uv[2];
25   } MCVERT;
26  
27   #define  MPATCHBLKSIZ   128             /* patch allocation block size */
# Line 68 | Line 73 | register MCVERT        *v1, *v2;
73  
74  
75   MESH *
76 < getmesh(mname, flags)                   /* get mesh data */
76 > getmesh(mname, flags)                   /* get new mesh data reference */
77   char    *mname;
78   int     flags;
79   {
# Line 78 | Line 83 | int    flags;
83          flags &= IO_LEGAL;
84          for (ms = mlist; ms != NULL; ms = ms->next)
85                  if (!strcmp(mname, ms->name)) {
86 <                        if ((ms->ldflags & flags) == flags) {
87 <                                ms->nref++;
83 <                                return(ms);             /* loaded */
84 <                        }
85 <                        break;                  /* load the rest */
86 >                        ms->nref++;     /* increase reference count */
87 >                        break;
88                  }
89 <        if (ms == NULL) {
89 >        if (ms == NULL) {               /* load first time */
90                  ms = (MESH *)calloc(1, sizeof(MESH));
91                  if (ms == NULL)
92                          error(SYSTEM, "out of memory in getmesh");
# Line 94 | Line 96 | int    flags;
96                  ms->next = mlist;
97                  mlist = ms;
98          }
99 <        if ((pathname = getpath(mname, getlibpath(), R_OK)) == NULL) {
99 >        if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) {
100                  sprintf(errmsg, "cannot find mesh file \"%s\"", mname);
101                  error(USER, errmsg);
102          }
# Line 128 | Line 130 | int    flags;
130                  ins->msh = NULL;
131                  o->os = (char *)ins;
132          }
133 <        if (ins->msh == NULL || (ins->msh->ldflags & flags) != flags)
133 >        if (ins->msh == NULL)
134                  ins->msh = getmesh(o->oargs.sarg[0], flags);
135 +        else if ((flags &= ~ins->msh->ldflags))
136 +                readmesh(ins->msh,
137 +                        getpath(o->oargs.sarg[0], getrlibpath(), R_OK),
138 +                                flags);
139          return(ins);
140   }
141  
142  
143   int
144   getmeshtrivid(tvid, mo, mp, ti)         /* get triangle vertex ID's */
145 < int4    tvid[3];
145 > int32   tvid[3];
146   OBJECT  *mo;
147   MESH    *mp;
148   OBJECT  ti;
# Line 199 | Line 205 | int
205   getmeshvert(vp, mp, vid, what)  /* get triangle vertex from ID */
206   MESHVERT        *vp;
207   MESH            *mp;
208 < int4            vid;
208 > int32           vid;
209   int             what;
210   {
211          int             pn = vid >> 8;
# Line 269 | Line 275 | MESH           *mp;
275   OBJECT          ti;
276   int             wha;
277   {
278 <        int4    tvid[3];
278 >        int32   tvid[3];
279  
280          if (!getmeshtrivid(tvid, mo, mp, ti))
281                  return(0);
# Line 282 | Line 288 | int            wha;
288   }
289  
290  
291 < int4
291 > int32
292   addmeshvert(mp, vp)             /* find/add a mesh vertex */
293   register MESH   *mp;
294   MESHVERT        *vp;
# Line 299 | Line 305 | MESHVERT       *vp;
305                          return(-1);
306                  if (vp->v[i] >= mp->mcube.cuorg[i] + mp->mcube.cusize)
307                          return(-1);
308 <                cv.xyz[i] = (uint4)(4294967296. *
308 >                cv.xyz[i] = (uint32)(4294967296. *
309                                  (vp->v[i] - mp->mcube.cuorg[i]) /
310                                  mp->mcube.cusize);
311          }
312 <        if (vp->fl & MT_N)
312 >        if (vp->fl & MT_N)              /* assumes normalized! */
313                  cv.norm = encodedir(vp->n);
314          if (vp->fl & MT_UV)
315                  for (i = 0; i < 2; i++) {
# Line 311 | Line 317 | MESHVERT       *vp;
317                                  return(-1);
318                          if (vp->uv[i] >= mp->uvlim[1][i])
319                                  return(-1);
320 <                        cv.uv[i] = (uint4)(4294967296. *
320 >                        cv.uv[i] = (uint32)(4294967296. *
321                                          (vp->uv[i] - mp->uvlim[0][i]) /
322                                          (mp->uvlim[1][i] - mp->uvlim[0][i]));
323                  }
# Line 328 | Line 334 | MESHVERT       *vp;
334          if (lvp == NULL)
335                  goto nomem;
336          if (lvp->key == NULL) {
337 <                lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int4));
338 <                bcopy((void *)&cv, (void *)lvp->key, sizeof(MCVERT));
337 >                lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int32));
338 >                memcpy((void *)lvp->key, (void *)&cv, sizeof(MCVERT));
339          }
340          if (lvp->data == NULL) {        /* new vertex */
341                  register MESHPATCH      *pp;
# Line 345 | Line 351 | MESHVERT       *vp;
351                                                  (void *)mp->patch,
352                                          (mp->npatches + MPATCHBLKSIZ)*
353                                                  sizeof(MESHPATCH));
354 <                                bzero((void *)(mp->patch + mp->npatches),
354 >                                memset((void *)(mp->patch + mp->npatches), '\0',
355                                          MPATCHBLKSIZ*sizeof(MESHPATCH));
356                          }
357                          if (mp->npatches++ >= 1L<<22)
# Line 353 | Line 359 | MESHVERT       *vp;
359                  }
360                  pp = &mp->patch[mp->npatches-1];
361                  if (pp->xyz == NULL) {
362 <                        pp->xyz = (uint4 (*)[3])calloc(256, 3*sizeof(int4));
362 >                        pp->xyz = (uint32 (*)[3])calloc(256, 3*sizeof(int32));
363                          if (pp->xyz == NULL)
364                                  goto nomem;
365                  }
# Line 361 | Line 367 | MESHVERT       *vp;
367                          pp->xyz[pp->nverts][i] = cv.xyz[i];
368                  if (cv.fl & MT_N) {
369                          if (pp->norm == NULL) {
370 <                                pp->norm = (int4 *)calloc(256, sizeof(int4));
370 >                                pp->norm = (int32 *)calloc(256, sizeof(int32));
371                                  if (pp->norm == NULL)
372                                          goto nomem;
373                          }
# Line 369 | Line 375 | MESHVERT       *vp;
375                  }
376                  if (cv.fl & MT_UV) {
377                          if (pp->uv == NULL) {
378 <                                pp->uv = (uint4 (*)[2])calloc(256,
379 <                                                2*sizeof(uint4));
378 >                                pp->uv = (uint32 (*)[2])calloc(256,
379 >                                                2*sizeof(uint32));
380                                  if (pp->uv == NULL)
381                                          goto nomem;
382                          }
# Line 379 | Line 385 | MESHVERT       *vp;
385                  }
386                  pp->nverts++;
387                  lvp->data = lvp->key + sizeof(MCVERT);
388 <                *(int4 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1);
388 >                *(int32 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1);
389          }
390 <        return(*(int4 *)lvp->data);
390 >        return(*(int32 *)lvp->data);
391   nomem:
392          error(SYSTEM, "out of memory in addmeshvert");
393          return(-1);
# Line 394 | Line 400 | MESH           *mp;
400   MESHVERT        tv[3];
401   OBJECT          mo;
402   {
403 <        int4                    vid[3], t;
403 >        int32                   vid[3], t;
404          int                     pn[3], i;
405          register MESHPATCH      *pp;
406  
# Line 407 | Line 413 | OBJECT         mo;
413                  pn[i] = vid[i] >> 8;
414          }
415                                  /* normalize material index */
416 <        if (mo != OVOID)
416 >        if (mo != OVOID) {
417                  if ((mo -= mp->mat0) >= mp->nmats)
418                          mp->nmats = mo+1;
419                  else if (mo < 0)
420                          error(INTERNAL, "modifier range error in addmeshtri");
421 +        }
422                                  /* assign triangle */
423          if (pn[0] == pn[1] && pn[1] == pn[2]) { /* local case */
424                  pp = &mp->patch[pn[0]];
# Line 428 | Line 435 | OBJECT         mo;
435                          if (pp->ntris == 0)
436                                  pp->solemat = mo;
437                          else if (pp->trimat == NULL && mo != pp->solemat) {
438 <                                pp->trimat = (int2 *)malloc(
439 <                                                512*sizeof(int2));
438 >                                pp->trimat = (int16 *)malloc(
439 >                                                512*sizeof(int16));
440                                  if (pp->trimat == NULL)
441                                          goto nomem;
442                                  for (i = pp->ntris; i--; )
# Line 539 | Line 546 | register MESH  *mp;
546                                  if (nouvbounds && pp->uv != NULL)
547                                          return("unreferenced uv coordinates");
548                          }
542                        if (pp->ntris + pp->nj1tris + pp->nj2tris <= 0)
543                                error(WARNING, "no triangles in patch");
549                          if (pp->ntris > 0 && pp->tri == NULL)
550                                  return("missing patch triangle list");
551                          if (pp->nj1tris > 0 && pp->j1tri == NULL)
# Line 608 | Line 613 | FILE   *fp;
613                  t2cnt += pp->nj2tris;
614          }
615          fprintf(fp, "Mesh statistics:\n");
616 <        fprintf(fp, "\t%d materials\n", ms->nmats);
616 >        fprintf(fp, "\t%ld materials\n", ms->nmats);
617          fprintf(fp, "\t%d patches (%.2f MBytes)\n", ms->npatches,
618                          (ms->npatches*sizeof(MESHPATCH) +
619 <                        vcnt*3*sizeof(uint4) +
620 <                        nscnt*sizeof(int4) +
621 <                        uvscnt*2*sizeof(uint4) +
619 >                        vcnt*3*sizeof(uint32) +
620 >                        nscnt*sizeof(int32) +
621 >                        uvscnt*2*sizeof(uint32) +
622                          tcnt*sizeof(struct PTri) +
623                          t1cnt*sizeof(struct PJoin1) +
624                          t2cnt*sizeof(struct PJoin2))/(1024.*1024.));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines