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

Comparing ray/src/ot/wfconv.c (file contents):
Revision 2.10 by greg, Fri Nov 8 16:49:04 2013 UTC vs.
Revision 2.12 by greg, Fri Jan 24 02:22:49 2014 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9   #include "copyright.h"
10   #include "standard.h"
11   #include "cvmesh.h"
12 + #include "triangulate.h"
13   #include <ctype.h>
14  
15   typedef int     VNDX[3];        /* vertex index (point,map,normal) */
# Line 244 | Line 245 | cvtndx(                                /* convert vertex string to index */
245          return(1);
246   }
247  
248 + /* determine dominant axis for triangle */
249 + static int
250 + dominant_axis(char *v1, char *v2, char *v3)
251 + {
252 +        VNDX    v1i, v2i, v3i;
253 +        FVECT   e1, e2, vn;
254 +        int     i, imax;
255  
256 +        if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3))
257 +                return(-1);
258 +        VSUB(e1, vlist[v2i[0]], vlist[v1i[0]]);
259 +        VSUB(e2, vlist[v3i[0]], vlist[v2i[0]]);
260 +        VCROSS(vn, e1, e2);
261 +        for (i = imax = 2; i--; )
262 +                if (vn[i]*vn[i] > vn[imax]*vn[imax])
263 +                        imax = i;
264 +        return(vn[imax]*vn[imax] > FTINY ? imax : -1);
265 + }
266 +
267 + /* callback for triangle output from polygon */
268   static int
269 + tri_out(const Vert2_list *tp, int a, int b, int c)
270 + {
271 +        return( puttri( ((char **)tp->p)[a],
272 +                        ((char **)tp->p)[b],
273 +                        ((char **)tp->p)[c] ) );
274 + }
275 +
276 + static int
277   putface(                                /* put out an N-sided polygon */
278          int     ac,
279          char    **av
280   )
281   {
282 <        char            *cp;
283 <        int     i;
282 >        Vert2_list      *poly = polyAlloc(ac);
283 >        int             i, ax, ay;
284  
285 <        while (ac > 3) {                /* break into triangles */
286 <                if (!puttri(av[0], av[1], av[2]))
285 >        if (poly == NULL)
286 >                return(0);
287 >        poly->p = (void *)av;
288 >        for (i = ac-3; i >= 0; i--)     /* identify dominant axis */
289 >                if ((ax = dominant_axis(av[i], av[i+1], av[i+2])) >= 0)
290 >                        break;
291 >        if (ax < 0)
292 >                return(1);              /* ignore degenerate face */
293 >        if (++ax >= 3) ax = 0;
294 >        ay = ax;
295 >        if (++ay >= 3) ay = 0;
296 >        for (i = 0; i < ac; i++) {      /* convert to 2-D polygon */
297 >                VNDX    vi;
298 >                if (!cvtndx(vi, av[i])) {
299 >                        error(WARNING, "bad vertex reference");
300 >                        polyFree(poly);
301                          return(0);
302 <                ac--;                   /* remove vertex & rotate */
303 <                cp = av[0];
304 <                for (i = 0; i < ac-1; i++)
263 <                        av[i] = av[i+2];
264 <                av[i] = cp;
302 >                }
303 >                poly->v[i].mX = vlist[vi[0]][ax];
304 >                poly->v[i].mY = vlist[vi[0]][ay];
305          }
306 <        return(puttri(av[0], av[1], av[2]));
306 >                                        /* break into triangles & output */
307 >        if (!polyTriangulate(poly, &tri_out))
308 >                error(WARNING, "self-intersecting face");
309 >        polyFree(poly);
310 >        return(1);
311   }
312  
313  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines