Does anyone know if the openmesh library can triangulate a simple closed polygon?
I'm currently creating a PolyMesh, where the boundary is represented by a sequence of vertices defining a simple closed polygon. However whan I save this in .ply file I get wrong results. Therefore I was thinking if specifying the polygon face as a collection of triangular faces, but in order to do this I need to perform a triangulation first.
It doesn't seem to me openmesh can do this, does anyone know?
FYI. I'm using pythonm, Also worth mentioning my polygon is a planar one.
As example you can look at the following ply:
ply
format ascii 1.0
element vertex 6
property float x
property float y
property float z
element face 4
property list uchar int vertex_indices
end_header
-5 -5 0
5 -5 0
5 10 0
0 10 0
0 5 0
-5 5 0
3 3 4 5
3 0 1 5
3 1 2 5
3 2 3 5
The original vertices:
-5 -5 0
5 -5 0
5 10 0
0 10 0
0 5 0
-5 5 0
Piece of code generating the ply:
def test_polymesh():
poly_mesh = om.PolyMesh()
coords_array = \
[
np.array([-5.0, -5.0, 0.0]),
np.array([5.0, -5.0, 0.0]),
np.array([5.0, 10.0, 0.0]),
np.array([0.0, 10.0, 0.0]),
np.array([0.0, 5.0, 0.0]),
np.array([-5.0, 5.0, 0.0])
]
vertex_handle = []
for v in coords_array:
vertex_handle.append(poly_mesh.add_vertex(v))
face_handle = poly_mesh.add_face(vertex_handle)
poly_mesh.triangulate()
om.write_mesh("test_polymesh.ply", poly_mesh)