How to trim the non-manifold triangle off the stl file?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone
I have a question about the 3D stl file processing.
Suppose that I have the 3D geometry (stl file).
I use stlread and trimesh command to plot it, then I found that some of elements are non-manifold.
I try to directly remove these two triangule faces for about entire afternoon, but I haven't done it succefully yet.
Could any one give me some suggestions?


Attached is the stl file, to view the stl file, with the codes as below:
fv=stlread('test.stl')
figure();
trimesh(fv);
axis equal
0 commentaires
Réponses (2)
Bruno Luong
le 23 Avr 2021
There is SW that can detect topology issue and attempt to correct it, such as
0 commentaires
DGM
le 8 Avr 2025 à 21:16
Modifié(e) : DGM
le 8 Avr 2025 à 21:25
I'd agree with Bruno on this. Especially if it's just a small fix on a single file, it's easier and quicker to just throw it in Meshlab.
That said, I figured I'd try to do it. Those two triangles are actually four. They're coincident faces, so if you just go looking for a 3-connected edge, you won't find one. You'll find two 4-connected edges. I decided that it was least ambiguous to start by removing coincident faces first. Assuming the model is a closed surface, any remaining open edges belong to flags. Just erode them away until you're left with a closed volume.
unzip test.zip
% an object we assume is a closed surface
T = stlread('test.stl');
% get rid of coincident faces
[~,ia] = unique(sort(T.ConnectivityList,2),'rows','stable');
T = triangulation(T.ConnectivityList(ia,:),T.Points);
% get rid of open edges
% this will get rid of t-connected faces, so long as they're not coincident.
% it will also destroy a surface with a hole or open edges
E = freeBoundary(T);
while ~isempty(E) % this could probably be simplified
EA = edgeAttachments(T,E(:,1),E(:,2));
F = T.ConnectivityList;
F(unique(cell2mat(EA)),:) = [];
T = triangulation(F,T.Points);
E = freeBoundary(T);
end
% get rid of those unused vertices and remap the face list
[F,V] = pruneunusedverts(T.ConnectivityList,T.Points);
T = triangulation(F,V);
% write it
stlwrite(T,'test2.stl')
% display it using patch()
patch('faces',T.ConnectivityList,'vertices',T.Points, ...
'facecolor','w','edgecolor','k');
view(3); camlight;
axis equal; grid on
xlabel('X'); ylabel('Y'); zlabel('Z')
This whole approach relies on some assumptions based on observing the model. There are plenty of other things that aren't being checked.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!