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

Function polylineOffset

source/MRMesh/MRDistanceMap.cpp:1376–1415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1374}
1375
1376Polyline2 polylineOffset( const Polyline2& polyline, float pixelSize, float offset )
1377{
1378 MR_TIMER;
1379
1380 assert( offset > 0.f );
1381
1382 const auto box = polyline.computeBoundingBox();
1383 const auto size = box.size();
1384
1385 const auto padding = offset + 2 * pixelSize;
1386
1387 ContourToDistanceMapParams params;
1388 params.pixelSize = {
1389 pixelSize,
1390 pixelSize,
1391 };
1392 params.resolution = {
1393 int( ( size.x + 2 * padding ) / pixelSize ),
1394 int( ( size.y + 2 * padding ) / pixelSize ),
1395 };
1396 params.orgPoint = {
1397 box.min.x - padding,
1398 box.min.y - padding,
1399 };
1400
1401 ContoursDistanceMapOptions options;
1402 //compute precise distances only in the cells crossed by offset-isoline
1403 options.maxDist = offset + pixelSize;
1404 options.minDist = std::max( offset - pixelSize, 0.0f );
1405
1406 const auto distanceMap = distanceMapFromContours( polyline, params, options );
1407
1408 auto isoline = distanceMapTo2DIsoPolyline( distanceMap, offset );
1409
1410 AffineXf3f xf( params );
1411 for ( auto& p : isoline.points )
1412 p = Vector2f( xf( { p.x, p.y, 0 } ) );
1413
1414 return isoline;
1415}
1416
1417} //namespace MR

Callers

nothing calls this directly

Calls 5

maxFunction · 0.85
distanceMapFromContoursFunction · 0.70
computeBoundingBoxMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected