I have an isosurface data in MATLAB. For example:
[x,y,z,v] = flow;
FV = isosurface(x,y,z,v);
FV =
vertices: [4208x3 double]
faces: [8192x3 double]
I also have a list of vertices indexes which I would like to remove:
verticesToRemove = [1183, 1852, 2219, 1925, 3684];
How can I remove these set of vertices from the mesh and update the faces list accordingly? I would like the topological structure of the mesh to remain the same (i.e. the deleted faces needs to be replaced by faces which don't go through deleted vertices).
Thanks!
The easiest thing to do (if you just want to display the mesh) is to simply set their value to NaN
, then you won't have to update your Faces
matrix and all faces which use these vertices will be ignored during rendering.
FV.vertices(verticesToRemove,:) = NaN;
If you actually want to update the structure to be used elsewhere, you can recompute the faces. After you remove the vertices.
% Remove the vertex values at the specified index values
newVertices = FV.vertices;
newVertices(verticesToRemove,:) = [];
% Find the new index for each of the new vertices
[~, newVertexIndex] = ismember(FV.vertices, newVertices, 'rows');
% Find any faces that used the vertices that we removed and remove them
newFaces = FV.faces(all(FV.faces ~= verticesToRemove, 2),:);
% Now update the vertex indices to the new ones
newFaces = newVertexIndex(newFaces);
FV.vertices = newVertices;
FV.faces = newFaces;