Some comments and minor fixes to admesh code by Andy Doucette

This commit is contained in:
Alessandro Ranellucci 2013-07-31 00:01:53 +02:00
parent 1b4878f305
commit dd935e2036
3 changed files with 14 additions and 3 deletions

View File

@ -82,6 +82,7 @@ stl_check_facets_exact(stl_file *stl)
{ {
facet = stl->facet_start[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], if( !memcmp(&facet.vertex[0], &facet.vertex[1],
sizeof(stl_vertex)) sizeof(stl_vertex))
|| !memcmp(&facet.vertex[1], &facet.vertex[2], || !memcmp(&facet.vertex[1], &facet.vertex[2],

View File

@ -121,9 +121,13 @@ stl_fix_normal_directions(stl_file *stl)
facet_num = 0; facet_num = 0;
//If normal vector is not within tolerance and backwards:
//Arbitrarily starts at face 0. If this one is wrong, we're screwed. Thankfully, the chances
// of it being wrong randomly are low if most of the triangles are right:
if(stl_check_normal_vector(stl, 0, 0) == 2) if(stl_check_normal_vector(stl, 0, 0) == 2)
stl_reverse_facet(stl, 0); stl_reverse_facet(stl, 0);
//Say that we've fixed this facet:
norm_sw[facet_num] = 1; norm_sw[facet_num] = 1;
/* edge_num = 0; /* edge_num = 0;
vnot = stl->neighbors_start[0].which_vertex_not[0]; vnot = stl->neighbors_start[0].which_vertex_not[0];
@ -133,19 +137,24 @@ stl_fix_normal_directions(stl_file *stl)
for(;;) for(;;)
{ {
/* Add neighbors_to_list. */ /* Add neighbors_to_list. */
//Add unconnected neighbors to the list:a
for(j = 0; j < 3; j++) for(j = 0; j < 3; j++)
{ {
/* Reverse the neighboring facets if necessary. */ /* Reverse the neighboring facets if necessary. */
if(stl->neighbors_start[facet_num].which_vertex_not[j] > 2) if(stl->neighbors_start[facet_num].which_vertex_not[j] > 2)
{ {
// If the facet has a neighbor that is -1, it means that edge isn't shared by another
// facet.
if(stl->neighbors_start[facet_num].neighbor[j] != -1) if(stl->neighbors_start[facet_num].neighbor[j] != -1)
{ {
stl_reverse_facet stl_reverse_facet
(stl, stl->neighbors_start[facet_num].neighbor[j]); (stl, stl->neighbors_start[facet_num].neighbor[j]);
} }
} }
//If this edge of the facet is connected:
if(stl->neighbors_start[facet_num].neighbor[j] != -1) if(stl->neighbors_start[facet_num].neighbor[j] != -1)
{ {
//If we haven't fixed this facet yet, add it to the list:
if(norm_sw[stl->neighbors_start[facet_num].neighbor[j]] != 1) if(norm_sw[stl->neighbors_start[facet_num].neighbor[j]] != 1)
{ {
/* Add node to beginning of list. */ /* Add node to beginning of list. */
@ -170,14 +179,14 @@ stl_fix_normal_directions(stl_file *stl)
head->next = head->next->next; head->next = head->next->next;
free(temp); free(temp);
} }
else else //if we ran out of facets to fix:
{ {
/* All of the facets in this part have been fixed. */ /* All of the facets in this part have been fixed. */
stl->stats.number_of_parts += 1; stl->stats.number_of_parts += 1;
/* There are (checked-checked_before) facets */ /* There are (checked-checked_before) facets */
/* in part stl->stats.number_of_parts */ /* in part stl->stats.number_of_parts */
checked_before = checked; checked_before = checked;
if(checked == stl->stats.number_of_facets) if(checked >= stl->stats.number_of_facets)
{ {
/* All of the facets have been checked. Bail out. */ /* All of the facets have been checked. Bail out. */
break; break;

View File

@ -198,6 +198,7 @@ stl_print_neighbors(stl_file *stl, char *file)
stl->neighbors_start[i].neighbor[2], stl->neighbors_start[i].neighbor[2],
(int)stl->neighbors_start[i].which_vertex_not[2]); (int)stl->neighbors_start[i].which_vertex_not[2]);
} }
fclose(fp);
} }
static void static void