differt.geometry.AbstractPathTracer#

class AbstractPathTracer[source]#

Bases: AbstractPathSolver

Abstract base class for exact path tracing solvers.

A path tracer generates path candidates (arrays of triangle indices together with interaction-type tags) and then traces them through the scene to produce TracedPaths.

Attributes

epsilon

Tolerance for checking ray / object intersections.

hit_tol

Tolerance for blockage checks.

Methods

generate_path_candidates(scene, order[, ...])

Return a tuple of (path_candidates, interaction_types).

generate_path_candidates_chunks_iter(scene, ...)

Return an iterator of chunked path candidate tuples.

trace_path_candidates(scene, ...[, ...])

Core logic to trace the exact paths from the proposed candidates.

trace_paths(scene, order[, chunk_size, ...])

Trace paths for the given scene and order(s).

Detailed documentation

epsilon: AbstractVar[float]#

Tolerance for checking ray / object intersections.

abstractmethod generate_path_candidates(scene, order, allowed_interactions=None)[source]#

Return a tuple of (path_candidates, interaction_types).

path_candidates contains primitive indices: a (quad-aware) triangle index for REFLECTION, SCATTERING, and TRANSMISSION bounces, or a flat half-edge index (3 * triangle_index + local_edge_index) for DIFFRACTION bounces, matching Mesh.wedge_angles. interaction_types classifies the bounce, matching InteractionType. A value of -1 in either array indicates an “inactive” interaction or padded bounce.

order may also be a sequence of orders, e.g., [1, 2, 3], a range (e.g., range(0, 6)), or a slice with a defined stop (e.g., slice(0, 6), equivalent to range(0, 6)), to combine candidates of multiple orders into a single array, with lower-order candidates padded with -1 up to the maximum requested order, see check_path_candidates for the exact placeholder convention. For most solvers, candidates are generated independently for each order and concatenated, so the size of the returned arrays is known ahead of time: it is the sum of the number of candidates generated for each individual order. SBRPathTracer is a notable exception: it shares a single, fixed-size buffer across all requested orders instead, see its documentation for details.

Parameters:
  • scene (Scene) – The scene.

  • order (int | Sequence[int] | slice) – The path order (number of bounces), or a sequence of orders (also accepted as a range or slice) to combine.

  • allowed_interactions (frozenset[InteractionType] | None) – The set of interaction types a bounce may take. Defaults to frozenset({InteractionType.REFLECTION}) when None. SBRPathTracer’s ray-shooting kernel only discovers REFLECTION bounces; requesting other interaction types falls back to (or, when mixed with REFLECTION, merges in) HybridPathTracer’s graph-based generation, see SBRPathTracer.

Return type:

tuple[Int[Array, "... num_path_candidates max_order"], Int[Array, "... num_path_candidates max_order"]]

Returns:

A 2-tuple of (path_candidates, interaction_types).

generate_path_candidates_chunks_iter(scene, order, *args, chunk_size, pad_chunks=False, **kwargs)[source]#

Return an iterator of chunked path candidate tuples.

The default implementation calls generate_path_candidates once and then slices the result. Subclasses may override this to generate candidates lazily.

Parameters:
Return type:

SizedIterator[tuple[Int[Array, "... chunk_size max_order"], Int[Array, "... chunk_size max_order"]]] | Iterator[tuple[Int[Array, "... chunk_size max_order"], Int[Array, "... chunk_size max_order"]]]

Returns:

A SizedIterator over (path_candidates, interaction_types) chunks.

hit_tol: AbstractVar[float]#

Tolerance for blockage checks.

abstractmethod trace_path_candidates(scene, path_candidates, interaction_types, allowed_interactions=None)[source]#

Core logic to trace the exact paths from the proposed candidates.

Parameters:
Return type:

TracedPaths

Returns:

The traced paths.

trace_paths(scene, order, chunk_size=None, pad_chunks=False, allowed_interactions=None)[source]#

Trace paths for the given scene and order(s).

If chunk_size is provided, returns an iterator of TracedPaths (one per chunk); otherwise returns a single TracedPaths.

If order is a sequence of orders, e.g., [1, 2, 3], then generate_path_candidates directly generates path candidates for every requested order, combining them into a single array, with lower-order candidates padded (with -1) up to the maximum requested order; the (single) combined array is then traced in one call to trace_path_candidates. This is not compatible with chunk_size.

Parameters:
Return type:

TracedPaths | SizedIterator[TracedPaths] | Iterator[TracedPaths]

Returns:

Traced paths, or a sized iterator thereof. If chunk_size is set and generate_path_candidates_chunks_iter was overridden to return a plain (unsized) iterator, a plain iterator is returned instead of a SizedIterator.

Raises:

NotImplementedError – If order is a sequence of orders and chunk_size is not None.