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 <array>
18#include <cstddef>
19#include <functional>
20#include <map>
21#include <string>
22#include <utility>
23#include <vector>
24
25#include "point_sampler.hpp"
26#include "point_sampler/point.hpp"
27
28#include "highmap/array.hpp"
29#include "highmap/functions.hpp"
31
32namespace hmap
33{
34
45
52static std::map<std::string, int> point_sampling_method_as_string = {
54 {"Halton sequence", PointSamplingMethod::RND_HALTON},
55 {"Hammersley sequence", PointSamplingMethod::RND_HAMMERSLEY},
56 {"Latin Hypercube Sampling", PointSamplingMethod::RND_LHS},
57};
58
72std::array<std::pair<float, float>, 2> bbox_to_ranges2d(const glm::vec4 &bbox);
73
82void expand_points_domain(std::vector<float> &x,
83 std::vector<float> &y,
84 std::vector<float> &value,
85 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
86
96void expand_points_at_domain_boundaries(std::vector<float> &x,
97 std::vector<float> &y,
98 std::vector<float> &value,
99 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f},
100 float boundary_value = 0.f);
101
111void expand_points_domain_corners(std::vector<float> &x,
112 std::vector<float> &y,
113 std::vector<float> &value,
114 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f},
115 float corner_value = 0.f);
116
143std::function<float(const ps::Point<float, 2> &)>
144make_pointwise_function_from_array(const Array &array, const glm::vec4 &bbox);
145
159std::array<std::vector<float>, 2> random_points(
160 size_t count,
161 std::uint32_t seed,
163 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
164
179std::array<std::vector<float>, 2> random_points_density(
180 size_t count,
181 const Array &density,
182 std::uint32_t seed,
183 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
184
198std::array<std::vector<float>, 2> random_points_distance(
199 float min_dist,
200 std::uint32_t seed,
201 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
202
219std::array<std::vector<float>, 2> random_points_distance(
220 float min_dist,
221 float max_dist,
222 const Array &density,
223 std::uint32_t seed,
224 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
225
242std::array<std::vector<float>, 2> random_points_distance_power_law(
243 float dist_min,
244 float dist_max,
245 float alpha,
246 std::uint32_t seed,
247 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
248
265std::array<std::vector<float>, 2> random_points_distance_weibull(
266 float dist_min,
267 float lambda,
268 float k,
269 std::uint32_t seed,
270 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
271
287std::array<std::vector<float>, 2> random_points_jittered(
288 size_t count,
289 const glm::vec2 &jitter_amount,
290 const glm::vec2 &stagger_ratio,
291 std::uint32_t seed,
292 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
293
301void remove_points_outside_bbox(std::vector<float> &x,
302 std::vector<float> &y,
303 std::vector<float> &value,
304 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
305
313void rescale_points_to_unit_square(std::vector<float> &x,
314 std::vector<float> &y,
315 glm::vec4 bbox);
316
317} // namespace hmap
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Defines modular function objects for procedural generation, including noise algorithms (Perlin,...
Definition algebra.hpp:23
std::function< float(const ps::Point< float, 2 > &)> make_pointwise_function_from_array(const Array &array, const glm::vec4 &bbox)
Create a continuous 2D function from a sampled array.
Definition point_sampling.cpp:45
std::array< std::vector< float >, 2 > random_points_density(size_t count, const Array &density, std::uint32_t seed, const glm::vec4 &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:107
void rescale_points_to_unit_square(std::vector< float > &x, std::vector< float > &y, glm::vec4 bbox)
Rescale coordinate (x, y) so that they fit in a unit-square box based on a given initial bounding box...
Definition grid.cpp:140
void expand_points_domain(std::vector< float > &x, std::vector< float > &y, std::vector< float > &value, glm::vec4 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:28
void expand_points_domain_corners(std::vector< float > &x, std::vector< float > &y, std::vector< float > &value, glm::vec4 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:90
std::array< std::vector< float >, 2 > random_points_distance_weibull(float dist_min, float lambda, float k, std::uint32_t seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates random 2D points with distances drawn from a Weibull distribution.
Definition point_sampling.cpp:179
void expand_points_at_domain_boundaries(std::vector< float > &x, std::vector< float > &y, std::vector< float > &value, glm::vec4 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:56
void remove_points_outside_bbox(std::vector< float > &x, std::vector< float > &y, std::vector< float > &value, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
Remove grid points that are outside a given bounding box.
PointSamplingMethod
Enumeration of point sampling methods.
Definition point_sampling.hpp:39
@ RND_LHS
Latin Hypercube Sampling.
Definition point_sampling.hpp:43
@ RND_HALTON
Low-discrepancy Halton sequence sampling.
Definition point_sampling.hpp:41
@ RND_RANDOM
Purely random uniform sampling.
Definition point_sampling.hpp:40
@ RND_HAMMERSLEY
Low-discrepancy Hammersley sequence sampling.
Definition point_sampling.hpp:42
std::array< std::vector< float >, 2 > random_points_distance(float min_dist, std::uint32_t seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates random 2D points with a minimum separation distance.
Definition point_sampling.cpp:122
std::array< std::pair< float, float >, 2 > bbox_to_ranges2d(const glm::vec4 &bbox)
Converts a 2D bounding box into coordinate ranges.
Definition point_sampling.cpp:36
std::array< std::vector< float >, 2 > random_points(size_t count, std::uint32_t seed, const PointSamplingMethod &method=PointSamplingMethod::RND_RANDOM, const glm::vec4 &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:67
std::array< std::vector< float >, 2 > random_points_distance_power_law(float dist_min, float dist_max, float alpha, std::uint32_t seed, const glm::vec4 &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:160
std::array< std::vector< float >, 2 > random_points_jittered(size_t count, const glm::vec2 &jitter_amount, const glm::vec2 &stagger_ratio, std::uint32_t seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates jittered grid-based 2D points.
Definition point_sampling.cpp:198