Skip to content

Commit

Permalink
Introduce eager serialization & update/clear APIs in the C++ SDK (#8727)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf authored Jan 21, 2025
1 parent e6e3b67 commit e7318f3
Show file tree
Hide file tree
Showing 139 changed files with 2,711 additions and 1,427 deletions.
305 changes: 230 additions & 75 deletions crates/build/re_types_builder/src/codegen/cpp/mod.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/build/re_types_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub const ATTR_RERUN_EXPERIMENTAL: &str = "attr.rerun.experimental";
pub const ATTR_PYTHON_ALIASES: &str = "attr.python.aliases";
pub const ATTR_PYTHON_ARRAY_ALIASES: &str = "attr.python.array_aliases";

pub const ATTR_CPP_ARCHETYPE_EAGER: &str = "attr.cpp.archetype_eager";
pub const ATTR_CPP_NO_FIELD_CTORS: &str = "attr.cpp.no_field_ctors";
pub const ATTR_CPP_RENAME_FIELD: &str = "attr.cpp.rename_field";

Expand Down
6 changes: 6 additions & 0 deletions crates/store/re_types/definitions/attributes/cpp.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ attribute "attr.cpp.no_field_ctors";
/// Changes the name of a field in the generated C++ code.
/// This can be used to avoid name clashes with C++ keywords or methods.
attribute "attr.cpp.rename_field";

/// The generated C++ object should be eagerly serialized, i.e. only comprised of Arrow arrays.
///
/// Applies only to archetypes. No-op otherwise.
// TODO(#7245): This should be always enabled.
attribute "attr.cpp.archetype_eager";
1 change: 1 addition & 0 deletions crates/store/re_types/definitions/attributes/rust.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ attribute "attr.rust.archetype_native";
/// The generated Rust object should be eagerly serialized, i.e. only comprised of Arrow arrays.
///
/// Applies only to archetypes. No-op otherwise.
// TODO(#7245): This should be always enabled.
attribute "attr.rust.archetype_eager";
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace rerun.archetypes;
/// \example archetypes/annotation_context_connections !api title="Connections" image="https://static.rerun.io/annotation_context_connections/4a8422bc154699c5334f574ff01b55c5cd1748e3/1200w.png"
table AnnotationContext (
// TODO(#7245): "attr.rust.archetype_eager",
"attr.cpp.archetype_eager",
"attr.rust.derive": "Eq, PartialEq",
"attr.docs.view_types": "Spatial2DView, Spatial3DView"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace rerun.archetypes;
/// \example archetypes/arrows2d_simple title="Simple batch of 2D arrows" image="https://static.rerun.io/arrow2d_simple/59f044ccc03f7bc66ee802288f75706618b29a6e/1200w.png"
table Arrows2D (
"attr.rust.archetype_eager",
"attr.cpp.archetype_eager",
"attr.rust.derive": "PartialEq",
"attr.rust.new_pub_crate",
"attr.cpp.no_field_ctors",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace rerun.archetypes;
/// \example archetypes/arrows3d_simple title="Simple batch of 3D arrows" image="https://static.rerun.io/arrow3d_simple/55e2f794a520bbf7527d7b828b0264732146c5d0/1200w.png"
table Arrows3D (
"attr.rust.archetype_eager",
"attr.cpp.archetype_eager",
"attr.rust.derive": "PartialEq",
"attr.rust.new_pub_crate",
"attr.cpp.no_field_ctors",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace rerun.archetypes;
/// \example archetypes/points3d_ui_radius title="Log points with radii given in UI points" image="https://static.rerun.io/point3d_ui_radius/e051a65b4317438bcaea8d0eee016ac9460b5336/1200w.png"
/// \example archetypes/points3d_send_columns title="Send several point clouds with varying point count over time in a single call" image="https://static.rerun.io/points3d_send_columns/633b524a2ee439b0e3afc3f894f4927ce938a3ec/1200w.png" missing="rs"
table Points3D (
"attr.rust.archetype_eager": "",
"attr.rust.archetype_eager",
"attr.cpp.archetype_eager",
"attr.rust.derive": "PartialEq",
"attr.docs.category": "Spatial 3D",
"attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace rerun.archetypes;
/// \example archetypes/transform3d_hierarchy title="Transform hierarchy" image="https://static.rerun.io/transform_hierarchy/cb7be7a5a31fcb2efc02ba38e434849248f87554/1200w.png"
table Transform3D (
"attr.rust.archetype_eager",
"attr.cpp.archetype_eager",
"attr.docs.category": "Spatial 3D",
"attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection",
"attr.rerun.log_missing_as_empty", // See https://github.com/rerun-io/rerun/issues/6909
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ namespace rerun.blueprint.archetypes;

/// Configuration for the background of a view.
table Background (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.python.aliases": "datatypes.Rgba32Like, blueprint_components.BackgroundKindLike",
"attr.rerun.scope": "blueprint",
"attr.rust.archetype_eager"
"attr.rerun.scope": "blueprint"
) {
// --- Required ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace rerun.blueprint.archetypes;
/// The description of a container.
table ContainerBlueprint (
"attr.rerun.scope": "blueprint",
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rust.archetype_native"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace rerun.blueprint.archetypes;

/// The query for the dataframe view.
table DataframeQuery (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Tries to move the center of mass of the graph to the origin.
struct ForceCenter (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Resolves collisions between the bounding circles, according to the radius of the nodes.
struct ForceCollisionRadius (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Aims to achieve a target distance between two nodes that are connected by an edge.
struct ForceLink (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace rerun.blueprint.archetypes;
///
/// If `strength` is smaller than 0, it pushes nodes apart, if it is larger than 0 it pulls them together.
struct ForceManyBody (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Similar to gravity, this force pulls nodes towards a specific position.
struct ForcePosition (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Configuration for the 3D line grid.
table LineGrid3D (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace rerun.blueprint.archetypes;

/// Configuration for the background map of the map view.
table MapBackground (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.python.aliases": "blueprint_components.MapProviderLike"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace rerun.blueprint.archetypes;
/// Configuration of the map view zoom level.
//TODO(ab): Turn this archetype into `MapArea` and include a `center: LatLon` componnent or similar
table MapZoom (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.python.aliases": "datatypes.Float64Like"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Controls the distance to the near clip plane in 3D scene units.
table NearClipPlane (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace rerun.blueprint.archetypes;

/// Shared state for the 3 collapsible panels.
table PanelBlueprint (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace rerun.blueprint.archetypes;

/// Configuration for the legend of a plot.
table PlotLegend (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace rerun.blueprint.archetypes;

/// Configuration for the scalar axis of a plot.
table ScalarAxis (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Configures how tensor scalars are mapped to color.
table TensorScalarMapping (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Specifies a 2D slice of a tensor.
table TensorSliceSelection (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace rerun.blueprint.archetypes;

/// Configures how a selected tensor slice is shown on screen.
table TensorViewFit (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace rerun.blueprint.archetypes;

/// The description of a single view.
table ViewBlueprint (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace rerun.blueprint.archetypes;
/// The last rule matching `/world` is `- /world`, so it is excluded.
/// The last rule matching `/world/house` is `+ /world/**`, so it is included.
table ViewContents (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace rerun.blueprint.archetypes;

/// The top-level description of the viewport.
table ViewportBlueprint (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace rerun.blueprint.archetypes;
/// - For time series views, the default is to show the entire timeline.
/// - For any other view, the default is to apply latest-at semantics.
table VisibleTimeRanges (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace rerun.blueprint.archetypes;
/// If no visual bounds are set, it will be determined automatically,
/// based on the bounding-box of the data or other camera information present in the view.
table VisualBounds2D (
"attr.cpp.archetype_eager",
"attr.rust.archetype_eager",
"attr.rerun.scope": "blueprint"
) {
Expand Down
18 changes: 2 additions & 16 deletions docs/snippets/all/archetypes/points3d_partial_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,12 @@ int main() {
}

rec.set_time_sequence("frame", i);
rec.log("points", rerun::Points3D::IndicatorComponent(), colors, radii);
// TODO(cmc): implement new APIs and use them!
// rec.log("points", rerun::Points3D::update_fields().with_radii(radii).with_colors(colors));
rec.log("points", rerun::Points3D::update_fields().with_radii(radii).with_colors(colors));
}

std::vector<rerun::Radius> radii;
radii.emplace_back(0.3f);

rec.set_time_sequence("frame", 20);
rec.log(
"points",
rerun::Points3D::IndicatorComponent(),
positions,
radii,
std::vector<rerun::components::Color>(),
std::vector<rerun::components::Text>(),
std::vector<rerun::components::ShowLabels>(),
std::vector<rerun::components::ClassId>(),
std::vector<rerun::components::KeypointId>()
);
// TODO(cmc): implement new APIs and use them!
// rec.log("points", rerun::Points3D::clear_fields().with_radii(radii).with_colors(colors));
rec.log("points", rerun::Points3D::clear_fields().with_positions(positions).with_radii(radii));
}
17 changes: 8 additions & 9 deletions docs/snippets/all/archetypes/transform3d_partial_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

float truncated_radians(int deg) {
auto degf = static_cast<float>(deg);
const auto pi = 3.14159265358979323846;
const auto pi = 3.14159265358979323846f;
return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f;
}

Expand All @@ -22,36 +22,35 @@ int main() {
// Update only the rotation of the box.
for (int deg = 0; deg <= 45; deg++) {
auto rad = truncated_radians(deg * 4);
// TODO(#8583): update_fields
rec.log(
"box",
rerun::Transform3D().with_rotation_axis_angle(
rerun::Transform3D::update_fields().with_rotation_axis_angle(
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
)
);
}

// Update only the position of the box.
for (int t = 0; t <= 45; t++) {
for (int t = 0; t <= 50; t++) {
rec.log(
"box",
rerun::Transform3D().with_translation({0.0f, 0.0f, static_cast<float>(t) / 10.0f})
rerun::Transform3D::update_fields().with_translation(
{0.0f, 0.0f, static_cast<float>(t) / 10.0f}
)
);
}

// Update only the rotation of the box.
for (int deg = 0; deg <= 45; deg++) {
auto rad = truncated_radians((deg + 45) * 4);
// TODO(#8583): update_fields
rec.log(
"box",
rerun::Transform3D().with_rotation_axis_angle(
rerun::Transform3D::update_fields().with_rotation_axis_angle(
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
)
);
}

// Clear all of the box's attributes, and reset its axis length.
// TODO(#8583): clear_fields
rec.log("box", rerun::Transform3D().with_axis_length(15.0));
rec.log("box", rerun::Transform3D::clear_fields().with_axis_length(15.0));
}
16 changes: 3 additions & 13 deletions docs/snippets/snippets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@

# These archetypes will ignore the associated snippets in the snippet index.
[snippets_ref.archetypes.opt_out]
"DataframeQuery" = [
"reference/dataframe_save_blueprint"
]
"DataframeQuery" = ["reference/dataframe_save_blueprint"]

# These components will ignore the associated snippets in the snippet index.
[snippets_ref.components.opt_out]
"ShowLabels" = [
"tutorials/data_out",
]
"ShowLabels" = ["tutorials/data_out"]

# These arbitrary feature names will be indexed exactly as written down.
# Add anything you can think about!
[snippets_ref.features]
"Dataframes" = [
"reference/dataframe_query",
"reference/dataframe_view_query",
]
"Dataframes" = ["reference/dataframe_query", "reference/dataframe_view_query"]
"`AnyValue`" = [
"tutorials/any_values",
"tutorials/extra_values",
Expand Down Expand Up @@ -271,9 +264,6 @@ quick_start = [ # These examples don't have exactly the same implementation.
"archetypes/transform3d_hierarchy" = [ # Uses a lot of trigonometry which is surprisingly easy to get the same on Rust & C++, but not on Python/Numpy
"py",
]
"archetypes/transform3d_partial_updates" = [
"cpp", # TODO(#8583): remove once C++ partial updates APIs have shipped
]
"archetypes/instance_poses3d_combined" = [ # TODO(#3235): Slight floating point differences in point grid.
"cpp",
"py",
Expand Down
Loading

0 comments on commit e7318f3

Please sign in to comment.