Reputation: 73
I am trying to use numpy-stl to extract the vertices from an stl model to use for coherent point drift registration. How do you go about extracting the vertices? I understand how to create a mesh from a list of vertices and faces, but not how to go backwards.
I've tried: Creating a new mesh from vertices and faces. Importing created mesh.
Upvotes: 6
Views: 7523
Reputation: 51
Let's take a .stl file of a cuboid with length 100, width 200, height 300.
from stl import mesh
import numpy as np
cuboid = mesh.Mesh.from_file("./cuboid.stl")
points = np.around(np.unique(cuboid.vectors.reshape([cuboid.vectors.size/3, 3]), axis=0),2)
print "Points are", points.tolist()
Output:
Points are [[0.0, 0.0, 0.0], [0.0, 0.0, 300.0], [0.0, 200.0, 0.0], [0.0, 200.0, 300.0], [100.0, 0.0, 0.0], [100.0, 0.0, 300.0], [100.0, 200.0, 0.0], [100.0, 200.0, 300.0]]
Upvotes: 5