LdsGen 1.2.6
Loading...
Searching...
No Matches
sphere_n.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <array>
8#include <memory>
9#include <mutex>
10#include <span>
11#include <vector>
12
13#include "lds.hpp"
14
15#ifndef M_PI
16# define M_PI 3.14159265358979323846264338327950288
17#endif
18
19namespace ldsgen {
20
21 constexpr double PI = M_PI;
22 constexpr double HALF_PI = M_PI / 2.0;
23
25 constexpr std::size_t TABLE_SIZE = 300;
26
28 extern const std::array<double, TABLE_SIZE> X;
29 extern const std::array<double, TABLE_SIZE> NEG_COSINE;
30 extern const std::array<double, TABLE_SIZE> SINE;
31 extern const std::array<double, TABLE_SIZE> F2;
32
36 std::vector<double> linspace(double start, double stop, unsigned int num);
37
41 double simple_interp(double x_value, std::span<const double> x_points,
42 std::span<const double> y_points);
43
49 std::vector<double> get_tp(unsigned int n);
50
56 class SphereGen {
57 public:
58 SphereGen() = default;
59 SphereGen(const SphereGen&) = default;
60 SphereGen(SphereGen&&) noexcept = default;
61 SphereGen& operator=(const SphereGen&) = default;
62 SphereGen& operator=(SphereGen&&) noexcept = default;
63 virtual ~SphereGen() = default;
64 virtual std::vector<double> pop() = 0;
65 virtual void reseed(unsigned long seed) = 0;
66 };
67
75 class Sphere3 {
76 public:
77 explicit Sphere3(std::span<const unsigned long> base);
78 std::array<double, 4> pop();
79 void reseed(unsigned long seed);
80
81 private:
82 VdCorput vdc_;
83 Sphere sphere2_;
84 mutable std::mutex mutex_;
85 };
86
90 class SphereWrapper : public SphereGen {
91 public:
92 explicit SphereWrapper(std::span<const unsigned long> base);
93 std::vector<double> pop() override;
94 void reseed(unsigned long seed) override;
95
96 private:
97 Sphere sphere_;
98 mutable std::mutex mutex_;
99 };
100
106 class SphereN : public SphereGen {
107 public:
108 explicit SphereN(std::span<const unsigned long> base);
109 std::vector<double> pop() override;
110 void reseed(unsigned long seed) override;
111
112 private:
113 VdCorput vdc_;
114 std::unique_ptr<SphereGen> s_gen_;
115 unsigned int n_;
116 std::vector<double> tp_;
117 double range_;
118 mutable std::mutex mutex_;
119 };
120} // namespace ldsgen
3-Sphere sequence generator (standalone, returns std::array).
Definition sphere_n.hpp:75
Sphere3(std::span< const unsigned long > base)
std::array< double, 4 > pop()
void reseed(unsigned long seed)
Base class for sphere generators.
Definition sphere_n.hpp:56
virtual void reseed(unsigned long seed)=0
SphereGen()=default
SphereGen(const SphereGen &)=default
virtual std::vector< double > pop()=0
SphereGen(SphereGen &&) noexcept=default
N-dimensional sphere sequence generator.
Definition sphere_n.hpp:106
std::vector< double > pop() override
void reseed(unsigned long seed) override
SphereN(std::span< const unsigned long > base)
Wrapper class to make Sphere compatible with SphereGen interface.
Definition sphere_n.hpp:90
void reseed(unsigned long seed) override
std::vector< double > pop() override
SphereWrapper(std::span< const unsigned long > base)
Sphere sequence generator.
Definition lds.hpp:615
Van der Corput sequence generator.
Definition lds.hpp:346
Low-discrepancy sequence generators with thread-safe runtime polymorphism (ldsgen).
#define M_PI
Definition lds.hpp:16
Definition lds.hpp:19
constexpr double PI
Definition sphere_n.hpp:21
constexpr double HALF_PI
Definition sphere_n.hpp:22
constexpr std::size_t TABLE_SIZE
Number of interpolation points for sphere mapping tables.
Definition sphere_n.hpp:25
const std::array< double, TABLE_SIZE > SINE
std::vector< double > linspace(double start, double stop, unsigned int num)
Generate evenly spaced numbers over a specified interval.
const std::array< double, TABLE_SIZE > F2
const std::array< double, TABLE_SIZE > X
Precomputed interpolation tables (static storage, no heap)
const std::array< double, TABLE_SIZE > NEG_COSINE
double simple_interp(double x_value, std::span< const double > x_points, std::span< const double > y_points)
Perform one-dimensional linear interpolation.
std::vector< double > get_tp(unsigned int n)
Compute Tp(n) recurrence for sphere mapping.