Skip to content

Commit c3343ca

Browse files
committed
MRSurfacePath: optionally returns computed surface distances
1 parent 50e6f66 commit c3343ca

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

source/MRMesh/MRSurfacePath.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ std::optional<MeshEdgePoint> SurfacePathBuilder::findPrevPoint( const MeshTriPoi
303303
return res;
304304
}
305305

306-
tl::expected<std::vector<MeshEdgePoint>, PathError> computeSurfacePath( const MeshPart & mp,
307-
const MeshTriPoint & start, const MeshTriPoint & end, int numPostProcessIters, const VertBitSet* vertRegion )
306+
tl::expected<std::vector<MeshEdgePoint>, PathError> computeSurfacePath( const MeshPart & mp,
307+
const MeshTriPoint & start, const MeshTriPoint & end, int numPostProcessIters,
308+
const VertBitSet* vertRegion, Vector<float, VertId> * outSurfaceDistances )
308309
{
309310
MR_TIMER;
310311
std::vector<MeshEdgePoint> res;
@@ -325,7 +326,7 @@ tl::expected<std::vector<MeshEdgePoint>, PathError> computeSurfacePath( const Me
325326

326327
// build distances from end to start, so to get correct path in reverse order
327328
bool connected = false;
328-
const auto distances = computeSurfaceDistances( mp.mesh, end, start, vertRegion, &connected );
329+
auto distances = computeSurfaceDistances( mp.mesh, end, start, vertRegion, &connected );
329330
if ( !connected )
330331
return tl::make_unexpected( PathError::StartEndNotConnected );
331332

@@ -345,14 +346,17 @@ tl::expected<std::vector<MeshEdgePoint>, PathError> computeSurfacePath( const Me
345346
assert( !res.empty() );
346347
reducePath( mp.mesh, start, res, end, numPostProcessIters );
347348

349+
if ( outSurfaceDistances )
350+
*outSurfaceDistances = std::move( distances );
348351
return res;
349352
}
350353

351354
HashMap<VertId, VertId> computeClosestSurfacePathTargets( const Mesh & mesh,
352-
const VertBitSet & starts, const VertBitSet & ends, const VertBitSet * vertRegion )
355+
const VertBitSet & starts, const VertBitSet & ends,
356+
const VertBitSet * vertRegion, Vector<float, VertId> * outSurfaceDistances )
353357
{
354358
MR_TIMER;
355-
const auto distances = computeSurfaceDistances( mesh, ends, starts, FLT_MAX, vertRegion );
359+
auto distances = computeSurfaceDistances( mesh, ends, starts, FLT_MAX, vertRegion );
356360

357361
HashMap<VertId, VertId> res;
358362
res.reserve( starts.count() );
@@ -384,6 +388,8 @@ HashMap<VertId, VertId> computeClosestSurfacePathTargets( const Mesh & mesh,
384388
res[v] = last->getClosestVertex( mesh.topology );
385389
} );
386390

391+
if ( outSurfaceDistances )
392+
*outSurfaceDistances = std::move( distances );
387393
return res;
388394
}
389395

source/MRMesh/MRSurfacePath.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ enum class PathError
1616
// returns intermediate points of the geodesic path from start to end, where it crosses mesh edges;
1717
// the path can be limited to given region: in face-format inside mp, or in vert-format in vertRegion argument
1818
MRMESH_API tl::expected<SurfacePath, PathError> computeSurfacePath( const MeshPart & mp,
19-
const MeshTriPoint & start, const MeshTriPoint & end, int numPostProcessIters = 5, const VertBitSet* vertRegion = nullptr );
19+
const MeshTriPoint & start, const MeshTriPoint & end, int numPostProcessIters = 5, const VertBitSet* vertRegion = nullptr,
20+
Vector<float, VertId> * outSurfaceDistances = nullptr );
2021

2122
// for each vertex from (starts) finds the closest vertex from (ends) in geodesic sense
2223
MRMESH_API HashMap<VertId, VertId> computeClosestSurfacePathTargets( const Mesh & mesh,
2324
const VertBitSet & starts, const VertBitSet & ends,
24-
const VertBitSet * vertRegion = nullptr ); //< consider paths going in this region only
25+
const VertBitSet * vertRegion = nullptr, //< consider paths going in this region only
26+
Vector<float, VertId> * outSurfaceDistances = nullptr );
2527

2628
// returns length of surface path, accumulate each segment
2729
MRMESH_API float surfacePathLength( const Mesh& mesh, const SurfacePath& surfacePath );

0 commit comments

Comments
 (0)