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

How to get the irregular triangle inside the concave hull built by the ConcaveHull class? #687

Open
pucx opened this issue May 16, 2023 · 3 comments

Comments

@pucx
Copy link

pucx commented May 16, 2023

By use ConcaveHull class:
https://github.com/NetTopologySuite/NetTopologySuite/blob/develop/src/NetTopologySuite/Algorithm/Hull/ConcaveHull.cs
How to get the irregular triangle inside the concave hull built by the ConcaveHull class?

@FObermaier
Copy link
Member

Can you elaborate a bit more what you try to achieve. Maybe some sample data/image to illustrate?

@pucx
Copy link
Author

pucx commented May 17, 2023

For discrete point data, first establish the concave hull of the discrete points, and then generate contour lines based on the irregular triangle mesh inside the concave hull. So I want to get the irregular triangles inside the concave hull ,thanks.

@FObermaier
Copy link
Member

If I understand you correctly you want to have access to the underlying (hull-)triangulation?
You can't out of the box because the parts are internal. You can -I suppose- copy and reuse the relevant code in your application:

public static IList<Tri> CreateDelaunayTriangulation(Geometry geom)
{
//TODO: implement a DT on Tris directly?
var dt = new DelaunayTriangulationBuilder();
dt.SetSites(geom);
var subdiv = dt.GetSubdivision();
var triList = ToTris(subdiv);
return triList;
}
private static IList<Tri> ToTris(QuadEdgeSubdivision subdiv)
{
var visitor = new HullTriVisitor();
subdiv.VisitTriangles(visitor, false);
var triList = visitor.GetTriangles();
TriangulationBuilder.Build(triList);
return triList;
}
class HullTriVisitor : ITriangleVisitor
{
private readonly List<Tri> _triList = new List<Tri>();
public void Visit(QuadEdge[] triEdges)
{
var p0 = triEdges[0].Orig.Coordinate;
var p1 = triEdges[1].Orig.Coordinate;
var p2 = triEdges[2].Orig.Coordinate;
HullTri tri;
if (Triangle.IsCCW(p0, p1, p2))
{
tri = new HullTri(p0, p2, p1);
}
else
{
tri = new HullTri(p0, p1, p2);
}
_triList.Add(tri);
}
public IList<Tri> GetTriangles()
{
return _triList;
}
}

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

2 participants