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.8 by schorsch, Sat Mar 27 12:41:45 2004 UTC vs.
Revision 2.11 by greg, Fri Jan 24 01:26:44 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) */
16  
17   #define CHUNKSIZ        1024    /* vertex allocation chunk size */
18  
19 < #define MAXARG          64      /* maximum # arguments in a statement */
19 > #define MAXARG          512     /* maximum # arguments in a statement */
20  
21   static FVECT    *vlist;         /* our vertex list */
22   static int      nvs;            /* number of vertices in our list */
# Line 26 | Line 27 | static int     nvts;
27  
28   static char     *inpfile;       /* input file name */
29   static int      havemats;       /* materials available? */
30 < static char     material[64];   /* current material name */
31 < static char     group[64];      /* current group name */
30 > static char     material[256];  /* current material name */
31 > static char     group[256];     /* current group name */
32   static int      lineno;         /* current line number */
33   static int      faceno;         /* current face number */
34  
# Line 158 | Line 159 | wfreadobj(             /* read in .OBJ file and convert */
159  
160   static int
161   getstmt(                                /* read the next statement from fp */
162 <        register char   *av[MAXARG],
162 >        char    *av[MAXARG],
163          FILE    *fp
164   )
165   {
166          static char     sbuf[MAXARG*16];
167 <        register char   *cp;
168 <        register int    i;
167 >        char    *cp;
168 >        int     i;
169  
170          do {
171                  if (fgetline(cp=sbuf, sizeof(sbuf), fp) == NULL)
# Line 176 | Line 177 | getstmt(                               /* read the next statement from fp */
177                                          lineno++;
178                                  *cp++ = '\0';
179                          }
180 <                        if (!*cp || i >= MAXARG-1)
180 >                        if (!*cp)
181                                  break;
182 +                        if (i >= MAXARG-1) {
183 +                                sprintf(errmsg,
184 +                        "%s: too many arguments near line %d (limit %d)\n",
185 +                                        inpfile, lineno+1, MAXARG-1);
186 +                                break;
187 +                        }
188                          av[i++] = cp;
189                          while (*++cp && !isspace(*cp))
190                                  ;
# Line 192 | Line 199 | getstmt(                               /* read the next statement from fp */
199  
200   static int
201   cvtndx(                         /* convert vertex string to index */
202 <        register VNDX   vi,
203 <        register char   *vs
202 >        VNDX    vi,
203 >        char    *vs
204   )
205   {
206                                          /* get point */
# Line 238 | 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 +        int     v1i = atoi(v1), v2i = atoi(v2), v3i = atoi(v3);
253 +        FVECT   e1, e2, vn;
254 +        int     i, imax;
255  
256 +        VSUB(e1, vlist[v2i], vlist[v1i]);
257 +        VSUB(e2, vlist[v3i], vlist[v2i]);
258 +        VCROSS(vn, e1, e2);
259 +        for (i = imax = 2; i--; )
260 +                if (vn[i]*vn[i] > vn[imax]*vn[imax])
261 +                        imax = i;
262 +        return(vn[imax]*vn[imax] > FTINY ? imax : -1);
263 + }
264 +
265 + /* callback for triangle output from polygon */
266   static int
267 + tri_out(const Vert2_list *tp, int a, int b, int c)
268 + {
269 +        return( puttri( ((char **)tp->p)[a],
270 +                        ((char **)tp->p)[b],
271 +                        ((char **)tp->p)[c] ) );
272 + }
273 +
274 + static int
275   putface(                                /* put out an N-sided polygon */
276          int     ac,
277 <        register char   **av
277 >        char    **av
278   )
279   {
280 <        char            *cp;
281 <        register int    i;
280 >        Vert2_list      *poly = polyAlloc(ac);
281 >        int             i, ax, ay;
282  
283 <        while (ac > 3) {                /* break into triangles */
284 <                if (!puttri(av[0], av[1], av[2]))
283 >        if (poly == NULL)
284 >                return(0);
285 >        poly->p = (void *)av;
286 >        for (i = ac-3; i >= 0; i--)     /* identify dominant axis */
287 >                if ((ax = dominant_axis(av[i], av[i+1], av[i+2])) >= 0)
288 >                        break;
289 >        if (ax < 0)
290 >                return(0);
291 >        if (++ax >= 3) ax = 0;
292 >        ay = ax;
293 >        if (++ay >= 3) ay = 0;
294 >        for (i = 0; i < ac; i++) {      /* convert to 2-D polygon */
295 >                VNDX    vi;
296 >                if (!cvtndx(vi, av[i])) {
297 >                        error(WARNING, "bad vertex reference");
298 >                        polyFree(poly);
299                          return(0);
300 <                ac--;                   /* remove vertex & rotate */
301 <                cp = av[0];
302 <                for (i = 0; i < ac-1; i++)
257 <                        av[i] = av[i+2];
258 <                av[i] = cp;
300 >                }
301 >                poly->v[i].mX = vlist[vi[0]][ax];
302 >                poly->v[i].mY = vlist[vi[0]][ay];
303          }
304 <        return(puttri(av[0], av[1], av[2]));
304 >                                        /* break into triangles & output */
305 >        if (!polyTriangulate(poly, &tri_out))
306 >                return(0);
307 >        polyFree(poly);
308 >        return(1);
309   }
310  
311  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines