1 /* GTS - Library for the manipulation of triangulated surfaces
2 * Copyright (C) 1999 St�phane Popinet
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 #include "gts.h"
21
write_vertex(GtsVertex * v,guint * nv)22 static void write_vertex (GtsVertex * v, guint * nv)
23 {
24 printf (" GtsVertex * v%u = gts_vertex_new (gts_vertex_class (), %g, %g, %g);\n",
25 *nv, GTS_POINT (v)->x, GTS_POINT (v)->y, GTS_POINT (v)->z);
26 GTS_OBJECT (v)->reserved = GUINT_TO_POINTER ((*nv)++);
27 }
28
write_edge(GtsSegment * s,guint * ne)29 static void write_edge (GtsSegment * s, guint * ne)
30 {
31 printf (" GtsEdge * e%u = gts_edge_new (gts_edge_class (), v%u, v%u);\n",
32 *ne,
33 GPOINTER_TO_UINT (GTS_OBJECT (s->v1)->reserved),
34 GPOINTER_TO_UINT (GTS_OBJECT (s->v2)->reserved));
35 GTS_OBJECT (s)->reserved = GUINT_TO_POINTER ((*ne)++);
36 }
37
write_face(GtsTriangle * t,guint * nf)38 static void write_face (GtsTriangle * t, guint * nf)
39 {
40 printf (" GtsFace * f%u = gts_face_new (gts_face_class (),\n"
41 " e%u, e%u, e%u);\n",
42 (*nf)++,
43 GPOINTER_TO_UINT (GTS_OBJECT (t->e1)->reserved),
44 GPOINTER_TO_UINT (GTS_OBJECT (t->e2)->reserved),
45 GPOINTER_TO_UINT (GTS_OBJECT (t->e3)->reserved));
46 }
47
main(int argc,char * argv[])48 int main (int argc, char * argv[])
49 {
50 GtsSurface * s;
51 guint i;
52 GtsFile * fp;
53 guint nv = 1, ne = 1, nf = 1;
54
55 s = gts_surface_new (gts_surface_class (),
56 gts_face_class (),
57 gts_edge_class (),
58 gts_vertex_class ());
59 fp = gts_file_new (stdin);
60 if (gts_surface_read (s, fp)) {
61 fputs ("gtstoc: file on standard input is not a valid GTS file\n",
62 stderr);
63 fprintf (stderr, "stdin:%d:%d: %s\n", fp->line, fp->pos, fp->error);
64 return 1; /* failure */
65 }
66
67 printf (" GtsSurface * surface = gts_surface_new (gts_surface_class (),\n"
68 " gts_face_class (),\n"
69 " gts_edge_class (),\n"
70 " gts_vertex_class ());\n\n");
71 gts_surface_foreach_vertex (s, (GtsFunc) write_vertex, &nv);
72 printf ("\n");
73 gts_surface_foreach_edge (s, (GtsFunc) write_edge, &ne);
74 printf ("\n");
75 gts_surface_foreach_face (s, (GtsFunc) write_face, &nf);
76 printf (" \n");
77 for (i = 1; i < nf; i++)
78 printf (" gts_surface_add_face (surface, f%u);\n", i);
79
80 return 0;
81 }
82