Пример #1
0
void
stl_check_facets_exact(stl_file *stl) {
  /* This function builds the neighbors list.  No modifications are made
   *  to any of the facets.  The edges are said to match only if all six
   *  floats of the first edge matches all six floats of the second edge.
   */

  stl_hash_edge  edge;
  stl_facet      facet;
  int            i;
  int            j;

  if (stl->error) return;

  stl->stats.connected_edges = 0;
  stl->stats.connected_facets_1_edge = 0;
  stl->stats.connected_facets_2_edge = 0;
  stl->stats.connected_facets_3_edge = 0;

  stl_initialize_facet_check_exact(stl);

  for(i = 0; i < stl->stats.number_of_facets; i++) {
    facet = stl->facet_start[i];

    /* If any two of the three vertices are found to be exactally the same, call them degenerate and remove the facet. */
    if(   !memcmp(&facet.vertex[0], &facet.vertex[1],
                  sizeof(stl_vertex))
          || !memcmp(&facet.vertex[1], &facet.vertex[2],
                     sizeof(stl_vertex))
          || !memcmp(&facet.vertex[0], &facet.vertex[2],
                     sizeof(stl_vertex))) {
      stl->stats.degenerate_facets += 1;
      stl_remove_facet(stl, i);
      i--;
      continue;

    }
    for(j = 0; j < 3; j++) {
      edge.facet_number = i;
      edge.which_edge = j;
      stl_load_edge_exact(stl, &edge, &facet.vertex[j],
                          &facet.vertex[(j + 1) % 3]);

      insert_hash_edge(stl, edge, stl_match_neighbors_exact);
    }
  }
  stl_free_edges(stl);
}
Пример #2
0
// This function builds the neighbors list.  No modifications are made
// to any of the facets.  The edges are said to match only if all six
// floats of the first edge matches all six floats of the second edge.
void stl_check_facets_exact(stl_file *stl)
{
  if (stl->error)
	  return;

  stl->stats.connected_edges = 0;
  stl->stats.connected_facets_1_edge = 0;
  stl->stats.connected_facets_2_edge = 0;
  stl->stats.connected_facets_3_edge = 0;

  // If any two of the three vertices are found to be exactally the same, call them degenerate and remove the facet.
  // Do it before the next step, as the next step stores references to the face indices in the hash tables and removing a facet
  // will break the references.
  for (int i = 0; i < stl->stats.number_of_facets;) {
	  stl_facet &facet = stl->facet_start[i];
	  if (facet.vertex[0] == facet.vertex[1] || facet.vertex[1] == facet.vertex[2] || facet.vertex[0] == facet.vertex[2]) {
		  // Remove the degenerate facet.
		  facet = stl->facet_start[--stl->stats.number_of_facets];
		  stl->stats.facets_removed += 1;
		  stl->stats.degenerate_facets += 1;
	  } else
		  ++ i;
  }

  // Connect neighbor edges.
  stl_initialize_facet_check_exact(stl);
  for (int i = 0; i < stl->stats.number_of_facets; i++) {
	const stl_facet &facet = stl->facet_start[i];
    for (int j = 0; j < 3; j++) {
	  stl_hash_edge  edge;
	  edge.facet_number = i;
      edge.which_edge = j;
      stl_load_edge_exact(stl, &edge, &facet.vertex[j], &facet.vertex[(j + 1) % 3]);
      insert_hash_edge(stl, edge, stl_record_neighbors);
    }
  }
  stl_free_edges(stl);

#if 0
  printf("Number of faces: %d, number of manifold edges: %d, number of connected edges: %d, number of unconnected edges: %d\r\n", 
    stl->stats.number_of_facets, stl->stats.number_of_facets * 3, 
    stl->stats.connected_edges, stl->stats.number_of_facets * 3 - stl->stats.connected_edges);
#endif
}