Skip to content

Commit

Permalink
don't do unnecessary work in DMesh3.FindTriangle. Add some utility fu…
Browse files Browse the repository at this point in the history
…nctions in other classes.
  • Loading branch information
rms80 committed Aug 31, 2017
1 parent fb372dd commit 77d126e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
13 changes: 7 additions & 6 deletions mesh/DMesh3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,16 +1084,17 @@ public int FindTriangle(int a, int b, int c)
if (eid == InvalidID)
return InvalidID;
int ei = 4 * eid;
int ti = 3*edges[ei + 2];
Index3i tri = new Index3i(triangles[ti], triangles[ti + 1], triangles[ti + 2]);
if (IndexUtil.is_same_triangle(a, b, c, ref tri))

// triangles attached to edge [a,b] must contain verts a and b...
int ti = 3 * edges[ei + 2];
if (triangles[ti] == c || triangles[ti + 1] == c || triangles[ti + 2] == c )
return edges[ei + 2];
if ( edges[ei + 3] != InvalidID ) {
if (edges[ei + 3] != InvalidID) {
ti = 3 * edges[ei + 3];
tri.a = triangles[ti]; tri.b = triangles[ti + 1]; tri.c = triangles[ti + 2];
if (IndexUtil.is_same_triangle(a, b, c, ref tri))
if (triangles[ti] == c || triangles[ti + 1] == c || triangles[ti + 2] == c )
return edges[ei + 3];
}

return InvalidID;
}

Expand Down
13 changes: 13 additions & 0 deletions mesh/DSubmesh3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public void MapVerticesToSubmesh(int[] vertices)
}


public int MapEdgeToSubmesh(int base_eid)
{
Index2i base_ev = BaseMesh.GetEdgeV(base_eid);
Index2i sub_ev = MapVerticesToSubmesh(base_ev);
return SubMesh.FindEdge(sub_ev.a, sub_ev.b);
}
public void MapEdgesToSubmesh(int[] edges)
{
for (int i = 0; i < edges.Length; ++i)
edges[i] = MapEdgeToSubmesh(edges[i]);
}


public void ComputeBoundaryInfo(int[] subTriangles) {
ComputeBoundaryInfo(subTriangles, subTriangles.Length);
}
Expand Down
11 changes: 11 additions & 0 deletions mesh/MeshConstraintUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,16 @@ public static void PreserveBoundaryLoops(Remesher r)
}



public static void AddTrackedEdges(MeshConstraints cons, int[] edges, int setID)
{
EdgeConstraint ec = EdgeConstraint.Unconstrained;
ec.TrackingSetID = setID;
for ( int i = 0; i < edges.Length; ++i ) {
cons.SetOrUpdateEdgeConstraint(edges[i], ec);
}
}


}
}
16 changes: 16 additions & 0 deletions mesh_selection/MeshBoundaryLoops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ public Index2i FindVertexIndex(int vID)
}



/// <summary>
/// find the loop that contains an edge, or return -1
/// </summary>
public int FindLoopContainingEdge(int eid)
{
int N = Loops.Count;
for (int li = 0; li < N; ++li) {
if (Loops[li].Edges.Contains(eid))
return li;
}
return -1;
}



/// <summary>
/// Find the set of boundary EdgeLoops. Note that if we encounter topological
/// issues, we will throw MeshBoundaryLoopsException w/ more info (if possible)
Expand Down
17 changes: 16 additions & 1 deletion queries/MeshValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public enum ValidationStatus
NotBoundaryEdge,

VerticesNotConnectedByEdge,
IncorrectLoopOrientation
IncorrectLoopOrientation,

DuplicateTriangles
}


Expand Down Expand Up @@ -70,5 +72,18 @@ public static ValidationStatus IsBoundaryLoop(DMesh3 mesh, EdgeLoop loop)
}



public static ValidationStatus HasDuplicateTriangles(DMesh3 mesh)
{
foreach (int tid in mesh.TriangleIndices()) {
Index3i nbrs = mesh.GetTriNeighbourTris(tid);
if (nbrs.a == nbrs.b && nbrs.b == nbrs.c && nbrs.a != DMesh3.InvalidID)
return ValidationStatus.DuplicateTriangles;
}

return ValidationStatus.Ok;
}


}
}

0 comments on commit 77d126e

Please sign in to comment.