Given the following data:
- The Cartesian co-ordinates of the vertices in the surface mesh: n vertices x 3
- The vertex indices of each face in the surface mesh: n faces x 3
I'm trying to export some 3D file that I can readily import to 3D Slicer for registration against a VTK file.
Faces: https://pastebin.com/qWq7aiEs
Vertices: https://pastebin.com/VxsxsdcM
I have been trying various packages/libraries etc. and keep running into various issues. The following issue is using the Trimesh in Python and I'm attributing the problem to my poor python ability rather than an issue with the package. I'm open to other solution as well.
I imported the CSV, extracted the arrays then converted to lists to match the example. I wasn't certain how to use the faces data given the example, so I just made a list that matched the length of vertices, not sure if that's right at all.
# Example: mesh objects can be created from existing faces and vertex data
mesh = trimesh.Trimesh(vertices=[[0, 0, 0], [0, 0, 1], [0, 1, 0]],
faces=[[0, 1, 2]])
# My attempt
vertex_x = vertices_csv[:,0]
vertex_y = vertices_csv[:,1]
vertex_z = vertices_csv[:,2]
vertex_x_list = vertex_x.tolist()
vertex_y_list = vertex_y.tolist()
vertex_z_list = vertex_z.tolist()
faces_list_mesh = [i for i in range(len(vertex_x_list))]
mesh = trimesh.Trimesh(vertices=[vertex_x_list, vertex_y_list, vertex_z_list],
... faces=[faces_list_mesh])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\...\Python\Python310\lib\site-packages\trimesh\base.py", line 190, in __init__
self.process(validate=validate,
File "C:\...\Python\Python310\lib\site-packages\trimesh\base.py", line 232, in process
self.merge_vertices(merge_tex=merge_tex,
File "C:\...\Python\Python310\lib\site-packages\trimesh\base.py", line 1123, in merge_vertices
grouping.merge_vertices(
File "C:\...\Python\Python310\lib\site-packages\trimesh\grouping.py", line 70, in merge_vertices
referenced[mesh.faces] = True
IndexError: index 3 is out of bounds for axis 0 with size 3
Any advice how to troubleshoot is greatly appreciated!