File Exchange

image thumbnail

splitFV - split a mesh

version 1.7 (2.84 KB) by

Splits a 2D or 3D mesh defined by faces and vertices into separately connected mesh pieces.

6 Downloads

Updated

View License

FVOUT = SPLITFV(F,V) separates disconnected pieces inside a patch defined by faces (F) and
vertices (V). FVOUT is a structure array with fields "faces" and "vertices". Each element of
this array indicates a separately connected patch.
FVOUT = SPLITFV(FV) takes in FV as a structure with fields "faces" and "vertices"

For example:
fullpatch.vertices = [2 4; 2 8; 8 4; 8 0; 0 4; 2 6; 2 2; 4 2; 4 0; 5 2; 5 0];
fullpatch.faces = [1 2 3; 1 3 4; 5 6 1; 7 8 9; 11 10 4];
figure, subplot(2,1,1), patch(fullpatch,'facecolor','r'), title('Unsplit mesh');
splitpatch = splitFV(fullpatch);
colours = lines(length(splitpatch));
subplot(2,1,2), hold on, title('Split mesh');
for i=1:length(splitpatch)
patch(splitpatch(i),'facecolor',colours(i,:));
end

Note: faces and vertices should be defined such that faces sharing a coincident vertex reference
the same vertex number, rather than having a separate vertice defined for each face (yet at the
same vertex location). In other words, running the following command: size(unique(v,'rows') ==
size(v) should return TRUE. An explicit test for this has not been included in this function so
as to allow for the deliberate splitting of a mesh at a given location by simply duplicating
those vertices.

See also PATCH

Comments and Ratings (9)

Fritz

Fritz (view profile)

Ben

Ben (view profile)

Sven

Sven (view profile)

Christopher, good spot and I agree completely - the xyzSub variable in the previous was not doing as intended. It would work in most cases simply because meshes are usually over-connected so the bug wouldn't come up. I've updated as per your change which should now be correct and a little faster.

Christopher

This implementation is slightly flawed. It does not work on the face matrix
5 9 10
5 4 9
4 8 9
4 3 8
3 7 8
3 2 7
2 6 7
2 1 6

It erroneously splits this mesh into two pieces.

It seems that the lines
[availFaceSub, xyzSub] = find(ismember(f(availFaceInds,:), openVertices));
fSets(availFaceInds(availFaceSub)) = currentSet;
openVertices = f(availFaceInds(availFaceSub),xyzSub);

should be replaced by
[availFaceSub, ~] = find(ismember(f(availFaceInds,:), openVertices));
fSets(availFaceInds(availFaceSub)) = currentSet;
openVertices = f(availFaceInds(availFaceSub),:);

xyzSub is unneeded and f(availFaceInds(availFaceSub),xyzSub) is probably not working as the author intended (I'm not sure what the author intended here)---xyzSub is basically replicating particular columns of f(availFaceInds(availFaceSub),:). Thus, if xyzSub doesn't contain 1, 2, or 3, there may be some vertices missing from the openVertices list.

Sharif

Sharif (view profile)

Anton Semechko

Anton Semechko (view profile)

Sven

Sven (view profile)

Thanks for the images Tom :)

Thomas Clark

This did exactly what I wanted, straight out of the box, without editing a single line of code.

That's my kind of FEX submission!

NB For users wondering about this, it works in 3D too.

Sven, would you like some JPEGs of it decomposing different vortices in a fluid flow?

Updates

1.7

Implemented Christopher's amendment to fix bug in following connectivity matrix.

1.6

Updated icon (thanks Tom Clark!)

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video