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.

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

Memory model, Running queries on a GPU

work with points and vectors

Vector types

read a mesh from a file, and query it

Reading data, Mesh distance functions, Half-edge meshes

build a BVH over your own primitives, and search it

BVH, BVH traversal

find nearest neighbors in a cloud of points or spheres

Point clouds

use analytic shapes, compose them, and compile a composition

Geometries

build objects of several materials, and the domains a solver computes in

Regions and domains

read models written in the .ebg language

Reading models in C++

trace rays and particles’ steps through a shape

Ray queries

render a shape, and look at it in a window

The renderer, The viewer

estimate a bounding box, or a normal, of any function

Octree subdivision

see what runs with SIMD instructions

SIMD-accelerated classes

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, float or double. 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_t index into the owning mesh’s own vertex/edge/face arrays. This makes VertexT/EdgeT/FaceT themselves 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-size Array<T, N> replace their std counterparts throughout the library, so its device code needs no special compiler flags. See Writing device code. GPU::parallelFor and GPU::transform run 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_assert guards template-parameter invariants decidable at compile time; the always-on EBGEOMETRY_REQUIRE macro checks what a caller controls, once, when an object is built; the opt-in EBGEOMETRY_EXPECT macro guards internal invariants, including on hot paths. See Configuration options.