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

Comparing ray/src/ot/cvmesh.c (file contents):
Revision 2.6 by schorsch, Thu Jun 26 00:58:10 2003 UTC vs.
Revision 2.12 by greg, Fri Jan 24 01:26:44 2014 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include "cvmesh.h"
11   #include "otypes.h"
12   #include "face.h"
13 + #include "tmesh.h"
14  
15   /*
16   * We need to divide faces into triangles and record auxiliary information
# Line 36 | Line 37 | MESH   *ourmesh = NULL;                /* our global mesh data structu
37  
38   FVECT   meshbounds[2];                  /* mesh bounding box */
39  
40 + static void add2bounds(FVECT vp, RREAL vc[2]);
41 + static OBJECT cvmeshtri(OBJECT obj);
42 + static OCTREE cvmeshoct(OCTREE ot);
43  
44 +
45 +
46   MESH *
47 < cvinit(nm)                      /* initialize empty mesh */
48 < char    *nm;
47 > cvinit(                 /* initialize empty mesh */
48 >        char    *nm
49 > )
50   {
51                                  /* free old mesh, first */
52          if (ourmesh != NULL) {
# Line 68 | Line 75 | nomem:
75   }
76  
77  
71 int
72 cvpoly(mo, n, vp, vn, vc)       /* convert a polygon to extended triangles */
73 OBJECT  mo;
74 int     n;
75 FVECT   *vp;
76 FVECT   *vn;
77 RREAL   (*vc)[2];
78 {
79        int     tcnt = 0;
80        int     flags;
81        RREAL   *tn[3], *tc[3];
82        int     *ord;
83        int     i, j;
84
85        if (n < 3)              /* degenerate face */
86                return(0);
87        flags = MT_V;
88        if (vn != NULL) {
89                tn[0] = vn[0]; tn[1] = vn[1]; tn[2] = vn[2];
90                flags |= MT_N;
91        } else {
92                tn[0] = tn[1] = tn[2] = NULL;
93        }
94        if (vc != NULL) {
95                tc[0] = vc[0]; tc[1] = vc[1]; tc[2] = vc[2];
96                flags |= MT_UV;
97        } else {
98                tc[0] = tc[1] = tc[2] = NULL;
99        }
100        if (n == 3)             /* output single triangle */
101                return(cvtri(mo, vp[0], vp[1], vp[2],
102                                tn[0], tn[1], tn[2],
103                                tc[0], tc[1], tc[2]));
104
105                                /* decimate polygon (assumes convex) */
106        ord = (int *)malloc(n*sizeof(int));
107        if (ord == NULL)
108                error(SYSTEM, "out of memory in cvpoly");
109        for (i = n; i--; )
110                ord[i] = i;
111        while (n >= 3) {
112                if (flags & MT_N)
113                        for (i = 3; i--; )
114                                tn[i] = vn[ord[i]];
115                if (flags & MT_UV)
116                        for (i = 3; i--; )
117                                tc[i] = vc[ord[i]];
118                tcnt += cvtri(mo, vp[ord[0]], vp[ord[1]], vp[ord[2]],
119                                tn[0], tn[1], tn[2],
120                                tc[0], tc[1], tc[2]);
121                        /* remove vertex and rotate */
122                n--;
123                j = ord[0];
124                for (i = 0; i < n-1; i++)
125                        ord[i] = ord[i+2];
126                ord[i] = j;
127        }
128        free((void *)ord);
129        return(tcnt);
130 }
131
132
78   static void
79 < add2bounds(vp, vc)              /* add point and uv coordinate to bounds */
80 < FVECT   vp;
81 < RREAL   vc[2];
79 > add2bounds(             /* add point and uv coordinate to bounds */
80 >        FVECT   vp,
81 >        RREAL   vc[2]
82 > )
83   {
84          register int    j;
85  
# Line 155 | Line 101 | RREAL  vc[2];
101  
102  
103   int                             /* create an extended triangle */
104 < cvtri(mo, vp1, vp2, vp3, vn1, vn2, vn3, vc1, vc2, vc3)
105 < OBJECT  mo;
106 < FVECT   vp1, vp2, vp3;
107 < FVECT   vn1, vn2, vn3;
108 < RREAL   vc1[2], vc2[2], vc3[2];
104 > cvtri(
105 >        OBJECT  mo,
106 >        FVECT   vp1,
107 >        FVECT   vp2,
108 >        FVECT   vp3,
109 >        FVECT   vn1,
110 >        FVECT   vn2,
111 >        FVECT   vn3,
112 >        RREAL   vc1[2],
113 >        RREAL   vc2[2],
114 >        RREAL   vc3[2]
115 > )
116   {
117          static OBJECT   fobj = OVOID;
118          char            buf[32];
# Line 169 | Line 122 | RREAL  vc1[2], vc2[2], vc3[2];
122          OBJREC          *fop;
123          int             j;
124          
125 <        flags = MT_V;
126 <        if (vn1 != NULL && vn2 != NULL && vn3 != NULL)
127 <                flags |= MT_N;
125 >        flags = MT_V;           /* check what we have */
126 >        if (vn1 != NULL && vn2 != NULL && vn3 != NULL) {
127 >                RREAL   *rp;
128 >                switch (flat_tri(vp1, vp2, vp3, vn1, vn2, vn3)) {
129 >                case ISBENT:
130 >                        flags |= MT_N;
131 >                        /* fall through */
132 >                case ISFLAT:
133 >                        break;
134 >                case RVBENT:
135 >                        flags |= MT_N;
136 >                        rp = vn1; vn1 = vn3; vn3 = rp;
137 >                        /* fall through */
138 >                case RVFLAT:
139 >                        rp = vp1; vp1 = vp3; vp3 = rp;
140 >                        rp = vc1; vc1 = vc3; vc3 = rp;
141 >                        break;
142 >                case DEGEN:
143 >                        error(WARNING, "degenerate triangle");
144 >                        return(0);
145 >                default:
146 >                        error(INTERNAL, "bad return from flat_tri()");
147 >                }
148 >        }
149          if (vc1 != NULL && vc2 != NULL && vc3 != NULL)
150                  flags |= MT_UV;
151          if (fobj == OVOID) {    /* create new triangle object */
# Line 181 | Line 155 | RREAL  vc1[2], vc2[2], vc3[2];
155                  fop = objptr(fobj);
156                  fop->omod = mo;
157                  fop->otype = OBJ_FACE;
158 <                sprintf(buf, "t%d", fobj);
158 >                sprintf(buf, "t%ld", (long)fobj);
159                  fop->oname = savqstr(buf);
160                  fop->oargs.nfargs = 9;
161                  fop->oargs.farg = (RREAL *)malloc(9*sizeof(RREAL));
# Line 240 | Line 214 | nomem:
214  
215  
216   static OBJECT
217 < cvmeshtri(obj)                  /* add an extended triangle to our mesh */
218 < OBJECT  obj;
217 > cvmeshtri(                      /* add an extended triangle to our mesh */
218 >        OBJECT  obj
219 > )
220   {
221          OBJREC          *o = objptr(obj);
222          TRIDATA         *ts;
# Line 277 | Line 252 | OBJECT obj;
252  
253  
254   void
255 < cvmeshbounds()                  /* set mesh boundaries */
255 > cvmeshbounds(void)                      /* set mesh boundaries */
256   {
257          int     i;
258  
# Line 301 | Line 276 | cvmeshbounds()                 /* set mesh boundaries */
276                  ourmesh->uvlim[1][0] = ourmesh->uvlim[1][1] = 0.;
277          } else {
278                  for (i = 0; i < 2; i++) {
279 <                        double  marg;
280 <                        marg = 1e-6*(ourmesh->uvlim[1][i] -
281 <                                        ourmesh->uvlim[0][i]);
279 >                        double  marg;           /* expand past endpoints */
280 >                        marg = (2./(1L<<(8*sizeof(uint16)))) *
281 >                                        (ourmesh->uvlim[1][i] -
282 >                                         ourmesh->uvlim[0][i]) + FTINY;
283                          ourmesh->uvlim[0][i] -= marg;
284                          ourmesh->uvlim[1][i] += marg;
285                  }
# Line 313 | Line 289 | cvmeshbounds()                 /* set mesh boundaries */
289  
290  
291   static OCTREE
292 < cvmeshoct(ot)                   /* convert triangles in subtree */
293 < OCTREE  ot;
292 > cvmeshoct(                      /* convert triangles in subtree */
293 >        OCTREE  ot
294 > )
295   {
296          int     i;
297  
# Line 338 | Line 315 | OCTREE ot;
315  
316  
317   MESH *
318 < cvmesh()                        /* convert mesh and octree leaf nodes */
318 > cvmesh(void)                    /* convert mesh and octree leaf nodes */
319   {
320          if (ourmesh == NULL)
321                  return(NULL);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines