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.

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!

1 Answers1

0

This test gives me the expected result:

from vedo import Mesh
vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0.5, 0.5, -1]]
faces = [[0, 1, 2, 3], [0, 1, 4], [1, 2, 4]]
Mesh([vertices, faces]).cmap('viridis', range(3), on='cells').show()

import numpy as np 
from pyvista import PolyData
vertices = np.array(vertices)
faces = np.hstack([[4, 0, 1, 2, 3],  # square
                   [3, 0, 1, 4],     # triangle
                   [3, 1, 2, 4]])    # triangle
PolyData(vertices, faces).plot(scalars=np.arange(3))

what error message do you get?

mmusy
  • 1,292
  • 9
  • 10
  • Thank you, much appreciated. I did not see this reply until now. I installed the module vedo. No error message. It shows me 2 triangles green and yellow, and a purple square. But please tell me, if I have 60,000 triangles, how do I get the triangulation information to give the face data. I guess I will have to plot each triangle separately? How do I close a PyVista plot (or vedo)? – zuheyr alsalihi Dec 14 '20 at 15:31