wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
624 stars 105 forks source link

Topological information of the stl files #152

Closed zuheyr closed 3 years ago

zuheyr commented 3 years ago

Dear Mr. van Hattem, I need to ask a question:

By reading the .stl files we can get the geometrical information from the triangular mesh, but can we generate the topological information from the .stl files (in matlab) ?? Is it necessary to define the data structure to generate the connectivity information??

0

Using the Python numpy-stl package: reading the .stl files we can get the geometrical information from the triangular mesh, vertex data, normals, areas etc, but can we access the topological information, the connectivity information? I am a newcomer to Python and everything... but there was once this question was asked and did not get any response.

The question I posed at the Stack overfow is:

I need to read a triangular stl mesh and plot some of the elements using Pyvista such as the one in the sample!

Vertices

vertices = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0.5, 0.5, -1]]) -> This I can

mesh faces

faces = np.hstack([[4, 0, 1, 2, 3], # square [3, 0, 1, 4], # triangle [3, 1, 2, 4]]) # triangle -> This I cannot.

Is it necessary to define the data structure to generate the connectivity information??

Thank you for reading!

wolph commented 3 years ago

The vertices are the points of the triangles and the faces are the combinations of points that make up the triangles. How they are stored depend on whether you are using the binary or the ascii STL format though. You will need to store the combination of both somehow but that can be done in many ways.

This library exposes the arrays in multiple ways, I believe the points might be useful to you: https://numpy-stl.readthedocs.io/en/latest/stl.html#stl.mesh.Mesh.points It exposes the points as a Nx9 array with the x, y and z coordinates for each point of a triangle.

With regards to Matlab however, there is native STL support it seems: https://www.mathworks.com/help/pde/ug/stl-file-import.html

zuheyr commented 3 years ago

Dear Mr. van Hattem,

Thank you very much for your kind reply. I am using the ASCII version of the STL format.  

"You will need to store the combination of both somehow but that can be done in many ways." 

I can also write the STL binary. Will this help? I do not want to have anything to do with matlab, I am using your library. It was just an example to see that the topological information can be recreated. This can perhaps also be used in your library, or maybe even perhaps it is done, in the "vectors" etc. This is what I wanted to know.

Thank you so much for this wonderful library.

Best regards, Zuheyr

wolph commented 3 years ago

Sorry for the slow response, I didn't see your message.

It all depends on what you want to do really. I'm not expert in this area so I doubt I can be of much help. But I might be able to point you in the right direction. What helps a lot for solving these types of issues is applying the Scipy spatial algorithms: https://docs.scipy.org/doc/scipy/reference/spatial.html

It's also possible that VTK can help you here: https://vtk.org/