// TODO: Is there a better way to draw stuff void ofxGtsSurface::draw(DrawType type) { if(!loaded) { //ofLog(OF_LOG_NOTICE, "Gts surface not loaded"); return; } GtsFace * first = NULL; // TODO: Do we really need to do this just to get the first face? gts_surface_foreach_face (surface, (GtsFunc) pick_first_face, &first); if (first) { GtsSurfaceTraverse * t = gts_surface_traverse_new (surface, first); GtsFace * f; guint level; glBegin((type == TRIANGLES) ? GL_TRIANGLE_STRIP : GL_LINES); while ((f = gts_surface_traverse_next (t, &level))) { // Edge 1 GtsPoint p1 = f->triangle.e1->segment.v1->p; GtsPoint p2 = f->triangle.e1->segment.v2->p; // Edge 2 GtsPoint p3 = f->triangle.e2->segment.v1->p; GtsPoint p4 = f->triangle.e2->segment.v2->p; // Edge 3 GtsPoint p5 = f->triangle.e3->segment.v1->p; GtsPoint p6 = f->triangle.e3->segment.v2->p; // TODO: Figure out what is going on with the normals if(type==TRIANGLES) { ofPoint normal = calculateNormal(p1, p2, p3); glNormal3f(normal.x, normal.y, normal.z); } glVertex3f(p1.x, p1.y, p1.z); glVertex3f(p2.x, p2.y, p2.z); glVertex3f(p3.x, p3.y, p3.z); if(type==TRIANGLES) { ofPoint normal = calculateNormal(p4, p5, p6); glNormal3f(normal.x, normal.y, normal.z); } glVertex3f(p4.x, p4.y, p4.z); glVertex3f(p5.x, p5.y, p5.z); glVertex3f(p6.x, p6.y, p6.z); } glEnd(); gts_surface_traverse_destroy (t); } }
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; }