@@ -493,11 +493,12 @@ void subdivideLoneContours( Mesh& mesh, const OneMeshContours& contours, FaceHas
493
493
}
494
494
}
495
495
496
- OneMeshContours getOneMeshIntersectionContours ( const Mesh& meshA, const Mesh& meshB, const ContinuousContours& contours, bool getMeshAIntersections,
496
+ void getOneMeshIntersectionContours ( const Mesh& meshA, const Mesh& meshB, const ContinuousContours& contours,
497
+ OneMeshContours* outA, OneMeshContours* outB,
497
498
const CoordinateConverters& converters, const AffineXf3f* rigidB2A /* = nullptr */ )
498
499
{
499
500
MR_TIMER;
500
- OneMeshContours res ;
501
+ assert ( outA || outB ) ;
501
502
502
503
std::function<Vector3f ( const Vector3f& coord, bool meshA )> getCoord;
503
504
@@ -518,52 +519,63 @@ OneMeshContours getOneMeshIntersectionContours( const Mesh& meshA, const Mesh& m
518
519
AffineXf3f inverseXf;
519
520
if ( rigidB2A )
520
521
inverseXf = rigidB2A->inverse ();
521
- const auto & mainMesh = getMeshAIntersections ? meshA : meshB;
522
- const auto & otherMesh = getMeshAIntersections ? meshB : meshA;
523
- res.resize ( contours.size () );
522
+ if ( outA )
523
+ outA->resize ( contours.size () );
524
+ if ( outB )
525
+ outB->resize ( contours.size () );
524
526
ParallelFor ( contours, [&]( size_t j )
525
527
{
526
- OneMeshContour cur;
527
- auto & curOutContour = cur.intersections ;
528
+ OneMeshContour curA, curB;
528
529
const auto & curInContour = contours[j];
529
- curOutContour.resize ( curInContour.size () );
530
+ curA.closed = curB.closed = isClosed ( curInContour );
531
+ if ( outA )
532
+ curA.intersections .resize ( curInContour.size () );
533
+ if ( outB )
534
+ curB.intersections .resize ( curInContour.size () );
530
535
531
- ParallelFor ( curOutContour , [&]( size_t i )
536
+ ParallelFor ( curInContour , [&]( size_t i )
532
537
{
533
538
Vector3f a, b, c, d, e;
534
539
const auto & inIntersection = curInContour[i];
535
- auto & outIntersection = curOutContour[i] ;
540
+ OneMeshIntersection pntA, pntB ;
536
541
537
- bool edgeMain = getMeshAIntersections == inIntersection.isEdgeATriB ;
538
- if ( edgeMain )
542
+ if ( inIntersection.isEdgeATriB )
539
543
{
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
+ pntA.primitiveId = inIntersection.edge ;
545
+ pntB.primitiveId = inIntersection.tri ;
546
+ meshB.getTriPoints ( inIntersection.tri , a, b, c );
547
+ d = meshA.orgPnt ( inIntersection.edge );
548
+ e = meshA.destPnt ( inIntersection.edge );
544
549
}
545
550
else
546
551
{
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 );
552
+ pntB.primitiveId = inIntersection.edge ;
553
+ pntA.primitiveId = inIntersection.tri ;
554
+ meshA.getTriPoints ( inIntersection.tri , a, b, c );
555
+ d = meshB.orgPnt ( inIntersection.edge );
556
+ e = meshB.destPnt ( inIntersection.edge );
551
557
}
552
558
// always calculate in mesh A space
553
- outIntersection .coordinate = findTriangleSegmentIntersectionPrecise (
559
+ pntA .coordinate = findTriangleSegmentIntersectionPrecise (
554
560
getCoord ( a, !inIntersection.isEdgeATriB ),
555
561
getCoord ( b, !inIntersection.isEdgeATriB ),
556
562
getCoord ( c, !inIntersection.isEdgeATriB ),
557
563
getCoord ( d, inIntersection.isEdgeATriB ),
558
564
getCoord ( e, inIntersection.isEdgeATriB ), converters );
559
565
560
- if ( !getMeshAIntersections && rigidB2A )
561
- outIntersection.coordinate = inverseXf ( outIntersection.coordinate );
566
+ if ( outA )
567
+ curA.intersections [i] = pntA;
568
+ if ( outB )
569
+ {
570
+ pntB.coordinate = rigidB2A ? inverseXf ( pntA.coordinate ) : pntA.coordinate ;
571
+ curB.intersections [i] = pntB;
572
+ }
562
573
} );
563
- cur.closed = isClosed ( curInContour );
564
- res[j] = std::move ( cur );
574
+ if ( outA )
575
+ (*outA)[j] = std::move ( curA );
576
+ if ( outB )
577
+ (*outB)[j] = std::move ( curB );
565
578
} );
566
- return res;
567
579
}
568
580
569
581
OneMeshContours getOneMeshSelfIntersectionContours ( const Mesh& mesh, const ContinuousContours& contours, const CoordinateConverters& converters, const AffineXf3f* rigidB2A /* = nullptr */ )
@@ -2311,8 +2323,8 @@ TEST( MRMesh, BooleanIntersectionsSort )
2311
2323
auto converters = getVectorConverters ( meshA, meshB );
2312
2324
auto intersections = findCollidingEdgeTrisPrecise ( meshA, meshB, converters.toInt );
2313
2325
auto contours = orderIntersectionContours ( meshA.topology , meshB.topology , intersections );
2314
- auto meshAContours = getOneMeshIntersectionContours ( meshA, meshB, contours, true , converters ) ;
2315
- auto meshBContours = getOneMeshIntersectionContours ( meshA, meshB, contours, false , converters );
2326
+ OneMeshContours meshAContours, meshBContours ;
2327
+ getOneMeshIntersectionContours ( meshA, meshB, contours, &meshAContours, &meshBContours , converters );
2316
2328
2317
2329
SortIntersectionsData dataForA{meshB,contours,converters.toInt ,nullptr ,meshA.topology .vertSize (),false };
2318
2330
@@ -2349,8 +2361,8 @@ TEST( MRMesh, MeshCollidePrecise )
2349
2361
// EXPECT_EQ( contours[2].size(), 7 );
2350
2362
// EXPECT_EQ( contours[3].size(), 7 );
2351
2363
2352
- const auto meshAContours = getOneMeshIntersectionContours ( meshA, meshB, contours, true , conv ) ;
2353
- const auto meshBContours = getOneMeshIntersectionContours ( meshA, meshB, contours, false , conv );
2364
+ OneMeshContours meshAContours, meshBContours ;
2365
+ getOneMeshIntersectionContours ( meshA, meshB, contours, &meshAContours, &meshBContours , conv );
2354
2366
EXPECT_EQ ( meshAContours.size (), 4 );
2355
2367
EXPECT_EQ ( meshBContours.size (), 4 );
2356
2368
0 commit comments