HighMap library (C++)
Loading...
Searching...
No Matches
point_sampling.hpp
Go to the documentation of this file.
1/* Copyright (c) 2025 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
16#pragma once
17#include <functional>
18
19#include "point_sampler.hpp"
20
21#include "highmap/functions.hpp"
23
24namespace hmap
25{
26
37
44static std::map<std::string, int> point_sampling_method_as_string = {
46 {"Halton sequence", PointSamplingMethod::RND_HALTON},
47 {"Hammersley sequence", PointSamplingMethod::RND_HAMMERSLEY},
48 {"Latin Hypercube Sampling", PointSamplingMethod::RND_LHS},
49};
50
64std::array<std::pair<float, float>, 2> bbox_to_ranges2d(
65 const Vec4<float> &bbox);
66
75void expand_points_domain(std::vector<float> &x,
76 std::vector<float> &y,
77 std::vector<float> &value,
78 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f});
79
89void expand_points_at_domain_boundaries(std::vector<float> &x,
90 std::vector<float> &y,
91 std::vector<float> &value,
92 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f},
93 float boundary_value = 0.f);
94
104void expand_points_domain_corners(std::vector<float> &x,
105 std::vector<float> &y,
106 std::vector<float> &value,
107 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f},
108 float corner_value = 0.f);
109
136std::function<float(const ps::Point<float, 2> &)>
137make_pointwise_function_from_array(const Array &array, const Vec4<float> &bbox);
138
152std::array<std::vector<float>, 2> random_points(
153 size_t count,
154 uint seed,
156 const Vec4<float> &bbox = {0.f, 1.f, 0.f, 1.f});
157
172std::array<std::vector<float>, 2> random_points_density(
173 size_t count,
174 const Array &density,
175 uint seed,
176 const Vec4<float> &bbox = {0.f, 1.f, 0.f, 1.f});
177
191std::array<std::vector<float>, 2> random_points_distance(
192 float min_dist,
193 uint seed,
194 const Vec4<float> &bbox = {0.f, 1.f, 0.f, 1.f});
195
212std::array<std::vector<float>, 2> random_points_distance(
213 float min_dist,
214 float max_dist,
215 const Array &density,
216 uint seed,
217 const Vec4<float> &bbox = {0.f, 1.f, 0.f, 1.f});
218
235std::array<std::vector<float>, 2> random_points_distance_power_law(
236 float dist_min,
237 float dist_max,
238 float alpha,
239 uint seed,
240 const Vec4<float> &bbox = {0.f, 1.f, 0.f, 1.f});
241
258std::array<std::vector<float>, 2> random_points_distance_weibull(
259 float dist_min,
260 float lambda,
261 float k,
262 uint seed,
263 const Vec4<float> &bbox = {0.f, 1.f, 0.f, 1.f});
264
280std::array<std::vector<float>, 2> random_points_jittered(
281 size_t count,
282 const hmap::Vec2<float> &jitter_amount,
283 const hmap::Vec2<float> &stagger_ratio,
284 uint seed,
285 const Vec4<float> &bbox = {0.f, 1.f, 0.f, 1.f});
286
294void remove_points_outside_bbox(std::vector<float> &x,
295 std::vector<float> &y,
296 std::vector<float> &value,
297 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f});
298
306void rescale_points_to_unit_square(std::vector<float> &x,
307 std::vector<float> &y,
308 Vec4<float> bbox);
309
310} // namespace hmap
unsigned int uint
Definition array.hpp:14
Defines modular function objects for procedural generation, including noise algorithms (Perlin,...
Definition algebra.hpp:28
std::array< std::vector< float >, 2 > random_points_distance_power_law(float dist_min, float dist_max, float alpha, uint seed, const Vec4< float > &bbox={0.f, 1.f, 0.f, 1.f})
Generates random 2D points with distances drawn from a power-law distribution.
Definition point_sampling.cpp:143
std::array< std::vector< float >, 2 > random_points_distance_weibull(float dist_min, float lambda, float k, uint seed, const Vec4< float > &bbox={0.f, 1.f, 0.f, 1.f})
Generates random 2D points with distances drawn from a Weibull distribution.
Definition point_sampling.cpp:162
void rescale_points_to_unit_square(std::vector< float > &x, std::vector< float > &y, Vec4< float > bbox)
Rescale coordinate (x, y) so that they fit in a unit-square box based on a given initial bounding box...
Definition grid.cpp:139
void expand_points_domain_corners(std::vector< float > &x, std::vector< float > &y, std::vector< float > &value, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f}, float corner_value=0.f)
Expand the grid by adding four points at the corner of the bounding box.
Definition grid.cpp:89
std::array< std::vector< float >, 2 > random_points_jittered(size_t count, const hmap::Vec2< float > &jitter_amount, const hmap::Vec2< float > &stagger_ratio, uint seed, const Vec4< float > &bbox={0.f, 1.f, 0.f, 1.f})
Generates jittered grid-based 2D points.
Definition point_sampling.cpp:181
void expand_points_at_domain_boundaries(std::vector< float > &x, std::vector< float > &y, std::vector< float > &value, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f}, float boundary_value=0.f)
Expand the grid by adding points on the boundaries of the bounding box.
Definition grid.cpp:55
std::array< std::vector< float >, 2 > random_points(size_t count, uint seed, const PointSamplingMethod &method=PointSamplingMethod::RND_RANDOM, const Vec4< float > &bbox={0.f, 1.f, 0.f, 1.f})
Generates random 2D points within a bounding box using a sampling method.
Definition point_sampling.cpp:48
void remove_points_outside_bbox(std::vector< float > &x, std::vector< float > &y, std::vector< float > &value, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f})
Remove grid points that are outside a given bounding box.
std::function< float(const ps::Point< float, 2 > &)> make_pointwise_function_from_array(const Array &array, const Vec4< float > &bbox)
Create a continuous 2D function from a sampled array.
Definition point_sampling.cpp:26
PointSamplingMethod
Enumeration of point sampling methods.
Definition point_sampling.hpp:31
@ RND_LHS
Latin Hypercube Sampling.
Definition point_sampling.hpp:35
@ RND_HALTON
Low-discrepancy Halton sequence sampling.
Definition point_sampling.hpp:33
@ RND_RANDOM
Purely random uniform sampling.
Definition point_sampling.hpp:32
@ RND_HAMMERSLEY
Low-discrepancy Hammersley sequence sampling.
Definition point_sampling.hpp:34
std::array< std::vector< float >, 2 > random_points_density(size_t count, const Array &density, uint seed, const Vec4< float > &bbox={0.f, 1.f, 0.f, 1.f})
Generates random 2D points within a bounding box based on a density map.
Definition point_sampling.cpp:88
void expand_points_domain(std::vector< float > &x, std::vector< float > &y, std::vector< float > &value, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f})
Expand grid by translating and copying the values of the current bounding box to the 8 first neighbor...
Definition grid.cpp:27
std::array< std::vector< float >, 2 > random_points_distance(float min_dist, uint seed, const Vec4< float > &bbox={0.f, 1.f, 0.f, 1.f})
Generates random 2D points with a minimum separation distance.
Definition point_sampling.cpp:103
std::array< std::pair< float, float >, 2 > bbox_to_ranges2d(const Vec4< float > &bbox)
Converts a 2D bounding box into coordinate ranges.
Definition point_sampling.cpp:17
Defines a class for representing and manipulating 3D points.
Vec2 class for basic manipulation of 2D vectors.
Definition algebra.hpp:40
Vec4 class for basic manipulation of 4D vectors.
Definition algebra.hpp:564