Skip to content

Commit 71a96fd

Browse files
authored
Large volume components (#6364)
* Large Volume Components * impl
1 parent b27567b commit 71a96fd

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

source/MRMesh/MRMeshComponents.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,29 @@ FaceBitSet getLargeByAreaComponents( const MeshPart& mp, float minArea, const Un
205205
return getLargeByAreaComponents( mp, unionFind, minArea );
206206
}
207207

208+
FaceBitSet getLargeByVolumeComponents( const MeshPart& mp, float minVolume )
209+
{
210+
if ( !mp.mesh.topology.isClosed( mp.region ) )
211+
{
212+
assert( !"getLargeByVolumeComponents: require closed mesh part" );
213+
return {};
214+
}
215+
auto mapAndNum = MeshComponents::getAllComponentsMap( mp );
216+
Vector<double, RegionId> volumes( mapAndNum.second, 0.0 );
217+
auto region = mp.mesh.topology.getFaceIds( mp.region );
218+
for ( auto f : region )
219+
{
220+
auto fp = mp.mesh.getTriPoints( f );
221+
volumes[mapAndNum.first[f]] += mixed( Vector3d( fp[0] ), Vector3d( fp[1] ), Vector3d( fp[2] ) );
222+
}
223+
BitSetParallelFor( region, [&] ( FaceId f )
224+
{
225+
if ( std::abs( volumes[mapAndNum.first[f]] ) < minVolume )
226+
region.reset( f );
227+
} );
228+
return region;
229+
}
230+
208231
Expected<FaceBitSet> expandToComponents( const MeshPart& mp, const FaceBitSet& seeds, const ExpandToComponentsParams& params /*= {} */ )
209232
{
210233
if ( params.coverRatio > 1.0f )

source/MRMesh/MRMeshComponents.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ enum FaceIncidence
5151
/// returns the union of connected components, each having at least given area
5252
[[nodiscard]] MRMESH_API FaceBitSet getLargeByAreaComponents( const MeshPart& meshPart, float minArea, const UndirectedEdgeBitSet * isCompBd );
5353

54+
/// returns the union of connected components, each having at least given volume
55+
/// note that function require closed mesh part
56+
[[nodiscard]] MRMESH_API FaceBitSet getLargeByVolumeComponents( const MeshPart& meshPart, float minVolume );
57+
5458
/// given prepared union-find structure returns the union of connected components, each having at least given area
5559
[[nodiscard]] MRMESH_API FaceBitSet getLargeByAreaComponents( const MeshPart& meshPart, BaseUnionFind<FaceId> & unionFind, float minArea,
5660
UndirectedEdgeBitSet * outBdEdgesBetweenLargeComps = nullptr );

0 commit comments

Comments
 (0)