Borrar filtros
Borrar filtros

Find holes and gaps in .stl files

37 visualizaciones (últimos 30 días)
Eduardo
Eduardo el 2 de Feb. de 2012
Comentada: mahmoud elmesery el 24 de Mayo de 2021
Hi,
I need to find gaps and holes in a stl file. I don´t know if there´s a function developed that can help me. I started to work with MATLAB recently and i´m finding some dificulties. I found 2 ways of doing this, each triangle should have 3 adjacent triangles or each edge must have 2 triangles in common. Hope someone could give a hand. Thank´s.
Eduardo G.
  3 comentarios
Walter Roberson
Walter Roberson el 9 de Dic. de 2013
Please be more specific about the errors you are observing.
agdfg sdgfdg
agdfg sdgfdg el 10 de Dic. de 2013
[unqEdges, ~, edgeNos] = unique(edges,'rows'); | Error: Expression or statement is incorrect--possibly unbalanced (, {, or [. this the error i observed.
And i request you to suggest some other algorithms or codes for STL File Correction.

Iniciar sesión para comentar.

Respuesta aceptada

Sven
Sven el 3 de Feb. de 2012
Hi Eduardo,
Firstly you need to read the .stl file in as faces and vertices. I'll presume you've already got that done (as Anton points out, stlread is available here http://www.mathworks.com/matlabcentral/fileexchange/22409-stl-file-reader).
Next, as you wrote: each edge must have 2 triangles in common... I think this is a good start. Here's some code that will make a test faces/vertices mesh, then determine such a thing:
% MAKE a face/vertices structure
tmpvol = zeros(20,20,20); % Empty voxel volume
tmpvol(8:12,8:12,5:15) = 1; % Turn some voxels on
fv = isosurface(tmpvol, 0.99);
% REMOVE a face
fv.faces(30,:) = []; % Remove a face!
% TEST for gaps or holes
edges = sort(cat(1, fv.faces(:,1:2), fv.faces(:,2:3), fv.faces(:,[3 1])),2);
[unqEdges, ~, edgeNos] = unique(edges,'rows');
if size(edges,1) == size(unqEdges,1)*2
% Every edge is used twice... consistent with a closed manifold mesh
disp('No problem!')
else
badEdgesMask = hist(edgeNos, 1:max(edgeNos))~=2;
badEdgeNos = edgeNos(badEdgesMask);
badNodeNos = edges(badEdgeNos,:);
badFaceNos = find(sum(ismember(fv.faces, badNodeNos),2)>=2);
end
Does this answer the question for you?
  2 comentarios
Eduardo
Eduardo el 22 de Feb. de 2012
Thanks. This is exactly what i was looking for. Now i have to fill in the hole if one or more were found... Do you have any idea how to do it?
mahmoud elmesery
mahmoud elmesery el 24 de Mayo de 2021
Hello, How to substract two stl files in matlab

Iniciar sesión para comentar.

Más respuestas (3)

Eduardo
Eduardo el 4 de Feb. de 2012
Hi,
First of all thanks. I´m using this 'stlread':
and then i´m using 'patchslim'. Now i´ll try your code and i´ll give you feedback.

Eduardo
Eduardo el 26 de Feb. de 2012
Hi. I´ve made some tests and discovered that when a hole is found this code is not working correctly. When we axecute "badEdgeNos = edgeNos(badEdgesMask);" this should compare badEdgesMask with the number 1 and not with the first element of edgeNos. Can you understand what i´m trying to explain?
  2 comentarios
Sven
Sven el 29 de Feb. de 2012
If you mean that the variable badEdgesMask only contains ones and zeros, then you need to realise that it's using logical indexing... if you're sure there's a problem, make a small example (such as the one I made) and show how it's not working.
Eduardo
Eduardo el 29 de Feb. de 2012
I´ve made a test with a simple cube. I removed 1 face and badEdgesMask is correct. The problem is in "badEdgeNos = edgeNos(badEdgesMask);" because badEdgesMask has 18 elements and edgeNos has 33. The comparison is made 1 by 1 element, so it compares the first logical value with the first element of edgeNos, i think it should be the first logical value with the element 1 of edgeNos (corresponding edge "1 2").

Iniciar sesión para comentar.


Eduardo
Eduardo el 25 de Mzo. de 2012
I made it like this to solve the problem i´ve told you:
edges = sort(cat(1, fv.faces(:,1:2), fv.faces(:,2:3), fv.faces(:,[3 1])),2);
[unqEdges, ~, edgeNos] = unique(edges,'rows');
if size(edges,1) == size(unqEdges,1)*2
% Every edge is used twice... consistent with a closed manifold mesh
disp('No problem!')
else
badEdgesMask = hist(edgeNos, 1:max(edgeNos))~=2;
[~, ~, edgeNos1] = unique(unqEdges,'rows');
badEdgeNos = edgeNos1(badEdgesMask);
badNodeNos = unqEdges(badEdgesMask,:);
badFaceNos = find(sum(ismember(fv.faces, badNodeNos),2)>=2);
end
I don´t know if this the best way to do it, but it works...

Community Treasure Hunt

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

Start Hunting!

Translated by