コード例 #1
0
ファイル: ofxGtsSurface.cpp プロジェクト: gnimmel/ofxGts
void ofxGtsSurface::setup() {
	surface = gts_surface_new(GTS_SURFACE_CLASS(gts_surface_class()), 
							  GTS_FACE_CLASS(gts_nface_class()), 
							  GTS_EDGE_CLASS(gts_nedge_class()), 
							  GTS_VERTEX_CLASS(gts_nvertex_class()));
	loaded = true;
}
コード例 #2
0
ファイル: ofxGtsSurface.cpp プロジェクト: gnimmel/ofxGts
void ofxGtsSurface::setup(string filename) {

	FILE * fptr;
	GtsFile * fp;
	
	string filePath = ofToDataPath(filename);
	
	/* open first file */
	if ((fptr = fopen (filePath.c_str(), "rt")) == NULL) {		
		ofLog(OF_LOG_ERROR, "Cannot open file: " + filePath);
		return;
	}
	/* reads in first surface file */
	surface = gts_surface_new(GTS_SURFACE_CLASS(gts_surface_class()), 
							  GTS_FACE_CLASS(gts_nface_class()), 
							  GTS_EDGE_CLASS(gts_nedge_class()), 
							  GTS_VERTEX_CLASS(gts_nvertex_class()));
	fp = gts_file_new(fptr);
	if (gts_surface_read (surface, fp)) {
		ofLog(OF_LOG_ERROR, filePath + " is not a valid GTS surface file");
		loaded = false;
		gts_object_destroy(GTS_OBJECT(surface));
	} else {
		ofLog(OF_LOG_NOTICE, "Gts surface file read: " + filePath);
		loaded = true;
	}
	gts_file_destroy (fp);
	fclose (fptr);	
}
コード例 #3
0
ファイル: ofxGtsSurface.cpp プロジェクト: gnimmel/ofxGts
void ofxGtsSurface::createBoolean(ofxGtsSurface &source, ofxGtsSurface &result, BooleanOperation operation) {

	result.surface = gts_surface_new(GTS_SURFACE_CLASS(gts_surface_class()), 
									 GTS_FACE_CLASS(gts_nface_class()), 
									 GTS_EDGE_CLASS(gts_nedge_class()), 
									 GTS_VERTEX_CLASS(gts_nvertex_class()));
	switch(operation) {
			
		case BOOLEAN_INTERSECTION:
			gts_surface_inter_boolean(si, result.surface, GTS_1_IN_2);
			gts_surface_inter_boolean(si, result.surface, GTS_2_IN_1);
			result.loaded = true;
			break;
			
		case BOOLEAN_UNION:
			gts_surface_inter_boolean(si, result.surface, GTS_1_OUT_2);
			gts_surface_inter_boolean(si, result.surface, GTS_2_OUT_1);
			result.loaded = true;
			break;
			
		case BOOLEAN_DIFFERENCE:
			gts_surface_inter_boolean(si, result.surface, GTS_1_OUT_2);
			gts_surface_inter_boolean(si, result.surface, GTS_2_IN_1);
			gts_surface_foreach_face(si->s2, (GtsFunc)gts_triangle_revert, NULL);
			gts_surface_foreach_face(source.surface, (GtsFunc)gts_triangle_revert, NULL);
			result.loaded = true;
			break;
			
		case BOOLEAN_REVERSE_DIFFERENCE:
			// TODO: Reverse difference can cause crashes, is there a way to catch them?
			gts_surface_inter_boolean(si, result.surface, GTS_2_OUT_1);
			gts_surface_inter_boolean(si, result.surface, GTS_1_IN_2);
			gts_surface_foreach_face(si->s1, (GtsFunc)gts_triangle_revert, NULL);
			gts_surface_foreach_face(surface, (GtsFunc)gts_triangle_revert, NULL);
			result.loaded = true;
			break;
	}
	
}
コード例 #4
0
ファイル: cartesian.c プロジェクト: ClavinSBU/gts
static GtsSurface * cartesian_grid_triangulate_holes (CartesianGrid * grid,
						      GtsSurface * s)
{
  GtsVertex * v1, * v2, * v3, * v4;
  GtsEdge * e1, * e2, * e3, * e4, * e5;
  gdouble w, h;
  GtsSurface * box;
  GSList * constraints = NULL, * vertices = NULL, * i;
  gpointer data[2];

  g_return_val_if_fail (grid != NULL, NULL);
  g_return_val_if_fail (s != NULL, NULL);

  /* build enclosing box */
  w = grid->xmax - grid->xmin;
  h = grid->ymax - grid->ymin;
  v1 = gts_vertex_new (s->vertex_class, grid->xmin - w, grid->ymin - h, 0.);
  v2 = gts_vertex_new (s->vertex_class, grid->xmax + w, grid->ymin - h, 0.);
  v3 = gts_vertex_new (s->vertex_class, grid->xmax + w, grid->ymax + h, 0.);
  v4 = gts_vertex_new (s->vertex_class, grid->xmin - w, grid->ymax + h, 0.);

  e1 = gts_edge_new (s->edge_class, v1, v2);
  e2 = gts_edge_new (s->edge_class, v2, v3);
  e3 = gts_edge_new (s->edge_class, v3, v4);
  e4 = gts_edge_new (s->edge_class, v4, v1);
  e5 = gts_edge_new (s->edge_class, v1, v3);

  box = gts_surface_new (GTS_SURFACE_CLASS (GTS_OBJECT (s)->klass), 
			 s->face_class, 
			 s->edge_class, 
			 s->vertex_class);
  gts_surface_add_face (box, gts_face_new (s->face_class, e1, e2, e5));
  gts_surface_add_face (box, gts_face_new (s->face_class, e3, e4, e5));

  /* build vertex and constraint list from the boundaries of the input
     surface s */
  data[0] = s;
  data[1] = &constraints;
  gts_surface_foreach_edge (s, (GtsFunc) build_constraint_list, data);
  vertices = gts_vertices_from_segments (constraints);

  /* triangulate holes */
  i = vertices;
  while (i) {
    g_assert (!gts_delaunay_add_vertex (box, i->data, NULL));
    i = i->next;
  }
  g_slist_free (vertices);

  i = constraints;
  while (i) {
    g_assert (!gts_delaunay_add_constraint (box, i->data));
    i = i->next;
  }

  /* destroy corners of the enclosing box */
  gts_allow_floating_vertices = TRUE;
  gts_object_destroy (GTS_OBJECT (v1));
  gts_object_destroy (GTS_OBJECT (v2));
  gts_object_destroy (GTS_OBJECT (v3));
  gts_object_destroy (GTS_OBJECT (v4));
  gts_allow_floating_vertices = FALSE;

  /* remove parts of the mesh which are not holes */
  i = constraints;
  while (i) {
    edge_mark_as_hole (i->data, box);
    i = i->next;
  }
  g_slist_free (constraints);

  /* remove marked and duplicate faces */
  gts_surface_foreach_face_remove (box, (GtsFunc) face_is_marked, NULL);

  /* box now contains only the triangulated holes. */
  return box;
}