Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions source/MRMesh/MRPolylineProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,16 @@ PolylineProjectionResult3 findProjectionOnMeshEdges( const Line3f& ln, const Mes
[ln]( const LineSegm3f & ls ) { return closestPoints( ln, ls ); } );
}

template<typename V>
void findEdgesInBallT( const Polyline<V>& polyline, const V& center, float radius, const FoundEdgeCallback<V>& foundCallback, AffineXf<V>* xf )
template<typename V, typename F>
void findEdgesInBallCore( const AABBTreePolyline<V>& tree, const V& center,
float radius, const FoundEdgeCallback<V>& foundCallback, AffineXf<V>* xf, F&& edgeToEndPoints )
{
if ( !foundCallback )
{
assert( false );
return;
}

const auto & tree = polyline.getAABBTree();
if ( tree.nodes().empty() )
return;

Expand All @@ -326,7 +326,8 @@ void findEdgesInBallT( const Polyline<V>& polyline, const V& center, float radiu

if ( node.leaf() )
{
auto segm = polyline.edgeSegment( node.leafId() );
LineSegm<V> segm;
edgeToEndPoints( node.leafId(), segm.a, segm.b );
if ( xf )
{
segm.a = ( *xf )( segm.a );
Expand All @@ -347,12 +348,29 @@ void findEdgesInBallT( const Polyline<V>& polyline, const V& center, float radiu

void findEdgesInBall( const Polyline2& polyline, const Vector2f& center, float radius, const FoundEdgeCallback2& foundCallback, AffineXf2f* xf )
{
findEdgesInBallT( polyline, center, radius, foundCallback, xf );
findEdgesInBallCore( polyline.getAABBTree(), center, radius, foundCallback, xf, [&] ( UndirectedEdgeId ue, Vector2f& a, Vector2f& b )
{
a = polyline.orgPnt( ue );
b = polyline.destPnt( ue );
} );
}

void findEdgesInBall( const Polyline3& polyline, const Vector3f& center, float radius, const FoundEdgeCallback3& foundCallback, AffineXf3f* xf )
{
findEdgesInBallT( polyline, center, radius, foundCallback, xf );
findEdgesInBallCore( polyline.getAABBTree(), center, radius, foundCallback, xf, [&] ( UndirectedEdgeId ue, Vector3f& a, Vector3f& b )
{
a = polyline.orgPnt( ue );
b = polyline.destPnt( ue );
} );
}

void findMeshEdgesInBall( const Mesh& mesh, const AABBTreePolyline3& tree, const Vector3f& center, float radius, const FoundEdgeCallback3& foundCallback, AffineXf3f* xf /*= nullptr */ )
{
findEdgesInBallCore( tree, center, radius, foundCallback, xf, [&] ( UndirectedEdgeId ue, Vector3f& a, Vector3f& b )
{
a = mesh.orgPnt( ue );
b = mesh.destPnt( ue );
} );
}

} //namespace MR
3 changes: 3 additions & 0 deletions source/MRMesh/MRPolylineProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ MRMESH_API void findEdgesInBall( const Polyline2& polyline, const Vector2f& cent
/// Finds all edges of given polyline that cross or touch given ball (center, radius)
MRMESH_API void findEdgesInBall( const Polyline3& polyline, const Vector3f& center, float radius, const FoundEdgeCallback3& foundCallback, AffineXf3f* xf = nullptr );

/// Finds all edges of given mesh edges (specified by the tree) that cross or touch given ball (center, radius)
MRMESH_API void findMeshEdgesInBall( const Mesh& mesh, const AABBTreePolyline3& tree, const Vector3f& center, float radius, const FoundEdgeCallback3& foundCallback, AffineXf3f* xf = nullptr );

/**
* \brief computes the closest point on the mesh edges (specified by the tree) to given point
* \param upDistLimitSq upper limit on the distance in question, if the real distance is larger than the function exists returning upDistLimitSq and no valid point
Expand Down