MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / getAllComponents

Function getAllComponents

source/MRMesh/MRPolylineComponents.cpp:85–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85std::pair<std::vector<UndirectedEdgeBitSet>, int> getAllComponents( const PolylineTopology& topology, int maxComponentCount )
86{
87 MR_TIMER;
88 auto unionFindStruct = getUnionFindStructure( topology );
89 const auto& allRoots = unionFindStruct.roots();
90 UndirectedEdgeBitSet region( topology.lastNotLoneUndirectedEdge() + 1 );
91 for ( auto e : undirectedEdges( topology ) )
92 region.set( e );
93 auto [uniqueRootsMap, componentsCount] = getUniqueRootIds( allRoots, region );
94 if ( !componentsCount )
95 return { {}, 0 };
96 const int componentsInGroup = maxComponentCount == INT_MAX ? 1 : ( componentsCount + maxComponentCount - 1 ) / maxComponentCount;
97 if ( componentsInGroup != 1 )
98 for ( RegionId& id : uniqueRootsMap )
99 id = RegionId( id / componentsInGroup );
100 componentsCount = ( componentsCount + componentsInGroup - 1 ) / componentsInGroup;
101 std::vector<UndirectedEdgeBitSet> res( componentsCount );
102 // this block is needed to limit allocations for not packed meshes
103 std::vector<int> resSizes( componentsCount, 0 );
104 for ( auto ue : undirectedEdges( topology ) )
105 {
106 int index = uniqueRootsMap[ue];
107 if ( ue > resSizes[index] )
108 resSizes[index] = ue;
109 }
110 for ( int i = 0; i < componentsCount; ++i )
111 res[i].resize( resSizes[i] + 1 );
112 // end of allocation block
113 for ( auto ue : undirectedEdges( topology ) )
114 res[uniqueRootsMap[ue]].set( ue );
115 return { std::move( res ), componentsInGroup };
116}
117
118std::vector<MR::UndirectedEdgeBitSet> getAllComponents( const PolylineTopology& topology )
119{

Callers

nothing calls this directly

Calls 6

getUnionFindStructureFunction · 0.85
undirectedEdgesFunction · 0.70
getUniqueRootIdsFunction · 0.70
setMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected