HighMap library (C++)
Loading...
Searching...
No Matches
cloud.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 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
31#pragma once
32#include <cmath>
33
34#include "highmap/array.hpp"
38
39namespace hmap
40{
41
42class Graph;
43
54class Cloud
55{
56public:
57 std::vector<Point> points = {};
58
64 Cloud(){};
65
66 virtual ~Cloud() = default;
67
81 Cloud(int npoints, uint seed, glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
82
91 Cloud(const std::vector<Point> &points) : points(points){};
92
105 Cloud(const std::vector<float> &x,
106 const std::vector<float> &y,
107 float default_value = 0.f);
108
121 Cloud(const std::vector<float> &x,
122 const std::vector<float> &y,
123 const std::vector<float> &v);
124
132 void add_point(const Point &p);
133
139 void clear();
140
160 bool from_csv(const std::string &fname);
161
172 glm::vec4 get_bbox() const;
173
185 Point get_center() const;
186
205 std::vector<int> get_convex_hull_point_indices() const;
206
215 size_t get_npoints() const;
216
226 std::vector<float> get_values() const;
227
236 float get_values_max() const;
237
246 float get_values_min() const;
247
257 virtual std::vector<float> get_x() const;
258
269 virtual std::vector<float> get_xy() const;
270
280 virtual std::vector<float> get_y() const;
281
294 std::vector<float> interpolate_values_from_array(const Array &array,
295 glm::vec4 bbox);
296
303 void print();
304
315 void randomize(uint seed, glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
316
346 void rejection_filter_density(const Array &density_mask,
347 uint seed,
348 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
349
359 void remap_values(float vmin, float vmax);
360
368 void remove_point(int point_idx);
369
373 void set_points(const std::vector<float> &x, const std::vector<float> &y);
374
384 void set_values(const std::vector<float> &new_values);
385
393 void set_values(float new_value);
394
407 void set_values_from_array(const Array &array,
408 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
409
425 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
426
437
448
465 void shuffle(float dx, float dy, uint seed, float dv = 0.f);
466
480 void to_array(Array &array, glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f}) const;
481
508 Array to_array_sdf(glm::ivec2 shape,
509 glm::vec4 bbox,
510 Array *p_noise_x = nullptr,
511 Array *p_noise_y = nullptr,
512 glm::vec4 bbox_array = {0.f, 1.f, 0.f, 1.f}) const;
513
541 void to_array_interp(Array &array,
542 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f},
543 InterpolationMethod2D interpolation_method =
545 Array *p_noise_x = nullptr,
546 Array *p_noise_y = nullptr,
547 glm::vec4 bbox_array = {0.f, 1.f, 0.f, 1.f}) const;
548
557 void to_csv(const std::string &fname) const;
558
568 Graph to_graph_delaunay();
569
592 void to_png(const std::string &fname,
593 int cmap,
594 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f},
595 int depth = CV_8U,
596 glm::ivec2 shape = {512, 512});
597};
598
616Cloud merge_cloud(const Cloud &cloud1, const Cloud &cloud2);
617Cloud merge_clouds(const std::vector<Cloud> &clouds);
618
643Cloud random_cloud(
644 size_t count,
645 uint seed,
647 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
648
672Cloud random_cloud_density(size_t count,
673 const Array &density,
674 uint seed,
675 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
676
700Cloud random_cloud_distance(float min_dist,
701 uint seed,
702 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
703
729Cloud random_cloud_distance(float min_dist,
730 float max_dist,
731 const Array &density,
732 uint seed,
733 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
734
761 float dist_min,
762 float dist_max,
763 float alpha,
764 uint seed,
765 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
766
793 float dist_min,
794 float lambda,
795 float k,
796 uint seed,
797 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
798
823Cloud random_cloud_jittered(size_t count,
824 const glm::vec2 &jitter_amount,
825 const glm::vec2 &stagger_ratio,
826 uint seed,
827 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
828
829} // namespace hmap
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
unsigned int uint
Definition array.hpp:14
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
Represents a collection of unordered points in 2D space.
Definition cloud.hpp:55
std::vector< int > get_convex_hull_point_indices() const
Computes the indices of the points that form the convex hull of a set of points.
Definition cloud.cpp:154
std::vector< float > interpolate_values_from_array(const Array &array, glm::vec4 bbox)
Interpolate values from an array at the points' (x, y) locations.
Definition cloud.cpp:230
void clear()
Clear all data from the cloud.
Definition cloud.cpp:64
Point get_center() const
Calculates the centroid of a set of points.
Definition cloud.cpp:146
void remap_values(float vmin, float vmax)
Remap the values of the cloud points to a target range.
Definition cloud.cpp:323
void to_array(Array &array, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}) const
Project the cloud points onto an array.
Definition cloud.cpp:430
virtual ~Cloud()=default
void set_values_from_border_distance(const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Sets point values based on their distance to the bounding box border.
Definition cloud.cpp:375
bool from_csv(const std::string &fname)
Loads point data from a CSV file into the Cloud object.
Definition cloud.cpp:69
size_t get_npoints() const
Get the number of points in the cloud.
Definition cloud.cpp:170
void randomize(uint seed, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
Randomize the positions and values of the cloud points.
Definition cloud.cpp:294
std::vector< float > get_values() const
Get the values assigned to the points in the cloud.
Definition cloud.cpp:175
void set_values_from_array(const Array &array, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Set the values of the cloud points using values from an underlying array.
Definition cloud.cpp:369
void set_values(const std::vector< float > &new_values)
Set new values for the cloud points.
Definition cloud.cpp:354
void set_points(const std::vector< float > &x, const std::vector< float > &y)
Set points of the using x, y coordinates.
Definition cloud.cpp:342
Cloud()
Default constructor for the Cloud class.
Definition cloud.hpp:64
Cloud(const std::vector< Point > &points)
Constructs a new Cloud object based on a list of existing points.
Definition cloud.hpp:91
Array to_array_sdf(glm::ivec2 shape, glm::vec4 bbox, Array *p_noise_x=nullptr, Array *p_noise_y=nullptr, glm::vec4 bbox_array={0.f, 1.f, 0.f, 1.f}) const
Generate an array filled with the signed distance function (SDF) to the cloud points.
Definition cloud.cpp:478
void rejection_filter_density(const Array &density_mask, uint seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Filter a point cloud using rejection sampling based on a density mask.
Definition cloud.cpp:305
float get_values_min() const
Get the minimum value among the points in the cloud.
Definition cloud.cpp:192
void to_array_interp(Array &array, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}, InterpolationMethod2D interpolation_method=InterpolationMethod2D::DELAUNAY, Array *p_noise_x=nullptr, Array *p_noise_y=nullptr, glm::vec4 bbox_array={0.f, 1.f, 0.f, 1.f}) const
Interpolate the values of an array using the cloud points.
Definition cloud.cpp:448
virtual std::vector< float > get_x() const
Get the x coordinates of the points in the cloud.
Definition cloud.cpp:200
std::vector< Point > points
Points of the cloud.
Definition cloud.hpp:57
virtual std::vector< float > get_xy() const
Get the concatenated x and y coordinates of the points in the cloud.
Definition cloud.cpp:209
void add_point(const Point &p)
Add a new point to the cloud.
Definition cloud.cpp:59
float get_values_max() const
Get the maximum value among the points in the cloud.
Definition cloud.cpp:184
virtual std::vector< float > get_y() const
Get the y coordinates of the points in the cloud.
Definition cloud.cpp:221
void set_values_from_min_distance()
Sets point values based on the distance to their nearest neighbor.
Definition cloud.cpp:405
void to_png(const std::string &fname, int cmap, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}, int depth=CV_8U, glm::ivec2 shape={512, 512})
Saves the current data as a PNG image file.
Definition cloud.cpp:546
Graph to_graph_delaunay()
Convert the cloud to a graph using Delaunay triangulation.
Definition cloud.cpp:528
void set_values_from_chull_distance()
Set the values of the cloud points based on the distance to the convex hull of the cloud.
Definition cloud.cpp:386
glm::vec4 get_bbox() const
Get the bounding box of the cloud.
Definition cloud.cpp:131
void to_csv(const std::string &fname) const
Export the cloud data to a CSV file.
Definition cloud.cpp:514
void print()
Print information about the cloud's points.
Definition cloud.cpp:270
void shuffle(float dx, float dy, uint seed, float dv=0.f)
Randomly perturbs the positions and values of all points in the cloud.
Definition cloud.cpp:417
void remove_point(int point_idx)
Remove a point from the cloud.
Definition cloud.cpp:337
A class to represent and manipulate 2D points that can carry a value.
Definition point.hpp:38
Header file for 2D interpolation methods.
Definition algebra.hpp:22
Cloud random_cloud_distance(float min_dist, uint seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates a random cloud of points separated by at least a given minimum distance.
Definition cloud.cpp:623
Cloud random_cloud_density(size_t count, const Array &density, uint seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates a random cloud of points based on a spatial density map.
Definition cloud.cpp:613
Cloud random_cloud_jittered(size_t count, const glm::vec2 &jitter_amount, const glm::vec2 &stagger_ratio, uint seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates a jittered grid cloud of points.
Definition cloud.cpp:667
Cloud random_cloud_distance_power_law(float dist_min, float dist_max, float alpha, uint seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates a random cloud of points with distances drawn from a power-law distribution.
Definition cloud.cpp:641
InterpolationMethod2D
Enumeration of 2D interpolation methods.
Definition interpolate2d.hpp:34
@ DELAUNAY
Delaunay triangulation method for 2D interpolation.
Definition interpolate2d.hpp:35
Cloud random_cloud(size_t count, uint seed, const PointSamplingMethod &method=PointSamplingMethod::RND_LHS, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates a random cloud of points within a bounding box.
Definition cloud.cpp:603
Cloud random_cloud_distance_weibull(float dist_min, float lambda, float k, uint seed, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Generates a random cloud of points with distances drawn from a Weibull distribution.
Definition cloud.cpp:656
PointSamplingMethod
Enumeration of point sampling methods.
Definition point_sampling.hpp:31
@ RND_LHS
Latin Hypercube Sampling.
Definition point_sampling.hpp:35
Cloud merge_cloud(const Cloud &cloud1, const Cloud &cloud2)
Merges two point clouds into one.
Definition cloud.cpp:557
Cloud merge_clouds(const std::vector< Cloud > &clouds)
Definition cloud.cpp:574
Defines a class for representing and manipulating 3D points.