|
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, std::uint32_t seed, const BBox2D &bbox=BBox2D{}) | |
| 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 (std::vector< Point > &&points) noexcept | |
| Move-constructs a new Cloud object from an existing points vector. | |
| 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 BBox2D &bbox=BBox2D{}) | |
| 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. | |
| BBox2D | 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 BBox2D &bbox=BBox2D{}) |
| Set the values of the cloud points using values from an underlying array. | |
| void | set_values_from_array (const Array &array, ArraySampling sampling, float radius=0.f, const BBox2D &bbox=BBox2D{}) |
| Set the values of the cloud points from an array, using a given sampling strategy. | |
| void | set_values_from_border_distance (const BBox2D &bbox=BBox2D{}) |
| 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. | |
| Point & | operator[] (size_t index) |
| Access point by index. | |
| const Point & | operator[] (size_t index) const |
| Access point by index (const). | |
| Point & | at (size_t index) |
| Access point with bounds checking. | |
| const Point & | at (size_t index) const |
| Access point with bounds checking (const). | |
| Point & | back () |
| Access the last point. | |
| const Point & | back () const |
| Access the last point (const). | |
| std::vector< Point >::iterator | begin () noexcept |
| Returns an iterator to the first point. | |
| std::vector< Point >::const_iterator | begin () const noexcept |
| Returns a const iterator to the first point. | |
| size_t | capacity () const noexcept |
| Returns the number of points that can be held in currently allocated storage. | |
| std::vector< Point >::const_iterator | cbegin () const noexcept |
| Returns a const iterator to the first point. | |
| std::vector< Point >::const_iterator | cend () const noexcept |
| Returns a const iterator to the end. | |
| void | clear () |
| Clear all data from the cloud. | |
| Point * | data () noexcept |
| Direct pointer to the underlying point array. | |
| const Point * | data () const noexcept |
| Direct pointer to the underlying point array (const). | |
| void | emplace_back (float x, float y, float v=0.f) |
| Appends a new point in-place. | |
| bool | empty () const |
| Check whether the cloud has no points. | |
| std::vector< Point >::iterator | end () noexcept |
| Returns an iterator to the end. | |
| std::vector< Point >::const_iterator | end () const noexcept |
| Returns a const iterator to the end. | |
| std::vector< Point >::iterator | erase (std::vector< Point >::const_iterator pos) |
| Erases the point at the specified position. | |
| std::vector< Point >::iterator | erase (std::vector< Point >::const_iterator first, std::vector< Point >::const_iterator last) |
| Erases the range of points [first, last). | |
| Point & | front () |
| Access the first point. | |
| const Point & | front () const |
| Access the first point (const). | |
| std::vector< Point >::iterator | insert (std::vector< Point >::const_iterator pos, const Point &value) |
| Inserts a point before pos. | |
| std::vector< Point >::iterator | insert (std::vector< Point >::const_iterator pos, Point &&value) |
| Inserts a point before pos (move). | |
| template<typename InputIt> | |
| std::vector< Point >::iterator | insert (std::vector< Point >::const_iterator pos, InputIt first, InputIt last) |
| Inserts elements from range [first, last) before pos. | |
| void | pop_back () |
| Removes the last point. | |
| void | push_back (const Point &p) |
| Appends a point. | |
| void | push_back (Point &&p) |
| Appends a point (move). | |
| void | reserve (size_t new_cap) |
| Reserves storage for at least the specified number of points. | |
| size_t | size () const |
| Get the number of points in the cloud. | |
| void | print () const |
| Print information about the cloud's points. | |
| void | randomize (std::uint32_t seed, const BBox2D &bbox=BBox2D{}) |
| 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, std::uint32_t seed, float dv=0.f) |
| Randomly perturbs the positions and values of all points in the cloud. | |
| void | snap_points_to_bounding_box (const BBox2D &bbox=BBox2D{}, 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, const BBox2D &bbox=BBox2D{}) const |
| Project the cloud points onto an array. | |
| Array | to_array (glm::ivec2 shape, const BBox2D &bbox) const |
| See hmap::to_array. | |
| void | to_array_interp (Array &array, const BBox2D &bbox=BBox2D{}, InterpolationMethod2D interpolation_method=InterpolationMethod2D::ITP2D_DELAUNAY, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, const BBox2D &bbox_array=BBox2D{}) 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 () const |
| Convert the cloud to a graph using Delaunay triangulation. | |
| void | to_png (const std::string &fname, int cmap, const BBox2D &bbox=BBox2D{}, int depth=0, glm::ivec2 shape={512, 512}) const |
| 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. | |
Protected 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
|
default |
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}. |
| hmap::Cloud::Cloud | ( | const std::vector< Point > & | points | ) |
|
noexcept |
| 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 BBox2D & | bbox = BBox2D{} ) |
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.
| BBox2D hmap::Cloud::get_bbox | ( | ) | const |
Get the bounding box of the cloud.
| 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.
| 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, ...].
| std::vector< float > hmap::Cloud::get_y | ( | ) | const |
Get the y coordinates of the points in the cloud.
| 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. |
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. |
| void hmap::Cloud::set_values_from_array | ( | const Array & | array, |
| ArraySampling | sampling, | ||
| float | radius = 0.f, | ||
| const BBox2D & | bbox = BBox2D{} ) |
Set the values of the cloud points from an array, using a given sampling strategy.
Points lying outside the bounding box are left untouched.
| array | The input array. |
| sampling | Sampling strategy (value at the point, or min / max / mean within a radius). |
| radius | Radius (in bbox units) of the neighborhood, ignored for ArraySampling::AS_POINT. |
| bbox | Bounding box mapping the point coordinates to the array. |
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.
| Point & hmap::Cloud::operator[] | ( | size_t | index | ) |
Access point by index.
| const Point & hmap::Cloud::operator[] | ( | size_t | index | ) | const |
Access point by index (const).
| Point & hmap::Cloud::at | ( | size_t | index | ) |
Access point with bounds checking.
| const Point & hmap::Cloud::at | ( | size_t | index | ) | const |
Access point with bounds checking (const).
| Point & hmap::Cloud::back | ( | ) |
Access the last point.
| const Point & hmap::Cloud::back | ( | ) | const |
Access the last point (const).
|
noexcept |
Returns an iterator to the first point.
|
noexcept |
Returns a const iterator to the first point.
|
noexcept |
Returns the number of points that can be held in currently allocated storage.
|
noexcept |
Returns a const iterator to the first point.
|
noexcept |
Returns a const iterator to the end.
| void hmap::Cloud::clear | ( | ) |
Clear all data from the cloud.
|
noexcept |
Direct pointer to the underlying point array.
|
noexcept |
Direct pointer to the underlying point array (const).
| void hmap::Cloud::emplace_back | ( | float | x, |
| float | y, | ||
| float | v = 0.f ) |
Appends a new point in-place.
| bool hmap::Cloud::empty | ( | ) | const |
Check whether the cloud has no points.
|
noexcept |
Returns an iterator to the end.
|
noexcept |
Returns a const iterator to the end.
Erases the point at the specified position.
| std::vector< Point >::iterator hmap::Cloud::erase | ( | std::vector< Point >::const_iterator | first, |
| std::vector< Point >::const_iterator | last ) |
Erases the range of points [first, last).
| Point & hmap::Cloud::front | ( | ) |
Access the first point.
| const Point & hmap::Cloud::front | ( | ) | const |
Access the first point (const).
| std::vector< Point >::iterator hmap::Cloud::insert | ( | std::vector< Point >::const_iterator | pos, |
| const Point & | value ) |
Inserts a point before pos.
| std::vector< Point >::iterator hmap::Cloud::insert | ( | std::vector< Point >::const_iterator | pos, |
| Point && | value ) |
Inserts a point before pos (move).
|
inline |
Inserts elements from range [first, last) before pos.
| void hmap::Cloud::pop_back | ( | ) |
Removes the last point.
| void hmap::Cloud::push_back | ( | const Point & | p | ) |
Appends a point.
| void hmap::Cloud::push_back | ( | Point && | p | ) |
Appends a point (move).
| void hmap::Cloud::reserve | ( | size_t | new_cap | ) |
Reserves storage for at least the specified number of points.
| size_t hmap::Cloud::size | ( | ) | const |
Get the number of points in the cloud.
| void hmap::Cloud::print | ( | ) | const |
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. |
| void hmap::Cloud::shuffle | ( | float | dx, |
| float | dy, | ||
| std::uint32_t | seed, | ||
| float | dv = 0.f ) |
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 BBox2D & | bbox = BBox2D{}, |
| 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. |
| void hmap::Cloud::to_array_interp | ( | Array & | array, |
| const BBox2D & | bbox = BBox2D{}, | ||
| InterpolationMethod2D | interpolation_method = InterpolationMethod2D::ITP2D_DELAUNAY, | ||
| const Array * | p_noise_x = nullptr, | ||
| const Array * | p_noise_y = nullptr, | ||
| const BBox2D & | bbox_array = BBox2D{} ) 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 | ( | ) | const |
Convert the cloud to a graph using Delaunay triangulation.
| void hmap::Cloud::to_png | ( | const std::string & | fname, |
| int | cmap, | ||
| const BBox2D & | bbox = BBox2D{}, | ||
| int | depth = 0, | ||
| glm::ivec2 | shape = {512, 512} ) const |
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.
|
protected |
Points of the cloud.