Hello!
I have an STL file which contains the facets and vertices. My concern is about the way the facets are saved because I have noticed that the facets don't seem to have any common nodes with each other which is not obvious for me, so it would be very much appreciated if anyone can tell if this is normal or I am having some problem in my file!
Note: I have attached a screenshot of the STL file
Thank you and best regards!facets_stl.png

3 commentaires

KSSV
KSSV le 4 Déc 2018
Modifié(e) : KSSV le 4 Déc 2018
Attach your file.....the faces/ triangles should be sharing nodes.
Ano
Ano le 4 Déc 2018
Thank you for you reply.
yes I agree that they should by they are not sharing nodes and the model seems to be correct!
Any ideas?!
Note: Please find attached the STL file and the facets and the nodes .
Thank you and best regards!
DGM
DGM le 27 Sep 2025
Modifié(e) : DGM le 27 Sep 2025
This is to be expected when using FEX #22409, or any other STL decoder which does not properly prune duplicate vertex data. It's a consequence of the way an STL file is structured. The vertex list will be exactly 3x as long as the face list. It will be full of redundant entries, and no two faces will share any vertices or edges.
The fix is simple. Don't use those old buggy decoders. It was understandable in late 2018, which was when the built-in tools were introduced. Today, almost everyone will be running a new enough version to have adequate STL tools. If you have an old copy of #22409 or another FEX download with the same name "stlread", find it, delete it, and adapt your usage to conform to the expectations of stlread().

Connectez-vous pour commenter.

 Réponse acceptée

Cris LaPierre
Cris LaPierre le 5 Déc 2018
Modifié(e) : Cris LaPierre le 5 Déc 2018

0 votes

How are you reading the file into MATLAB? If I follow the example on the stlread documentation, I can import and plot the mesh.
data = stlread('femur.stl');
trimesh(data,'FaceColor','none','EdgeColor','k')
The interesting thing is the numbers from the various files are different.
  • stlread imports 33332x3 points and 66670x3 ConnectivityList
  • Your screenshot shows the values similar to what I see in ConnectivityList, but 178726x3 of them.
  • fv contains 66674x3 faces and 200022x3 vertices. How were faces and vertices created?

9 commentaires

Cris LaPierre
Cris LaPierre le 5 Déc 2018
Modifié(e) : Cris LaPierre le 5 Déc 2018
About the connections - they are there. If I look at data.ConnectivityList for femur.stl, I can see that the first face (line 1) contains points 1, 2 and 3. The 6th face, made up of points 1, 9 and 2, shares the line between points 1 and 2 with face 1.
By combining information from data.Points and data.ConnectivityList, you can recreate the mesh yourself using plot3. Note that this is very slow, so it it much quicker to use plotting functions designed for this (trimesh, triplot)
To avoid getting extraneous lines as the ConnectivityList jumps around, you need to plot each face one by one. For triangles, that means we need 4 points to close them off. Copying the 1st column to the 4th column accomplishes this.
data.ConnectivityList(:,[1:3 1])
We now have the node indices, but we need the X,Y and Z data. Combine node indices with data.Points to get that. Even though you pass in a nx3, the output is a 3*nx1. Because MATLAB uses column major order, to keep the nodes of a face together, we want to transpose data.ConnectivityList.
data.Points(data.ConnectivityList(:,[1:3 1])',:)
Finally, MATLAB plots each column as a single series. We want to plot faces, so we use reshape to place the 4 points of each face in its own column. We can also extract the X,Y and Z points at the same time
X = reshape(data.Points(data.ConnectivityList(:,[1:3 1])',1),4,[]);
Y = reshape(data.Points(data.ConnectivityList(:,[1:3 1])',2),4,[]);
Z = reshape(data.Points(data.ConnectivityList(:,[1:3 1])',3),4,[]);
So now if we plot the first 10 faces, we should see the faces lining up.
And now the full femur using plot3. Super slow, and I couldn't save it. I had to get a screen grab instead.
plot3(X,Y,Z,'k')
femurFull.png
Ano
Ano le 5 Déc 2018
Modifié(e) : Cris LaPierre le 5 Déc 2018
Hello!
I am deeply grateful for your time and effort!
just to make sure that we are using the same terminology you mean by data.ConnectivityList = data.faces
data.Points= data.vertices
Now, for me I don't see that any face is actually sharing any node with another, how did you get it?
Thank you!
Cris LaPierre
Cris LaPierre le 5 Déc 2018
Modifié(e) : Cris LaPierre le 5 Déc 2018
What version of MATLAB are you using? I'm using 2018b. Here's what I see in data when I run the following command
data = stlread('femur.stl');
I'm using the stl you attached - femur.stl. You had previously said (in a now deleted comment) that the screenshots you are showing are from a different stl, which I don't have. There are tens of thousands of lines of data (178726 actually), so I'm not able to conclude from a screenshot of 17 lines that none of the edges are shared.
At this point, you should be able to use the code I've shared to inspect this for yourself. I've written it in a way that should work for any valid stl file.
Ano
Ano le 5 Déc 2018
thank you for your reply!
here what I get when executing the same line with the same version of Matlab that you are usingversion__of__matlab.png!
Cris LaPierre
Cris LaPierre le 5 Déc 2018
What stl file are you loading? Please share your code as well.
Also, I suspect you are using a file exchange function, while I am using the function that comes with MATLAB. Please run the command
which stlread
I get 'C:\Program Files\MATLAB\R2018b\toolbox\matlab\polyfun\stlread.m'
Poornima Jayamani
Poornima Jayamani le 15 Oct 2019
Hi, Cris your suggestions worked well in my case. i am trying to calculate the volume of a triangular meshed left atrium using divergence theorem. However, when i try to iterate through 1 to number of triangles , the loop picking the same point as a first and third point after 16th iteration . i am not sure what could be wrong with my code.
Cris LaPierre
Cris LaPierre le 18 Oct 2019
Hard to say without seeing your file, but it sounds like you might need to clean up your stl file first. How was it generated?
Consider checking to see if the file is 3D printable. Also consider running it through an stl repair routine (many available online) just in case.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by