I have a mesh like below consisting of groups of connected triangles. I have to detect the triangle groups. Is there any convenient tool or algorithm for this job? I'm researching and I'm afraid there might be such a thing which I'm unaware of!
-
1Maybe something inspired by a floodfill algorithm? – Pierre Baret Jan 31 '19 at 16:41
-
@PierreBaret Thanks. I'm going to research on it ☺ – Megidd Jan 31 '19 at 16:59
-
1You can split a mesh into connected components with Meshlab. – Stéphane Laurent Apr 19 '19 at 09:38
-
@StéphaneLaurent I intended to do it programatically. Does MeshLab has any API for it? – Megidd Apr 19 '19 at 11:04
-
1Meshlab is a graphical interface to the vcglib C++ library. – Stéphane Laurent Apr 19 '19 at 13:04
2 Answers
A simple solution would be to keep a multimap whose keys are 3D points which are the vertices of all of the triangles. If a triangle shares a vertex with another one, we can assume they are connected.
Now to keep information on which triangles belong to which group, you can use the union-find data structure (https://en.wikipedia.org/wiki/Disjoint-set_data_structure) which has a nearly linear complexity.

- 6,918
- 2
- 29
- 39
-
How would you get a list of all the unions you would need to do? Wouldn't this task be very computationally expensive? – Ken May 12 '21 at 21:24
-
1@Ken I'm not sure I understand your question. The union-find algorithm allows you to do just that very efficiently. – ciamej May 13 '21 at 13:40
A graph algorithm can be used to find your "groups of connected triangles".
In graph terminology, your triangle meshes are graphs. You don't care about geometry, you only care about connectivity. For instance you can see every 3D vertex as a graph's node and every triangle edge as a graph's edge connecting two nodes.
Your "groups of connected triangles" would be Connected Components in graph terminology.
An efficient algorithm for finding all connected components in a graph can be seen in this answer:
https://stackoverflow.com/a/21078752/9147444
Which uses the Union-Find datastructure (also known as Disjoint-Set)

- 1,422
- 1
- 7
- 9
-
It seems like this union find method requires that you know all the unions, but how would you find all the required unions in this case? – Ken May 12 '21 at 21:25