1 #ifndef MEDUSA_BITS_DOMAINS_DISCRETIZATION_HELPERS_HPP_
2 #define MEDUSA_BITS_DOMAINS_DISCRETIZATION_HELPERS_HPP_
21 namespace discretization_helpers {
34 template <
typename vec_t,
typename func_t>
38 assert_msg(dist >= 1e-15,
"Points %s and %s are equal.", p, q);
39 vec_t dir = (q-p) / dist;
42 while (cur_dist < dist) {
43 cur_dist += delta_r(p+cur_dist*dir);
44 dists.push_back(cur_dist);
47 if (dists.
size() <= 2)
return {};
49 scalar_t spacing_with_last_point = dist - dists.back();
50 scalar_t spacing_without_last_point = dist - dists[dists.
size()-2];
51 scalar_t desired_spacing = delta_r(q);
52 scalar_t error_with = std::abs(1 - spacing_with_last_point / desired_spacing);
53 scalar_t error_without = std::abs(1 - spacing_without_last_point / desired_spacing);
54 if (error_without < error_with) {
59 for (
int i = 0; i < dists.size(); ++i) {
60 points[i] = p + dists[i]*dir;
74 template <
typename scalar_t,
int dim>
83 template <
typename generator_t>
84 static std::vector<Eigen::Matrix<scalar_t, dim, 1>,
85 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, dim, 1>>>
construct(
86 scalar_t radius,
int num_samples, generator_t& generator) {
89 scalar_t offset = distribution(generator);
90 std::vector<Eigen::Matrix<scalar_t, dim, 1>,
91 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, dim, 1>>> result;
92 for (
int i = 0; i < num_samples / 2; ++i) {
95 int slice_n =
static_cast<int>(std::ceil(num_samples * std::sin(phi)));
96 if (slice_n == 0)
continue;
98 radius * std::sin(phi), slice_n, generator);
99 Eigen::Matrix<scalar_t, dim, 1> v;
100 for (
const auto& p : slice) {
101 v[0] = radius * std::cos(phi);
102 v.template tail<
dim - 1>() = p;
109 static std::vector<Eigen::Matrix<scalar_t, dim, 1>,
110 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, dim, 1>>>
construct(
113 std::vector<Eigen::Matrix<scalar_t, dim, 1>,
114 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, dim, 1>>> result;
115 for (
int i = 0; i < num_samples / 2; ++i) {
118 int slice_n =
static_cast<int>(std::ceil(num_samples * std::sin(phi)));
119 if (slice_n == 0)
continue;
121 radius * std::sin(phi), slice_n);
122 Eigen::Matrix<scalar_t, dim, 1> v;
123 for (
const auto& p : slice) {
124 v[0] = radius * std::cos(phi);
125 v.template tail<
dim - 1>() = p;
134 template <
typename scalar_t>
137 template <
typename generator_t>
138 static std::vector<Eigen::Matrix<scalar_t, 2, 1>,
139 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, 2, 1>>>
construct(
140 scalar_t radius,
int num_samples, generator_t& generator) {
143 scalar_t offset = distribution(generator);
144 std::vector<Eigen::Matrix<scalar_t, 2, 1>,
145 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, 2, 1>>> result;
146 for (
int i = 0; i < num_samples; ++i) {
148 result.emplace_back(radius * std::cos(phi), radius * std::sin(phi));
153 static std::vector<Eigen::Matrix<scalar_t, 2, 1>,
154 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, 2, 1>>>
construct(
157 std::vector<Eigen::Matrix<scalar_t, 2, 1>,
158 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, 2, 1>>> result;
159 for (
int i = 0; i < num_samples; ++i) {
161 result.emplace_back(radius * std::cos(phi), radius * std::sin(phi));
168 template <
typename scalar_t>
170 template <
typename generator_t>
172 static std::vector<Eigen::Matrix<scalar_t, 1, 1>,
173 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, 1, 1>>>
construct(
174 scalar_t radius,
int, generator_t&) {
175 return {Eigen::Matrix<scalar_t, 1, 1>(-radius), Eigen::Matrix<scalar_t, 1, 1>(radius)};
178 static std::vector<Eigen::Matrix<scalar_t, 1, 1>,
179 Eigen::aligned_allocator<Eigen::Matrix<scalar_t, 1, 1>>>
construct(
181 return {Eigen::Matrix<scalar_t, 1, 1>(-radius), Eigen::Matrix<scalar_t, 1, 1>(radius)};
188 #endif // MEDUSA_BITS_DOMAINS_DISCRETIZATION_HELPERS_HPP_