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

Function fromDisjointMeshPieces

source/MRMesh/MRMeshBuilder.cpp:375–425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373}
374
375MeshTopology fromDisjointMeshPieces( const Triangulation & t, VertId maxVertId,
376 const std::vector<MeshPiece> & pieces,
377 const BuildSettings & settings0 )
378{
379 MR_TIMER;
380
381 // construct empty final mesh with enough number of elements
382 const auto numParts = pieces.size();
383 std::vector<EdgeId> firstPartEdge( numParts + 1 );
384 firstPartEdge[0] = 0_e;
385 FaceBitSet region;
386 if ( settings0.region )
387 region = std::move( *settings0.region );
388 region.resize( t.size() );
389 for ( int i = 0; i < pieces.size(); ++i )
390 {
391 const auto & p = pieces[i];
392 firstPartEdge[i + 1] = firstPartEdge[i] + (int)p.topology.edgeSize();
393 for ( FaceId f : p.rem ) // remaining triangles
394 region.set( p.fmap[f] );
395 }
396 int numEdgesInParts = firstPartEdge.back();
397
398 MeshTopology res;
399 const auto borderTriCount = region.count();
400 res.edgeReserve( numEdgesInParts + 6 * borderTriCount ); // should be enough even if all border triangles are disconnected
401 res.resizeBeforeParallelAdd( numEdgesInParts, maxVertId + 1, t.size() );
402
403 // add pieces in res in parallel
404 tbb::parallel_for( tbb::blocked_range<size_t>( 0, numParts, 1 ), [&]( const tbb::blocked_range<size_t> & range )
405 {
406 assert( range.begin() + 1 == range.end() );
407 for ( size_t myPartId = range.begin(); myPartId < range.end(); ++myPartId )
408 {
409 const auto & part = pieces[myPartId];
410 res.addPackedPart( part.topology, firstPartEdge[myPartId], part.fmap, part.vmap );
411 }
412 } );
413 res.computeValidsFromEdges();
414
415 // and add border triangles
416 BuildSettings settings = settings0;
417 settings.region = &region;
418 addTrianglesSeqCore( res, t, settings );
419 if ( settings0.skippedFaceCount )
420 *settings0.skippedFaceCount = (int)region.count();
421 if ( settings0.region )
422 *settings0.region = std::move( region );
423
424 return res;
425}
426
427constexpr size_t minTrisInPart = 32768;
428

Callers 1

fromTrianglesParFunction · 0.85

Calls 12

addTrianglesSeqCoreFunction · 0.85
countMethod · 0.80
addPackedPartMethod · 0.80
sizeMethod · 0.45
resizeMethod · 0.45
edgeSizeMethod · 0.45
setMethod · 0.45
edgeReserveMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected