From 8d25b9e53f16974c7d26f836a37731cb136d1e2d Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Fri, 14 Apr 2023 16:09:02 -0400 Subject: [PATCH] Restore: New API to reset_time (#1826) (#1854) --- 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 5385dda58c9a..3674fa642291 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -528,3 +528,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 6132616027fc..d7485517047c 100644 --- a/rerun_py/src/python_bridge.rs +++ b/rerun_py/src/python_bridge.rs @@ -65,6 +65,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; @@ -92,6 +96,10 @@ impl ThreadInfo { self.time_point.remove(&timeline); } } + + fn reset_time(&mut self) { + self.time_point = TimePoint::default(); + } } // ---------------------------------------------------------------------------- @@ -155,6 +163,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)?)?; @@ -486,6 +495,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]),