Skip to content

Commit

Permalink
Restore: New API to reset_time (rerun-io#1826) (rerun-io#1854)
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Apr 14, 2023
1 parent 666c0c6 commit 8d25b9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
14 changes: 14 additions & 0 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>(f: impl FnOnce(&mut ThreadInfo) -> R) -> R {
use std::cell::RefCell;
Expand Down Expand Up @@ -92,6 +96,10 @@ impl ThreadInfo {
self.time_point.remove(&timeline);
}
}

fn reset_time(&mut self) {
self.time_point = TimePoint::default();
}
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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)?)?;
Expand Down Expand Up @@ -486,6 +495,11 @@ fn set_time_nanos(timeline: &str, ns: Option<i64>) {
);
}

#[pyfunction]
fn reset_time() {
ThreadInfo::reset_thread_time();
}

fn convert_color(color: Vec<u8>) -> PyResult<[u8; 4]> {
match &color[..] {
[r, g, b] => Ok([*r, *g, *b, 255]),
Expand Down

0 comments on commit 8d25b9e

Please sign in to comment.