|
1 | 1 | #include "MRContoursCut.h" |
2 | 2 | #include "MRAffineXf3.h" |
3 | 3 | #include "MRMesh.h" |
| 4 | +#include "MRPolyline.h" |
4 | 5 | #include "MRTriangleIntersection.h" |
5 | 6 | #include "MRMeshTopology.h" |
6 | 7 | #include "MRMeshDelone.h" |
@@ -2190,6 +2191,37 @@ CutMeshResult cutMesh( Mesh& mesh, const OneMeshContours& contours, const CutMes |
2190 | 2191 | return res; |
2191 | 2192 | } |
2192 | 2193 |
|
| 2194 | +Expected<FaceBitSet> cutMeshByContour( Mesh& mesh, const Contour3f& contour, const AffineXf3f& xf ) |
| 2195 | +{ |
| 2196 | + std::vector<MeshTriPoint> surfaceLine( contour.size() ); |
| 2197 | + tbb::task_group_context ctx; |
| 2198 | + bool ok = true; |
| 2199 | + ParallelFor( (size_t)0, contour.size(), [&] ( size_t i ) |
| 2200 | + { |
| 2201 | + PointOnFace projPt; |
| 2202 | + if ( !mesh.projectPoint( xf( contour[i] ), projPt ) ) |
| 2203 | + { |
| 2204 | + if ( ctx.cancel_group_execution() ) |
| 2205 | + ok = false; |
| 2206 | + return; |
| 2207 | + } |
| 2208 | + surfaceLine[i] = mesh.toTriPoint( projPt ); |
| 2209 | + } ); |
| 2210 | + if ( !ok ) |
| 2211 | + return unexpected( "Cannot project point to mesh" ); |
| 2212 | + |
| 2213 | + auto meshContour = convertMeshTriPointsToMeshContour( mesh, surfaceLine ); |
| 2214 | + if ( !meshContour ) |
| 2215 | + return unexpected( "Cannot convert tri points to mesh contour: " + meshContour.error() ); |
| 2216 | + |
| 2217 | + auto cutRes = cutMesh( mesh, { *meshContour } ); |
| 2218 | + if ( !cutRes.fbsWithCountourIntersections.none() ) |
| 2219 | + return unexpected( "Cannot cut mesh because of contour self intersections" ); |
| 2220 | + auto sideFbv = fillContourLeft( mesh.topology, cutRes.resultCut ); |
| 2221 | + return sideFbv; |
| 2222 | +} |
| 2223 | + |
| 2224 | + |
2193 | 2225 | TEST( MRMesh, BooleanIntersectionsSort ) |
2194 | 2226 | { |
2195 | 2227 | Mesh meshA; |
|
0 commit comments