random_points_on_mesh.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public License
  4. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  5. // obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <test_common.h>
  7. #include <igl/readOBJ.h>
  8. #include <igl/random_points_on_mesh.h>
  9. TEST_CASE("random_points_on_mesh: decimated-knight", "[igl]")
  10. {
  11. Eigen::MatrixXd V;
  12. Eigen::MatrixXi F;
  13. igl::readOBJ(test_common::data_path("decimated-knight.obj"),V,F);
  14. static constexpr int n = 1000;
  15. Eigen::MatrixXd P;
  16. {
  17. Eigen::MatrixXd B;
  18. Eigen::VectorXi I;
  19. igl::random_points_on_mesh(n,V,F,B,I,P);
  20. }
  21. REQUIRE(P.rows() == n);
  22. }
  23. namespace random_points_on_mesh
  24. {
  25. template<typename URBG>
  26. void test_reproduce()
  27. {
  28. Eigen::MatrixXd V;
  29. Eigen::MatrixXi F;
  30. igl::readOBJ(test_common::data_path("decimated-knight.obj"),V,F);
  31. static constexpr int n = 100;
  32. static constexpr int seed = 0;
  33. Eigen::MatrixXd P1, Px1;
  34. {
  35. Eigen::MatrixXd B;
  36. Eigen::VectorXi I;
  37. URBG rng1(seed);
  38. igl::random_points_on_mesh(n,V,F,B,I,P1 ,rng1);
  39. igl::random_points_on_mesh(n,V,F,B,I,Px1,rng1);
  40. }
  41. Eigen::MatrixXd P2, Px2;
  42. {
  43. Eigen::MatrixXd B;
  44. Eigen::VectorXi I;
  45. URBG rng2(seed);
  46. igl::random_points_on_mesh(n,V,F,B,I,P2 ,rng2);
  47. igl::random_points_on_mesh(n,V,F,B,I,Px2,rng2);
  48. }
  49. test_common::assert_eq(P1, P2);
  50. test_common::assert_eq(Px1, Px2);
  51. test_common::assert_neq(P1, Px1);
  52. test_common::assert_neq(P2, Px2);
  53. }
  54. }
  55. TEST_CASE("random_points_on_mesh: minstd_rand0_reproduce", "[igl]")
  56. {
  57. random_points_on_mesh::test_reproduce<std::minstd_rand0>();
  58. }
  59. TEST_CASE("random_points_on_mesh: minstd_rand_reproduce", "[igl]")
  60. {
  61. random_points_on_mesh::test_reproduce<std::minstd_rand>();
  62. }
  63. TEST_CASE("random_points_on_mesh: mt19937_reproduce", "[igl]")
  64. {
  65. random_points_on_mesh::test_reproduce<std::mt19937>();
  66. }
  67. TEST_CASE("random_points_on_mesh: mt19937_64_reproduce", "[igl]")
  68. {
  69. random_points_on_mesh::test_reproduce<std::mt19937_64>();
  70. }