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
1 change: 1 addition & 0 deletions source/MRMesh/MRClosestWeightedPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ std::optional<ClosestTriPoint> findClosestWeightedTriPoint( const Vector3d& locd
ws[i] = pointWeight( vs[i] );
}

// considering unsigned distances, each triangle has two planes where euclidean distance equals interpolated point weight
const auto maybePlane = ( dot( locd - ps[0], dirDblArea( ps ) ) >= 0 ) ?
tangentPlaneToSpheres( ps[0], ps[1], ps[2], ws[0], ws[1], ws[2] ) :
tangentPlaneToSpheres( ps[1], ps[0], ps[2], ws[1], ws[0], ws[2] );
Expand Down
32 changes: 32 additions & 0 deletions source/MRTest/MRPointCloudVariadicOffsetTests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <MRMesh/MRClosestWeightedPoint.h>
#include <MRMesh/MRPointCloud.h>
#include <MRMesh/MRMesh.h>
#include <MRMesh/MRGTest.h>

namespace MR
Expand Down Expand Up @@ -45,4 +46,35 @@ TEST( MRMesh, findClosestWeightedPoint )
}
}

TEST( MRMesh, findClosestWeightedMeshPoint )
{
Triangulation t{
{ 0_v, 1_v, 2_v }
};
VertCoords vs{
{-1, -1, 0 }, //0_v
{-1, 1, 0 }, //1_v
{ 1, 0, 0 }, //2_v
};
auto mesh = Mesh::fromTriangles( std::move( vs ), t );

DistanceFromWeightedPointsComputeParams params;
auto distance = [&]( Vector3f loc )
{
auto pd = findClosestWeightedMeshPoint( loc, mesh, params );
assert( !pd.mtp.onEdge( mesh.topology ) );
return pd.dist;
};

params.pointWeight = [&]( VertId ) { return 1; };
params.maxWeight = 1;
for ( float z = -2; z <= 2; z += 0.1f )
EXPECT_NEAR( distance( Vector3f( 0, 0, z ) ), -1 + std::abs( z ), 1e-7f );

params.pointWeight = [&]( VertId ) { return -1; };
params.maxWeight = -1;
for ( float z = -2; z <= 2; z += 0.1f )
EXPECT_NEAR( distance( Vector3f( 0, 0, z ) ), 1 + std::abs( z ), 1e-7f );
}

} //namespace MR
Loading