Skip to main content

Module geometry

Module geometry 

Source
Expand description

Target geometry: the engine-facing Geometry trait, the 1D layered Stack, the 3D VoxelGrid, the triangle-mesh MeshGeometry and the constructive-solid-geometry CsgGeometry.

§Coordinates

x is depth, measured from the front surface (x = 0) into the target; y and z are lateral. Lengths are metres (SI, see crate::units). A Stack is an ordered list of layers, each homogeneous and laterally infinite (the planar slab model of amorphous-target binary-collision codes, e.g. J. P. Biersack and L. G. Haggmark, Nucl. Instrum. Methods 174 (1980) 257). The last layer may be semi-infinite (a substrate); otherwise the target has a back face at its total thickness.

§The Geometry contract

A geometry is a set of numbered regions (layers of a stack, voxels of a grid), each filled by one of a numbered list of materials. A transport engine keeps a particle’s current region, asks Geometry::exit how far a straight flight can go before something changes, truncates the free path there, and carries the unused optical depth into the next region (the same contract as the layer interface of the M0 engine). “Something changes” means the material changes, the particle leaves the target, or it wraps through a periodic boundary; crossing into a region of the same material is not an event, so a voxel boundary inside a homogeneous block costs nothing. Per-material data (scattering, stopping) is cached by material index, never per region.

§Voxel grids

VoxelGrid is a regular box [0, Lx] x [0, Ly] x [0, Lz], with L = n h for n voxels of spacing h on each axis, and the origin at the corner of the front face (x = 0 is the front surface, so a grid can encode a Stack with the layers along x). Voxel (i, j, k) has the flat region index i + nx (j + ny k) (x fastest). It owns the half-open box [i h, (i + 1) h) on each axis, so a point exactly on an interior face belongs to the voxel with the higher index, as a depth exactly on a layer interface belongs to the deeper layer of a stack.

Each axis is either Boundary::Vacuum (a particle reaching either end of the axis leaves the target) or Boundary::Periodic (it re-enters at the opposite face with the same direction; the travelled length and so the energy loss are those of the unwrapped path). Faces on the x axis are reported as Face::Front (x = 0) and Face::Back (x = Lx); faces on y and z are Face::Side.

The exact ray traversal is the 3D digital differential analyser of J. Amanatides and A. Woo, “A fast voxel traversal algorithm for ray tracing”, Eurographics ’87 (1987) 3-10: the distance to the next face of each axis is (face - position) / direction, the axis with the smallest distance is crossed, and the face distances are recomputed from the face coordinates (not accumulated), so rounding does not drift along a long ray. Axes with a zero direction component are never crossed. When several axes reach a face at exactly the same distance (an edge or corner), they are crossed together, so the ray passes directly to the diagonal voxel without visiting the voxels it only touches. If a tied crossing leaves the target through several vacuum faces, the face of the lowest axis (x, then y, then z) is reported.

§Triangle meshes

MeshGeometry (module mesh) is a set of closed STL/OBJ triangle solids, one region each, with a BVH for ray queries. Its overlap, surface and tolerance rules, the Face mapping of its escapes, the loaders and the watertightness rules are in the mesh module docs.

§CSG

CsgGeometry (module csg) is a set of Csg solids built from box, cylinder and half-space Primitives by union, intersection and difference, one region per top-level solid, classified along each flight by ray casting. It follows the mesh ownership and tolerance rules, so a box gives the same events as a CSG solid, a mesh or a voxel grid; the rules, the handling of unbounded half-spaces and the algorithms are in the csg module docs.

Re-exports§

pub use csg::Csg;
pub use csg::CsgGeometry;
pub use csg::Primitive;
pub use mesh::MeshGeometry;
pub use mesh::TriMesh;

Modules§

csg
Constructive solid geometry: box, cylinder and half-space primitives, combined by union, intersection and difference, and the CsgGeometry target built from them.
mesh
Triangle-mesh solids: loaders (STL, OBJ), the watertightness check, and the MeshGeometry target built on a BVH.

Structs§

Exit
The first event along a straight flight.
Layer
One homogeneous layer.
Stack
A 1D layered target: finite layers front to back, optionally ending in a semi-infinite substrate.
VoxelGrid
A regular 3D grid of voxels, each filled by one material. See the module docs for the origin, flattening order, face ownership, boundary behaviour and the traversal algorithm.

Enums§

Boundary
What a voxel grid does to a particle that reaches the ends of one axis.
ExitOutcome
What happens at the end of a flight segment returned by Geometry::exit.
Face
Which face of the target a particle left through.
Flight
The outcome of a flight query, Geometry::flight.
GeometryError
Errors from building a Stack, a VoxelGrid, a MeshGeometry or a CsgGeometry.

Traits§

Geometry
The engine-facing description of a target. See the module docs for the contract. Implemented by Stack, VoxelGrid, MeshGeometry and CsgGeometry.