wo80 / Triangle.NET

C# / .NET version of Jonathan Shewchuk's Triangle mesh generator.
442 stars 81 forks source link

QualityMesher stuck in EnforceQuality method #39

Closed AmosEgel closed 12 months ago

AmosEgel commented 12 months ago

Hey Christian, thanks a lot for your effort to put up and maintain this fantastic repository!

I call the triangle mesher with the following commands:

TriangleNet.Meshing.QualityOptions triQuality = new TriangleNet.Meshing.QualityOptions() { MinimumAngle = 30.0 };
TriangleNet.Meshing.IMesh mesh = TriangleNet.Geometry.ExtensionMethods.Triangulate(triNetPoly, triQuality);

In some cases, the mesher seems to have problems to come up with a triangulation of that quality. Then, the mesher tends to get stuck in the while-loop inside the QualityMesher.EnforceQuality() method.

Is there an option to make the mesher stop after a certain number of trials? I mean, if the input polygon is such that the meshing with the demanded quality cannot be provided in a reasonable time, I'd rather have it interrupted.

I'd love to provide the data for a minimum reproducible example - however, when I tried to isolate the call to the mesher and take it out of the context from which we usually call it, the behaviour is not reproducible. Instead, the mesher runs fine or throws an error ("The new vertex is at the circumcenter of triangle.")

wo80 commented 12 months ago

Is there an option to make the mesher stop after a certain number of trials?

You can use QualityOptions.SteinerPoints to limit the number of Steiner points.

Also make sure to take a look at https://www.cs.cmu.edu/~quake/triangle.trouble.html and check your input polygon. If you need further help, export the input polygon using TriangleNet.IO.FileProcessor.Write(poly, filename) and post the data here.

AmosEgel commented 12 months ago

Thanks a lot for your quick and helpful reply.

Seems that it is probably the (almost) collinear polygon segments that caused the problem. I'll try with SteinerPoints and with an Exclude function (to exclude triangles with a very small internal angle) in the QualityOptions.