void ofxGtsSurface::printStats() { if(loaded) { gts_surface_print_stats (surface, stdout); } else { ofLog(OF_LOG_NOTICE, "Gts surface not loaded"); } }
int main (int argc, char * argv[]) { GtsSurface * s; GtsBBox * bbox; gdouble delta; GtsPoint * p1, * p2, * p3; guint nt; GtsRange cluster_stats; GtsClusterGrid * cluster_grid; if (argc != 2) { fprintf (stderr, "usage: oocs DELTA < infile > outfile\n"); return 1; } s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); bbox = gts_bbox_new (gts_bbox_class (), s, 0., 0., 0., 0., 0., 0.); scanf ("%u", &nt); scanf ("%lf %lf %lf", &bbox->x1, &bbox->y1, &bbox->z1); scanf ("%lf %lf %lf", &bbox->x2, &bbox->y2, &bbox->z2); delta = atof (argv[1])*sqrt (gts_bbox_diagonal2 (bbox)); cluster_grid = gts_cluster_grid_new (gts_cluster_grid_class (), gts_cluster_class (), s, bbox, delta); p1 = gts_point_new (gts_point_class (), 0., 0., 0.); p2 = gts_point_new (gts_point_class (), 0., 0., 0.); p3 = gts_point_new (gts_point_class (), 0., 0., 0.); while (scanf ("%lf %lf %lf", &p1->x, &p1->y, &p1->z) == 3 && scanf ("%lf %lf %lf", &p2->x, &p2->y, &p2->z) == 3 && scanf ("%lf %lf %lf", &p3->x, &p3->y, &p3->z) == 3) gts_cluster_grid_add_triangle (cluster_grid, p1, p2, p3, NULL); cluster_stats = gts_cluster_grid_update (cluster_grid); gts_object_destroy (GTS_OBJECT (p1)); gts_object_destroy (GTS_OBJECT (p2)); gts_object_destroy (GTS_OBJECT (p3)); gts_object_destroy (GTS_OBJECT (cluster_grid)); fprintf (stderr, "Initial number of triangles: %u\n", nt); fprintf (stderr, "%d clusters of size: min: %g avg: %.1f|%.1f max: %g\n", cluster_stats.n, cluster_stats.min, cluster_stats.mean, cluster_stats.stddev, cluster_stats.max); gts_surface_print_stats (s, stderr); gts_surface_write (s, stdout); return 0; }
int main (int argc, char * argv[]) { int c = 0; gboolean verbose = FALSE; GtsSurface * s; CostFunc cost_func = (CostFunc) height_cost; gpointer cost_data = NULL; GtsStopFunc stop_func = NULL; gpointer stop_data = NULL; StopOptions stop = NUMBER; guint number = 0; gdouble cmin = 0.0; gboolean logcost = FALSE; gboolean flat = FALSE; gdouble relative = 0.; gboolean keep_enclosing = FALSE; gboolean closed = FALSE; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"closed", no_argument, NULL, 'C'}, {"keep", no_argument, NULL, 'k'}, {"relative", required_argument, NULL, 'r'}, {"flat", no_argument, NULL, 'f'}, {"log", no_argument, NULL, 'l'}, {"number", required_argument, NULL, 'n'}, {"cost", required_argument, NULL, 'c'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, { NULL } }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvn:c:lfr:kC", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvn:c:lfr:kC"))) { #endif /* not HAVE_GETOPT_LONG */ case 'C': /* closed */ closed = TRUE; keep_enclosing = TRUE; break; case 'k': /* keep */ keep_enclosing = TRUE; break; case 'r': /* relative */ cost_func = (CostFunc) relative_height_cost; relative = strtod (optarg, NULL); cost_data = &relative; if (relative <= 0.) { fprintf (stderr, "happrox: argument for -r option must be strictly positive\n"); return 1; } break; case 'f': /* flat file */ flat = TRUE; break; case 'l': /* log cost */ logcost = TRUE; break; case 'n': /* stop by number */ stop = NUMBER; number = strtol (optarg, NULL, 0); break; case 'c': /* stop by cost */ stop = COST; cmin = strtod (optarg, NULL); break; case 'h': /* help */ fprintf (stderr, "Usage: happrox [OPTION]... < [input.pgm|input] > output.gts\n" "Returns a simplified triangulation of a set of points using\n" "algorithm III of Garland and Heckbert (1995).\n" "\n" " -n N, --number=N stop the refinement process if the number of\n" " vertices is larger than N\n" " -c C, --cost=C stop the refinement process if the cost of insertion\n" " of a vertex is smaller than C\n" " -f --flat input is a flat file with three x,y,z columns\n" " (default is PGM file)\n" " -r Z --relative=Z use relative height cost for all heights larger than Z\n" " -k --keep keep enclosing triangle\n" " -C --closed close the surface\n" " -l --log log evolution of cost\n" " -v, --verbose display surface statistics\n" " -h, --help display this help and exit\n" "\n" "Report bugs to %s\n", GTS_MAINTAINER); return 0; break; case 'v': verbose = TRUE; break; case '?': /* wrong options */ fprintf (stderr, "Try `happrox --help' for more information.\n"); return 1; } } switch (stop) { case NUMBER: if (verbose) stop_func = (GtsStopFunc) stop_number_verbose; else stop_func = (GtsStopFunc) stop_number; if (logcost) stop_func = (GtsStopFunc) stop_number_log_cost; stop_data = &number; break; case COST: if (verbose) stop_func = (GtsStopFunc) stop_cost_verbose; else stop_func = (GtsStopFunc) stop_cost; stop_data = &cmin; break; default: g_assert_not_reached (); } if (flat) { GSList * points = NULL; guint n = 0; gdouble x, y, z; while (scanf ("%lf %lf %lf", &x, &y, &z) == 3) { points = g_slist_prepend (points, gts_vertex_new (gts_vertex_class (), x, y, z)); n++; } if (verbose) fprintf (stderr, "happrox: %d vertices\n", n); s = happrox_list (points, keep_enclosing, closed, cost_func, cost_data, stop_func, stop_data); } else { gint width, height; gray ** g, maxgray; g = pgm_readpgm (stdin, &width, &height, &maxgray); if (verbose) fprintf (stderr, "happrox: width: %d height: %d maxgray: %d\n", width, height, maxgray); s = happrox (g, width, height, cost_func, cost_data, stop_func, stop_data); } if (verbose) { fputc ('\n', stderr); gts_surface_print_stats (s, stderr); } gts_surface_write (s, stdout); return 0; }
int main (int argc, char * argv[]) { gboolean verbose = FALSE; gboolean triangulate_holes = TRUE; gboolean write_holes = FALSE; int c = 0; CartesianGrid * grid; guint line = 0; GtsSurface * s; GTimer * timer; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"holes", no_argument, NULL, 'H'}, {"keep", no_argument, NULL, 'k'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, { NULL } }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvHk", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvHk"))) { #endif /* not HAVE_GETOPT_LONG */ case 'H': /* holes */ write_holes = TRUE; break; case 'k': /* keep */ triangulate_holes = FALSE; break; case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: cartesian [OPTION] < FILE\n" "Triangulates vertices of a regular cartesian mesh\n" "(possibly containing holes)\n" "\n" " -k --keep keep holes\n" " -H --holes write holes only\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `cartesian --help' for more information.\n"); return 1; /* failure */ } } grid = cartesian_grid_read (gts_vertex_class (), &line); if (grid == NULL) { fprintf (stderr, "cartesian: file on standard input is not a valid cartesian grid\n" "error at line %u\n", line); return 1; } timer = g_timer_new (); g_timer_start (timer); s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); cartesian_grid_triangulate (grid, s); if (triangulate_holes) { GtsSurface * holes = cartesian_grid_triangulate_holes (grid, s); if (write_holes) { gts_object_destroy (GTS_OBJECT (s)); s = holes; } else gts_surface_merge (s, holes); } g_timer_stop (timer); if (verbose) { gts_surface_print_stats (s, stderr); fprintf (stderr, "# Triangulation time: %g s speed: %.0f vertex/s\n", g_timer_elapsed (timer, NULL), gts_surface_vertex_number (s)/g_timer_elapsed (timer, NULL)); } gts_surface_write (s, stdout); return 0; /* success */ }
int main (int argc, char * argv[]) { GtsSurface * s; GtsFile * fp; GtsMatrix * m; int c = 0; gboolean verbose = FALSE; gboolean revert = FALSE; gboolean normalize = FALSE; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); m = gts_matrix_identity (NULL); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"rx", required_argument, NULL, 'r'}, {"ry", required_argument, NULL, 'm'}, {"rz", required_argument, NULL, 'n'}, {"scale", required_argument, NULL, 's'}, {"sx", required_argument, NULL, 'R'}, {"sy", required_argument, NULL, 'M'}, {"sz", required_argument, NULL, 'N'}, {"tx", required_argument, NULL, 't'}, {"ty", required_argument, NULL, 'u'}, {"tz", required_argument, NULL, 'w'}, {"revert", no_argument, NULL, 'i'}, {"normalize", no_argument, NULL, 'o'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, { NULL } }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvr:m:n:s:R:M:N:it:u:w:o", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvr:m:n:s:R:M:N:it:u:w:o"))) { #endif /* not HAVE_GETOPT_LONG */ case 'o': /* normalize */ normalize = TRUE; break; case 'r': { /* rotate around x-axis */ gdouble angle, cosa, sina; GtsMatrix * rot, * p; rot = gts_matrix_identity (NULL); angle = atof (optarg)*PI/180.; cosa = cos (angle); sina = sin (angle); rot[1][1] = cosa; rot[1][2] = -sina; rot[2][1] = sina; rot[2][2] = cosa; p = gts_matrix_product (m, rot); gts_matrix_destroy (rot); gts_matrix_destroy (m); m = p; break; } case 'm': { /* rotate around y-axis */ gdouble angle, cosa, sina; GtsMatrix * rot, * p; rot = gts_matrix_identity (NULL); angle = atof (optarg)*PI/180.; cosa = cos (angle); sina = sin (angle); rot[0][0] = cosa; rot[0][2] = sina; rot[2][0] = -sina; rot[2][2] = cosa; p = gts_matrix_product (m, rot); gts_matrix_destroy (rot); gts_matrix_destroy (m); m = p; break; } case 'n': { /* rotate around z-axis */ gdouble angle, cosa, sina; GtsMatrix * rot, * p; rot = gts_matrix_identity (NULL); angle = atof (optarg)*PI/180.; cosa = cos (angle); sina = sin (angle); rot[0][0] = cosa; rot[0][1] = -sina; rot[1][0] = sina; rot[1][1] = cosa; p = gts_matrix_product (m, rot); gts_matrix_destroy (rot); gts_matrix_destroy (m); m = p; break; } case 's': { /* scale */ GtsMatrix * scale, * p; gdouble s = atof (optarg); scale = gts_matrix_identity (NULL); scale[0][0] = scale[1][1] = scale[2][2] = s; p = gts_matrix_product (m, scale); gts_matrix_destroy (scale); gts_matrix_destroy (m); m = p; break; } case 'R': { /* sx */ GtsMatrix * scale, * p; gdouble s = atof (optarg); scale = gts_matrix_identity (NULL); scale[0][0] = s; p = gts_matrix_product (m, scale); gts_matrix_destroy (scale); gts_matrix_destroy (m); m = p; break; } case 'M': { /* sy */ GtsMatrix * scale, * p; gdouble s = atof (optarg); scale = gts_matrix_identity (NULL); scale[1][1] = s; p = gts_matrix_product (m, scale); gts_matrix_destroy (scale); gts_matrix_destroy (m); m = p; break; } case 'N': { /* sz */ GtsMatrix * scale, * p; gdouble s = atof (optarg); scale = gts_matrix_identity (NULL); scale[2][2] = s; p = gts_matrix_product (m, scale); gts_matrix_destroy (scale); gts_matrix_destroy (m); m = p; break; } case 't': /* tx */ m[0][3] += atof (optarg); break; case 'u': /* ty */ m[1][3] += atof (optarg); break; case 'w': /* tz */ m[2][3] += atof (optarg); break; case 'i': /* revert */ revert = TRUE; break; case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: transform [OPTION] < file.gts\n" "Apply geometric transformations to the input.\n" "\n" " -r ANGLE --rx=ANGLE rotate around x-axis (angle in degrees)\n" " -m ANGLE --ry=ANGLE rotate around y-axis\n" " -n ANGLE --rz=ANGLE rotate around z-axis\n" " -s FACTOR --scale=FACTOR scale by FACTOR\n" " -R FACTOR --sx=FACTOR scale x-axis by FACTOR\n" " -M FACTOR --sy=FACTOR scale y-axis by FACTOR\n" " -N FACTOR --sz=FACTOR scale z-axis by FACTOR\n" " -t V --tx=V translate of V along x-axis\n" " -u V --ty=V translate of V along y-axis\n" " -w V --tz=V translate of V along z-axis\n" " -i --revert turn surface inside out\n" " -o --normalize fit the resulting surface in a cube of\n" " size 1 centered at the origin\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `transform --help' for more information.\n"); return 1; /* failure */ } } s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); fp = gts_file_new (stdin); if (gts_surface_read (s, fp)) { fputs ("transform: file on standard input is not a valid GTS file\n", stderr); fprintf (stderr, "stdin:%d:%d: %s\n", fp->line, fp->pos, fp->error); return 1; /* failure */ } if (verbose) gts_surface_print_stats (s, stderr); if (revert) gts_surface_foreach_face (s, (GtsFunc) gts_triangle_revert, NULL); gts_surface_foreach_vertex (s, (GtsFunc) gts_point_transform, m); if (normalize) { GtsBBox * bb = gts_bbox_surface (gts_bbox_class (), s); gdouble scale = bb->x2 - bb->x1; GtsMatrix * sc; if (bb->y2 - bb->y1 > scale) scale = bb->y2 - bb->y1; if (bb->z2 - bb->z1 > scale) scale = bb->z2 - bb->z1; if (scale > 0.) scale = 1./scale; else scale = 1.; sc = gts_matrix_identity (NULL); sc[0][3] = - (bb->x1 + bb->x2)/2.; sc[1][3] = - (bb->y1 + bb->y2)/2.; sc[2][3] = - (bb->z1 + bb->z2)/2.; gts_surface_foreach_vertex (s, (GtsFunc) gts_point_transform, sc); sc[0][0] = sc[1][1] = sc[2][2] = scale; sc[0][3] = sc[1][3] = sc[2][3] = 0.; gts_surface_foreach_vertex (s, (GtsFunc) gts_point_transform, sc); gts_matrix_destroy (sc); } gts_surface_write (s, stdout); return 0; }
/* stripe - Turns the input surface into triangle strips and outputs a Geomview representation of the result. */ int main (int argc, char * argv[]) { GtsSurface * s; GSList * strips = NULL, * i; gboolean verbose = FALSE; int c = 0; GtsFile * fp; /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'} }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hv", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hv"))) { #endif /* not HAVE_GETOPT_LONG */ case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: stripe [OPTION] < FILE\n" "Turns the input surface into triangle strips and outputs a\n" "Geomview representation of the result.\n" "\n" " -v --verbose print statistics about the surface and strips\n" " -h --help display this help and exit\n" "\n" "Report bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `stripe --help' for more information.\n"); return 1; /* failure */ } } /* read surface in */ s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); fp = gts_file_new (stdin); if (gts_surface_read (s, fp)) { fputs ("stripe: file on standard input is not a valid GTS file\n", stderr); fprintf (stderr, "stdin:%d:%d: %s\n", fp->line, fp->pos, fp->error); return 1; /* failure */ } gts_file_destroy (fp); if (verbose) gts_surface_print_stats (s, stderr); strips = gts_surface_strip (s); /* if verbose on print stats */ if (verbose) { GtsRange l; gts_range_init (&l); i = strips; while (i) { gts_range_add_value (&l, g_slist_length (i->data)); i = i->next; } gts_range_update (&l); fprintf (stderr, "# Strips: %d\n# length : ", l.n); gts_range_print (&l, stderr); fputc ('\n', stderr); } puts ("LIST {\n"); i = strips; while (i) { GList * j = i->data; GtsTriangle * oldt = NULL; GtsColor c; c.r = rand ()/(gdouble) RAND_MAX; c.g = rand ()/(gdouble) RAND_MAX; c.b = rand ()/(gdouble) RAND_MAX; while (j) { GtsTriangle * t = j->data; GtsPoint * p1 = GTS_POINT (GTS_SEGMENT (t->e1)->v1), * p2 = GTS_POINT (GTS_SEGMENT (t->e1)->v2), * p3 = GTS_POINT (gts_triangle_vertex (t)); printf ("OFF 3 1 3\n%g %g %g\n%g %g %g\n%g %g %g\n3 0 1 2 %g %g %g\n", p1->x, p1->y, p1->z, p2->x, p2->y, p2->z, p3->x, p3->y, p3->z, c.r, c.g, c.b); if (oldt) { GtsSegment * cs = GTS_SEGMENT (gts_triangles_common_edge (t, oldt)); GtsPoint * op1 = GTS_POINT (GTS_SEGMENT (oldt->e1)->v1), * op2 = GTS_POINT (GTS_SEGMENT (oldt->e1)->v2), * op3 = GTS_POINT (gts_triangle_vertex (oldt)); printf ("VECT 1 3 0 3 0 %g %g %g %g %g %g %g %g %g\n", (op1->x + op2->x + op3->x)/3., (op1->y + op2->y + op3->y)/3., (op1->z + op2->z + op3->z)/3., (GTS_POINT (cs->v1)->x + GTS_POINT (cs->v2)->x)/2., (GTS_POINT (cs->v1)->y + GTS_POINT (cs->v2)->y)/2., (GTS_POINT (cs->v1)->z + GTS_POINT (cs->v2)->z)/2., (p1->x + p2->x + p3->x)/3., (p1->y + p2->y + p3->y)/3., (p1->z + p2->z + p3->z)/3.); } oldt = t; j = j->next; } i = i->next; } puts ("}\n"); return 0; /* success */ }
int main (int argc, char * argv[]) { GPtrArray * vertices; GtsFifo * edges; guint i, line; GtsTriangle * t; GtsVertex * v1, * v2, * v3; GtsSurface * surface; gboolean keep_hull = TRUE; gboolean verbose = FALSE; gboolean add_constraints = TRUE; gboolean remove_holes = FALSE; gboolean check_delaunay = FALSE; gboolean conform = FALSE; gboolean refine = FALSE; gboolean split_constraints = FALSE; gboolean randomize = FALSE; gboolean remove_duplicates = FALSE; gint steiner_max = -1; gdouble quality = 0., area = G_MAXDOUBLE; int c = 0, status = 0; const char * fname = NULL; GTimer * timer; /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"duplicates", no_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, {"randomize", no_argument, NULL, 'r'}, {"hull", no_argument, NULL, 'b'}, {"noconst", no_argument, NULL, 'e'}, {"holes", no_argument, NULL, 'H'}, {"split", no_argument, NULL, 'S'}, {"check", no_argument, NULL, 'c'}, {"files", required_argument, NULL, 'f'}, {"conform", no_argument, NULL, 'o'}, {"steiner", required_argument, NULL, 's'}, {"quality", required_argument, NULL, 'q'}, {"area", required_argument, NULL, 'a'} }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvbecf:os:q:a:HSrd", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvbecf:os:q:a:HSrd"))) { #endif /* not HAVE_GETOPT_LONG */ case 'd': /* duplicates */ remove_duplicates = TRUE; break; case 'b': /* do not keep convex hull */ keep_hull = FALSE; break; case 'e': /* do not add constrained edges */ add_constraints = FALSE; break; case 'H': /* remove holes */ remove_holes = TRUE; break; case 'S': /* split constraints */ split_constraints = TRUE; break; case 'r': /* randomize */ randomize = TRUE; break; case 'c': /* check Delaunay property */ check_delaunay = TRUE; break; case 'f': /* generates files */ fname = optarg; break; case 'v': /* verbose */ verbose = TRUE; break; case 'o': /* conform */ conform = TRUE; break; case 's': /* steiner */ steiner_max = atoi (optarg); break; case 'q': /* quality */ conform = TRUE; refine = TRUE; quality = atof (optarg); break; case 'a': /* area */ conform = TRUE; refine = TRUE; area = atof (optarg); break; case 'h': /* help */ fprintf (stderr, "Usage: delaunay [OPTION] < file.gts\n" "Construct the constrained Delaunay triangulation of the input\n" "\n" " -b --hull do not keep convex hull\n" " -e --noconst do not add constrained edges\n" " -S --split split constraints (experimental)\n" " -H --holes remove holes from the triangulation\n" " -d --duplicates remove duplicate vertices\n" " -r --randomize shuffle input vertex list\n" " -c --check check Delaunay property\n" " -f FNAME --files=FNAME generate evolution files\n" " -o --conform generate conforming triangulation\n" " -s N --steiner=N maximum number of Steiner points for\n" " conforming triangulation (default is no limit)\n" " -q Q --quality=Q Set the minimum acceptable face quality\n" " -a A --area=A Set the maximum acceptable face area\n" " -v --verbose print statistics about the triangulation\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `delaunay --help' for more information.\n"); return 1; /* failure */ } } /* read file => two lists: vertices and constraints */ edges = gts_fifo_new (); vertices = g_ptr_array_new (); if (add_constraints) /* the edge class is a GtsConstraintClass */ line = read_list (vertices, edges, GTS_EDGE_CLASS (gts_constraint_class ()), stdin); else /* the edge class is a "normal" edge: GtsEdgeClass */ line = read_list (vertices, edges, gts_edge_class (), stdin); if (line > 0) { fprintf (stderr, "delaunay: error in input file at line %u\n", line); return 1; } timer = g_timer_new (); g_timer_start (timer); if (randomize) shuffle_array (vertices); /* create triangle enclosing all the vertices */ { GSList * list = NULL; for (i = 0; i < vertices->len; i++) list = g_slist_prepend (list, g_ptr_array_index (vertices, i)); t = gts_triangle_enclosing (gts_triangle_class (), list, 100.); g_slist_free (list); } gts_triangle_vertices (t, &v1, &v2, &v3); /* create surface with one face: the enclosing triangle */ surface = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); gts_surface_add_face (surface, gts_face_new (gts_face_class (), t->e1, t->e2, t->e3)); /* add vertices */ for (i = 0; i < vertices->len; i++) { GtsVertex * v1 = g_ptr_array_index (vertices, i); GtsVertex * v = gts_delaunay_add_vertex (surface, v1, NULL); g_assert (v != v1); if (v != NULL) { if (!remove_duplicates) { fprintf (stderr, "delaunay: duplicate vertex (%g,%g) in input file\n", GTS_POINT (v)->x, GTS_POINT (v)->y); return 1; /* Failure */ } else gts_vertex_replace (v1, v); } if (fname) { static guint nf = 1; char s[80]; FILE * fp; g_snprintf (s, 80, "%s.%u", fname, nf++); fp = fopen (s, "wt"); gts_surface_write_oogl (surface, fp); fclose (fp); if (check_delaunay && gts_delaunay_check (surface)) { fprintf (stderr, "delaunay: triangulation is not Delaunay\n"); return 1; } } } g_ptr_array_free (vertices, TRUE); /* add remaining constraints */ if (add_constraints) gts_fifo_foreach (edges, (GtsFunc) add_constraint, surface); /* destroy enclosing triangle */ gts_allow_floating_vertices = TRUE; gts_object_destroy (GTS_OBJECT (v1)); gts_object_destroy (GTS_OBJECT (v2)); gts_object_destroy (GTS_OBJECT (v3)); gts_allow_floating_vertices = FALSE; if (!keep_hull) gts_delaunay_remove_hull (surface); if (remove_holes) delaunay_remove_holes (surface); if (split_constraints) { gpointer data[2]; data[0] = surface; data[1] = edges; gts_fifo_foreach (edges, (GtsFunc) split_constraint, data); } if (conform) { guint encroached_number = gts_delaunay_conform (surface, steiner_max, (GtsEncroachFunc) gts_vertex_encroaches_edge, NULL); if (encroached_number == 0 && refine) { guint unrefined_number; gpointer data[2]; data[0] = &quality; data[1] = &area; unrefined_number = gts_delaunay_refine (surface, steiner_max, (GtsEncroachFunc) gts_vertex_encroaches_edge, NULL, (GtsKeyFunc) triangle_cost, data); if (verbose && unrefined_number > 0) fprintf (stderr, "delaunay: ran out of Steiner points (max: %d) during refinement\n" "%d unrefined faces left\n", steiner_max, unrefined_number); } else if (verbose && encroached_number > 0) fprintf (stderr, "delaunay: ran out of Steiner points (max: %d) during conforming\n" "Delaunay triangulation: %d encroached constraints left\n", steiner_max, encroached_number); } g_timer_stop (timer); if (verbose) { gts_surface_print_stats (surface, stderr); fprintf (stderr, "# Triangulation time: %g s speed: %.0f vertex/s\n", g_timer_elapsed (timer, NULL), gts_surface_vertex_number (surface)/g_timer_elapsed (timer, NULL)); } if (check_delaunay && gts_delaunay_check (surface)) { fprintf (stderr, "delaunay: triangulation is not Delaunay\n"); status = 1; /* failure */ } /* write triangulation */ gts_surface_write (surface, stdout); return status; }
int main (int argc, char * argv[]) { GtsSurface * s; GtsFile * fp; int c = 0; gboolean verbose = FALSE; guint n, niter; gdouble lambda; gpointer data[4]; gboolean fold = FALSE; gdouble maxcosine2 = 0.; guint nfold = 1; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"fold", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'} }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvf:", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvf:"))) { #endif /* not HAVE_GETOPT_LONG */ case 'f': /* fold */ fold = TRUE; maxcosine2 = cos (atof (optarg)*3.14159265359/180.); maxcosine2 *= maxcosine2; break; case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: smooth [OPTION] LAMBDA NITER < file.gts > smooth.gts\n" "Smooth a GTS file by applying NITER iterations of a Laplacian filter\n" "of parameter LAMBDA.\n" "\n" " -f VAL --fold=VAL smooth only folds\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `smooth --help' for more information.\n"); return 1; /* failure */ } } if (optind >= argc) { /* missing lambda */ fprintf (stderr, "smooth: missing LAMBDA\n" "Try `smooth --help' for more information.\n"); return 1; /* failure */ } lambda = atof (argv[optind++]); if (optind >= argc) { /* missing niter */ fprintf (stderr, "smooth: missing NITER\n" "Try `smooth --help' for more information.\n"); return 1; /* failure */ } niter = atoi (argv[optind++]); s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); fp = gts_file_new (stdin); if (gts_surface_read (s, fp)) { fputs ("smooth: file on standard input is not a valid GTS file\n", stderr); fprintf (stderr, "stdin:%d:%d: %s\n", fp->line, fp->pos, fp->error); return 1; /* failure */ } if (verbose) gts_surface_print_stats (s, stderr); data[0] = s; data[1] = λ data[2] = &maxcosine2; data[3] = &nfold; for (n = 1; n <= niter && (!fold || nfold > 0); n++) { if (fold) { nfold = 0; gts_surface_foreach_vertex (s, (GtsFunc) smooth_fold, data); } else gts_surface_foreach_vertex (s, (GtsFunc) smooth_vertex, data); if (verbose) fprintf (stderr, "\rIteration: %10u %3.0f%% ", n, 100.*n/niter); } if (verbose) { fputc ('\n', stderr); gts_surface_print_stats (s, stderr); } gts_surface_write (s, stdout); return 0; }
/* coarsen - produce a coarsened version of the input */ int main (int argc, char * argv[]) { GtsSurface * s; GtsPSurface * ps = NULL; gboolean verbose = FALSE; gboolean progressive = FALSE; gboolean log_cost = FALSE; guint number = 0; gdouble cmax = 0.0; StopOptions stop = NUMBER; CostOptions cost = COST_OPTIMIZED; MidvertexOptions mid = OPTIMIZED; GtsKeyFunc cost_func = NULL; GtsCoarsenFunc coarsen_func = NULL; GtsStopFunc stop_func = NULL; gpointer stop_data = NULL; int c = 0; GtsFile * fp; gdouble fold = PI/180.; GtsVolumeOptimizedParams params = { 0.5, 0.5, 0. }; gpointer coarsen_data = NULL, cost_data = NULL; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"angle", no_argument, NULL, 'a'}, {"progressive", no_argument, NULL, 'p'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, {"number", required_argument, NULL, 'n'}, {"length", no_argument, NULL, 'l'}, {"midvertex", no_argument, NULL, 'm'}, {"cost", required_argument, NULL, 'c'}, {"fold", required_argument, NULL, 'f'}, {"vweight", required_argument, NULL, 'w'}, {"bweight", required_argument, NULL, 'b'}, {"sweight", required_argument, NULL, 's'}, {"log", no_argument, NULL, 'L'} }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvmc:n:lpf:w:b:s:La", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvmc:n:lpf:w:b:s:La"))) { #endif /* not HAVE_GETOPT_LONG */ case 'a': /* angle */ cost = COST_ANGLE; break; case 'L': /* log */ log_cost = TRUE; break; case 'p': /* write progressive surface */ progressive = TRUE; break; case 'n': /* stop by number */ stop = NUMBER; number = atoi (optarg); break; case 'c': /* stop by cost */ stop = COST; cmax = atof (optarg); break; case 'v': /* verbose */ verbose = TRUE; break; case 'm': /* midvertex */ mid = MIDVERTEX; break; case 'l': /* cost is length */ cost = COST_LENGTH; break; case 'f': /* fold angle */ fold = atof (optarg)*PI/180.; break; case 'w': /* volume optimized weight */ params.volume_weight = atof (optarg); break; case 'b': /* boundary optimized weight */ params.boundary_weight = atof (optarg); break; case 's': /* shape optimized weight */ params.shape_weight = atof (optarg); break; case 'h': /* help */ fprintf (stderr, "Usage: coarsen [OPTION] < file.gts\n" "Construct a coarsened version of the input.\n" "\n" " -n N, --number=N stop the coarsening process if the number of\n" " edges was to fall below N\n" " -c C, --cost=C stop the coarsening process if the cost of collapsing\n" " an edge is larger than C\n" " -m --midvertex use midvertex as replacement vertex\n" " default is volume optimized point\n" " -l --length use length^2 as cost function\n" " default is optimized point cost\n" " -f F, --fold=F set maximum fold angle to F degrees\n" " default is one degree\n" " -w W, --vweight=W set weight used for volume optimization\n" " default is 0.5\n" " -b W, --bweight=W set weight used for boundary optimization\n" " default is 0.5\n" " -s W, --sweight=W set weight used for shape optimization\n" " default is 0.0\n" " -p --progressive write progressive surface file\n" " -L --log logs the evolution of the cost\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `coarsen --help' for more information.\n"); return 1; /* failure */ } } /* read surface in */ s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); fp = gts_file_new (stdin); if (gts_surface_read (s, fp)) { fputs ("coarsen: the file on standard input is not a valid GTS file\n", stderr); fprintf (stderr, "stdin:%d:%d: %s\n", fp->line, fp->pos, fp->error); return 1; /* failure */ } /* if verbose on print stats */ if (verbose) { gts_surface_print_stats (s, stderr); fprintf (stderr, "# volume: %g area: %g\n", gts_surface_volume (s), gts_surface_area (s)); } /* select the right coarsening process */ switch (cost) { case COST_OPTIMIZED: cost_func = (GtsKeyFunc) gts_volume_optimized_cost; cost_data = ¶ms; break; case COST_LENGTH: cost_func = NULL; break; case COST_ANGLE: cost_func = (GtsKeyFunc) cost_angle; break; default: g_assert_not_reached (); } switch (mid) { case MIDVERTEX: coarsen_func = NULL; break; case OPTIMIZED: coarsen_func = (GtsCoarsenFunc) gts_volume_optimized_vertex; coarsen_data = ¶ms; break; default: g_assert_not_reached (); } if (log_cost) stop_func = (GtsStopFunc) stop_log_cost; else { switch (stop) { case NUMBER: if (verbose) stop_func = (GtsStopFunc) stop_number_verbose; else stop_func = (GtsStopFunc) gts_coarsen_stop_number; stop_data = &number; break; case COST: if (verbose) stop_func = (GtsStopFunc) stop_cost_verbose; else stop_func = (GtsStopFunc) gts_coarsen_stop_cost; stop_data = &cmax; break; default: g_assert_not_reached (); } } if (progressive) ps = gts_psurface_new (gts_psurface_class (), s, gts_split_class (), cost_func, cost_data, coarsen_func, coarsen_data, stop_func, stop_data, fold); else gts_surface_coarsen (s, cost_func, cost_data, coarsen_func, coarsen_data, stop_func, stop_data, fold); /* if verbose on print stats */ if (verbose) { fputc ('\n', stderr); gts_surface_print_stats (s, stderr); fprintf (stderr, "# volume: %g area: %g\n", gts_surface_volume (s), gts_surface_area (s)); } /* write resulting surface to standard output */ if (progressive) gts_psurface_write (ps, stdout); else gts_surface_write (s, stdout); return 0; /* success */ }
int main (int argc, char * argv[]) { GtsSurface * s; gboolean verbose = FALSE; gdouble threshold; int c = 0; GtsFile * fp; GtsRange angle; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, { NULL } }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hv", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hv"))) { #endif /* not HAVE_GETOPT_LONG */ case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: optimize [OPTION] THRESHOLD < FILE\n" "\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Report bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `optimize --help' for more information.\n"); return 1; /* failure */ } } if (optind >= argc) { /* missing threshold */ fprintf (stderr, "optimize: missing THRESHOLD\n" "Try `optimize --help' for more information.\n"); return 1; /* failure */ } threshold = strtod (argv[optind], NULL); if (threshold < 0.0) { /* threshold must be positive */ fprintf (stderr, "optimize: THRESHOLD must be >= 0.0\n" "Try `optimize --help' for more information.\n"); return 1; /* failure */ } /* read surface in */ s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); fp = gts_file_new (stdin); if (gts_surface_read (s, fp)) { fputs ("optimize: file on standard input is not a valid GTS file\n", stderr); fprintf (stderr, "stdin:%d:%d: %s\n", fp->line, fp->pos, fp->error); return 1; /* failure */ } /* if verbose on print stats */ if (verbose) { gts_surface_print_stats (s, stderr); gts_range_init (&angle); gts_surface_foreach_edge (s, (GtsFunc) angle_stats, &angle); gts_range_update (&angle); fputs ("# angle : ", stderr); gts_range_print (&angle, stderr); fputc ('\n', stderr); } surface_optimize (s, -threshold); /* if verbose on print stats */ if (verbose) { gts_surface_print_stats (s, stderr); gts_range_init (&angle); gts_surface_foreach_edge (s, (GtsFunc) angle_stats, &angle); gts_range_update (&angle); fputs ("# angle : ", stderr); gts_range_print (&angle, stderr); fputc ('\n', stderr); } /* write surface */ gts_surface_write (s, stdout); return 0; /* success */ }
/* inside - check if points are inside a surface */ int main (int argc, char * argv[]) { GtsSurface * s1; GNode * tree1; GtsPoint P; FILE * fptr; GtsFile * fp; int c = 0, cnt = 0; double x,y,z; gboolean verbose = FALSE; gchar * file1, * file2; gboolean is_open1, is_inside; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'} }; int option_index = 0; switch ((c = getopt_long (argc, argv, "shv", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "shv"))) { #endif /* not HAVE_GETOPT_LONG */ case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: gtsinside [OPTION] FILE1 FILE2\n" "Test whether points are inside a closed surface.\n" "FILE1 is a surface file. FILE2 is a text file where each line\n" "contains the three coordinates of a point, separated with blanks.\n" "\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", "https://savannah.nongnu.org/projects/pyformex/"); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `gtsinside --help' for more information.\n"); return 1; /* failure */ } } if (optind >= argc) { /* missing FILE1 */ fprintf (stderr, "gtsinside: missing FILE1\n" "Try `inside --help' for more information.\n"); return 1; /* failure */ } file1 = argv[optind++]; if (optind >= argc) { /* missing FILE2 */ fprintf (stderr, "gtsinside: missing FILE2\n" "Try `gtsinside --help' for more information.\n"); return 1; /* failure */ } file2 = argv[optind++]; /* open first file */ if ((fptr = fopen (file1, "rt")) == NULL) { fprintf (stderr, "gtsinside: can not open file `%s'\n", file1); return 1; } /* reads in first surface file */ s1 = GTS_SURFACE (gts_object_new (GTS_OBJECT_CLASS (gts_surface_class ()))); fp = gts_file_new (fptr); if (gts_surface_read (s1, fp)) { fprintf (stderr, "gtsinside: `%s' is not a valid GTS surface file\n", file1); fprintf (stderr, "%s:%d:%d: %s\n", file1, fp->line, fp->pos, fp->error); return 1; } gts_file_destroy (fp); fclose (fptr); /* open second file */ if ((fptr = fopen (file2, "rt")) == NULL) { fprintf (stderr, "gtsinside: can not open file `%s'\n", file2); return 1; } /* display summary information about the surface */ if (verbose) { gts_surface_print_stats (s1, stderr); } /* check that the surface is an orientable manifold */ if (!gts_surface_is_orientable (s1)) { fprintf (stderr, "gtsinside: surface `%s' is not an orientable manifold\n", file1); return 1; } /* build bounding box tree for the surface */ tree1 = gts_bb_tree_surface (s1); is_open1 = gts_surface_volume (s1) < 0. ? TRUE : FALSE; /* scan file 2 for points and determine if it they are inside surface */ while ( fscanf(fptr, "%lg %lg %lg", &x, &y, &z) == 3 ) { P.x = x; P.y = y; P.z = z; is_inside = gts_point_is_inside_surface(&P,tree1,is_open1); if (is_inside) printf("%d\n",cnt); //printf("Point %d: %lf, %lf, %lf: %d\n",cnt,P.x,P.y,P.z,is_inside); cnt++; } if ( !feof(fptr) ) { fprintf (stderr, "gtsinside: error while reading points from file `%s'\n", file2); return 1; } fclose (fptr); /* destroy surface */ gts_object_destroy (GTS_OBJECT (s1)); /* destroy bounding box tree (including bounding boxes) */ gts_bb_tree_destroy (tree1, TRUE); return 0; }
/* set - compute set operations between surfaces */ int main (int argc, char * argv[]) { GtsSurface * s1, * s2, * s3; GtsSurfaceInter * si; GNode * tree1, * tree2; FILE * fptr; GtsFile * fp; int c = 0; gboolean verbose = TRUE; gboolean inter = FALSE; gboolean check_self_intersection = FALSE; gchar * operation, * file1, * file2; gboolean closed = TRUE, is_open1, is_open2; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"inter", no_argument, NULL, 'i'}, {"self", no_argument, NULL, 's'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'} }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvis", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvis"))) { #endif /* not HAVE_GETOPT_LONG */ case 's': /* self */ check_self_intersection = TRUE; break; case 'i': /* inter */ inter = TRUE; break; case 'v': /* verbose */ verbose = FALSE; break; case 'h': /* help */ fprintf (stderr, "Usage: set [OPTION] OPERATION FILE1 FILE2\n" "Compute set operations between surfaces, where OPERATION is either.\n" "union, inter, diff.\n" "\n" " -i --inter output an OOGL (Geomview) representation of the curve\n" " intersection of the surfaces\n" " -s --self checks that the surfaces are not self-intersecting\n" " if one of them is, the set of self-intersecting faces\n" " is written (as a GtsSurface) on standard output\n" " -v --verbose do not print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `set --help' for more information.\n"); return 1; /* failure */ } } if (optind >= argc) { /* missing OPERATION */ fprintf (stderr, "set: missing OPERATION\n" "Try `set --help' for more information.\n"); return 1; /* failure */ } operation = argv[optind++]; if (optind >= argc) { /* missing FILE1 */ fprintf (stderr, "set: missing FILE1\n" "Try `set --help' for more information.\n"); return 1; /* failure */ } file1 = argv[optind++]; if (optind >= argc) { /* missing FILE2 */ fprintf (stderr, "set: missing FILE2\n" "Try `set --help' for more information.\n"); return 1; /* failure */ } file2 = argv[optind++]; /* open first file */ if ((fptr = fopen (file1, "rt")) == NULL) { fprintf (stderr, "set: can not open file `%s'\n", file1); return 1; } /* reads in first surface file */ s1 = GTS_SURFACE (gts_object_new (GTS_OBJECT_CLASS (gts_surface_class ()))); fp = gts_file_new (fptr); if (gts_surface_read (s1, fp)) { fprintf (stderr, "set: `%s' is not a valid GTS surface file\n", file1); fprintf (stderr, "%s:%d:%d: %s\n", file1, fp->line, fp->pos, fp->error); return 1; } gts_file_destroy (fp); fclose (fptr); /* open second file */ if ((fptr = fopen (file2, "rt")) == NULL) { fprintf (stderr, "set: can not open file `%s'\n", file2); return 1; } /* reads in second surface file */ s2 = GTS_SURFACE (gts_object_new (GTS_OBJECT_CLASS (gts_surface_class ()))); fp = gts_file_new (fptr); if (gts_surface_read (s2, fp)) { fprintf (stderr, "set: `%s' is not a valid GTS surface file\n", file2); fprintf (stderr, "%s:%d:%d: %s\n", file2, fp->line, fp->pos, fp->error); return 1; } gts_file_destroy (fp); fclose (fptr); /* display summary information about both surfaces */ if (verbose) { gts_surface_print_stats (s1, stderr); gts_surface_print_stats (s2, stderr); } /* check that the surfaces are orientable manifolds */ if (!gts_surface_is_orientable (s1)) { fprintf (stderr, "set: surface `%s' is not an orientable manifold\n", file1); return 1; } if (!gts_surface_is_orientable (s2)) { fprintf (stderr, "set: surface `%s' is not an orientable manifold\n", file2); return 1; } /* check that the surfaces are not self-intersecting */ if (check_self_intersection) { GtsSurface * self_intersects; self_intersects = gts_surface_is_self_intersecting (s1); if (self_intersects != NULL) { fprintf (stderr, "set: surface `%s' is self-intersecting\n", file1); if (verbose) gts_surface_print_stats (self_intersects, stderr); gts_surface_write (self_intersects, stdout); gts_object_destroy (GTS_OBJECT (self_intersects)); return 1; } self_intersects = gts_surface_is_self_intersecting (s2); if (self_intersects != NULL) { fprintf (stderr, "set: surface `%s' is self-intersecting\n", file2); if (verbose) gts_surface_print_stats (self_intersects, stderr); gts_surface_write (self_intersects, stdout); gts_object_destroy (GTS_OBJECT (self_intersects)); return 1; } } /* build bounding box tree for first surface */ tree1 = gts_bb_tree_surface (s1); is_open1 = gts_surface_volume (s1) < 0. ? TRUE : FALSE; /* build bounding box tree for second surface */ tree2 = gts_bb_tree_surface (s2); is_open2 = gts_surface_volume (s2) < 0. ? TRUE : FALSE; si = gts_surface_inter_new (gts_surface_inter_class (), s1, s2, tree1, tree2, is_open1, is_open2); g_assert (gts_surface_inter_check (si, &closed)); if (!closed) { fprintf (stderr, "set: the intersection of `%s' and `%s' is not a closed curve\n", file1, file2); return 1; } s3 = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); if (!strcmp (operation, "union")) { gts_surface_inter_boolean (si, s3, GTS_1_OUT_2); gts_surface_inter_boolean (si, s3, GTS_2_OUT_1); } else if (!strcmp (operation, "inter")) { gts_surface_inter_boolean (si, s3, GTS_1_IN_2); gts_surface_inter_boolean (si, s3, GTS_2_IN_1); } else if (!strcmp (operation, "diff")) { gts_surface_inter_boolean (si, s3, GTS_1_OUT_2); gts_surface_inter_boolean (si, s3, GTS_2_IN_1); gts_surface_foreach_face (si->s2, (GtsFunc) gts_triangle_revert, NULL); gts_surface_foreach_face (s2, (GtsFunc) gts_triangle_revert, NULL); } else { fprintf (stderr, "set: operation `%s' unknown\n" "Try `set --help' for more information.\n", operation); return 1; } /* check that the resulting surface is not self-intersecting */ if (check_self_intersection) { GtsSurface * self_intersects; self_intersects = gts_surface_is_self_intersecting (s3); if (self_intersects != NULL) { fprintf (stderr, "set: the resulting surface is self-intersecting\n"); if (verbose) gts_surface_print_stats (self_intersects, stderr); gts_surface_write (self_intersects, stdout); gts_object_destroy (GTS_OBJECT (self_intersects)); return 1; } } /* display summary information about the resulting surface */ if (verbose) gts_surface_print_stats (s3, stderr); /* write resulting surface to standard output */ if (inter) { printf ("LIST {\n"); g_slist_foreach (si->edges, (GFunc) write_edge, stdout); printf ("}\n"); } else { GTS_POINT_CLASS (gts_vertex_class ())->binary = TRUE; gts_surface_write (s3, stdout); } /* destroy surfaces */ gts_object_destroy (GTS_OBJECT (s1)); gts_object_destroy (GTS_OBJECT (s2)); gts_object_destroy (GTS_OBJECT (s3)); gts_object_destroy (GTS_OBJECT (si)); /* destroy bounding box trees (including bounding boxes) */ gts_bb_tree_destroy (tree1, TRUE); gts_bb_tree_destroy (tree2, TRUE); return 0; }
/* sphere - generate a triangulated unit sphere by recursive subdivision. First approximation is an isocahedron; each level of refinement increases the number of triangles by a factor of 4. */ int main (int argc, char * argv[]) { GtsSurface * s; gboolean verbose = FALSE; guint level=4; int c = 0; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, { NULL } }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hv", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hv"))) { #endif /* not HAVE_GETOPT_LONG */ case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: sphere [OPTION] [level]\n" "Generate a triangulated unit sphere by recursive subdivision.\n" "First approximation is an isocahedron; each level of refinement\n" "increases the number of triangles by a factor of 4.\n" "level must be a positive integer setting the recursion level\n" "(geodesation order), default is 4.\n" "\n" "Documentation: http://mathworld.wolfram.com/GeodesicDome.html\n" "\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `sphere --help' for more information.\n"); return 1; /* failure */ } } /* read level */ if (optind < argc) level = atoi(argv[optind]); /* generate triangulated sphere */ s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); gts_surface_generate_sphere (s, level); /* if verbose on print stats */ if (verbose) gts_surface_print_stats (s, stderr); /* write generating surface to standard output */ gts_surface_write (s, stdout); return 0; /* success */ }
int main (int argc, char * argv[]) { GtsSurface * s; GtsFile * fp; GtsFace * first = NULL; int c = 0; gboolean verbose = FALSE; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); colormap = colormap_red_blue (); /* default */ /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"cmap", required_argument, NULL, 'c'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, { NULL } }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvc:", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvc:"))) { #endif /* not HAVE_GETOPT_LONG */ case 'c': { /* cmap */ FILE * fptr = fopen (optarg, "rt"); if (!fptr) { fprintf (stderr, "traverse: cannot open colormap file `%s'.\n", optarg); return 1; } colormap = colormap_read (fptr); fclose (fptr); break; } case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: traverse [OPTION] < file.gts > file.oogl\n" "Output an OOGL (geomview) surface colored according to the (graph) distance\n" "from a random face to the others\n" "\n" " -c FILE --cmap=FILE load FILE as colormap\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `traverse --help' for more information.\n"); return 1; /* failure */ } } s = gts_surface_new (gts_surface_class (), GTS_FACE_CLASS (depth_face_class ()), gts_edge_class (), gts_vertex_class ()); fp = gts_file_new (stdin); if (gts_surface_read (s, fp)) { fputs ("traverse: file on standard input is not a valid GTS file\n", stderr); fprintf (stderr, "stdin:%d:%d: %s\n", fp->line, fp->pos, fp->error); return 1; /* failure */ } if (verbose) gts_surface_print_stats (s, stderr); gts_surface_foreach_face (s, (GtsFunc) pick_first_face, &first); gts_range_init (&depth_range); if (first) { GtsSurfaceTraverse * t = gts_surface_traverse_new (s, first); GtsFace * f; guint level; while ((f = gts_surface_traverse_next (t, &level))) { DEPTH_FACE (f)->depth = level; gts_range_add_value (&depth_range, level); } gts_surface_traverse_destroy (t); } gts_range_update (&depth_range); if (verbose) { fputs ("distance: ", stderr); gts_range_print (&depth_range, stderr); fputc ('\n', stderr); } gts_surface_write_oogl (s, stdout); return 0; }
int main (int argc, char * argv[]) { GtsSurface * s; gboolean verbose = FALSE; int c = 0; if (!setlocale (LC_ALL, "POSIX")) g_warning ("cannot set locale to POSIX"); /* parse options using getopt */ while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hv", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hv"))) { #endif /* not HAVE_GETOPT_LONG */ case 'v': /* verbose */ verbose = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: merge [OPTION] file1.gts file2.gts ...\n" "Merges files and outputs the resulting GTS surface.\n" "\n" " -v --verbose print statistics about the surface\n" " -h --help display this help and exit\n" "\n" "Reports bugs to %s\n", GTS_MAINTAINER); return 0; /* success */ break; case '?': /* wrong options */ fprintf (stderr, "Try `merge --help' for more information.\n"); return 1; /* failure */ } } s = GTS_SURFACE (gts_object_new (GTS_OBJECT_CLASS (gts_surface_class ()))); while (optind < argc) { FILE * f = fopen (argv[optind], "r"); GtsFile * fp; GtsSurface * s1; if (f == NULL) { fprintf (stderr, "merge: can not open file `%s'\n", argv[optind]); return 1; } fp = gts_file_new (f); s1 = GTS_SURFACE (gts_object_new (GTS_OBJECT_CLASS (gts_surface_class ()))); if (gts_surface_read (s1, fp)) { fprintf (stderr, "merge: `%s' is not a valid GTS surface file\n", argv[optind]); fprintf (stderr, "%s:%d:%d: %s\n", argv[optind], fp->line, fp->pos, fp->error); return 1; } gts_surface_merge (s, s1); gts_object_destroy (GTS_OBJECT (s1)); gts_file_destroy (fp); fclose (f); optind++; } if (verbose) gts_surface_print_stats (s, stderr); gts_surface_write (s, stdout); return 0; }
int main (int argc, char * argv[]) { int c = 0; gboolean verbose = FALSE; gboolean revert = FALSE; GtsSurface * s; GtsFile * fp; while (c != EOF) { #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"revert", no_argument, NULL, 'r'}, {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'} }; int option_index = 0; switch ((c = getopt_long (argc, argv, "hvr", long_options, &option_index))) { #else /* not HAVE_GETOPT_LONG */ switch ((c = getopt (argc, argv, "hvr"))) { #endif /* not HAVE_GETOPT_LONG */ case 'r': /* revert */ revert = TRUE; break; case 'h': /* help */ fprintf (stderr, "Usage: gts2stl [OPTION]... < input.gts > output.stl\n" "Convert a GTS file to STL format.\n" "\n" " -r, --revert revert face normals\n" " -v, --verbose display surface statistics\n" " -h, --help display this help and exit\n" "\n" "Report bugs to %s\n", GTS_MAINTAINER); return 0; break; case 'v': verbose = TRUE; break; case '?': /* wrong options */ fprintf (stderr, "Try `gts2stl --help' for more information.\n"); return 1; } } s = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ()); fp = gts_file_new (stdin); if (gts_surface_read (s, fp)) { fputs ("gts2stl: file on standard input is not a valid GTS file\n", stderr); fprintf (stderr, "stdin:%d:%d: %s\n", fp->line, fp->pos, fp->error); return 1; /* failure */ } if (revert) gts_surface_foreach_face (s, (GtsFunc) gts_triangle_revert, NULL); if (verbose) gts_surface_print_stats (s, stderr); puts ("solid"); gts_surface_foreach_face (s, (GtsFunc) write_face, NULL); puts ("endsolid"); return 0; }