differt.geometry.AbstractPathTracer#
- class AbstractPathTracer[source]#
Bases:
AbstractPathSolverAbstract 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
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
- abstractmethod generate_path_candidates(scene, order, allowed_interactions=None)[source]#
Return a tuple of
(path_candidates, interaction_types).path_candidatescontains primitive indices: a (quad-aware) triangle index forREFLECTION,SCATTERING, andTRANSMISSIONbounces, or a flat half-edge index (3 * triangle_index + local_edge_index) forDIFFRACTIONbounces, matchingMesh.wedge_angles.interaction_typesclassifies the bounce, matchingInteractionType. A value of-1in either array indicates an “inactive” interaction or padded bounce.ordermay also be a sequence of orders, e.g.,[1, 2, 3], arange(e.g.,range(0, 6)), or aslicewith a definedstop(e.g.,slice(0, 6), equivalent torange(0, 6)), to combine candidates of multiple orders into a single array, with lower-order candidates padded with-1up to the maximum requested order, seecheck_path_candidatesfor 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.SBRPathTraceris 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 arangeorslice) to combine.allowed_interactions (
frozenset[InteractionType] |None) – The set of interaction types a bounce may take. Defaults tofrozenset({InteractionType.REFLECTION})whenNone.SBRPathTracer’s ray-shooting kernel only discoversREFLECTIONbounces; requesting other interaction types falls back to (or, when mixed withREFLECTION, merges in)HybridPathTracer’s graph-based generation, seeSBRPathTracer.
- 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_candidatesonce and then slices the result. Subclasses may override this to generate candidates lazily.- Parameters:
scene (
Scene) – The scene.*args (
Any) – Forwarded togenerate_path_candidates.chunk_size (
int) – Number of candidates per chunk.pad_chunks (
bool) – IfTrue, the last chunk is zero-padded (with-1) tochunk_size.**kwargs (
Any) – Forwarded togenerate_path_candidates.
- 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
SizedIteratorover(path_candidates, interaction_types)chunks.
- 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:
scene (
Scene) – The scene.path_candidates (
Int[Array, "... num_path_candidates max_order"]) – Primitive indices for each candidate, seegenerate_path_candidates.interaction_types (
Int[Array, "... num_path_candidates max_order"]) – Interaction type for each bounce.allowed_interactions (
frozenset[InteractionType] |None) – The set of interaction types that was used to generatepath_candidates(seegenerate_path_candidates): needed again here because it determines how mixed-type candidates are geometrically solved (e.g., whether a DIFFRACTION bounce may be present, requiring the general Fermat solver instead of the exact image method), which must be resolved ahead of any traced computation. Defaults tofrozenset({InteractionType.REFLECTION})whenNone.
- Return type:
- 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_sizeis provided, returns an iterator ofTracedPaths(one per chunk); otherwise returns a singleTracedPaths.If
orderis a sequence of orders, e.g.,[1, 2, 3], thengenerate_path_candidatesdirectly 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 totrace_path_candidates. This is not compatible withchunk_size.- Parameters:
scene (
Scene) – The scene.chunk_size (
int|None) – If notNone, iterate through chunks of this size.pad_chunks (
bool) – IfTrueandchunk_sizeis set, pad the last chunk.allowed_interactions (
frozenset[InteractionType] |None) – The set of interaction types a bounce may take, seegenerate_path_candidates.
- Return type:
TracedPaths|SizedIterator[TracedPaths] |Iterator[TracedPaths]- Returns:
Traced paths, or a sized iterator thereof. If
chunk_sizeis set andgenerate_path_candidates_chunks_iterwas overridden to return a plain (unsized) iterator, a plain iterator is returned instead of aSizedIterator.- Raises:
NotImplementedError – If
orderis a sequence of orders andchunk_sizeis notNone.