Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

stl

numpy-stl

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.

like image 316
stanatomist Avatar asked Aug 07 '19 11:08

stanatomist


1 Answers

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]]
like image 197
Dharmendra Avatar answered Sep 18 '22 07:09

Dharmendra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!