|
HighMap library (C++)
|
Container and processor for spatial ScatterItem collections. More...
#include <scatter_field.hpp>


Public Member Functions | |
| ScatterField ()=default | |
| Default constructor initializing an empty field. | |
| ScatterField (const std::vector< ScatterItem > &items) | |
| Constructs a ScatterField from a vector of items. | |
| ScatterField (std::vector< ScatterItem > &&items) noexcept | |
| Move-constructs a ScatterField from a vector of items. | |
| ScatterField (const Cloud &cloud, uint32_t class_id=0, float default_radius=HMAP_DEFAULT_SCATTER_RADIUS) | |
| Constructs a ScatterField from a Cloud of 2D points. | |
| virtual | ~ScatterField ()=default |
| ScatterItem & | at (size_t index) |
| const ScatterItem & | at (size_t index) const |
| ScatterItem & | back () |
| const ScatterItem & | back () const |
| auto | begin () noexcept |
| auto | begin () const noexcept |
| auto | cbegin () const noexcept |
| size_t | capacity () const noexcept |
| void | clear () noexcept |
| ScatterItem * | data () noexcept |
| const ScatterItem * | data () const noexcept |
| template<typename... Args> | |
| ScatterItem & | emplace_back (Args &&...args) |
| bool | empty () const noexcept |
| auto | end () noexcept |
| auto | end () const noexcept |
| auto | cend () const noexcept |
| ScatterItem & | front () |
| const ScatterItem & | front () const |
| ScatterItem & | operator[] (size_t index) |
| const ScatterItem & | operator[] (size_t index) const |
| void | push_back (const ScatterItem &item) |
| void | push_back (ScatterItem &&item) |
| void | reserve (size_t new_cap) |
| size_t | size () const noexcept |
| void | densify (float default_radius=HMAP_DEFAULT_SCATTER_RADIUS) |
| Densifies the scatter field by adding Voronoi vertices (circumcenters of Delaunay triangles). | |
| ScatterField | filter_by_class (uint32_t class_id) const |
| Returns a new ScatterField containing only items matching the given class_id. | |
| BBox2D | get_bbox () const |
| Computes the 2D bounding box enclosing all item positions. | |
| std::vector< uint32_t > | get_class_ids () const |
| Returns a sorted list of unique class identifiers present in the field. | |
| std::vector< float > | get_radius () const |
| Extracts the characteristic radius of all items. | |
| std::vector< float > | get_x () const |
| Extracts the x-coordinate of all items. | |
| std::vector< float > | get_y () const |
| Extracts the y-coordinate of all items. | |
| std::vector< float > | get_z () const |
| Extracts the z-coordinate (elevation) of all items. | |
| void | perturb_positions (float dx, float dy=0.0f, uint32_t seed=0) |
| Slightly perturbs the 2D (x, y) coordinates of scatter items. | |
| void | pack_interstitial (size_t count, const Array &density={}, float r_min=5e-4f, float r_max=2e-3f, uint32_t class_id=0, uint32_t seed=0, const UvRect &uv_rect={0.f, 1.f, 0.f, 1.f}) |
| Packs smaller interstitial items in the voids between existing larger items without displacing existing items. | |
| void | prune_collisions () |
| Resolves overlapping items by discarding smaller items in collision. | |
| void | prune_collisions (const ScatterField &other) |
| Prunes items in this field that overlap with (fall within the influence radius of) items in another field. | |
| void | prune_density (const Array &density_mask, float target_ratio=0.8f, uint32_t seed=0, const UvRect &uv_rect={0.f, 1.f, 0.f, 1.f}) |
| Prunes items in the field using density-based acceptance sampling modulated to reach an approximate target retention ratio. | |
| void | regularize_positions (size_t k_neighbors=8, float step_size=0.1f, size_t iterations=10) |
| Relaxes/regularizes item positions using k-nearest neighbor repulsion. | |
| void | reinforce_class_clusters (size_t iterations=2, size_t k_neighbors=4, bool include_self=true) |
| Reinforces spatial clustering of classes by iteratively assigning each item the dominant class among its nearest neighbors. | |
| void | resolve_collisions (size_t iterations=20, float tolerance=0.f, float step_size=2., size_t triangulation_substep=5) |
| Resolves overlapping items by iteratively moving colliding items apart using Delaunay triangulation neighborhood and repulsive relaxation. | |
| void | resolve_collisions (const ScatterField &other, size_t iterations=20, float tolerance=0.f, float step_size=2.f, size_t triangulation_substep=5) |
| Resolves collisions with another static ScatterField by pushing items in this field away from colliding items in the other field, using joint Delaunay triangulation neighborhood and repulsive relaxation. | |
| void | set_elevation_from_terrain (const Array &elevation, const UvRect &uv_rect={0.f, 1.f, 0.f, 1.f}) |
| Sets the elevation (z-coordinate) of all items by sampling a terrain heightmap. | |
| void | shuffle_classes (float ratio=0.1f, size_t k_neighbors=4, uint32_t seed=0) |
| Randomly shuffles class identifiers between neighboring items. | |
| Cloud | to_cloud () const |
| Converts the field into a Cloud of 2D points (x, y) with value set to radius. | |
| Array | to_density_map (glm::ivec2 shape, float sigma=0.0f, std::optional< uint32_t > class_id=std::nullopt, bool weighted_by_area=false, const UvTile ®ion=UvTile::dummy(), ICommunicator &comm=SingleArrayComm::instance()) const |
| Exports the local density map of the field as a 2D Array using 2D Kernel Density Estimation (Gaussian splatting / KDE). | |
| Array | to_heightmap (glm::ivec2 shape, ScatterShape shape_type=SCATTER_SHAPE_DISK, float height_radius_ratio=1.0f, std::optional< uint32_t > class_id=std::nullopt, Array *p_rock_map=nullptr, uint32_t seed=0, const UvRect &uv_rect=UvRect::unit()) const |
| Converts the scatter field into a heightmap by representing each scattered object as a local elevation increase on GPU. | |
| void | to_csv (const std::string &fname) const |
| Exports the items to a CSV file (x, y, z, class_id, radius). | |
| std::vector< uint8_t > | to_img_8bit (glm::ivec2 shape, const Array &background={}, const UvRect &uv_rect=UvRect::unit(), bool flip_y=false) const |
| Renders the scatter field to an 8-bit RGB image buffer. | |
| void | to_ply (const std::string &fname) const |
| Exports the items to a PLY file with radius and class as custom parameters. | |
| void | to_png (const std::string &fname, glm::ivec2 shape, const Array &background={}, const UvRect &uv_rect=UvRect::unit()) const |
| Exports a visual representation of the scatter field as a PNG image. | |
| virtual std::string | to_string () const |
| Returns a multi-line formatted summary string of the scatter field. | |
Protected Attributes | |
| std::vector< ScatterItem > | items = {} |
| List of scatter item instances. | |
Container and processor for spatial ScatterItem collections.
|
default |
Default constructor initializing an empty field.
| hmap::ScatterField::ScatterField | ( | const std::vector< ScatterItem > & | items | ) |
Constructs a ScatterField from a vector of items.
| items | Vector of ScatterItem instances. |
|
noexcept |
Move-constructs a ScatterField from a vector of items.
| items | Rvalue vector of ScatterItem instances. |
| hmap::ScatterField::ScatterField | ( | const Cloud & | cloud, |
| uint32_t | class_id = 0, | ||
| float | default_radius = HMAP_DEFAULT_SCATTER_RADIUS ) |
Constructs a ScatterField from a Cloud of 2D points.
If a point's value v is non-zero, it is used as the item's radius; otherwise default_radius is assigned.
| cloud | Input point cloud. |
| class_id | Class identifier assigned to all imported items. |
| default_radius | Default radius assigned if point value is 0. |
|
virtualdefault |
| ScatterItem & hmap::ScatterField::at | ( | size_t | index | ) |
| const ScatterItem & hmap::ScatterField::at | ( | size_t | index | ) | const |
| ScatterItem & hmap::ScatterField::back | ( | ) |
| const ScatterItem & hmap::ScatterField::back | ( | ) | const |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
| ScatterItem & hmap::ScatterField::front | ( | ) |
| const ScatterItem & hmap::ScatterField::front | ( | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
| void hmap::ScatterField::densify | ( | float | default_radius = HMAP_DEFAULT_SCATTER_RADIUS | ) |
Densifies the scatter field by adding Voronoi vertices (circumcenters of Delaunay triangles).
| default_radius | Default radius assigned to newly added items. |
| ScatterField hmap::ScatterField::filter_by_class | ( | uint32_t | class_id | ) | const |
Returns a new ScatterField containing only items matching the given class_id.
| class_id | Class identifier to filter by. |
| BBox2D hmap::ScatterField::get_bbox | ( | ) | const |
Computes the 2D bounding box enclosing all item positions.
| std::vector< uint32_t > hmap::ScatterField::get_class_ids | ( | ) | const |
Returns a sorted list of unique class identifiers present in the field.
| std::vector< float > hmap::ScatterField::get_radius | ( | ) | const |
Extracts the characteristic radius of all items.
| std::vector< float > hmap::ScatterField::get_x | ( | ) | const |
Extracts the x-coordinate of all items.
| std::vector< float > hmap::ScatterField::get_y | ( | ) | const |
Extracts the y-coordinate of all items.
| std::vector< float > hmap::ScatterField::get_z | ( | ) | const |
Extracts the z-coordinate (elevation) of all items.
| void hmap::ScatterField::perturb_positions | ( | float | dx, |
| float | dy = 0.0f, | ||
| uint32_t | seed = 0 ) |
Slightly perturbs the 2D (x, y) coordinates of scatter items.
| dx | Maximum displacement along the x-axis. |
| dy | Maximum displacement along the y-axis (defaults to 0.0). |
| seed | Random seed for reproducibility. |
| void hmap::ScatterField::pack_interstitial | ( | size_t | count, |
| const Array & | density = {}, | ||
| float | r_min = 5e-4f, | ||
| float | r_max = 2e-3f, | ||
| uint32_t | class_id = 0, | ||
| uint32_t | seed = 0, | ||
| const UvRect & | uv_rect = {0.f, 1.f, 0.f, 1.f} ) |
Packs smaller interstitial items in the voids between existing larger items without displacing existing items.
| count | Target number of items to pack. |
| density | Optional 2D spatial probability density array for candidate sampling. |
| r_min | Minimum interstitial item radius. |
| r_max | Maximum interstitial item radius. |
| class_id | Class identifier for the packed items. |
| seed | Random seed for candidate sampling. |
| bbox | Domain bounding box {xmin, xmax, ymin, ymax}. |
| void hmap::ScatterField::prune_collisions | ( | ) |
Resolves overlapping items by discarding smaller items in collision.
| void hmap::ScatterField::prune_collisions | ( | const ScatterField & | other | ) |
Prunes items in this field that overlap with (fall within the influence radius of) items in another field.
The other field remains constant and unmodified. For each item in this field, if its distance to any item in other is strictly less than the sum of their radii, it is pruned.
| other | Const reference to the reference ScatterField (e.g. rocks). |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| void hmap::ScatterField::prune_density | ( | const Array & | density_mask, |
| float | target_ratio = 0.8f, | ||
| uint32_t | seed = 0, | ||
| const UvRect & | uv_rect = {0.f, 1.f, 0.f, 1.f} ) |
Prunes items in the field using density-based acceptance sampling modulated to reach an approximate target retention ratio.
| density_mask | 2D array defining the spatial density field. |
| target_ratio | Approximate target fraction of items to retain in [0, 1]. |
| seed | Random seed for reproducible pruning. |
| bbox | Bounding box defining the domain of the density mask. |
| void hmap::ScatterField::regularize_positions | ( | size_t | k_neighbors = 8, |
| float | step_size = 0.1f, | ||
| size_t | iterations = 10 ) |
Relaxes/regularizes item positions using k-nearest neighbor repulsion.
Uses PointSampler's relaxation algorithm to reduce clustering and obtain a more uniform or blue-noise-like spatial distribution.
| k_neighbors | Number of nearest neighbors to consider for repulsion. |
| step_size | Step size per relaxation iteration. |
| iterations | Number of relaxation iterations. |
| void hmap::ScatterField::reinforce_class_clusters | ( | size_t | iterations = 2, |
| size_t | k_neighbors = 4, | ||
| bool | include_self = true ) |
Reinforces spatial clustering of classes by iteratively assigning each item the dominant class among its nearest neighbors.
| iterations | Number of smoothing/reinforcement iterations. |
| k_neighbors | Number of spatial nearest neighbors to query. |
| include_self | If true, considers the item's own current class in the majority vote. |
| void hmap::ScatterField::resolve_collisions | ( | size_t | iterations = 20, |
| float | tolerance = 0.f, | ||
| float | step_size = 2., | ||
| size_t | triangulation_substep = 5 ) |
Resolves overlapping items by iteratively moving colliding items apart using Delaunay triangulation neighborhood and repulsive relaxation.
Preserves item count and overall distribution while moving items until overlap is resolved or max iterations are reached.
| iterations | Maximum number of relaxation iterations. |
| tolerance | Collision tolerance ratio in [0, 1) where 0 means no overlap allowed. |
| step_size | Relaxation step size / movement rate. |
| triangulation_substep | Frequency (in iterations) to recompute the Delaunay triangulation. |
| void hmap::ScatterField::resolve_collisions | ( | const ScatterField & | other, |
| size_t | iterations = 20, | ||
| float | tolerance = 0.f, | ||
| float | step_size = 2.f, | ||
| size_t | triangulation_substep = 5 ) |
Resolves collisions with another static ScatterField by pushing items in this field away from colliding items in the other field, using joint Delaunay triangulation neighborhood and repulsive relaxation.
The other field remains constant and unmodified.
| other | Const reference to the reference ScatterField. |
| iterations | Maximum number of relaxation iterations. |
| tolerance | Collision tolerance ratio in [0, 1). |
| step_size | Relaxation step size. |
| triangulation_substep | Frequency (in iterations) to recompute the Delaunay triangulation. |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| void hmap::ScatterField::set_elevation_from_terrain | ( | const Array & | elevation, |
| const UvRect & | uv_rect = {0.f, 1.f, 0.f, 1.f} ) |
Sets the elevation (z-coordinate) of all items by sampling a terrain heightmap.
| elevation | Terrain heightmap array. |
| bbox | Bounding box defining the domain of the elevation array. |
| void hmap::ScatterField::shuffle_classes | ( | float | ratio = 0.1f, |
| size_t | k_neighbors = 4, | ||
| uint32_t | seed = 0 ) |
Randomly shuffles class identifiers between neighboring items.
| ratio | Fraction of items to attempt class shuffling on in [0, 1]. |
| k_neighbors | Number of nearest spatial neighbors to consider. |
| seed | Random seed for reproducibility. |
| Cloud hmap::ScatterField::to_cloud | ( | ) | const |
| Array hmap::ScatterField::to_density_map | ( | glm::ivec2 | shape, |
| float | sigma = 0.0f, | ||
| std::optional< uint32_t > | class_id = std::nullopt, | ||
| bool | weighted_by_area = false, | ||
| const UvTile & | region = UvTile::dummy(), | ||
| ICommunicator & | comm = SingleArrayComm::instance() ) const |
Exports the local density map of the field as a 2D Array using 2D Kernel Density Estimation (Gaussian splatting / KDE).
| shape | Dimensions of the output density map {nx, ny}. |
| sigma | Gaussian kernel standard deviation (bandwidth) in world/domain coordinates. If <= 0, automatically derived. |
| class_id | Optional class identifier to compute density for a specific class only. |
| weighted_by_area | If true, weights density by footprint area ($\pi r^2$). |
| region | Tile region defining the domain and overlap layout. |
| comm | Communicator for tile boundary synchronization. |
| Array hmap::ScatterField::to_heightmap | ( | glm::ivec2 | shape, |
| ScatterShape | shape_type = SCATTER_SHAPE_DISK, | ||
| float | height_radius_ratio = 1.0f, | ||
| std::optional< uint32_t > | class_id = std::nullopt, | ||
| Array * | p_rock_map = nullptr, | ||
| uint32_t | seed = 0, | ||
| const UvRect & | uv_rect = UvRect::unit() ) const |
Converts the scatter field into a heightmap by representing each scattered object as a local elevation increase on GPU.
| shape | Dimensions of the output heightmap {nx, ny}. |
| shape_type | Object geometry shape (default SCATTER_SHAPE_DISK). |
| height_radius_ratio | Ratio of object maximum height relative to its radius (default 1.0f). |
| class_id | Optional class identifier to filter items. |
| p_rock_map | Optional output array for the rock map with normalized amplitude in [0, 1]. |
| seed | Random seed for procedural shape variation (e.g. polygon). |
| bbox | Domain bounding box {xmin, xmax, ymin, ymax}. |
| void hmap::ScatterField::to_csv | ( | const std::string & | fname | ) | const |
Exports the items to a CSV file (x, y, z, class_id, radius).
| fname | Output file path. |
| std::vector< uint8_t > hmap::ScatterField::to_img_8bit | ( | glm::ivec2 | shape, |
| const Array & | background = {}, | ||
| const UvRect & | uv_rect = UvRect::unit(), | ||
| bool | flip_y = false ) const |
Renders the scatter field to an 8-bit RGB image buffer.
| shape | Image dimensions {width, height}. |
| background | Optional background terrain array. |
| bbox | Bounding box {xmin, xmax, ymin, ymax} of the domain. |
| flip_y | If true, row 0 is top (screen/image space). If false, row 0 is bottom (Cartesian domain space). |
| void hmap::ScatterField::to_ply | ( | const std::string & | fname | ) | const |
Exports the items to a PLY file with radius and class as custom parameters.
| fname | Output file path. |
| void hmap::ScatterField::to_png | ( | const std::string & | fname, |
| glm::ivec2 | shape, | ||
| const Array & | background = {}, | ||
| const UvRect & | uv_rect = UvRect::unit() ) const |
Exports a visual representation of the scatter field as a PNG image.
| fname | Output PNG file path. |
| shape | Image dimensions {width, height}. |
| background | Optional background terrain array. |
| bbox | Bounding box {xmin, xmax, ymin, ymax} of the domain. |
|
virtual |
Returns a multi-line formatted summary string of the scatter field.
Reimplemented in hmap::Forest, and hmap::RockField.
|
protected |
List of scatter item instances.