This project is read-only.

Great project and a question

Apr 19 at 9:01 PM
This is an awesome library, thanks for doing it!

I have been struggling to solve the below problem for some time now and hope someone is still watching this board.

Sometimes the input points to my mesh are arranged in a near-perfect grid. Unfortunately in these cases, since the grid is not exactly perfect, the mesh ends up with some long narrow triangles (so narrow they look like lines) along the edges. Is there a way to eliminate or prevent these? I know I can use contours, but the input points come from an outside source and the layout is unknown to me ahead of time.

I am using beta 4 and code like below to generate the mesh:
// nodes are the input coordinates
var poly = new Polygon(nodes.Count());
foreach (var n in nodes)
{
    poly.Add(new Vertex(n.X, n.Y, 1));
}

var options = new ConstraintOptions { SegmentSplitting = 1, ConformingDelaunay = true, Convex = false };
var mesh = (Mesh)poly.Triangulate(options);
Thanks for any help and for a great library!

Mike
Apr 24 at 9:50 AM
There was a similar discussion not too long ago, see here.

Basically, there's no way avoiding those thin triangles on the boundary and Triangle.NET won't eliminate them automatically. So it's up to you to find invalid triangles in a post-processing step and then remove them.

Since you don't have any constraints in your input, setting the ConstraintOptions will have no effect.
Apr 24 at 9:53 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 26 at 6:49 PM
Thanks for the reply!

"...it's up to you to find invalid triangles in a post-processing step and then remove them"

Ah, thanks for confirming. I did try this approach at one point, but I wasn't able to figure out the correct way to remove a triangle from the mesh. Could I trouble you to point me in the right direction by any chance?

Also, thanks for explaining why changing the ConstraintOptions never seemed to do anything :)

Mike
May 8 at 3:46 PM
I usually just ignore invalid triangles (setting the triangle.Label of any invalid triangle to some value I can recongnize).

Triangle.NET does not support deleting triangles from the mesh directly, but there are a couple of options:
  • Create a copy of the mesh, that does not contain the unwanted triangles.
  • Convert the mesh to a DCEL (using TriangleNet.Meshing.Converter.ToDCEL(Mesh mesh)). All properties of the DCEL datastructure are writable, so you can modify the mesh any way you want.
  • Add your own DeleteTriangle(tri) method to the Mesh class using otri.Dissolve(). See TriangleNet.Meshing.ConstraintMesher.Plague(), your code would be a subset of this method.
Marked as answer by mpeet on 5/16/2017 at 7:17 AM
May 9 at 11:16 AM
I've updated the source code and written a short example: Example 10 - Troubleshooting 1
May 16 at 2:27 PM
This is awesome, thank you so much for the reply. I followed your third suggestion and added a method to the Mesh class to remove a list of triangles. It is basically the second phase of TriangleNet.Meshing.ConstraintMesher.Plague() since the invalid triangles are already identified. This was exactly the nudge I needed.

Thanks again!

Mike