How do you extract vertices from a numpy-stl mesh?
Asked Answered
J

1

6

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.

Jog answered 7/8, 2019 at 11:4 Comment(0)
S
5

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]]
Sirois answered 19/9, 2019 at 12:30 Comment(1)
You need to edit the following to work: int(cuboid.vectors.size/3)Unfasten

© 2022 - 2024 — McMap. All rights reserved.