Skip to content

Commit

Permalink
MRSurfacePath: optionally returns computed surface distances
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedr committed Jan 25, 2022
1 parent 50e6f66 commit c3343ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions source/MRMesh/MRSurfacePath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ std::optional<MeshEdgePoint> SurfacePathBuilder::findPrevPoint( const MeshTriPoi
return res;
}

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

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

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

if ( outSurfaceDistances )
*outSurfaceDistances = std::move( distances );
return res;
}

HashMap<VertId, VertId> computeClosestSurfacePathTargets( const Mesh & mesh,
const VertBitSet & starts, const VertBitSet & ends, const VertBitSet * vertRegion )
const VertBitSet & starts, const VertBitSet & ends,
const VertBitSet * vertRegion, Vector<float, VertId> * outSurfaceDistances )
{
MR_TIMER;
const auto distances = computeSurfaceDistances( mesh, ends, starts, FLT_MAX, vertRegion );
auto distances = computeSurfaceDistances( mesh, ends, starts, FLT_MAX, vertRegion );

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

if ( outSurfaceDistances )
*outSurfaceDistances = std::move( distances );
return res;
}

Expand Down
6 changes: 4 additions & 2 deletions source/MRMesh/MRSurfacePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ enum class PathError
// returns intermediate points of the geodesic path from start to end, where it crosses mesh edges;
// the path can be limited to given region: in face-format inside mp, or in vert-format in vertRegion argument
MRMESH_API tl::expected<SurfacePath, PathError> computeSurfacePath( const MeshPart & mp,
const MeshTriPoint & start, const MeshTriPoint & end, int numPostProcessIters = 5, const VertBitSet* vertRegion = nullptr );
const MeshTriPoint & start, const MeshTriPoint & end, int numPostProcessIters = 5, const VertBitSet* vertRegion = nullptr,
Vector<float, VertId> * outSurfaceDistances = nullptr );

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

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

0 comments on commit c3343ca

Please sign in to comment.