Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API to reset_time #1826

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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()
14 changes: 14 additions & 0 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>(f: impl FnOnce(&mut ThreadInfo) -> R) -> R {
use std::cell::RefCell;
Expand Down Expand Up @@ -86,6 +90,10 @@ impl ThreadInfo {
self.time_point.remove(&timeline);
}
}

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

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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)?)?;
Expand Down Expand Up @@ -404,6 +413,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