Closed rasunag27 closed 3 years ago
The data
attribute of a numpy-stl mesh is a regular numpy.array
so you can sort it as such: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.sort.html#numpy.ndarray.sort
The columns of the array can be found in the dtype: https://github.com/WoLpH/numpy-stl/blob/85f573294c09fe609660e50294e9a7df5fe3b348/stl/base.py#L172-L176
If sorting using mesh.data.sort(...)
is not flexible enough you can also resort to using an external sorting method and replacing the mesh.data
with the newly created array. Nearly all attributes in mesh are simply linking to the data
attribute.
As for the order in numpy-stl. The order of the mesh in numpy-stl is actually identical to how it's defined in the STL file. The library simply reads and writes the STL files as is without mutation (except for being able to recalculate normals and/or clearing empty areas).
Dear WoLpH,
Thank you very much for the code.
I have an stl file which is constructed from 3D point cloud data using Open3D python library. The stl file consists of a surface and a base integrated together in a single stl.
I need this stl file to be split into two files. One for the surface and one for the base.
My idea was to sort the stl file in terms of base mesh and surface mesh coordinates and then create two lists of stl and save as two stls. But I am finding it difficult to achieve using numpy-stl.
From numpy-stl, I could access the vertex, facet and normals but not in an order of what stl file actually. How do I sort the stl contents in an order I need and convert to two stls? I have attached the stl link for reference.
stl file link: STL file
Any leads will be appreciated.
Regards,
Sunag R A.