0

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)
user8469759
  • 2,522
  • 6
  • 26
  • 50
  • For a very simple polygon you could use https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Delaunay.html or https://matplotlib.org/3.1.0/api/tri_api.html example: https://stackoverflow.com/questions/45243563/creating-a-triangulation-for-use-in-matplotlibs-plot-trisurf-with-matplotlib-tr of course there are a lot of cases where this fails. – Joe Jul 02 '19 at 13:30
  • But it should work http://www.openmesh.org/media/Documentations/OpenMesh-4.0-Documentation/a00240.html#a7e406f2fc8e7f5273080c96d0caea919 – Joe Jul 02 '19 at 13:34
  • @Joe The "triangulate" method, doesn't seem to do anything. Though I have openmesh 1.1 something (for some reason I cannot manage to install the latest version). It might be a bug. – user8469759 Jul 02 '19 at 14:11
  • @Joe, the function you point out doesn't split the polygon into monotone pieces, therefore it would still fail in some cases. – user8469759 Jul 02 '19 at 16:17
  • And from the openmesh documentation it seems to me it would only work for convex polygons. – user8469759 Jul 02 '19 at 16:38
  • Maybe you don't need that at all. Could you give an example what happens when you save as ply? – Joe Jul 02 '19 at 18:35
  • @Joe, updated with a ply, after the triangulate call. – user8469759 Jul 03 '19 at 09:00
  • What's the problem with the vertices, they are the same. Are you wondering what e.g. `3 3 4 5` is? – Joe Jul 03 '19 at 09:20
  • If you open the ply, you'll see the one triangle which is not supposed if you would triangulate the monotone polygon. I cannot attach a picture right now. – user8469759 Jul 03 '19 at 09:59
  • Ok, I see it. Which tool are you using to create the ply file? – Joe Jul 03 '19 at 10:22
  • @Joe, see my update. There's a python function that does everything. – user8469759 Jul 03 '19 at 10:25
  • Ok, I get it now. You were right, it only works for convex polygons as it creates a triangle fan. I found a feature request to fix this: https://graphics.rwth-aachen.de:9000/OpenMesh/OpenMesh/issues/33 – Joe Jul 03 '19 at 11:41
  • They mention that the ear clipping algorithm is implemented in OpenFlipper https://www.openflipper.org/media/Documentation/OpenFlipper-3.0/a01331.html#a505a920d3a9eb73f41ef5c1326866e01 which seems to be related to OpenMesh – Joe Jul 03 '19 at 11:41
  • This might also be an option https://stackoverflow.com/a/17790235/7919597 – Joe Jul 03 '19 at 11:49
  • https://doc-snapshots.qt.io/qt5-5.9/qtlocation-attribution-poly2tri.html – Joe Jul 03 '19 at 11:52
  • https://github.com/jhasse/poly2tri/tree/master/poly2tri or https://github.com/greenm01/poly2tri, now sure with one is the original implementaion – Joe Jul 03 '19 at 11:52
  • And someone who worked on a Cython wrapper for it https://github.com/davidcarne/poly2tri.python – Joe Jul 03 '19 at 11:54
  • And I just tried two little scripts that provide ear-clipping and work fine with your example: https://github.com/mrbaozi/triangulation and the other one is https://github.com/linuxlewis/tripy/blob/master/tripy.py – Joe Jul 03 '19 at 12:24
  • @Joe, I cannot open the link with the bug fix request. – user8469759 Jul 03 '19 at 12:52
  • I would like to give openflipper a shot anyway. Though I can't find a quick way to install it. – user8469759 Jul 03 '19 at 12:59
  • About the bug report, you might be behind a corporate firewall, right? – Joe Jul 03 '19 at 13:02
  • Yeah probably, anyway granted is a bug. – user8469759 Jul 03 '19 at 13:07
  • I've used tripy at last. Thank you – user8469759 Jul 05 '19 at 07:30

0 Answers0