From b395f317140d109ede001bf9e6efba0db0568277 Mon Sep 17 00:00:00 2001 From: Berend Baas Date: Mon, 28 Apr 2025 19:37:42 +0200 Subject: [PATCH] Adding a int|none seed parameters to random_points_on_mesh --- src/random_points_on_mesh.cpp | 9 +++++++-- tests/test_all.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/random_points_on_mesh.cpp b/src/random_points_on_mesh.cpp index 7fd51f2a..70752008 100644 --- a/src/random_points_on_mesh.cpp +++ b/src/random_points_on_mesh.cpp @@ -1,8 +1,10 @@ #include "default_types.h" #include +#include #include #include #include +#include namespace nb = nanobind; using namespace nb::literals; @@ -13,11 +15,13 @@ namespace pyigl auto random_points_on_mesh( const Integer n, const nb::DRef &V, - const nb::DRef &F) + const nb::DRef &F, + const std::optional seed) { + std::mt19937 urbg = seed.has_value() ? std::mt19937(*seed) : igl::generate_default_urbg(); Eigen::VectorXI FI; Eigen::MatrixXN B,X; - igl::random_points_on_mesh(n, V, F, B, FI, X); + igl::random_points_on_mesh(n, V, F, B, FI, X, urbg); return std::make_tuple(B, FI, X); } } @@ -32,6 +36,7 @@ void bind_random_points_on_mesh(nb::module_ &m) "n"_a, "V"_a, "F"_a, + "seed"_a = nb::none(), R"( Randomly sample a mesh (V,F) n times. diff --git a/tests/test_all.py b/tests/test_all.py index 1dd1a13e..b445179c 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -327,6 +327,19 @@ def test_sample(): I = igl.knn(X,X,1,point_indices,CH,CN,W) B,FI,P = igl.blue_noise(V,F,0.5) + # Test equal seed yields same result + B1,I1,X1 = igl.random_points_on_mesh(10,V,F, 1) + B1_,I1_,X1_ = igl.random_points_on_mesh(10,V,F, 1) + assert np.all(B1 == B1_) + assert np.all(I1 == I1_) + assert np.all(X1 == X1_) + # Test different seed yields different result + B2,I2,X2 = igl.random_points_on_mesh(10,V,F,2) + assert not np.all(B1 == B2) + assert not np.all(I1 == I2) + assert not np.all(X1 == X2) + + def test_curvature(): V,F = igl.icosahedron() K = igl.gaussian_curvature(V,F)