HighMap library (C++)
Loading...
Searching...
No Matches
hmap::TerrainTriMesh Class Reference

Triangle mesh representation of a terrain surface. More...

#include <terrain_tri_mesh.hpp>

Classes

struct  BoundingBox
 Axis-aligned 2D bounding box. More...
 
struct  Edge
 Undirected edge between two vertices. More...
 
struct  EdgeHash
 Hash functor for Edge. More...
 
struct  Neighbor
 Neighbor vertex information. More...
 
struct  NeighborData
 Vertex adjacency lists. More...
 
struct  ShortestPathResult
 Result of a shortest-path computation. More...
 
struct  Triangle
 Triangle defined by three vertex indices. More...
 

Public Member Functions

 TerrainTriMesh ()=default
 Construct an empty mesh.
 
 TerrainTriMesh (const std::vector< glm::vec3 > &ref_points)
 Construct a mesh from 3D points.
 
 TerrainTriMesh (const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &z)
 Construct a mesh from coordinate arrays.
 
void triangulate_delaunay ()
 Build the Delaunay triangulation.
 
void compute_neighbors ()
 Compute vertex adjacency.
 
void compute_gradients ()
 Compute vertex gradients.
 
void relax_xy (float lambda=0.5f, int iterations=1, bool preserve_chull=true)
 Relax vertex positions in the XY plane.
 
void relax_xyz (float lambda=0.5f, int iterations=1, bool preserve_chull=true)
 Relax vertex positions in 3D.
 
void relax_xyz_taubin (float lambda=0.5f, float mu=-0.55f, int iterations=1, bool preserve_chull=true)
 Apply Taubin smoothing.
 
void remap_z (float vmin=0.f, float vmax=1.f)
 Remap elevation values.
 
void slope_limiter (float max_slope, int iterations=10, float sigma=0.1f)
 Limit terrain slopes.
 
void slope_limiter (const std::vector< float > &max_slope, int iterations=10, float sigma=0.1f)
 Limit terrain slopes with per-vertex thresholds.
 
void subdivise ()
 Subdivide mesh triangles.
 
void flow_breach (float epsilon, float uphill_tolerance=0.f)
 Breach terrain depressions for flow routing.
 
bool barycentric (const glm::vec2 &p, size_t i0, size_t i1, size_t i2, float &w0, float &w1, float &w2) const
 Compute barycentric coordinates.
 
int find_triangle (const glm::vec2 &p, int start_tri=0, bool linear_search=false) const
 Find the triangle containing a point.
 
int neighbor_triangle (int tri_index, int edge_index) const
 Return the neighboring triangle across an edge.
 
float interpolate_z_linear (const glm::vec2 &p, int &last_tri, float fill_value=0.f) const
 Linearly interpolate elevation.
 
float interpolate_z_linear_gradient (const glm::vec2 &p, int &last_tri, float fill_value=0.f, float gradient_scaling=1.f) const
 Gradient-enhanced linear interpolation.
 
float interpolate_z_nearest (const glm::vec2 &p) const
 Nearest-neighbor interpolation.
 
float interpolate_z_nearest_approx (const glm::vec2 &p, int &last_tri, float fill_value=0.f) const
 Approximate nearest-neighbor interpolation.
 
BoundingBox get_bbox () const
 Return the mesh bounding box.
 
glm::vec2 get_range_z () const
 Return the elevation range.
 
glm::vec3 get_reference_lengths () const
 Return reference mesh dimensions.
 
std::vector< float > get_vertex_areas (bool normalized) const
 Compute vertex areas.
 
float get_reference_area_xy () const
 Return the projected mesh area.
 
float get_reference_area () const
 Return the mesh surface area.
 
size_t size () const
 Return the number of vertices.
 
ShortestPathResult compute_shortest_paths_to_hull (bool use_delta_z=false, float elevation_weight=1.f) const
 Compute shortest paths to the convex hull.
 
ShortestPathResult compute_shortest_paths (size_t start, bool use_delta_z=false, float elevation_weight=1.f) const
 Compute shortest paths from a source vertex.
 
std::vector< size_t > shortest_path (size_t start, size_t end, bool use_delta_z=false, float elevation_weight=1.f) const
 Compute the shortest path between two vertices.
 
std::vector< size_t > path_to_hull (size_t start, const ShortestPathResult &result) const
 Reconstruct a path to the convex hull.
 
const std::vector< glm::vec3 > & get_points () const
 Return mesh vertices.
 
std::vector< glm::vec3 > & get_points ()
 Return mesh vertices.
 
const std::vector< Triangle > & get_triangles () const
 Return mesh triangles.
 
const std::vector< size_t > & get_convex_hull () const
 Return convex hull vertex indices.
 
const NeighborDataget_neighbors () const
 Return vertex neighbors.
 
bool export_obj (const std::string &filepath) const
 Export the mesh as an OBJ file.
 
std::string info_string () const
 Return a mesh summary string.
 
void print_info () const
 Print mesh information.
 
Array to_array (const glm::ivec2 &shape, const std::vector< float > &values={}, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f}) const
 Rasterize the mesh into an array.
 
void to_csv (const std::string &fname) const
 Export vertices to CSV.
 

Detailed Description

Triangle mesh representation of a terrain surface.

Stores vertices, triangulation, connectivity, and provides geometry, interpolation, smoothing, and pathfinding utilities.

Constructor & Destructor Documentation

◆ TerrainTriMesh() [1/3]

hmap::TerrainTriMesh::TerrainTriMesh ( )
default

Construct an empty mesh.

◆ TerrainTriMesh() [2/3]

hmap::TerrainTriMesh::TerrainTriMesh ( const std::vector< glm::vec3 > &  ref_points)

Construct a mesh from 3D points.

◆ TerrainTriMesh() [3/3]

hmap::TerrainTriMesh::TerrainTriMesh ( const std::vector< float > &  x,
const std::vector< float > &  y,
const std::vector< float > &  z 
)

Construct a mesh from coordinate arrays.

Member Function Documentation

◆ triangulate_delaunay()

void hmap::TerrainTriMesh::triangulate_delaunay ( )

Build the Delaunay triangulation.

◆ compute_neighbors()

void hmap::TerrainTriMesh::compute_neighbors ( )

Compute vertex adjacency.

◆ compute_gradients()

void hmap::TerrainTriMesh::compute_gradients ( )

Compute vertex gradients.

◆ relax_xy()

void hmap::TerrainTriMesh::relax_xy ( float  lambda = 0.5f,
int  iterations = 1,
bool  preserve_chull = true 
)

Relax vertex positions in the XY plane.

◆ relax_xyz()

void hmap::TerrainTriMesh::relax_xyz ( float  lambda = 0.5f,
int  iterations = 1,
bool  preserve_chull = true 
)

Relax vertex positions in 3D.

◆ relax_xyz_taubin()

void hmap::TerrainTriMesh::relax_xyz_taubin ( float  lambda = 0.5f,
float  mu = -0.55f,
int  iterations = 1,
bool  preserve_chull = true 
)

Apply Taubin smoothing.

◆ remap_z()

void hmap::TerrainTriMesh::remap_z ( float  vmin = 0.f,
float  vmax = 1.f 
)

Remap elevation values.

◆ slope_limiter() [1/2]

void hmap::TerrainTriMesh::slope_limiter ( float  max_slope,
int  iterations = 10,
float  sigma = 0.1f 
)

Limit terrain slopes.

◆ slope_limiter() [2/2]

void hmap::TerrainTriMesh::slope_limiter ( const std::vector< float > &  max_slope,
int  iterations = 10,
float  sigma = 0.1f 
)

Limit terrain slopes with per-vertex thresholds.

◆ subdivise()

void hmap::TerrainTriMesh::subdivise ( )

Subdivide mesh triangles.

◆ flow_breach()

void hmap::TerrainTriMesh::flow_breach ( float  epsilon,
float  uphill_tolerance = 0.f 
)

Breach terrain depressions for flow routing.

◆ barycentric()

bool hmap::TerrainTriMesh::barycentric ( const glm::vec2 &  p,
size_t  i0,
size_t  i1,
size_t  i2,
float &  w0,
float &  w1,
float &  w2 
) const

Compute barycentric coordinates.

◆ find_triangle()

int hmap::TerrainTriMesh::find_triangle ( const glm::vec2 &  p,
int  start_tri = 0,
bool  linear_search = false 
) const

Find the triangle containing a point.

◆ neighbor_triangle()

int hmap::TerrainTriMesh::neighbor_triangle ( int  tri_index,
int  edge_index 
) const

Return the neighboring triangle across an edge.

◆ interpolate_z_linear()

float hmap::TerrainTriMesh::interpolate_z_linear ( const glm::vec2 &  p,
int &  last_tri,
float  fill_value = 0.f 
) const

Linearly interpolate elevation.

◆ interpolate_z_linear_gradient()

float hmap::TerrainTriMesh::interpolate_z_linear_gradient ( const glm::vec2 &  p,
int &  last_tri,
float  fill_value = 0.f,
float  gradient_scaling = 1.f 
) const

Gradient-enhanced linear interpolation.

◆ interpolate_z_nearest()

float hmap::TerrainTriMesh::interpolate_z_nearest ( const glm::vec2 &  p) const

Nearest-neighbor interpolation.

◆ interpolate_z_nearest_approx()

float hmap::TerrainTriMesh::interpolate_z_nearest_approx ( const glm::vec2 &  p,
int &  last_tri,
float  fill_value = 0.f 
) const

Approximate nearest-neighbor interpolation.

◆ get_bbox()

TerrainTriMesh::BoundingBox hmap::TerrainTriMesh::get_bbox ( ) const

Return the mesh bounding box.

◆ get_range_z()

glm::vec2 hmap::TerrainTriMesh::get_range_z ( ) const

Return the elevation range.

◆ get_reference_lengths()

glm::vec3 hmap::TerrainTriMesh::get_reference_lengths ( ) const

Return reference mesh dimensions.

◆ get_vertex_areas()

std::vector< float > hmap::TerrainTriMesh::get_vertex_areas ( bool  normalized) const

Compute vertex areas.

◆ get_reference_area_xy()

float hmap::TerrainTriMesh::get_reference_area_xy ( ) const

Return the projected mesh area.

◆ get_reference_area()

float hmap::TerrainTriMesh::get_reference_area ( ) const

Return the mesh surface area.

◆ size()

size_t hmap::TerrainTriMesh::size ( ) const

Return the number of vertices.

◆ compute_shortest_paths_to_hull()

TerrainTriMesh::ShortestPathResult hmap::TerrainTriMesh::compute_shortest_paths_to_hull ( bool  use_delta_z = false,
float  elevation_weight = 1.f 
) const

Compute shortest paths to the convex hull.

◆ compute_shortest_paths()

TerrainTriMesh::ShortestPathResult hmap::TerrainTriMesh::compute_shortest_paths ( size_t  start,
bool  use_delta_z = false,
float  elevation_weight = 1.f 
) const

Compute shortest paths from a source vertex.

◆ shortest_path()

std::vector< size_t > hmap::TerrainTriMesh::shortest_path ( size_t  start,
size_t  end,
bool  use_delta_z = false,
float  elevation_weight = 1.f 
) const

Compute the shortest path between two vertices.

◆ path_to_hull()

std::vector< size_t > hmap::TerrainTriMesh::path_to_hull ( size_t  start,
const ShortestPathResult result 
) const

Reconstruct a path to the convex hull.

◆ get_points() [1/2]

const std::vector< glm::vec3 > & hmap::TerrainTriMesh::get_points ( ) const

Return mesh vertices.

◆ get_points() [2/2]

std::vector< glm::vec3 > & hmap::TerrainTriMesh::get_points ( )

Return mesh vertices.

◆ get_triangles()

const std::vector< TerrainTriMesh::Triangle > & hmap::TerrainTriMesh::get_triangles ( ) const

Return mesh triangles.

◆ get_convex_hull()

const std::vector< size_t > & hmap::TerrainTriMesh::get_convex_hull ( ) const

Return convex hull vertex indices.

◆ get_neighbors()

const TerrainTriMesh::NeighborData & hmap::TerrainTriMesh::get_neighbors ( ) const

Return vertex neighbors.

◆ export_obj()

bool hmap::TerrainTriMesh::export_obj ( const std::string &  filepath) const

Export the mesh as an OBJ file.

◆ info_string()

std::string hmap::TerrainTriMesh::info_string ( ) const

Return a mesh summary string.

◆ print_info()

void hmap::TerrainTriMesh::print_info ( ) const

Print mesh information.

◆ to_array()

Array hmap::TerrainTriMesh::to_array ( const glm::ivec2 &  shape,
const std::vector< float > &  values = {},
const glm::vec4 &  bbox = {0.f, 1.f, 0.f, 1.f} 
) const

Rasterize the mesh into an array.

◆ to_csv()

void hmap::TerrainTriMesh::to_csv ( const std::string &  fname) const

Export vertices to CSV.


The documentation for this class was generated from the following files: