Skip to content

Commit

Permalink
selectRandom accepts a random generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
phcerdan committed Feb 7, 2018
1 parent e38c943 commit 7c5056c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/DGtal/topology/VoxelComplexFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ namespace DGtal
selectRandom(
const typename TComplex::Clique & clique);

/**
* Select random voxel from input clique.
*
* @tparam TComplex CubicalComplex
* @tparam TRandomGenerator RandomGenerator
* @param clique from where cell is chosen
* @param gen random generator
*
* @return random voxel from input clique.
*/
template < typename TComplex, typename TRandomGenerator >
std::pair<typename TComplex::Cell, typename TComplex::Data>
selectRandom(
const typename TComplex::Clique & clique,
TRandomGenerator & gen);

/**
* Select cell from clique that has max value looking at the input dist_map.
* The points in the dist_map and in the clique must refer
Expand Down
12 changes: 10 additions & 2 deletions src/DGtal/topology/VoxelComplexFunctions.ih
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,17 @@ std::pair<typename TComplex::Cell, typename TComplex::Data>
DGtal::functions::selectRandom(
const typename TComplex::Clique & clique)
{
static std::random_device rd;
static std::mt19937 gen(rd()); // TODO tothink provide seed?
static std::mt19937 gen( std::random_device{}() );
return selectRandom<TComplex>(clique, gen);
}

template < typename TComplex, typename TRandomGenerator >
std::pair<typename TComplex::Cell, typename TComplex::Data>
DGtal::functions::selectRandom(
const typename TComplex::Clique & clique,
TRandomGenerator & gen
)
{
auto size = clique.nbCells(3);
std::uniform_int_distribution<> dis(0, size - 1);
auto it = clique.begin(3);
Expand Down

0 comments on commit 7c5056c

Please sign in to comment.