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

Function computeDistanceMap_

source/MRMesh/MRDistanceMap.cpp:260–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258
259template <typename T = float>
260DistanceMap computeDistanceMap_( const MeshPart& mp, const MeshToDistanceMapParams& params, ProgressCallback cb,
261 std::vector<MeshTriPoint> * outSamples )
262{
263 DistanceMap distMap( params.resolution.x, params.resolution.y );
264
265 // precomputed some values
266 IntersectionPrecomputes<T> prec( Vector3<T>( params.direction ) );
267
268 auto ori = params.orgPoint;
269 float shift = 0.f;
270 if ( params.allowNegativeValues )
271 {
272 AffineXf3f xf( Matrix3f( params.xRange.normalized(), params.yRange.normalized(), params.direction.normalized() ), Vector3f() );
273 Box box = mp.mesh.computeBoundingBox( mp.region,&xf );
274 shift = dot( params.direction, ori - box.min );
275 if ( shift > 0.f )
276 {
277 ori -= params.direction * shift;
278 }
279 else
280 {
281 shift = T( 0 );
282 }
283 }
284
285 const T xStep_1 = T( 1 ) / T( params.resolution.x );
286 const T yStep_1 = T( 1 ) / T( params.resolution.y );
287
288 if ( outSamples )
289 {
290 outSamples->clear();
291 outSamples->resize( size_t( params.resolution.x ) * params.resolution.y );
292 }
293 if ( !ParallelFor( 0, params.resolution.y, [&]( int y )
294 {
295 for ( int x = 0; x < params.resolution.x; ++x )
296 {
297 Vector3<T> rayOri = Vector3<T>( ori ) +
298 Vector3<T>( params.xRange ) * ( ( T( x ) + T( 0.5 ) ) * xStep_1 ) +
299 Vector3<T>( params.yRange ) * ( ( T( y ) + T( 0.5 ) ) * yStep_1 );
300 if ( auto meshIntersectionRes = rayMeshIntersect( mp, Line3<T>( Vector3<T>( rayOri ), Vector3<T>( params.direction ) ),
301 -std::numeric_limits<T>::max(), std::numeric_limits<T>::max(), &prec ) )
302 {
303 if ( !params.useDistanceLimits
304 || ( meshIntersectionRes.distanceAlongLine < params.minValue )
305 || ( meshIntersectionRes.distanceAlongLine > params.maxValue ) )
306 {
307 const auto i = distMap.toIndex( { x, y } );
308 distMap.set( i, meshIntersectionRes.distanceAlongLine );
309 if ( outSamples )
310 (*outSamples)[i] = meshIntersectionRes.mtp;
311 }
312 }
313 }
314 }, cb, 1 ) )
315 return DistanceMap{};
316
317 if ( params.allowNegativeValues )

Callers

nothing calls this directly

Calls 12

ParallelForFunction · 0.85
rayMeshIntersectFunction · 0.85
maxFunction · 0.85
toIndexMethod · 0.80
numPointsMethod · 0.80
dotFunction · 0.70
normalizedMethod · 0.45
computeBoundingBoxMethod · 0.45
clearMethod · 0.45
resizeMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected