Skip to content

Commit b395f31

Browse files
author
Berend Baas
committed
Adding a int|none seed parameters to random_points_on_mesh
1 parent 51439ef commit b395f31

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/random_points_on_mesh.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "default_types.h"
22
#include <igl/random_points_on_mesh.h>
3+
#include <igl/generate_default_urbg.h>
34
#include <nanobind/nanobind.h>
45
#include <nanobind/eigen/dense.h>
56
#include <nanobind/stl/tuple.h>
7+
#include <nanobind/stl/optional.h>
68

79
namespace nb = nanobind;
810
using namespace nb::literals;
@@ -13,11 +15,13 @@ namespace pyigl
1315
auto random_points_on_mesh(
1416
const Integer n,
1517
const nb::DRef<const Eigen::MatrixXN> &V,
16-
const nb::DRef<const Eigen::MatrixXI> &F)
18+
const nb::DRef<const Eigen::MatrixXI> &F,
19+
const std::optional<int> seed)
1720
{
21+
std::mt19937 urbg = seed.has_value() ? std::mt19937(*seed) : igl::generate_default_urbg();
1822
Eigen::VectorXI FI;
1923
Eigen::MatrixXN B,X;
20-
igl::random_points_on_mesh(n, V, F, B, FI, X);
24+
igl::random_points_on_mesh(n, V, F, B, FI, X, urbg);
2125
return std::make_tuple(B, FI, X);
2226
}
2327
}
@@ -32,6 +36,7 @@ void bind_random_points_on_mesh(nb::module_ &m)
3236
"n"_a,
3337
"V"_a,
3438
"F"_a,
39+
"seed"_a = nb::none(),
3540
R"(
3641
Randomly sample a mesh (V,F) n times.
3742

tests/test_all.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,19 @@ def test_sample():
327327
I = igl.knn(X,X,1,point_indices,CH,CN,W)
328328
B,FI,P = igl.blue_noise(V,F,0.5)
329329

330+
# Test equal seed yields same result
331+
B1,I1,X1 = igl.random_points_on_mesh(10,V,F, 1)
332+
B1_,I1_,X1_ = igl.random_points_on_mesh(10,V,F, 1)
333+
assert np.all(B1 == B1_)
334+
assert np.all(I1 == I1_)
335+
assert np.all(X1 == X1_)
336+
# Test different seed yields different result
337+
B2,I2,X2 = igl.random_points_on_mesh(10,V,F,2)
338+
assert not np.all(B1 == B2)
339+
assert not np.all(I1 == I2)
340+
assert not np.all(X1 == X2)
341+
342+
330343
def test_curvature():
331344
V,F = igl.icosahedron()
332345
K = igl.gaussian_curvature(V,F)

0 commit comments

Comments
 (0)