Search code examples
pythonnumpymeshvtkdecimation

Initialize triangular mesh in e.g. VTK based on np array with coordinates of vertices and np array with triangles


Could you tell me how do I initialize triangular mesh based on np array with coordinates of vertices and np array with triangles (it contains triples of indices of vertices from first array)?

Could be done in VTK or any other Python library, the final goal is to do decimation on this mesh.

Thank you.


Solution

  • A solution using vedo which is based on vtk:

    https://github.com/marcomusy/vedo/blob/master/examples/basic/buildmesh.py

    from vedo import Mesh, show
    
    verts = [(50,50,50), (70,40,50), (50,40,80), (80,70,50)]
    faces = [(0,1,2), (2,1,3), (1,0,3)]
    # (the first triangle face is formed by vertex 0, 1 and 2)
    
    # Build the polygonal Mesh object:
    mesh = Mesh([verts, faces])
    #mesh.decimate()
    show(mesh)
    

    enter image description here