|
HighMap library (C++)
|
Represents a collection of unordered points in 2D space. More...
#include <cloud.hpp>


Public Member Functions | |
| Cloud () | |
| Default constructor for the Cloud class. | |
| virtual | ~Cloud ()=default |
| Cloud (int npoints, uint seed, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}) | |
| Constructs a new Cloud object with random positions and values. | |
| Cloud (const std::vector< Point > &points) | |
| Constructs a new Cloud object based on a list of existing points. | |
| Cloud (const std::vector< float > &x, const std::vector< float > &y, float default_value=0.f) | |
Constructs a new Cloud object from lists of x and y coordinates. | |
| Cloud (const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &v) | |
Constructs a new Cloud object from lists of x and y coordinates with assigned values. | |
| Cloud (const std::vector< glm::ivec2 > &indices, const glm::ivec2 &shape, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f}) | |
| Construct a point cloud from grid indices mapped to a bounding box. | |
| Cloud (const std::vector< glm::vec3 > &xyv) | |
| Constructs a new Cloud object from lists of xyz data as glm::vec3. | |
| void | add_point (const Point &p) |
| Add a new point to the cloud. | |
| void | remove_point (int point_idx) |
| Remove a point from the cloud. | |
| glm::vec4 | get_bbox () const |
| Get the bounding box of the cloud. | |
| Point | get_center () const |
| Calculates the centroid of a set of points. | |
| std::vector< int > | get_convex_hull () const |
| Computes the indices of the points that form the convex hull of a set of points. | |
| std::vector< float > | get_values () const |
| Get the values assigned to the points in the cloud. | |
| float | get_values_max () const |
| Get the maximum value among the points in the cloud. | |
| float | get_values_min () const |
| Get the minimum value among the points in the cloud. | |
| std::vector< float > | get_x () const |
Get the x coordinates of the points in the cloud. | |
| std::vector< float > | get_xy () const |
Get the concatenated x and y coordinates of the points in the cloud. | |
| std::vector< float > | get_y () const |
Get the y coordinates of the points in the cloud. | |
| size_t | nearest_point (const glm::vec2 &xy) const |
| Find the index of the nearest point in the cloud. | |
| void | set_points (const std::vector< float > &x, const std::vector< float > &y) |
| Set points of the using x, y coordinates. | |
| void | set_values (const std::vector< float > &new_values) |
| Set new values for the cloud points. | |
| void | set_values (float new_value) |
| Set a single value for all cloud points. | |
| 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. | |
| 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. | |
| void | set_values_from_chull_distance () |
| Set the values of the cloud points based on the distance to the convex hull of the cloud. | |
| void | set_values_from_min_distance () |
| Sets point values based on the distance to their nearest neighbor. | |
| size_t | size () const |
| Get the number of points in the cloud. | |
| void | clear () |
| Clear all data from the cloud. | |
| void | print () |
| Print information about the cloud's points. | |
| void | randomize (uint seed, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}) |
| Randomize the positions and values of the cloud points. | |
| void | remap_values (float vmin, float vmax) |
| Remap the values of the cloud points to a target range. | |
| void | shuffle (float dx, float dy, uint seed, float dv=0.f) |
| Randomly perturbs the positions and values of all points in the cloud. | |
| 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. | |
| bool | from_csv (const std::string &fname) |
| Loads point data from a CSV file into the Cloud object. | |
| void | to_array (Array &array, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}) const |
| Project the cloud points onto an array. | |
| Array | to_array (glm::ivec2 shape, glm::vec4 bbox) const |
| See hmap::to_array. | |
| 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. | |
| void | to_csv (const std::string &fname) const |
| Export the cloud data to a CSV file. | |
| Graph | to_graph_delaunay () |
| Convert the cloud to a graph using Delaunay triangulation. | |
| 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. | |
| std::vector< glm::vec3 > | to_vec3 () const |
| Convert path points to a vector of 3D positions. | |
Public Attributes | |
| std::vector< Point > | points = {} |
| Points of the cloud. | |
Represents a collection of unordered points in 2D space.
The Cloud class provides functionality to manage and manipulate an unordered set of points in a 2D space. It supports various operations such as adding points, calculating the centroid, merging with other point clouds, and more. This class is useful for applications involving point cloud processing, geometric computations, and spatial analysis.
See unit tests: test_cloud.cpp
|
inline |
Default constructor for the Cloud class.
Initializes an empty cloud with no points.
|
virtualdefault |
Constructs a new Cloud object with random positions and values.
| npoints | Number of points to generate. |
| seed | Random seed used to generate the points. Using the same seed will produce the same set of points. |
| bbox | Bounding box within which the points will be generated. The bounding box is defined as {xmin, xmax, ymin, ymax}. |
|
inline |
| hmap::Cloud::Cloud | ( | const std::vector< float > & | x, |
| const std::vector< float > & | y, | ||
| float | default_value = 0.f |
||
| ) |
Constructs a new Cloud object from lists of x and y coordinates.
| x | A vector of x coordinates for the points. |
| y | A vector of y coordinates for the points. |
| default_value | The default value assigned to each point. Defaults to 0 if not specified. |
| hmap::Cloud::Cloud | ( | const std::vector< float > & | x, |
| const std::vector< float > & | y, | ||
| const std::vector< float > & | v | ||
| ) |
Constructs a new Cloud object from lists of x and y coordinates with assigned values.
| x | A vector of x coordinates for the points. |
| y | A vector of y coordinates for the points. |
| v | A vector of values associated with each point. |
| hmap::Cloud::Cloud | ( | const std::vector< glm::ivec2 > & | indices, |
| const glm::ivec2 & | shape, | ||
| const glm::vec4 & | bbox = {0.f, 1.f, 0.f, 1.f} |
||
| ) |
Construct a point cloud from grid indices mapped to a bounding box.
Each index is normalized by the grid shape and remapped to the given bounding box. The resulting points are stored as 3D positions (z = 1).
| indices | Input grid indices. |
| shape | Grid dimensions. |
| bbox | Bounding box (xmin, xmax, ymin, ymax). |
| hmap::Cloud::Cloud | ( | const std::vector< glm::vec3 > & | xyv | ) |
Constructs a new Cloud object from lists of xyz data as glm::vec3.
| void hmap::Cloud::add_point | ( | const Point & | p | ) |
Add a new point to the cloud.
| p | The point to be added to the cloud. |
| void hmap::Cloud::remove_point | ( | int | point_idx | ) |
Remove a point from the cloud.
| point_idx | Index of the point to be removed. |
| glm::vec4 hmap::Cloud::get_bbox | ( | ) | const |
Get the bounding box of the cloud.
[xmin, xmax, ymin, ymax]. | Point hmap::Cloud::get_center | ( | ) | const |
Calculates the centroid of a set of points.
This function computes the center (or centroid) of a collection of points by averaging their coordinates. It sums up all the point coordinates and then divides the result by the total number of points to obtain the average position. The centroid represents the geometric center of the point cloud.
| std::vector< int > hmap::Cloud::get_convex_hull | ( | ) | const |
Computes the indices of the points that form the convex hull of a set of points.
Example
Result
| std::vector< float > hmap::Cloud::get_values | ( | ) | const |
Get the values assigned to the points in the cloud.
| float hmap::Cloud::get_values_max | ( | ) | const |
Get the maximum value among the points in the cloud.
| float hmap::Cloud::get_values_min | ( | ) | const |
Get the minimum value among the points in the cloud.
| std::vector< float > hmap::Cloud::get_x | ( | ) | const |
Get the x coordinates of the points in the cloud.
x coordinates of the points. | std::vector< float > hmap::Cloud::get_xy | ( | ) | const |
Get the concatenated x and y coordinates of the points in the cloud.
This method returns a vector containing the x and y coordinates of all points in the cloud, arranged in the form [x0, y0, x1, y1, ...].
x and y coordinates of the points. | std::vector< float > hmap::Cloud::get_y | ( | ) | const |
Get the y coordinates of the points in the cloud.
y coordinates of the points. | size_t hmap::Cloud::nearest_point | ( | const glm::vec2 & | xy | ) | const |
Find the index of the nearest point in the cloud.
Computes the point whose (x,y) position is closest to xy using squared Euclidean distance.
| xy | Query position |
| void hmap::Cloud::set_points | ( | const std::vector< float > & | x, |
| const std::vector< float > & | y | ||
| ) |
Set points of the using x, y coordinates.
| x | A vector containing the x coordinates of the points. |
| y | A vector containing the y coordinates of the points. |
| void hmap::Cloud::set_values | ( | const std::vector< float > & | new_values | ) |
Set new values for the cloud points.
| new_values | A vector of new values to assign to the points. |
| void hmap::Cloud::set_values | ( | float | new_value | ) |
Set a single value for all cloud points.
This method assigns the same value to all points in the cloud.
| new_value | The value to assign to all points. |
| void hmap::Cloud::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.
This method assigns values to the cloud points by interpolating values from an input array. The positions of the cloud points are mapped to the array using the specified bounding box.
| array | The input array from which to derive the values. |
| bbox | The bounding box that defines the mapping from the cloud points' coordinates to the array's coordinates. |
Sets point values based on their distance to the bounding box border.
For each point in the cloud, this method computes the shortest distance to the edges of the given bounding box and stores it as the point's value.
| bbox | Bounding box in the format {xmin, xmax, ymin, ymax}. |
| void hmap::Cloud::set_values_from_chull_distance | ( | ) |
Set the values of the cloud points based on the distance to the convex hull of the cloud.
This method assigns values to the cloud points based on their distance to the convex hull of the cloud. The convex hull must be initialized using to_graph_delaunay() before this method is called to ensure the correct indices of the convex hull points are available.
| void hmap::Cloud::set_values_from_min_distance | ( | ) |
Sets point values based on the distance to their nearest neighbor.
| size_t hmap::Cloud::size | ( | ) | const |
Get the number of points in the cloud.
| void hmap::Cloud::clear | ( | ) |
Clear all data from the cloud.
| void hmap::Cloud::print | ( | ) |
Print information about the cloud's points.
Randomize the positions and values of the cloud points.
| seed | Random seed number for generating positions and values. |
| bbox | Bounding box within which the points will be randomized. |
| void hmap::Cloud::remap_values | ( | float | vmin, |
| float | vmax | ||
| ) |
Remap the values of the cloud points to a target range.
| vmin | The lower bound of the target range. |
| vmax | The upper bound of the target range. |
Randomly perturbs the positions and values of all points in the cloud.
| dx | Scale factor for the random displacement along the X-axis. |
| dy | Scale factor for the random displacement along the Y-axis. |
| seed | Seed value for the pseudo-random number generator, ensuring reproducibility. |
| dv | Scale factor for the random displacement applied to the point's value component v. |
| void hmap::Cloud::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.
Points within a tolerance distance from the bounding box edges are projected onto the closest edge. Afterwards, the closest point to each corner is snapped exactly to that corner.
| bbox | Bounding box defined as (xmin, xmax, ymin, ymax). |
| tolerance_ratio | Ratio used to compute the snapping distance relative to the average point spacing. |
| bool hmap::Cloud::from_csv | ( | const std::string & | fname | ) |
Loads point data from a CSV file into the Cloud object.
This function reads a CSV file where each line contains either 2D (X, Y) or 3D (X, Y, Z) point data. The function automatically detects the dimensionality of the points based on the number of values per line. The loaded points are stored in the points member of the Cloud object.
| fname | The path to the CSV file to be read. |
Project the cloud points onto an array.
This method projects the cloud points' values onto a given array, mapping their positions within the specified bounding box. The resulting array will be populated with the values of the points at their corresponding positions.
| array | The input array where the cloud points' values will be projected. |
| bbox | The bounding box that defines the mapping from the cloud points' coordinates to the array's coordinates. |
| Array hmap::Cloud::to_array | ( | glm::ivec2 | shape, |
| glm::vec4 | bbox | ||
| ) | const |
See hmap::to_array.
| void hmap::Cloud::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.
This method populates an array with interpolated values based on the positions and values of the cloud points. The interpolation method can be specified, and optional noise arrays can be used for domain warping.
| array | The output array that will be populated with interpolated values. |
| bbox | The bounding box that defines the cloud's coordinate system. |
| interpolation_method | The method used for interpolation (e.g., nearest neighbor, bilinear). |
| p_noise_x | Optional reference to a noise array applied to the x-coordinates for domain warping (not in pixels). |
| p_noise_y | Optional reference to a noise array applied to the y-coordinates for domain warping (not in pixels). |
| bbox_array | The bounding box of the destination array. |
Example
Result
| void hmap::Cloud::to_csv | ( | const std::string & | fname | ) | const |
Export the cloud data to a CSV file.
| fname | The name of the output CSV file. |
| Graph hmap::Cloud::to_graph_delaunay | ( | ) |
Convert the cloud to a graph using Delaunay triangulation.
| void hmap::Cloud::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.
| fname | The file name for the output PNG image. This should include the file extension (e.g., "output.png"). |
| cmap | An integer specifying the colormap to be used for rendering the data. This index refers to a predefined colormap. |
| bbox | A glm::vec4 specifying the bounding box of the data to be included in the image. It is given as {xmin, xmax, ymin, ymax}. The default is {0.f, 1.f, 0.f, 1.f}. |
| depth | An integer specifying the bit depth of the image. It should be a value defined by OpenCV (e.g., CV_8U for 8-bit unsigned). The default is CV_8U. |
| shape | A glm::ivec2 specifying the dimensions of the output image. It is given as {width, height}. The default is {512, 512}. |
| std::vector< glm::vec3 > hmap::Cloud::to_vec3 | ( | ) | const |
Convert path points to a vector of 3D positions.
| std::vector<Point> hmap::Cloud::points = {} |
Points of the cloud.