|
HighMap library (C++)
|
This page describes the primary data structures and representations used in HighMap.
HighMap provides three main structures for 2D height data:
| Structure | Type | Description |
|---|---|---|
| Array | hmap::Array | In-memory 2D array of floats with contiguous storage. |
| HeightMap | hmap::HeightMap | Tiled 2D array designed for parallel computation. |
| VirtualArray | hmap::VirtualArray | Tiled structure supporting disk and RAM storage for large grids. |
Array is the basic container for 2D elevation fields. Data is stored in row-major order. It supports arithmetic operators, statistical queries, slicing, and filtering.
Continuous functions deriving from hmap::Function represent mathematical surfaces $f(x, y)$ independently of resolution:
Geometric entities represent vector features and integrate with height arrays:
When simulating erosion or analyzing terrain gradients, HighMap distinguishes between talus and slope:
In HighMap, the talus is defined as the direct elevation difference between neighboring grid cells (or the critical vertical threshold per grid step):
$$\text{talus} = \Delta z = z_{i+1, j} - z_{i, j}$$
The slope is the metric rate of change of elevation with respect to physical horizontal distance in the terrain domain:
$$\text{slope} = \frac{\Delta z}{\Delta x} = \frac{z(\mathbf{x}_2) - z(\mathbf{x}_1)}{|\mathbf{x}_2 - \mathbf{x}_1|}$$
where $\Delta x = L_x / N_x$ represents the physical cell spacing for a domain of size $L_x$.
In unit-box normalized domains ($L_x = 1$), the physical cell spacing is $\Delta x = 1 / N_x$. Substituting $\Delta x$ into the slope definition yields:
$$\text{slope} = \frac{\Delta z}{\Delta x} = \frac{\text{talus}}{1 / N_x} = \text{talus} \cdot N_x$$
Rearranging for the grid-cell talus threshold gives:
$$\text{talus} = \frac{\text{slope}}{N_x}$$
This identity is why erosion parameters throughout HighMap are specified by dividing a reference slope by the grid dimension:
The scattering system handles the distribution of discrete objects over a terrain:
HighMap distinguishes three complementary 2D spatial representations depending on whether coordinates are normalized, axis-aligned in world space, or oriented:
| Concept | Type | Coordinate Space | Rotation | Primary Use |
|---|---|---|---|---|
| UV | hmap::UvRect | Normalized $[0, 1]^2$ | No | Tiling (VirtualArray, VirtualTexture), texture/UV slicing |
| BBox | hmap::BBox2D | World / domain space | No | Axis-aligned bounds (Cloud, Path, Graph, function domains) |
| CoordFrame | hmap::CoordFrame | World + local $[0, 1]^2$ | Yes | Oriented regions, stamps, and local-to-global transforms |
UV coordinates $(u, v) \in [0, 1]^2$ represent a normalized, resolution-independent unit square. VirtualArray and VirtualTexture canonically span $[0, 1]^2$ in UV space, and each tile carries its own UvRect slice.
A bounding box defines an axis-aligned rectangular region in world or domain coordinates using (xmin, xmax, ymin, ymax). It is used for spatial extents of geometric primitives (Cloud, Path, Graph), evaluation domains, and fast overlap checks.
hmap::CoordFrame defines an oriented 2D coordinate frame with an origin, size, and rotation_angle. It maps between local unit coordinates $(r_x, r_y) \in [0, 1]^2$ (map_to_global_coords) and global world coordinates $(g_x, g_y)$ (map_to_relative_coords), and can compute its enclosing axis-aligned bounding box via compute_bounding_box().