GIBBON icon indicating copy to clipboard operation
GIBBON copied to clipboard

select patch

Open jpv20 opened this issue 3 years ago • 3 comments

Kevin,

i have used triSurfSlice to separate a surface (F,V). this process generated multiple disconnected surfaces. how can i isolate/select/keep one of these subsurfaces..say the one with the largest area?

jonathan

jpv20 avatar Aug 12 '22 18:08 jpv20

You can use the tesgroup function. To do this.

If F describes your faces for the mesh you use the following to get a node-connected group labeling for each face.

optionStruct.outputType='label'; %Important since the 'array' option can be much slower
[G,~,groupSize]=tesgroup(Fs,optionStruct); %Get face group labels

The output G is $n \times 1$ in size if you have $n$ faces, so you can use it to color the faces, for instance to inspect group label. E.g. using gpatch(F,V,G).

You can get the group id for the group with the most members using:

[~,largestGroupId]=max(groupSize); %Get id of largest group

Then you can access the faces using:

Fs=F(G==largestGroupId,:); %Selecting the largest group

See also this documentation: https://www.gibboncode.org/html/HELP_tesgroup.html

Let me know if this helps.

Kevin-Mattheus-Moerman avatar Aug 12 '22 19:08 Kevin-Mattheus-Moerman

FYI the tesgroup (tessellation grouping) function shamefully requires MATLAB for-loops and can therefore be quite slow for large meshes.

Kevin-Mattheus-Moerman avatar Aug 12 '22 19:08 Kevin-Mattheus-Moerman

@jpv20 the above uses "the most faces" rather than areas. You can use something like this to do it based on areas:

groupArea=nan(1,max(G(:))); %Initialize areas
A=patchArea(F,V); %Compute areas for all faces
for q=1:1:max(G(:)) %Loop over all groups
       groupArea(q)=sum(A(G==q)); %Assign current area
end
[~,largestGroupId]=max(groupArea); %Get id of largest group in terms of area

I used patchArea :point_up: but for triangles the tri_area works too and may be simpler and faster.

Kevin-Mattheus-Moerman avatar Aug 12 '22 20:08 Kevin-Mattheus-Moerman

Closing this as stale

Kevin-Mattheus-Moerman avatar May 22 '23 14:05 Kevin-Mattheus-Moerman