Overview
EBGeometry answers spatial queries on geometry, on the host and on a device. A mesh, an analytic shape, a composition of thousands of objects and a cloud of particles are kinds of geometry; how far away, which part is closest, where a ray meets it and what lies nearest are kinds of queries. The library is the table of which queries each kind of geometry answers, the acceleration structures that make them fast, and the memory model that lets the same query run on a GPU.
Geometry and queries
Distance and inside |
Closest |
Rays |
Neighbors |
|
|---|---|---|---|---|
Analytic shapes |
signed distance |
the surface |
yes |
– |
Meshes |
signed distance |
the face |
yes |
– |
Compositions (CSG, regions) |
signed distance, plus the region at a point |
the leaf and the surface, with the regions on its sides |
yes, plus where the region changes |
– |
Sphere clouds |
signed distance (a shape) |
the sphere and its surface |
yes |
contacts within a gap |
Point clouds |
unsigned distance to the nearest point |
the k nearest points to any point |
– |
each point’s k nearest other points |
The rows are described in The four sections, the columns in Queries.
Several cells are the same question asked of different geometry:
A nearest neighbor is a closest-point query on a set of points. A point cloud has no surface and no inside, so its distance is unsigned and its closest part is a point, but the query is the one a mesh answers with its closest face.
A sphere cloud is both a cloud and a shape. Give each point a radius and the cloud has a surface, an inside and a signed distance: it composes, ray traces and renders like any shape, and it still answers the cloud’s own question, which spheres touch which.
Every shape answers every point and ray query. A composition of meshes, analytic shapes and sphere clouds is itself a shape, so a query written for one kind of geometry runs on all of them.
The empty cells are choices, not missing pieces of one design:
No rays against a point cloud. A point has no extent, so a ray almost surely misses every point of a cloud. Give the points a radius and trace the sphere cloud instead.
No neighbor searches on a mesh or a composition. Their parts are faces and leaves, found through the closest query; neighbor searches are for discrete sets of particles.
No search within a radius on a point cloud. A point cloud answers for the k nearest; a sphere cloud finds the spheres within a gap of a sphere.
The four sections
The rest of this guide follows the table.
Geometry: what you can describe. A shape is anything with a signed value at a point and a bounding box (Geometry as a function): analytic shapes and your own, meshes read from files (Surface meshes), clouds of points and spheres (Clouds of points and spheres), and compositions of all of them (Constructive solid geometry). Regions, materials, labels and surface groups (Leaves, surfaces and labels, Regions, materials and domains) are a layer of meaning on that geometry: what a part of it is, and what a solver does with it.
Queries: what you can ask of it (Queries), from the value at a point to a ray’s first crossing (Rays and segments) and a picture made of many rays (Rendering).
Acceleration: why the queries are fast. Bounding volume hierarchies (Bounding volume hierarchies) and uniform grids (Searching clouds) are one idea, ruling out most of the geometry without measuring the distance to it, used for the faces of a mesh, the objects of a union and the points of a cloud alike.
Where it runs: memory pools that hold the geometry in one block, copied whole to a GPU and read there at their new address (Memory model), and running the queries there (Running queries on a GPU).
Each section explains the ideas first, then the classes and calls. The Glossary defines the words these pages give a meaning of their own.
Finding a call by task
#include <EBGeometry.hpp> gives all of the library, in the namespace EBGeometry.
To |
Read |
|---|---|
keep geometry in memory that can be copied to a GPU |
|
work with points and vectors |
|
read a mesh from a file, and query it |
|
build a BVH over your own primitives, and search it |
|
find nearest neighbors in a cloud of points or spheres |
|
use analytic shapes, compose them, and compile a composition |
|
build objects of several materials, and the domains a solver computes in |
|
read models written in the |
|
trace rays and particles’ steps through a shape |
|
render a shape, and look at it in a window |
|
estimate a bounding box, or a normal, of any function |
|
see what runs with SIMD instructions |
The namespaces follow the components: DCEL, BVH, Fused, PointCloud, SphereCloud,
TapeFeature, GPU, Render, SFC, Parser and Language. The Doxygen reference
(EBGeometry) lists every class and function.
Design choices
A handful of choices recur throughout the library:
Precision templating. The geometry is templated on a floating-point type
T,floatordouble. Precision is a compile-time choice: the library has no “current” precision at run time, and nothing dispatches on it.Plain value types everywhere, and a compiled tape for composition. The analytic shapes, the surface-mesh distance fields and the BVH unions are plain, trivially copyable value types with no virtual functions, so they can be copied to a GPU and evaluated there. Transformations and CSG combinations are described with an expression builder and compiled into a
Tape, a program over arrays of primitives that needs no virtual dispatch either. See Geometries.The same acceleration structure for different problems. Finding the closest facet in a surface mesh, the closest object in a CSG union of many objects, and the closest point in a cloud are all, structurally, “find the closest of \(N\) things” queries. EBGeometry solves them with the same bounding volume hierarchy machinery, reducing an \(\mathcal{O}(N)\) linear scan to an \(\mathcal{O}(\log N)\) tree traversal in each case. See BVH.
Value types, even where topology is needed. A DCEL mesh’s half-edges, their pairs, and their owning faces are genuinely different objects referencing each other – but rather than pointers or reference-counted back-references, every such cross-reference is a plain
uint32_tindex into the owning mesh’s own vertex/edge/face arrays. This makesVertexT/EdgeT/FaceTthemselves trivially copyable value types, the same as a bounding-volume-hierarchy node stored by index offset rather than by pointer, so both can be packed tightly in memory and, where the data layout allows it, evaluated with SIMD instructions. See Half-edge meshes and BVH.SIMD as an opt-in, compile-time-detected layer. SIMD acceleration is implemented with compiler intrinsics in three places (the SoA triangle and point blocks, and
PackedBVH’s child-bounding-box pruning), selected at compile time from the standard compiler-predefined ISA macros – never a runtime dispatch. See SIMD-accelerated classes.Device-callable basics. Scalar helpers and numeric limits (
Math::min,Math::max,Math::clamp,Math::Limits) and the fixed-sizeArray<T, N>replace theirstdcounterparts throughout the library, so its device code needs no special compiler flags. See Writing device code.GPU::parallelForandGPU::transformrun a functor over many indices or inputs, in a kernel in a CUDA or HIP build and in a host loop otherwise; see Running queries on a GPU.Three checking mechanisms.
static_assertguards template-parameter invariants decidable at compile time; the always-onEBGEOMETRY_REQUIREmacro checks what a caller controls, once, when an object is built; the opt-inEBGEOMETRY_EXPECTmacro guards internal invariants, including on hot paths. See Configuration options.