From 33ddb9c753f9157ebeec0c1f3471084837e84d84 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 12 Apr 2023 16:04:38 +0200 Subject: [PATCH] New API to reset_time --- rerun_py/rerun_sdk/rerun/__init__.py | 16 ++++++++++++++++ rerun_py/src/python_bridge.rs | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/rerun_py/rerun_sdk/rerun/__init__.py b/rerun_py/rerun_sdk/rerun/__init__.py index f58664c7f72a..19e921fec733 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -484,3 +484,19 @@ def set_time_nanos(timeline: str, nanos: Optional[int]) -> None: return bindings.set_time_nanos(timeline, nanos) + + +def reset_time() -> None: + """ + Clear all timeline information on this thread. + + This is the same as calling `set_time_*` with `None` for all of the active timelines. + + Used for all subsequent logging on the same thread, + until the next call to [`rerun.set_time_nanos`][] or [`rerun.set_time_seconds`][]. + """ + + if not bindings.is_enabled(): + return + + bindings.reset_time() diff --git a/rerun_py/src/python_bridge.rs b/rerun_py/src/python_bridge.rs index 738059999692..e66a6a593f9b 100644 --- a/rerun_py/src/python_bridge.rs +++ b/rerun_py/src/python_bridge.rs @@ -59,6 +59,10 @@ impl ThreadInfo { Self::with(|ti| ti.set_time(timeline, time_int)); } + pub fn reset_thread_time() { + Self::with(|ti| ti.reset_time()); + } + /// Get access to the thread-local [`ThreadInfo`]. fn with(f: impl FnOnce(&mut ThreadInfo) -> R) -> R { use std::cell::RefCell; @@ -86,6 +90,10 @@ impl ThreadInfo { self.time_point.remove(&timeline); } } + + fn reset_time(&mut self) { + self.time_point = TimePoint::default(); + } } // ---------------------------------------------------------------------------- @@ -144,6 +152,7 @@ fn rerun_bindings(py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(set_time_sequence, m)?)?; m.add_function(wrap_pyfunction!(set_time_seconds, m)?)?; m.add_function(wrap_pyfunction!(set_time_nanos, m)?)?; + m.add_function(wrap_pyfunction!(reset_time, m)?)?; m.add_function(wrap_pyfunction!(log_unknown_transform, m)?)?; m.add_function(wrap_pyfunction!(log_rigid3, m)?)?; @@ -404,6 +413,11 @@ fn set_time_nanos(timeline: &str, ns: Option) { ); } +#[pyfunction] +fn reset_time() { + ThreadInfo::reset_thread_time(); +} + fn convert_color(color: Vec) -> PyResult<[u8; 4]> { match &color[..] { [r, g, b] => Ok([*r, *g, *b, 255]),