Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Jul 10, 2023
1 parent dab37ee commit b8742cf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: cgalMeshes
Title: R6 Based Utilities for 3D Meshes using 'CGAL'
Version: 3.0.0.9001
Version: 3.0.0.9002
Authors@R:
person("Stéphane", "Laurent", , "[email protected]", role = c("aut", "cre"))
Maintainer: Stéphane Laurent <[email protected]>
Expand Down
4 changes: 3 additions & 1 deletion R/cgalMesh.R
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,9 @@ cgalMesh <- R6Class(
},

#' @description Random sampling in the volume bounded by the mesh. The
#' mesh must be closed and triangle.
#' mesh must be closed and triangle. The method consists in sampling in
#' the optimal bounding box of the mesh and rejecting the points that
#' do not fall inside the volume.
#' @param nsims integer, the desired number of simulations
#' @return A \code{nsims x 3} matrix containing the simulations.
"sampleInMesh" = function(nsims) {
Expand Down
2 changes: 1 addition & 1 deletion inst/essais/essai_samplingInMesh.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library(cgalMeshes)
cyclide <- cyclideMesh(a = 97, c = 32, mu = 57)
mesh <- cgalMesh$new(cyclide)
sims <- mesh$sampleInMesh(100)
sims <- mesh$sampleInMesh(10)
mean(sims[, 3] > 0)
summary(sims)

Expand Down
4 changes: 3 additions & 1 deletion man/cgalMesh.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/MODULE.h
Original file line number Diff line number Diff line change
Expand Up @@ -2028,13 +2028,12 @@ class CGALmesh {
vol1, vol2, vol3, vol4, vol5
);
Rcpp::NumericVector probs = volumes / sum(volumes);
boost::random::discrete_distribution<> dist(probs.begin(), probs.end());
boost::random::discrete_distribution<> die5(probs.begin(), probs.end());
// sampling
Rcpp::NumericMatrix Sims(3, nsims);
unsigned i = 0;
while(i < nsims) {
// Rcpp::IntegerVector index = Rcpp::sample(5, 1, true, probs, false);
int index = dist(gen);
int index = die5(gen);
std::array<Vector3, 4> th = ths[index];
Vector3 v = sampleTetrahedron(th[0], th[1], th[2], th[3], gen);
Point3 p = V3toP3(v);
Expand Down
4 changes: 3 additions & 1 deletion src/unexported_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ std::array<std::array<Vector3, 4>, 5> hexahedronTetrahedra(
return tetrahedra;
}

Vector3 sampleTetrahedron(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, boost::mt19937 gen) {
Vector3 sampleTetrahedron(
Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, boost::mt19937 gen
) {
boost::random::uniform_real_distribution<double> runif(0.0, 1.0);
double c1 = runif(gen);
double c2 = runif(gen);
Expand Down

0 comments on commit b8742cf

Please sign in to comment.