# Issue connectivity faces with isosurface

6 views (last 30 days)
Ouatehaouks on 11 Oct 2023
Commented: Ouatehaouks on 19 Oct 2023
Hi,
Say I have a gaussian-like function from which I extract the 0.5 isosurface. When I look at the list of faces, I see that the following faces are not necessarily connected i.e. the face(i,:) does not necessarily have two indices in common with the face(i+1,:). Does anyone know an efficient way to order that list in order to get this kind of connectivity property ? Thanks !
Code to see the issue:
x=linspace(-1,1,100);
[X,Y,Z]=meshgrid(x,x,x);
gaus = exp(-(X.^2+Y.^2+Z.^2)/2/0.1^2);
fv = isosurface(X,Y,Z,gaus,0.5);
hold on
for i=1:1:100
p1 = fv.vertices(fv.faces(i,1),:);
p2 = fv.vertices(fv.faces(i,2),:);
p3 = fv.vertices(fv.faces(i,3),:);
plot3([p1(1) p2(1)],[p1(2) p2(2)],[p1(3) p2(3)])
plot3([p1(1) p3(1)],[p1(2) p3(2)],[p1(3) p3(3)])
plot3([p3(1) p2(1)],[p3(2) p2(2)],[p3(3) p2(3)])
pause
end
Walter Roberson on 18 Oct 2023
It appears that isosurface() only produces triangle meshes. If it does not duplicate faces, then possibly that has implications for a traversal order.
Pick a vertex and a starting face. Traverse the three triangles in (say) counter-clockwise order, and then flip "down" to the next level, and traverse in the same order along the bottom of what you had already traversed, then move to the next level and so on.
Ouatehaouks on 19 Oct 2023
what do you mean by level ? If it is the row in faces, I'm not sure this will be sufficient. When one launches my exemple, one can see that triangles appear connected from one another and then at some point it jumps to another region of my sphere which is completely disconnected, so I need to find another level that stays connected and it does not seem to be a matter of counterclockwise to me. Or maybe I misunderstood your point.

Fabio Freschi on 15 Oct 2023
Sorting of the faces does not guaratee the property you think exist. If you check, your isosurface is a closed surface: all edges are shared by two triangles
clear all, close all
x=linspace(-1,1,100);
[X,Y,Z]=meshgrid(x,x,x);
gaus = exp(-(X.^2+Y.^2+Z.^2)/2/0.1^2);
fv = isosurface(X,Y,Z,gaus,0.5);
% plot isosurface (graphic check)
figure, axis equal, view([1 1 1]);
p = patch(fv,'FaceColor','r');
% load data on triangulation class
DT = triangulation(fv.faces,fv.vertices);
% mesh edges
E = edges(DT);
% find triangles attached to edges
tri = edgeAttachments(DT,E);
% check the number of triangels attached to edges
nTri = cellfun(@length,tri);
% check if the all edges are shared by two triangles
all(nTri == 2)
ans = logical
1
Ouatehaouks on 17 Oct 2023
Thank you for your help. The triangulation seems to be a good way, I did not know you could triangulate a 3D surface, I thought it would connect points in 3D a well...I'm not sure though how to use E and tri to sort fv.faces so that fv.faces(i,:) and fv.faces(i+1,:) have two indices in common ?
Fabio Freschi on 17 Oct 2023
I don't think it is possible to have that property for a generic mesh, if you want to label all triangles