Class MeshSegmentTracer
Defined in File mesh_segment_tracer.h
Nested Relationships
Nested Types
Class Documentation
-
class MeshSegmentTracer
Traversal of straight segments through the local cells of a mesh, decided by exact geometric predicates.
Every cell is traced as a set of convex pieces whose boundaries are triangles: a triangular face is one triangle, and a face with more vertices is the fan of triangles from its sides to its centroid. The centroid of a face is computed from the vertices in a canonical order, so that the two cells sharing a face hold bit-identical triangles. A cell that is convex, with every vertex of it on the inner side of every triangle, is one piece. Any other cell is split into its side tetrahedra, each formed by a boundary triangle and an interior point of the cell, which requires the cell to be star-shaped about that point; the tracer rejects a cell that is not.
A segment leaves a convex piece through the one boundary triangle that its line threads outward, decided from the signs of the orientation predicate of the segment against the three edges of the triangle (Platis and Theoharis 2003, Lagae and Dutre 2008). The predicates are evaluated exactly (Shewchuk 1997), and the two pieces on either side of a triangle test the same edges from the same points, so the traversal never finds a gap or an overlap between pieces: it cannot lose a segment in the interior of a conforming mesh. Whether the segment ends in a piece is decided exactly as well. Only the distances along the segment at which it crosses the triangles are computed in floating point, and they are kept monotone, so the lengths of a traversal are nonnegative and sum to the segment length.
A segment whose line passes exactly through an edge or a vertex, or lies in the plane of a face, makes a predicate zero. The tracer then traces the segment translated by a few units in the last place of the coordinates, in several directions, which keeps the lengths within that round-off, and reports the segment as reaching its end if the segment translated in any direction does.
The tracer works on the local cells of a mesh and treats a face whose neighbor is not local as a boundary face.
Public Functions
-
explicit MeshSegmentTracer(const Mesh &grid, bool split_all_cells = false)
Builds the pieces of every local cell and the vertex-to-cell adjacency.
O(cells). A cell that is not convex is traced through the tetrahedra of its triangles and an interior point about which it is star-shaped, searched for from the average of its points. Throws std::invalid_argument for a cell that is not star-shaped about any point.
With split_all_cells, every cell is traced through its side tetrahedra, as a non-convex cell is. The result is the same up to round-off; the option exists to test that path on meshes of convex cells.
-
bool Trace(std::uint32_t start_cell, const Vector3 &start, const Vector3 &end, std::vector<Segment> &segments) const
Traces the segment from start to end, beginning in the local cell start_cell, which contains start, has it on its boundary, or is next to the cell that does.
A start that lies outside start_cell by the round-off of its coordinates, as a point computed to lie on one of its faces can, is moved into it. Appends the cells that the segment crosses, in order, with the length of the segment in each, to segments.
Returns true when the segment reaches end, which includes an end that lies outside a boundary face by the round-off of its coordinates. Returns false when the segment leaves the local cells first, through a boundary face, a face whose neighbor is not local, or a gap in a non-conforming mesh; segments then holds the part traced before the segment left. Throws if start does not lie in, on, or near start_cell.
-
inline bool IsConvexCell(std::uint32_t cell_local_id) const
Whether the cell is traced as one convex piece rather than through its side tetrahedra.
-
struct Segment
A part of a segment in one local cell.
-
explicit MeshSegmentTracer(const Mesh &grid, bool split_all_cells = false)