Can Anyone help me understanding the following code?

1 visualizzazione (ultimi 30 giorni)
Hello there, I have the following code that related to the mesh split functionality. can someone help me understanding what the author exactly did in order to split the mesh components? i found the function here: https://www.mathworks.com/matlabcentral/fileexchange/27667-splitfv-split-a-mesh
function fvOut = splitFV( f, v )
%SPLITFV Splits faces and vertices into connected pieces
% 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"
% Copyright Sven Holcombe
% $Date: 2010/05/19 $
%%Extract f and v
if nargin==1 && isstruct(f) && all(isfield(f,{'faces','vertices'}))
v = f.vertices;
f = f.faces;
elseif nargin==2
% f and v are already defined
else
error('splitFV:badArgs','splitFV takes a faces/vertices structure, or these fields passed individually')
end
%%Organise faces into connected fSets that share nodes
fSets = zeros(size(f,1),1,'uint32');
currentSet = 0;
while any(fSets==0)
currentSet = currentSet + 1;
fprintf('Connecting set #%d vertices...',currentSet);
nextAvailFace = find(fSets==0,1,'first');
openVertices = f(nextAvailFace,:);
while ~isempty(openVertices)
availFaceInds = find(fSets==0);
[availFaceSub, ~] = find(ismember(f(availFaceInds,:), openVertices));
fSets(availFaceInds(availFaceSub)) = currentSet;
openVertices = f(availFaceInds(availFaceSub),:);
end
fprintf(' done! Set #%d has %d faces.\n',currentSet,nnz(fSets==currentSet));
end
numSets = currentSet;
%%Create separate faces/vertices structures for each fSet
fvOut = repmat(struct('faces',[],'vertices',[]),numSets,1);
for currentSet = 1:numSets
setF = f(fSets==currentSet,:);
[unqVertIds, ~, newVertIndices] = unique(setF);
fvOut(currentSet).faces = reshape(newVertIndices,size(setF));
fvOut(currentSet).vertices = v(unqVertIds,:);
end
  2 Commenti
Sven
Sven il 6 Set 2018
Sana, you will need to be more specific - you haven't actually asked a question. Is there a particular part of the code that you don't understand? Do you already understand how faces and vertices are defined for a mesh? If not, you should start there.
sana3 sal
sana3 sal il 6 Set 2018
Yes of-course i know that , what i need to understanding what the author exactly did in order to split the mesh components? It is worthy to mention that i can understand it theoretically, but i need to understand the code itself.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by