Skip to content

Commit 8d25b9e

Browse files
authored
Restore: New API to reset_time (#1826) (#1854)
1 parent 666c0c6 commit 8d25b9e

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

rerun_py/rerun_sdk/rerun/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,19 @@ def set_time_nanos(timeline: str, nanos: Optional[int]) -> None:
528528
return
529529

530530
bindings.set_time_nanos(timeline, nanos)
531+
532+
533+
def reset_time() -> None:
534+
"""
535+
Clear all timeline information on this thread.
536+
537+
This is the same as calling `set_time_*` with `None` for all of the active timelines.
538+
539+
Used for all subsequent logging on the same thread,
540+
until the next call to [`rerun.set_time_nanos`][] or [`rerun.set_time_seconds`][].
541+
"""
542+
543+
if not bindings.is_enabled():
544+
return
545+
546+
bindings.reset_time()

rerun_py/src/python_bridge.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ impl ThreadInfo {
6565
Self::with(|ti| ti.set_time(timeline, time_int));
6666
}
6767

68+
pub fn reset_thread_time() {
69+
Self::with(|ti| ti.reset_time());
70+
}
71+
6872
/// Get access to the thread-local [`ThreadInfo`].
6973
fn with<R>(f: impl FnOnce(&mut ThreadInfo) -> R) -> R {
7074
use std::cell::RefCell;
@@ -92,6 +96,10 @@ impl ThreadInfo {
9296
self.time_point.remove(&timeline);
9397
}
9498
}
99+
100+
fn reset_time(&mut self) {
101+
self.time_point = TimePoint::default();
102+
}
95103
}
96104

97105
// ----------------------------------------------------------------------------
@@ -155,6 +163,7 @@ fn rerun_bindings(py: Python<'_>, m: &PyModule) -> PyResult<()> {
155163
m.add_function(wrap_pyfunction!(set_time_sequence, m)?)?;
156164
m.add_function(wrap_pyfunction!(set_time_seconds, m)?)?;
157165
m.add_function(wrap_pyfunction!(set_time_nanos, m)?)?;
166+
m.add_function(wrap_pyfunction!(reset_time, m)?)?;
158167

159168
m.add_function(wrap_pyfunction!(log_unknown_transform, m)?)?;
160169
m.add_function(wrap_pyfunction!(log_rigid3, m)?)?;
@@ -486,6 +495,11 @@ fn set_time_nanos(timeline: &str, ns: Option<i64>) {
486495
);
487496
}
488497

498+
#[pyfunction]
499+
fn reset_time() {
500+
ThreadInfo::reset_thread_time();
501+
}
502+
489503
fn convert_color(color: Vec<u8>) -> PyResult<[u8; 4]> {
490504
match &color[..] {
491505
[r, g, b] => Ok([*r, *g, *b, 255]),

0 commit comments

Comments
 (0)