Mesh GetNakedEdges Fails

I’ve run into a mesh geometry that is causing the call to Mesh.GetNakedEdges to fail to return, causing Rhino to become non-responsive. Although I would say the mesh not of an especially good quality, having many degenerate faces, Mesh.IsValid still returns true. Below is a sample command that demonstrates the issue, along with the problem geometry I am attaching. It would be ideal of course if GetNakeEdges could return the desired edges or at least null, but failing that is there was a way to tell apriori that this mesh will pose a problem for GetNakedEdges?

Thanks, Larry

public class RhinoMeshNakedEdgeTest : Command
{
	public override string EnglishName => "GetMeshNakedEdges";

	protected override Result RunCommand(RhinoDoc doc, RunMode mode)
	{
		if (RhinoGet.GetOneObject("Select mesh to get naked edges", false, ObjectType.Mesh, out ObjRef objRef) == Result.Success)
		{
			var nakedEdges = objRef.Mesh()?.GetNakedEdges();
			return nakedEdges != null ? Result.Success : Result.Failure; ;
		}
		return Result.Failure;
	}
}

MeshCantGetNakedEdges.3dm (7.6 MB)

Model Attached

Hi @LarryL,

Mesh.GetNakedEdges goes out to lunch because the method tries to join all the edges (e.g. line segments) into polylines. In the case of this mesh, there are a lot of naked edges - 472978 - so joining take a long time.

If you are just looking to find the topological edges that are naked, you can do this:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var rc = RhinoGet.GetOneObject("Select mesh to get naked edges", false, ObjectType.Mesh, out var objRef);
  if (rc != Result.Success)
    return rc;

  var mesh = objRef.Mesh();
  if (null == mesh)
    return Result.Failure;

  if (mesh.IsClosed)
    return Result.Nothing;

  var naked_count = 0;
  for (var ei = 0; ei < mesh.TopologyEdges.Count; ei++)
  {
    var faces = mesh.TopologyEdges.GetConnectedFaces(ei);
    if (null != faces && 1 == faces.Length)
      naked_count++;
  }

  RhinoApp.WriteLine("Total number of mesh edges = {0}", mesh.TopologyEdges.Count);
  RhinoApp.WriteLine("Number of naked mesh edges = {0}", naked_count);

  return Result.Success;
}

– Dale

Thanks Dale!

I think that’s all I really need. I need to draw the edges in a display conduit (but only need to calculate them once). I’ll give it a go a see what the performance looks like.

Larry