diff options
Diffstat (limited to 'src/Util/Sampler.hpp')
| -rw-r--r-- | src/Util/Sampler.hpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Util/Sampler.hpp b/src/Util/Sampler.hpp new file mode 100644 index 0000000..3a4ff4f --- /dev/null +++ b/src/Util/Sampler.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include <functional> +#include "../Math/Vector.hpp" +#include "../Math/Grid.hpp" + +namespace MC::Util { + +template<size_t D, typename T> +class Sampler { + using Pos = Vector<D>; + using Sample = std::function<T(Pos)>; + using Interpolate = std::function<T(Pos, Sample)>; +public: + Sampler( + Sample sample, + Pos offset = {}, + float scale = 1.0f, + Interpolate interpolate = nearest_interpolation + ) : m_sample([=](Sampler::Pos pos) -> T { + return interpolate(pos, [=](Sampler::Pos p) -> T { return sample(p * scale + offset); }); + }) {} + + T sample(Pos at) { + return m_sample(at); + } + + static T nearest_interpolation(Pos pos, Sample sample) { + return sample(pos); + } + +private: + Sample m_sample; +}; + +} \ No newline at end of file |
