Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeshClean stack overflow #110

Open
electroremy opened this issue Mar 18, 2018 · 0 comments
Open

MeshClean stack overflow #110

electroremy opened this issue Mar 18, 2018 · 0 comments

Comments

@electroremy
Copy link

electroremy commented Mar 18, 2018

Hello everybody,

This C# port of Poly2Tri is not up to date ; indeed, Java version of Poly2Tri contains several bug fixes.

As reported here (#12) the most important update you should made is to replace MeshClean by a non recursive version in the DTSweepContext.cs file, as follow :

    public void MeshClean(DelaunayTriangle triangle)
    {
        MeshCleanReqNoStack(triangle);
    }
    private void MeshCleanReqNoStack(DelaunayTriangle triangle)
    {
        var stack = new System.Collections.Generic.Stack <DelaunayTriangle>();
        stack.Push(triangle);
        while (stack.Count > 0)
        {
            var t = stack.Pop();
            if (t != null && !t.IsInterior)
            {
                t.IsInterior = true;
                Triangulatable.AddTriangle(t);
                for (int i = 0; i < 3; i++)
                {
                    if (!t.EdgeIsConstrained[i])
                    {
                        stack.Push(t.Neighbors[i]);
                    }
                }
            }
        }
    }

This update will solve the stack overflow problem when you try to triangulate polygons with a lot of holes that contains a hight number of points :-)

But it's very important to understand that Poly2Tri still don't manage 100% of polygons generated with Clipper, because poly2tri does not support vertices with same coordinates (coincident).

So if you use Clipper to make polygons data and then Poly2Tri to get triangulation, your software is not robust because there are still some cases that you get a "Edge Event" exeption. Unfortunatelly, there is no easy way to deal with these cases. Clipper "strictly simple" does NOT give us a solution.

The problem is that you can't tranform any possible 2D shape in polygon tree structure without coincident points. It's not possible, so poly2tri cannot be used if your software needs to deals with any possible 2D shape.

Also, poly2tri is a good library to triangulate polygons if you are 100% sure that your data imput have not coincident points.

Another important point : this "poly2tri" project is not the same and not inherits from this project : http://sites-final.uclouvain.be/mema/Poly2Tri/

You can find here another interesting new triangulation project in .NET : https://github.com/speps/LibTessDotNet and it's fork https://github.com/Pro100AlexHell/LibTessDotNet

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant