Callbacks

Callback methods

Methods launching callables provided to the NpOptiX constructor and corresponding setters to configure callbacks after initialization.

NpOptiX.set_launch_finished_cb(cb) → None[source]

Set callback function(s) executed after each finished frame.

Parameters

cb (callable or list) – Callable or list of callables to set as the launch finished callback.

NpOptiX._launch_finished_callback(rt_result: int) → None[source]

Callback executed after each finished frame (min_accumulation_step accumulation frames are raytraced together). This callback is executed in the raytracing thread and should not compute extensively (make a copy of the image data and process it in another thread).

Override this method in the UI class, call this base implementation and update image in UI (or raise an event to do so).

Actions provided with on_launch_finished parameter of NpOptiX constructor are executed here.

Parameters

rt_result (int) – Raytracing result code corresponding to plotoptix.enums.RtResult.

NpOptiX._scene_rt_starting_callback() → None[source]

Callback executed before starting frame raytracing. Appropriate to override in UI class and apply scene edits (or raise an event to do so) like camera rotations, etc. made by a user in UI.

This callback is executed in the raytracing thread and should not compute extensively.

NpOptiX.set_accum_done_cb(cb) → None[source]

Set callback function(s) executed when all accumulation frames are completed.

Parameters

cb (callable or list) – Callable or list of callables to set as the accum done callback.

NpOptiX._accum_done_callback() → None[source]

Callback executed when all accumulation frames are completed.

Do not override, it is intended to launch on_rt_accum_done actions provided with NpOptiX constructor parameters.

Executed in the raytracing thread, so do not compute or write files (make a copy of the image data and process it in another thread).

NpOptiX.set_scene_compute_cb(cb) → None[source]

Set callback function(s) executed on each frame ray tracing start.

Callback(s) executed in parallel to the raytracing and intended for CPU intensive computations. Note, set compute_timeout to appropriate value if your computations are longer than single frame ray tracing, see plotoptix.NpOptiX.set_param().

Parameters

cb (callable or list) – Callable or list of callables to set as the scene compute callback.

NpOptiX._start_scene_compute_callback(n_frames: int) → None[source]

Compute callback executed together with the start of each frame raytracing.

This callback is executed in parallel to the raytracing and is intended for CPU intensive computations. Do not set, update data, cameras, lights, etc. here, as it will block until the end of raytracing in the parallel thread.

Callback execution can be suspended / resumed with plotoptix.NpOptiX.pause_compute() / plotoptix.NpOptiX.resume_compute() methods.

Do not override, this method is intended to launch on_scene_compute actions provided with NpOptiX constructor parameters.

Parameters

n_frames (int) – Number of the raytraced frames since the last call (excluding paused cycles).

NpOptiX.set_rt_completed_cb(cb) → None[source]

Set callback function(s) executed on each frame ray tracing finished.

Callback(s) executed in the same thread as the scene compute callback. Note, set compute_timeout to appropriate value if your computations are longer than single frame ray tracing, see plotoptix.NpOptiX.set_param().

Parameters

cb (callable or list) – Callable or list of callables to set as the RT completed callback.

NpOptiX._scene_rt_completed_callback(rt_result: int) → None[source]

Callback executed in the same thread as _start_scene_compute_callback, after it finishes computations.

This callback is synchronized also with the raytracing thread and should be used for any uploads of the updated scene to GPU: data, cameras, lights setup or updates. Image updates in UI are also possible here, but note that callback execution can be suspended / resumed with pause_compute() / resume_compute() methods.

Do not override, this method is intended to launch on_rt_completed actions provided with __init__ method parameters.

Parameters

rt_result (int) – Raytracing result code corresponding to RtResult enum.

Pause and resume compute

Scene computation callbacks can be paused/resumed, without stopping the raytracing loop, using following two methods:

NpOptiX.pause_compute() → None[source]

Suspend execution of on_scene_compute / on_rt_completed actions.

NpOptiX.resume_compute() → None[source]

Resume execution of on_scene_compute / on_rt_completed actions.