#include <algorithm>
#include <vector>
-//! Compute points of the Halton sequence with with digit-permutations for different bases.
+//! Compute points of the Halton sequence with digit-permutations for different bases.
class OpenGl_HaltonSampler
{
public:
public:
//! Init the permutation arrays using Faure-permutations.
- //! Alternatively, initRandom() can be called before the sampling functionality can be used.
- void initFaure();
-
- //! Init the permutation arrays using randomized permutations.
- //! Alternatively, initFaure() can be called before the sampling functionality can be used.
- //! The client needs to specify a random number generator function object that can be used to generate a random sequence of integers.
- //! That is: if f is a random number generator and N is a positive integer,
- //! then f(N) will return an integer less than N and greater than or equal to 0.
- template <typename Random_number_generator>
- void initRandom (Random_number_generator& theRand);
+ OpenGl_HaltonSampler()
+ {
+ initFaure();
+ }
//! Return the Halton sample for the given dimension (component) and index.
- //! The client must have called initRandom or initFaure() at least once before.
+ //! The client must have called initFaure() at least once before.
//! dimension must be smaller than the value returned by get_num_dimensions().
float sample (unsigned theDimension, unsigned theIndex) const
{
private:
+ //! Init the permutation arrays using Faure-permutations.
+ void initFaure();
+
static unsigned short invert (unsigned short theBase, unsigned short theDigits,
unsigned short theIndex, const std::vector<unsigned short>& thePerm)
{
initTables (aPerms);
}
-template <typename Random_number_generator>
-void OpenGl_HaltonSampler::initRandom (Random_number_generator& theRand)
-{
- const unsigned THE_MAX_BASE = 5u;
- std::vector<std::vector<unsigned short> > aPerms(THE_MAX_BASE + 1);
- for (unsigned k = 1; k <= 3; ++k) // Keep identity permutations for base 1, 2, 3.
- {
- aPerms[k].resize (k);
- for (unsigned i = 0; i < k; ++i)
- {
- aPerms[k][i] = i;
- }
- }
-
- for (unsigned aBase = 4; aBase <= THE_MAX_BASE; ++aBase)
- {
- aPerms[aBase].resize (aBase);
- for (unsigned i = 0; i < aBase; ++i)
- {
- aPerms[aBase][i] = i;
- }
- std::random_shuffle (aPerms[aBase].begin(), aPerms[aBase].end(), theRand);
- }
- initTables (aPerms);
-}
-
#endif // _OpenGl_HaltonSampler_H