Skip to content

Commit 55f3144

Browse files
authored
optimize getOneMeshIntersectionContours function (#4621)
1 parent 44134a2 commit 55f3144

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

source/MRMesh/MRContoursCut.cpp

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -521,50 +521,48 @@ OneMeshContours getOneMeshIntersectionContours( const Mesh& meshA, const Mesh& m
521521
const auto& mainMesh = getMeshAIntersections ? meshA : meshB;
522522
const auto& otherMesh = getMeshAIntersections ? meshB : meshA;
523523
res.resize( contours.size() );
524-
for ( int j = 0; j < contours.size(); ++j )
524+
ParallelFor( contours, [&]( size_t j )
525525
{
526-
auto& curOutContour = res[j].intersections;
526+
OneMeshContour cur;
527+
auto& curOutContour = cur.intersections;
527528
const auto& curInContour = contours[j];
528-
res[j].closed = isClosed( curInContour );
529529
curOutContour.resize( curInContour.size() );
530530

531-
tbb::parallel_for( tbb::blocked_range<size_t>( 0, curInContour.size() ),
532-
[&]( const tbb::blocked_range<size_t>& range )
531+
ParallelFor( curOutContour, [&]( size_t i )
533532
{
534533
Vector3f a, b, c, d, e;
535-
for ( size_t i = range.begin(); i < range.end(); ++i )
536-
{
537-
const auto& inIntersection = curInContour[i];
538-
auto& outIntersection = curOutContour[i];
539-
540-
bool edgeMain = getMeshAIntersections == inIntersection.isEdgeATriB;
541-
if ( edgeMain )
542-
{
543-
outIntersection.primitiveId = inIntersection.edge;
544-
otherMesh.getTriPoints( inIntersection.tri, a, b, c );
545-
d = mainMesh.orgPnt( inIntersection.edge );
546-
e = mainMesh.destPnt( inIntersection.edge );
547-
}
548-
else
549-
{
550-
outIntersection.primitiveId = inIntersection.tri;
551-
mainMesh.getTriPoints( inIntersection.tri, a, b, c );
552-
d = otherMesh.orgPnt( inIntersection.edge );
553-
e = otherMesh.destPnt( inIntersection.edge );
554-
}
555-
// always calculate in mesh A space
556-
outIntersection.coordinate = findTriangleSegmentIntersectionPrecise(
557-
getCoord( a, !inIntersection.isEdgeATriB ),
558-
getCoord( b, !inIntersection.isEdgeATriB ),
559-
getCoord( c, !inIntersection.isEdgeATriB ),
560-
getCoord( d, inIntersection.isEdgeATriB ),
561-
getCoord( e, inIntersection.isEdgeATriB ), converters );
534+
const auto& inIntersection = curInContour[i];
535+
auto& outIntersection = curOutContour[i];
562536

563-
if ( !getMeshAIntersections && rigidB2A )
564-
outIntersection.coordinate = inverseXf( outIntersection.coordinate );
537+
bool edgeMain = getMeshAIntersections == inIntersection.isEdgeATriB;
538+
if ( edgeMain )
539+
{
540+
outIntersection.primitiveId = inIntersection.edge;
541+
otherMesh.getTriPoints( inIntersection.tri, a, b, c );
542+
d = mainMesh.orgPnt( inIntersection.edge );
543+
e = mainMesh.destPnt( inIntersection.edge );
544+
}
545+
else
546+
{
547+
outIntersection.primitiveId = inIntersection.tri;
548+
mainMesh.getTriPoints( inIntersection.tri, a, b, c );
549+
d = otherMesh.orgPnt( inIntersection.edge );
550+
e = otherMesh.destPnt( inIntersection.edge );
565551
}
552+
// always calculate in mesh A space
553+
outIntersection.coordinate = findTriangleSegmentIntersectionPrecise(
554+
getCoord( a, !inIntersection.isEdgeATriB ),
555+
getCoord( b, !inIntersection.isEdgeATriB ),
556+
getCoord( c, !inIntersection.isEdgeATriB ),
557+
getCoord( d, inIntersection.isEdgeATriB ),
558+
getCoord( e, inIntersection.isEdgeATriB ), converters );
559+
560+
if ( !getMeshAIntersections && rigidB2A )
561+
outIntersection.coordinate = inverseXf( outIntersection.coordinate );
566562
} );
567-
}
563+
cur.closed = isClosed( curInContour );
564+
res[j] = std::move( cur );
565+
} );
568566
return res;
569567
}
570568

0 commit comments

Comments
 (0)