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

Function offsetMesh

source/MRVoxels/MROffset.cpp:33–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33Expected<Mesh> offsetMesh( const MeshPart & mp, float offset, const OffsetParameters& params /*= {} */ )
34{
35 MR_TIMER;
36 assert( params.signDetectionMode == SignDetectionMode::Unsigned
37 || params.signDetectionMode == SignDetectionMode::OpenVDB
38 || params.signDetectionMode == SignDetectionMode::HoleWindingRule );
39
40 if ( params.voxelSize <= 0 )
41 {
42 assert( false );
43 return unexpected( "invalid voxelSize value" );
44 }
45
46 float voxelSize = params.voxelSize;
47 bool useShell = params.signDetectionMode == SignDetectionMode::Unsigned;
48 bool signPostprocess = params.signDetectionMode == SignDetectionMode::HoleWindingRule;
49
50 if ( useShell )
51 offset = std::abs( offset );
52
53 auto offsetInVoxels = offset / voxelSize;
54
55 auto voxelSizeVector = Vector3f::diagonal( voxelSize );
56 // Make grid
57 FloatGrid grid;
58 if ( !useShell && !signPostprocess )
59 {
60 // Compute signed distance grid
61 grid = meshToLevelSet( mp, AffineXf3f(), voxelSizeVector, std::abs( offsetInVoxels ) + 2,
62 subprogress( params.callBack, 0.0f, 0.5f ) );
63 }
64 else
65 {
66 // Compute unsigned distance grid
67 grid = meshToDistanceField( mp, AffineXf3f(), voxelSizeVector, std::abs( offsetInVoxels ) + 2,
68 subprogress( params.callBack, 0.0f, signPostprocess ? 0.33f : 0.5f ) );
69 setLevelSetType( grid ); // to flip mesh normals
70 }
71
72 if ( !grid )
73 return unexpectedOperationCanceled();
74
75 if ( signPostprocess )
76 {
77 auto signRes = makeSignedByWindingNumber( grid, Vector3f::diagonal( voxelSize ), mp.mesh,
78 {
79 .fwn = params.fwn,
80 .windingNumberThreshold = params.windingNumberThreshold,
81 .windingNumberBeta = params.windingNumberBeta,
82 .progress = subprogress( params.callBack, 0.33f, 0.66f )
83 } );
84 if ( !signRes.has_value() )
85 return unexpected( std::move( signRes.error() ) );
86 }
87
88 // Make offset mesh
89 auto newMesh = gridToMesh( std::move( grid ), GridToMeshSettings{
90 .voxelSize = voxelSizeVector,

Callers 6

TestOffsetsMethod · 0.85
preprocessMeshFunction · 0.85
generalOffsetMeshFunction · 0.85
offsetPolylineFunction · 0.85
EMSCRIPTEN_BINDINGSFunction · 0.85
mainFunction · 0.85

Calls 11

absFunction · 0.85
diagonalFunction · 0.85
meshToLevelSetFunction · 0.85
subprogressFunction · 0.85
meshToDistanceFieldFunction · 0.85
setLevelSetTypeFunction · 0.85
gridToMeshFunction · 0.85
errorMethod · 0.80
unexpectedFunction · 0.50

Tested by 1

TestOffsetsMethod · 0.68