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 <stdlib.h>
21 #include "config.h"
22 #ifdef HAVE_GETOPT_H
23 # include <getopt.h>
24 #endif /* HAVE_GETOPT_H */
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif /* HAVE_UNISTD_H */
28 #include "gts.h"
29
30 /* sphere - generate a triangulated unit sphere by recursive subdivision.
31 First approximation is an isocahedron; each level of refinement
32 increases the number of triangles by a factor of 4.
33 */
main(int argc,char * argv[])34 int main (int argc, char * argv[])
35 {
36 GtsSurface * s;
37 gboolean verbose = FALSE;
38 guint level=4;
39 int c = 0;
40
41 /* parse options using getopt */
42 while (c != EOF) {
43 #ifdef HAVE_GETOPT_LONG
44 static struct option long_options[] = {
45 {"help", no_argument, NULL, 'h'},
46 {"verbose", no_argument, NULL, 'v'}
47 };
48 int option_index = 0;
49 switch ((c = getopt_long (argc, argv, "hv",
50 long_options, &option_index))) {
51 #else /* not HAVE_GETOPT_LONG */
52 switch ((c = getopt (argc, argv, "hv"))) {
53 #endif /* not HAVE_GETOPT_LONG */
54 case 'v': /* verbose */
55 verbose = TRUE;
56 break;
57 case 'h': /* help */
58 fprintf (stderr,
59 "Usage: sphere [OPTION] [level]\n"
60 "Generate a triangulated unit sphere by recursive subdivision.\n"
61 "First approximation is an isocahedron; each level of refinement\n"
62 "increases the number of triangles by a factor of 4.\n"
63 "level must be a positive integer setting the recursion level\n"
64 "(geodesation order), default is 4.\n"
65 "\n"
66 "Documentation: http://mathworld.wolfram.com/GeodesicDome.html\n"
67 "\n"
68 " -v --verbose print statistics about the surface\n"
69 " -h --help display this help and exit\n"
70 "\n"
71 "Reports bugs to %s\n",
72 GTS_MAINTAINER);
73 return 0; /* success */
74 break;
75 case '?': /* wrong options */
76 fprintf (stderr, "Try `sphere --help' for more information.\n");
77 return 1; /* failure */
78 }
79 }
80
81 /* read level */
82 if (optind < argc)
83 level = atoi(argv[optind]);
84
85 /* generate triangulated sphere */
86 s = gts_surface_new (gts_surface_class (),
87 gts_face_class (),
88 gts_edge_class (),
89 gts_vertex_class ());
90 gts_surface_generate_sphere (s, level);
91
92 /* if verbose on print stats */
93 if (verbose)
94 gts_surface_print_stats (s, stderr);
95
96 /* write generating surface to standard output */
97 gts_surface_write (s, stdout);
98
99 return 0; /* success */
100 }
101