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

Function fix

source/MRMesh/MRFixSelfIntersections.cpp:108–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108Expected<void> fix( Mesh& mesh, const Settings& settings )
109{
110 MR_TIMER;
111
112 if ( !reportProgress( settings.callback, 0.0f ) )
113 return unexpectedOperationCanceled();
114
115 if ( settings.touchIsIntersection )
116 {
117 auto faceToRegionMap = MeshComponents::getAllComponentsMap( { mesh } ).first;
118 auto res = findSelfCollidingTrianglesBS( mesh,
119 subprogress( settings.callback, 0.0f, 0.2f ),
120 &faceToRegionMap, settings.touchIsIntersection );
121
122 if ( !res.has_value() )
123 return unexpected( std::move( res.error() ) );
124 if ( res->none() )
125 return {};
126
127 FixMeshDegeneraciesParams fdParams;
128 fdParams.maxDeviation = mesh.getBoundingBox().diagonal() * 1e-4f;
129 fdParams.tinyEdgeLength = fdParams.maxDeviation * 0.1f;
130
131 // do not subdivide if it is explicitly forbidden by user
132 fdParams.mode = FixMeshDegeneraciesParams::Mode::Decimate;
133 if ( settings.subdivideEdgeLen < FLT_MAX )
134 fdParams.mode = FixMeshDegeneraciesParams::Mode::Remesh;
135
136 fdParams.cb = subprogress( settings.callback, 0.2f, 0.3f );
137 auto fdRes = fixMeshDegeneracies( mesh, fdParams );
138 if ( !fdRes.has_value() )
139 return fdRes;
140 }
141
142 auto faceToRegionMap = MeshComponents::getAllComponentsMap( { mesh } ).first;
143
144 if ( !reportProgress( settings.callback, 0.3f ) )
145 return unexpectedOperationCanceled();
146
147 auto res = findSelfCollidingTrianglesBS( mesh,
148 subprogress( settings.callback, 0.3f, 0.5f ),
149 &faceToRegionMap, settings.touchIsIntersection );
150 if ( !res.has_value() )
151 return unexpected( res.error() );
152
153 if ( res->none() )
154 return {};
155
156 expand( mesh.topology, *res, std::max( settings.maxExpand, 1 ) );
157
158 Settings currentSettings = settings;
159 if ( currentSettings.subdivideEdgeLen < FLT_MAX )
160 {
161 auto box = mesh.computeBoundingBox( &res.value() );
162 if ( currentSettings.subdivideEdgeLen <= 0.0f )
163 currentSettings.subdivideEdgeLen = box.valid() ? box.diagonal() * 1e-2f : mesh.getBoundingBox().diagonal() * 1e-4f;
164
165 SubdivideSettings ssettings;

Callers

nothing calls this directly

Calls 15

reportProgressFunction · 0.85
getAllComponentsMapFunction · 0.85
subprogressFunction · 0.85
fixMeshDegeneraciesFunction · 0.85
expandFunction · 0.85
maxFunction · 0.85
subdivideMeshFunction · 0.85
getIncidentVertsFunction · 0.85
findRightBoundaryFunction · 0.85

Tested by

no test coverage detected