Skip to content

Commit 124305c

Browse files
authored
Add incremental_logging example (#5462)
Showcases how to incrementally log data belonging to the same archetype, and re-use some or all of it across frames. Turns out the first thing I immediately wanted was clamping-edge semantics 🥲 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/5462/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/5462/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/5462/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! - [PR Build Summary](https://build.rerun.io/pr/5462) - [Docs preview](https://rerun.io/preview/28ff483ad15c8d29334984ae730b0cd2d1677131/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/28ff483ad15c8d29334984ae730b0cd2d1677131/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
1 parent 2af4da0 commit 124305c

12 files changed

Lines changed: 274 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_subdirectory(clock)
22
add_subdirectory(custom_collection_adapter)
33
add_subdirectory(dna)
44
add_subdirectory(external_data_loader)
5+
add_subdirectory(incremental_logging)
56
add_subdirectory(log_file)
67
add_subdirectory(minimal)
78
add_subdirectory(shared_recording)
@@ -13,6 +14,7 @@ add_custom_target(examples)
1314
add_dependencies(examples example_clock)
1415
add_dependencies(examples example_custom_collection_adapter)
1516
add_dependencies(examples example_dna)
17+
add_dependencies(examples example_incremental_logging)
1618
add_dependencies(examples example_log_file)
1719
add_dependencies(examples example_minimal)
1820
add_dependencies(examples example_shared_recording)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 3.16...3.27)
2+
3+
# If you use the example outside of the Rerun SDK you need to specify
4+
# where the rerun_c build is to be found by setting the `RERUN_CPP_URL` variable.
5+
# This can be done by passing `-DRERUN_CPP_URL=<path to rerun_sdk_cpp zip>` to cmake.
6+
if(DEFINED RERUN_REPOSITORY)
7+
add_executable(example_incremental_logging main.cpp)
8+
rerun_strict_warning_settings(example_incremental_logging)
9+
else()
10+
project(example_incremental_logging LANGUAGES CXX)
11+
12+
add_executable(example_incremental_logging main.cpp)
13+
14+
# Set the path to the rerun_c build.
15+
set(RERUN_CPP_URL "https://github.com/rerun-io/rerun/releases/latest/download/rerun_cpp_sdk.zip" CACHE STRING "URL to the rerun_cpp zip.")
16+
17+
# Download the rerun_sdk
18+
include(FetchContent)
19+
FetchContent_Declare(rerun_sdk URL ${RERUN_CPP_URL})
20+
FetchContent_MakeAvailable(rerun_sdk)
21+
22+
# Rerun requires at least C++17, but it should be compatible with newer versions.
23+
set_property(TARGET example_incremental_logging PROPERTY CXX_STANDARD 17)
24+
endif()
25+
26+
# Link against rerun_sdk.
27+
target_link_libraries(example_incremental_logging PRIVATE rerun_sdk)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!--[metadata]
2+
title = "Incremental Logging"
3+
tags = ["3d", "api-example"]
4+
description = "Showcases how to incrementally log data belonging to the same archetype."
5+
thumbnail = "https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/480w.png"
6+
thumbnail_dimensions = [480, 285]
7+
channel = "main"
8+
-->
9+
10+
11+
<picture>
12+
<img src="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/full.png" alt="">
13+
<source media="(max-width: 480px)" srcset="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/480w.png">
14+
<source media="(max-width: 768px)" srcset="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/768w.png">
15+
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/1024w.png">
16+
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/1200w.png">
17+
</picture>
18+
19+
Showcases how to incrementally log data belonging to the same archetype, and re-use some or all of it across frames.
20+
21+
22+
To build it from a checkout of the repository (requires a Rust toolchain):
23+
```bash
24+
cmake .
25+
cmake --build . --target example_incremental_logging
26+
./examples/cpp/incremental/example_incremental_logging
27+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Showcase how to incrementally log data belonging to the same archetype, and re-use some or all
2+
// of it across frames.
3+
4+
#include <rerun.hpp>
5+
6+
#include <algorithm>
7+
#include <random>
8+
9+
int main() {
10+
const auto rec = rerun::RecordingStream("rerun_example_incremental_logging");
11+
rec.spawn().exit_on_failure();
12+
13+
// TODO(#5264): just log one once clamp-to-edge semantics land.
14+
std::vector<rerun::Color> colors(10, rerun::Color(255, 0, 0));
15+
std::vector<rerun::Radius> radii(10, rerun::Radius(0.1f));
16+
17+
// Only log colors and radii once.
18+
rec.set_time_sequence("frame_nr", 0);
19+
rec.log("points", colors, radii);
20+
// Logging timelessly with `RecordingStream::log_timeless` would also work.
21+
// rec.log_timeless("points", colors, radii);
22+
23+
std::default_random_engine gen;
24+
std::uniform_real_distribution<float> dist_pos(-5.0f, 5.0f);
25+
26+
// Then log only the points themselves each frame.
27+
//
28+
// They will automatically re-use the colors and radii logged at the beginning.
29+
for (int i = 0; i < 10; ++i) {
30+
rec.set_time_sequence("frame_nr", i);
31+
32+
std::vector<rerun::Position3D> points(10);
33+
std::generate(points.begin(), points.end(), [&] {
34+
return rerun::Position3D(dist_pos(gen), dist_pos(gen), dist_pos(gen));
35+
});
36+
rec.log("points", rerun::Points3D(points));
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--[metadata]
2+
title = "Incremental Logging"
3+
tags = ["3d", "api-example"]
4+
description = "Showcases how to incrementally log data belonging to the same archetype."
5+
thumbnail = "https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/480w.png"
6+
thumbnail_dimensions = [480, 301]
7+
channel = "main"
8+
-->
9+
10+
11+
<picture>
12+
<img src="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/full.png" alt="">
13+
<source media="(max-width: 480px)" srcset="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/480w.png">
14+
<source media="(max-width: 768px)" srcset="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/768w.png">
15+
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/1024w.png">
16+
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/incremental_logging/b7a2bd889b09c3840f56dc31bd6d677934ab3126/1200w.png">
17+
</picture>
18+
19+
Showcases how to incrementally log data belonging to the same archetype, and re-use some or all of it across frames.
20+
21+
22+
To build it from a checkout of the repository (requires a Rust toolchain):
23+
```bash
24+
python examples/python/incremental_logging/main.py
25+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
"""Showcases how to incrementally log data belonging to the same archetype, and re-use some or all of it across frames."""
3+
from __future__ import annotations
4+
5+
import argparse
6+
7+
import numpy as np
8+
import rerun as rr
9+
from numpy.random import default_rng
10+
11+
parser = argparse.ArgumentParser(description="Showcases how to incrementally log data belonging to the same archetype.")
12+
rr.script_add_args(parser)
13+
args = parser.parse_args()
14+
15+
rr.script_setup(args, "rerun_example_incremental_logging")
16+
17+
# TODO(#5264): just log one once clamp-to-edge semantics land.
18+
colors = rr.components.ColorBatch(np.repeat(0xFF0000FF, 10))
19+
radii = rr.components.RadiusBatch(np.repeat(0.1, 10))
20+
21+
# Only log colors and radii once.
22+
rr.set_time_sequence("frame_nr", 0)
23+
rr.log_components("points", [colors, radii])
24+
# Logging timelessly would also work.
25+
# rr.log_components("points", [colors, radii], timeless=True)
26+
27+
rng = default_rng(12345)
28+
29+
# Then log only the points themselves each frame.
30+
#
31+
# They will automatically re-use the colors and radii logged at the beginning.
32+
for i in range(10):
33+
rr.set_time_sequence("frame_nr", i)
34+
rr.log("points", rr.Points3D(rng.uniform(-5, 5, size=[10, 3])))
35+
36+
rr.script_teardown(args)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
numpy
2+
rerun-sdk

examples/python/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
-r face_tracking/requirements.txt
1212
-r gesture_detection/requirements.txt
1313
-r human_pose_tracking/requirements.txt
14+
-r incremental_logging/requirements.txt
1415
-r lidar/requirements.txt
1516
-r live_camera_edge_detection/requirements.txt
1617
-r live_depth_sensor/requirements.txt
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "incremental_logging"
3+
version = "0.15.0-alpha.2"
4+
edition = "2021"
5+
rust-version = "1.74"
6+
license = "MIT OR Apache-2.0"
7+
publish = false
8+
9+
[dependencies]
10+
rerun = { path = "../../../crates/rerun", features = ["web_viewer", "clap"] }
11+
12+
anyhow = "1.0"
13+
clap = { version = "4.0", features = ["derive"] }
14+
glam = "0.22"
15+
rand = "0.8"

0 commit comments

Comments
 (0)