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
460 void snap_points_to_bounding_box(const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f},
461 float tolerance_ratio = 1.f);
462
479 void shuffle(float dx, float dy, uint seed, float dv = 0.f);
480
494 void to_array(Array &array, glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f}) const;
495
522 Array to_array_sdf(glm::ivec2 shape,
523 glm::vec4 bbox,
524 Array *p_noise_x = nullptr,
525 Array *p_noise_y = nullptr,
526 glm::vec4 bbox_array = {0.f, 1.f, 0.f, 1.f}) const;
527
555 void to_array_interp(Array &array,
556 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f},
557 InterpolationMethod2D interpolation_method =
559 Array *p_noise_x = nullptr,
560 Array *p_noise_y = nullptr,
561 glm::vec4 bbox_array = {0.f, 1.f, 0.f, 1.f}) const;
562
571 void to_csv(const std::string &fname) const;
572
582 Graph to_graph_delaunay();
583
606 void to_png(const std::string &fname,
607 int cmap,
608 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f},
609 int depth = CV_8U,
610 glm::ivec2 shape = {512, 512});
611
612 std::vector<glm::vec3> to_vec3() const;
613};
614
632Cloud merge_cloud(const Cloud &cloud1, const Cloud &cloud2);
633Cloud merge_clouds(const std::vector<Cloud> &clouds);
634
659Cloud random_cloud(
660 size_t count,
661 uint seed,
663 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
664
688Cloud random_cloud_density(size_t count,
689 const Array &density,
690 uint seed,
691 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
692
716Cloud random_cloud_distance(float min_dist,
717 uint seed,
718 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
719
745Cloud random_cloud_distance(float min_dist,
746 float max_dist,
747 const Array &density,
748 uint seed,
749 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
750
777 float dist_min,
778 float dist_max,
779 float alpha,
780 uint seed,
781 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
782
809 float dist_min,
810 float lambda,
811 float k,
812 uint seed,
813 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
814
839Cloud random_cloud_jittered(size_t count,
840 const glm::vec2 &jitter_amount,
841 const glm::vec2 &stagger_ratio,
842 uint seed,
843 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
844
845} // 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:496
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
std::vector< glm::vec3 > to_vec3() const
Definition cloud.cpp:622
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
void snap_points_to_bounding_box(const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f}, float tolerance_ratio=1.f)
Snap points to the bounding box edges and corners.
Definition cloud.cpp:417
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:543
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
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 to_array_interp(Array &array, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}, InterpolationMethod2D interpolation_method=InterpolationMethod2D::ITP2D_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:514
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:611
Graph to_graph_delaunay()
Convert the cloud to a graph using Delaunay triangulation.
Definition cloud.cpp:593
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:579
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:483
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:39
Header file for 2D interpolation methods.
Definition algebra.hpp:23
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:699
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:689
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:743
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:717
InterpolationMethod2D
Enumeration of 2D interpolation methods.
Definition interpolate2d.hpp:45
@ ITP2D_DELAUNAY
Delaunay triangulation method for 2D interpolation.
Definition interpolate2d.hpp:46
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:679
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:732
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:633
Cloud merge_clouds(const std::vector< Cloud > &clouds)
Definition cloud.cpp:650
Defines a class for representing and manipulating 3D points.