diff --git a/docs/snippets/INDEX.md b/docs/snippets/INDEX.md index 7ae27d8bee17f..26ab29d14dcfa 100644 --- a/docs/snippets/INDEX.md +++ b/docs/snippets/INDEX.md @@ -71,6 +71,8 @@ _All snippets, organized by the [`Archetype`](https://rerun.io/docs/reference/ty | **[`Capsules3D`](https://rerun.io/docs/reference/types/archetypes/capsules3d)** | `archetypes/capsules3d_batch` | Log a batch of capsules | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/capsules3d_batch.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/capsules3d_batch.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/capsules3d_batch.cpp) | | **[`Clear`](https://rerun.io/docs/reference/types/archetypes/clear)** | `archetypes/clear_simple` | Log and then clear data | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/clear_simple.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/clear_simple.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/clear_simple.cpp) | | **[`Clear`](https://rerun.io/docs/reference/types/archetypes/clear)** | `archetypes/clear_recursive` | Log and then clear data recursively | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/clear_recursive.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/clear_recursive.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/clear_recursive.cpp) | +| **[`Clear`](https://rerun.io/docs/reference/types/archetypes/clear)** | `archetypes/points3d_partial_updates` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.cpp) | +| **[`Clear`](https://rerun.io/docs/reference/types/archetypes/clear)** | `archetypes/points3d_partial_updates_legacy` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp) | | **[`Clear`](https://rerun.io/docs/reference/types/archetypes/clear)** | `concepts/different_data_per_timeline` | Log different data on different timelines | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.cpp) | | **[`DepthImage`](https://rerun.io/docs/reference/types/archetypes/depth_image)** | `archetypes/depth_image_simple` | Create and log a depth image | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/depth_image_simple.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/depth_image_simple.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/depth_image_simple.cpp) | | **[`DepthImage`](https://rerun.io/docs/reference/types/archetypes/depth_image)** | `archetypes/depth_image_3d` | Create and log a depth image and pinhole camera | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/depth_image_3d.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/depth_image_3d.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/depth_image_3d.cpp) | @@ -128,6 +130,8 @@ _All snippets, organized by the [`Archetype`](https://rerun.io/docs/reference/ty | **[`Points3D`](https://rerun.io/docs/reference/types/archetypes/points3d)** | `archetypes/points3d_simple` | Log some very simple points | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_simple.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_simple.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_simple.cpp) | | **[`Points3D`](https://rerun.io/docs/reference/types/archetypes/points3d)** | `archetypes/points3d_send_columns` | Use the `send_columns` API to send several point clouds over time in a single call | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_send_columns.py) | | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_send_columns.cpp) | | **[`Points3D`](https://rerun.io/docs/reference/types/archetypes/points3d)** | `archetypes/points3d_random` | Log some random points with color and radii | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_random.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_random.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_random.cpp) | +| **[`Points3D`](https://rerun.io/docs/reference/types/archetypes/points3d)** | `archetypes/points3d_partial_updates_legacy` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp) | +| **[`Points3D`](https://rerun.io/docs/reference/types/archetypes/points3d)** | `archetypes/points3d_partial_updates` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.cpp) | | **[`Points3D`](https://rerun.io/docs/reference/types/archetypes/points3d)** | `archetypes/annotation_context_connections` | Log annotation context with connections between keypoints | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/annotation_context_connections.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/annotation_context_connections.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/annotation_context_connections.cpp) | | **[`Points3D`](https://rerun.io/docs/reference/types/archetypes/points3d)** | `archetypes/ellipsoids3d_simple` | Log random points and the corresponding covariance ellipsoid | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/ellipsoids3d_simple.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/ellipsoids3d_simple.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/ellipsoids3d_simple.cpp) | | **[`Points3D`](https://rerun.io/docs/reference/types/archetypes/points3d)** | `archetypes/instance_poses3d_combined` | Log a simple 3D box with a regular & instance pose transform | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/instance_poses3d_combined.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/instance_poses3d_combined.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/instance_poses3d_combined.cpp) | @@ -196,6 +200,8 @@ _All snippets, organized by the [`Component`](https://rerun.io/docs/reference/ty | **[`AnnotationContext`](https://rerun.io/docs/reference/types/components/annotation_context)** | `archetypes/annotation_context_connections` | Log annotation context with connections between keypoints | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/annotation_context_connections.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/annotation_context_connections.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/annotation_context_connections.cpp) | | **[`AnnotationContext`](https://rerun.io/docs/reference/types/components/annotation_context)** | `archetypes/segmentation_image_simple` | Create and log a segmentation image | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/segmentation_image_simple.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/segmentation_image_simple.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/segmentation_image_simple.cpp) | | **[`AnnotationContext`](https://rerun.io/docs/reference/types/components/annotation_context)** | `tutorials/annotation-context` | | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/annotation-context.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/annotation-context.rs) | | +| **[`Color`](https://rerun.io/docs/reference/types/components/color)** | `archetypes/points3d_partial_updates` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.cpp) | +| **[`Color`](https://rerun.io/docs/reference/types/components/color)** | `archetypes/points3d_partial_updates_legacy` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp) | | **[`Color`](https://rerun.io/docs/reference/types/components/color)** | `archetypes/points3d_send_columns` | Use the `send_columns` API to send several point clouds over time in a single call | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_send_columns.py) | | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_send_columns.cpp) | | **[`Color`](https://rerun.io/docs/reference/types/components/color)** | `concepts/different_data_per_timeline` | Log different data on different timelines | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.cpp) | | **[`Color`](https://rerun.io/docs/reference/types/components/color)** | `concepts/viscomp-component-default` | Add a component default | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/viscomp-component-default.py) | | | @@ -216,6 +222,8 @@ _All snippets, organized by the [`Component`](https://rerun.io/docs/reference/ty | **[`MediaType`](https://rerun.io/docs/reference/types/components/media_type)** | `views/text_document` | Use a blueprint to show a text document | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/views/text_document.py) | | | | **[`Plane3D`](https://rerun.io/docs/reference/types/components/plane3d)** | `views/spatial3d` | Use a blueprint to customize a Spatial3DView | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/views/spatial3d.py) | | | | **[`Position3D`](https://rerun.io/docs/reference/types/components/position3d)** | `archetypes/mesh3d_partial_updates` | Log a simple colored triangle, then update its vertices' positions each frame | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/mesh3d_partial_updates.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/mesh3d_partial_updates.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/mesh3d_partial_updates.cpp) | +| **[`Position3D`](https://rerun.io/docs/reference/types/components/position3d)** | `archetypes/points3d_partial_updates` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.cpp) | +| **[`Position3D`](https://rerun.io/docs/reference/types/components/position3d)** | `archetypes/points3d_partial_updates_legacy` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp) | | **[`Position3D`](https://rerun.io/docs/reference/types/components/position3d)** | `archetypes/points3d_send_columns` | Use the `send_columns` API to send several point clouds over time in a single call | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_send_columns.py) | | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_send_columns.cpp) | | **[`Position3D`](https://rerun.io/docs/reference/types/components/position3d)** | `descriptors/descr_builtin_component` | | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/descriptors/descr_builtin_component.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/descriptors/descr_builtin_component.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/descriptors/descr_builtin_component.cpp) | | **[`Position3D`](https://rerun.io/docs/reference/types/components/position3d)** | `descriptors/descr_custom_archetype` | | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/descriptors/descr_custom_archetype.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/descriptors/descr_custom_archetype.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/descriptors/descr_custom_archetype.cpp) | @@ -226,6 +234,8 @@ _All snippets, organized by the [`Component`](https://rerun.io/docs/reference/ty | **[`Radius`](https://rerun.io/docs/reference/types/components/radius)** | `archetypes/line_strips2d_ui_radius` | Log lines with ui points & scene unit radii | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/line_strips2d_ui_radius.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/line_strips2d_ui_radius.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/line_strips2d_ui_radius.cpp) | | **[`Radius`](https://rerun.io/docs/reference/types/components/radius)** | `archetypes/geo_line_strings_simple` | Log a simple geospatial line string | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/geo_line_strings_simple.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/geo_line_strings_simple.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/geo_line_strings_simple.cpp) | | **[`Radius`](https://rerun.io/docs/reference/types/components/radius)** | `archetypes/geo_points_simple` | Log some very simple geospatial point | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/geo_points_simple.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/geo_points_simple.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/geo_points_simple.cpp) | +| **[`Radius`](https://rerun.io/docs/reference/types/components/radius)** | `archetypes/points3d_partial_updates` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.cpp) | +| **[`Radius`](https://rerun.io/docs/reference/types/components/radius)** | `archetypes/points3d_partial_updates_legacy` | Demonstrates usage of the new partial updates APIs | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp) | | **[`Radius`](https://rerun.io/docs/reference/types/components/radius)** | `concepts/different_data_per_timeline` | Log different data on different timelines | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/concepts/different_data_per_timeline.cpp) | | **[`Radius`](https://rerun.io/docs/reference/types/components/radius)** | `views/map` | Use a blueprint to customize a map view | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/views/map.py) | | | | **[`RotationAxisAngle`](https://rerun.io/docs/reference/types/components/rotation_axis_angle)** | `archetypes/capsules3d_batch` | Log a batch of capsules | [🐍](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/capsules3d_batch.py) | [🦀](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/capsules3d_batch.rs) | [🌊](https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/capsules3d_batch.cpp) | diff --git a/docs/snippets/all/archetypes/points3d_partial_updates.cpp b/docs/snippets/all/archetypes/points3d_partial_updates.cpp new file mode 100644 index 0000000000000..ca78984793102 --- /dev/null +++ b/docs/snippets/all/archetypes/points3d_partial_updates.cpp @@ -0,0 +1,58 @@ +//! Demonstrates usage of the new partial updates APIs. + +#include + +#include +#include + +int main() { + const auto rec = rerun::RecordingStream("rerun_example_points3d_partial_updates"); + rec.spawn().exit_on_failure(); + + std::vector positions; + for (int i = 0; i < 10; ++i) { + positions.emplace_back(static_cast(i), 0.0f, 0.0f); + } + + rec.set_time_sequence("frame", 0); + rec.log("points", rerun::Points3D(positions)); + + for (int i = 0; i < 10; ++i) { + std::vector colors; + for (int n = 0; n < 10; ++n) { + if (n < i) { + colors.emplace_back(rerun::Color(20, 200, 20)); + } else { + colors.emplace_back(rerun::Color(200, 20, 20)); + } + } + + std::vector radii; + for (int n = 0; n < 10; ++n) { + if (n < i) { + radii.emplace_back(rerun::Radius(0.6f)); + } else { + radii.emplace_back(rerun::Radius(0.2f)); + } + } + + rec.set_time_sequence("frame", i); + rec.log("points", colors, radii); + // TODO(cmc): implement new APIs and use them! + // rec.log("points", rerun::Points3D::update_fields().with_radii(radii).with_colors(colors)); + } + + // TODO(cmc): remove this! + // We cannot replicate the clear_fields() logic! + rec.set_time_sequence("frame", 20); + rec.log("points", rerun::Clear::FLAT); + + std::vector radii; + radii.emplace_back(rerun::Radius(0.3)); + + rec.set_time_sequence("frame", 20); + rec.log("points", positions, radii); + + // TODO(cmc): implement new APIs and use them! + // rec.log("points", rerun::Points3D::clear_fields().with_radii(radii).with_colors(colors)); +} diff --git a/docs/snippets/all/archetypes/points3d_partial_updates.py b/docs/snippets/all/archetypes/points3d_partial_updates.py new file mode 100644 index 0000000000000..065d64b71abdd --- /dev/null +++ b/docs/snippets/all/archetypes/points3d_partial_updates.py @@ -0,0 +1,30 @@ +"""Demonstrates usage of the new partial updates APIs.""" + +import rerun as rr + +rr.init("rerun_example_points3d_partial_updates", spawn=True) + +positions = [[i, 0, 0] for i in range(0, 10)] + +rr.set_time_sequence("frame", 0) +rr.log("points", rr.Points3D(positions)) + +for i in range(0, 10): + colors = [[20, 200, 20] if n < i else [200, 20, 20] for n in range(0, 10)] + radii = [0.6 if n < i else 0.2 for n in range(0, 10)] + + rr.set_time_sequence("frame", i) + rr.log("points", [rr.components.ColorBatch(colors), rr.components.RadiusBatch(radii)]) + # TODO(cmc): implement new APIs and use them! + # rr.log("points", rr.Points3D.update_fields(radii=radii, colors=colors)) + +# TODO(cmc): remove this! +# We cannot replicate the clear_fields() logic! +rr.set_time_sequence("frame", 20) +rr.log("points", rr.Clear(recursive=False)) + +rr.set_time_sequence("frame", 20) +rr.log("points", [rr.components.Position3DBatch(positions), rr.components.RadiusBatch(0.3)]) + +# TODO(cmc): implement new APIs and use them! +# rr.log("points", rr.Points3D.clear_fields().update_fields(positions=positions, radii=0.3)) diff --git a/docs/snippets/all/archetypes/points3d_partial_updates.rs b/docs/snippets/all/archetypes/points3d_partial_updates.rs new file mode 100644 index 0000000000000..725c19e4dbc8b --- /dev/null +++ b/docs/snippets/all/archetypes/points3d_partial_updates.rs @@ -0,0 +1,45 @@ +//! Demonstrates usage of the new partial updates APIs. + +use rand::{distributions::Uniform, Rng as _}; + +fn main() -> Result<(), Box> { + let mut rng = rand::thread_rng(); + let dist = Uniform::new(-5., 5.); + + let rec = + rerun::RecordingStreamBuilder::new("rerun_example_points3d_partial_updates").spawn()?; + + let positions = (0..10).map(|i| (i as f32, 0.0, 0.0)).collect::>(); + + rec.set_time_sequence("frame", 0); + rec.log("points", &rerun::Points3D::new(&positions))?; + + for i in 0..10 { + let colors = (0..10).map(|n| { + if n < i { + rerun::Color::from_rgb(20, 200, 20) + } else { + rerun::Color::from_rgb(200, 20, 20) + } + }); + let radii = (0..10).map(|n| if n < i { 0.6 } else { 0.2 }); + + rec.set_time_sequence("frame", i); + rec.log( + "points", + &rerun::Points3D::update_fields() + .with_radii(radii) + .with_colors(colors), + )?; + } + + rec.set_time_sequence("frame", 20); + rec.log( + "points", + &rerun::Points3D::clear_fields() + .with_positions(positions) + .with_radii([0.3]), + )?; + + Ok(()) +} diff --git a/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp b/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp new file mode 100644 index 0000000000000..9bb1ee0083b31 --- /dev/null +++ b/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp @@ -0,0 +1,52 @@ +// Demonstrates usage of the legacy partial updates APIs. + +#include + +#include +#include + +int main() { + const auto rec = rerun::RecordingStream("rerun_example_points3d_partial_updates_legacy"); + rec.spawn().exit_on_failure(); + + std::vector positions; + for (int i = 0; i < 10; ++i) { + positions.emplace_back(static_cast(i), 0.0f, 0.0f); + } + + rec.set_time_sequence("frame", 0); + rec.log("points", rerun::Points3D(positions)); + + for (int i = 0; i < 10; ++i) { + std::vector colors; + for (int n = 0; n < 10; ++n) { + if (n < i) { + colors.emplace_back(rerun::Color(20, 200, 20)); + } else { + colors.emplace_back(rerun::Color(200, 20, 20)); + } + } + + std::vector radii; + for (int n = 0; n < 10; ++n) { + if (n < i) { + radii.emplace_back(rerun::Radius(0.6f)); + } else { + radii.emplace_back(rerun::Radius(0.2f)); + } + } + + rec.set_time_sequence("frame", i); + rec.log("points", colors, radii); + } + + // We cannot replicate the clear_fields() logic! + rec.set_time_sequence("frame", 20); + rec.log("points", rerun::Clear::FLAT); + + std::vector radii; + radii.emplace_back(rerun::Radius(0.3)); + + rec.set_time_sequence("frame", 20); + rec.log("points", positions, radii); +} diff --git a/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py b/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py new file mode 100644 index 0000000000000..c95c2632ba091 --- /dev/null +++ b/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py @@ -0,0 +1,24 @@ +"""Demonstrates usage of the new partial updates APIs.""" + +import rerun as rr + +rr.init("rerun_example_points3d_partial_updates_legacy", spawn=True) + +positions = [[i, 0, 0] for i in range(0, 10)] + +rr.set_time_sequence("frame", 0) +rr.log("points", rr.Points3D(positions)) + +for i in range(0, 10): + colors = [[20, 200, 20] if n < i else [200, 20, 20] for n in range(0, 10)] + radii = [0.6 if n < i else 0.2 for n in range(0, 10)] + + rr.set_time_sequence("frame", i) + rr.log("points", [rr.components.ColorBatch(colors), rr.components.RadiusBatch(radii)]) + +# We cannot replicate the clear_fields() logic! +rr.set_time_sequence("frame", 20) +rr.log("points", rr.Clear(recursive=False)) + +rr.set_time_sequence("frame", 20) +rr.log("points", [rr.components.Position3DBatch(positions), rr.components.RadiusBatch(0.3)]) diff --git a/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs b/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs new file mode 100644 index 0000000000000..7375b829811f1 --- /dev/null +++ b/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs @@ -0,0 +1,54 @@ +//! Demonstrates usage of the legacy partial updates APIs. + +use rand::{distributions::Uniform, Rng as _}; + +fn main() -> Result<(), Box> { + let mut rng = rand::thread_rng(); + let dist = Uniform::new(-5., 5.); + + let rec = rerun::RecordingStreamBuilder::new("rerun_example_points3d_partial_updates_legacy") + .spawn()?; + + let positions = (0..10).map(|i| (i as f32, 0.0, 0.0)).collect::>(); + + rec.set_time_sequence("frame", 0); + rec.log("points", &rerun::Points3D::new(positions.clone()))?; + + for i in 0..10 { + let colors: Vec = (0..10) + .map(|n| { + if n < i { + rerun::Color::from_rgb(20, 200, 20) + } else { + rerun::Color::from_rgb(200, 20, 20) + } + }) + .collect(); + let radii: Vec = (0..10) + .map(|n| if n < i { 0.6 } else { 0.2 }) + .map(Into::into) + .collect(); + + rec.set_time_sequence("frame", i); + rec.log("points", &[&colors as &dyn rerun::ComponentBatch, &radii])?; + } + + // We cannot replicate the clear_fields() logic! + rec.set_time_sequence("frame", 20); + rec.log("points", &rerun::Clear::flat())?; + + rec.set_time_sequence("frame", 20); + let positions: Vec = (0..10) + .map(|i| (i as f32, 0.0, 0.0)) + .map(Into::into) + .collect(); + rec.log( + "points", + &[ + &positions as &dyn rerun::ComponentBatch, + &rerun::components::Radius(0.3.into()), + ], + )?; + + Ok(()) +} diff --git a/docs/snippets/snippets.toml b/docs/snippets/snippets.toml index d911b5f21f6c2..fd2cc9c2058ec 100644 --- a/docs/snippets/snippets.toml +++ b/docs/snippets/snippets.toml @@ -235,6 +235,10 @@ quick_start = [ # These examples don't have exactly the same implementation. "py", "rust", ] +"archetypes/points3d_partial_updates" = [ # TODO(cmc): not supported yet + "py", + "cpp", +] "archetypes/points3d_random" = [ # TODO(#3206): examples use different RNGs "cpp", "py",