-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding Faure samplers, fixing memory and UI bugs
- Loading branch information
Showing
4 changed files
with
156 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** \file Faure.h | ||
\author Wojciech Jarosz | ||
*/ | ||
#pragma once | ||
|
||
#include <sampler/Sampler.h> | ||
#include <vector> | ||
|
||
/// Stochastic Faure quasi-random number sequence. | ||
/** | ||
A wrapper for Helmer's Owen-scrambled stochastic (0,s) Faure sampler with s=3,5,7,11 | ||
*/ | ||
class Faure : public TSamplerMinMaxDim<1, 11> | ||
{ | ||
public: | ||
Faure(unsigned dimensions = 2, unsigned numSamples = 1); | ||
|
||
void sample(float[], unsigned i) override; | ||
|
||
/// Returns an appropriate grid resolution to help visualize stratification | ||
int coarseGridRes(int samples) const override | ||
{ | ||
return int(std::pow(samples, (1.f / s()))); | ||
} | ||
|
||
unsigned dimensions() const override | ||
{ | ||
return m_numDimensions; | ||
} | ||
void setDimensions(unsigned n) override; | ||
|
||
bool randomized() const override | ||
{ | ||
return m_owen; | ||
} | ||
void setRandomized(bool b = true) override | ||
{ | ||
m_owen = b; | ||
regenerate(); | ||
} | ||
|
||
std::string name() const override; | ||
|
||
int numSamples() const override | ||
{ | ||
return m_numSamples; | ||
} | ||
int setNumSamples(unsigned n) override; | ||
|
||
protected: | ||
void regenerate(); | ||
unsigned s() const; | ||
|
||
unsigned m_numSamples; | ||
unsigned m_numDimensions; | ||
bool m_owen; | ||
std::vector<double> m_samples; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** \file Faure.cpp | ||
\author Wojciech Jarosz | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <iostream> | ||
#include <sampler/Faure.h> | ||
#include <sampler/Misc.h> | ||
|
||
#include "sampling/sfaure.h" | ||
|
||
Faure::Faure(unsigned dimensions, unsigned numSamples) : m_numSamples(numSamples), m_numDimensions(dimensions) | ||
{ | ||
regenerate(); | ||
} | ||
|
||
unsigned Faure::s() const | ||
{ | ||
if (m_numDimensions <= 3) | ||
return 3; | ||
else if (m_numDimensions <= 5) | ||
return 5; | ||
else if (m_numDimensions <= 7) | ||
return 7; | ||
else // if (m_numDimensions <= 11) | ||
return 11; | ||
} | ||
|
||
std::string Faure::name() const | ||
{ | ||
return "Stochastic Faure (0," + std::to_string(s()) + ")"; | ||
} | ||
|
||
void Faure::regenerate() | ||
{ | ||
std::cout << "regenerating " << m_numSamples << std::endl; | ||
// compute all points, and store them | ||
m_samples.clear(); | ||
m_samples.resize(m_numSamples * s()); | ||
|
||
if (m_numSamples > 0) | ||
{ | ||
if (m_numDimensions <= 3) | ||
sampling::GetStochasticFaure03Samples(m_numSamples, s(), false, 1, m_owen, &m_samples[0]); | ||
else if (m_numDimensions <= 5) | ||
sampling::GetStochasticFaure05Samples(m_numSamples, s(), false, 1, m_owen, &m_samples[0]); | ||
else if (m_numDimensions <= 7) | ||
sampling::GetStochasticFaure07Samples(m_numSamples, s(), false, 1, m_owen, &m_samples[0]); | ||
else if (m_numDimensions <= 11) | ||
sampling::GetStochasticFaure011Samples(m_numSamples, s(), false, 1, m_owen, &m_samples[0]); | ||
} | ||
} | ||
|
||
void Faure::setDimensions(unsigned n) | ||
{ | ||
auto newD = std::clamp(n, (unsigned)MIN_DIMENSION, (unsigned)MAX_DIMENSION); | ||
if (newD != m_numDimensions) | ||
{ | ||
m_numDimensions = newD; | ||
regenerate(); | ||
} | ||
} | ||
|
||
int Faure::setNumSamples(unsigned n) | ||
{ | ||
auto oldN = m_numSamples; | ||
m_numSamples = (n == 0) ? 1 : n; | ||
if (oldN < m_numSamples) | ||
regenerate(); | ||
|
||
return m_numSamples; | ||
} | ||
|
||
void Faure::sample(float r[], unsigned i) | ||
{ | ||
assert(i < m_numSamples); | ||
for (unsigned d = 0; d < dimensions(); ++d) | ||
{ | ||
assert(s() * i + d < m_samples.size()); | ||
r[d] = m_samples[s() * i + d]; | ||
} | ||
} |