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

[C++] Rename rerun::ComponentBatch to rerun::Collection (and related constructs) #4236

Merged
merged 2 commits into from
Nov 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions crates/re_types_builder/src/codegen/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl QuotedObject {
let quoted_docs = quote_obj_docs(obj);

let mut cpp_includes = Includes::new(obj.fqname.clone());
cpp_includes.insert_rerun("component_batch_adapter_builtins.hpp");
cpp_includes.insert_rerun("collection_adapter_builtins.hpp");
hpp_includes.insert_system("utility"); // std::move
hpp_includes.insert_rerun("indicator_component.hpp");

Expand Down Expand Up @@ -1342,15 +1342,15 @@ fn component_to_data_cell_method(type_ident: &Ident, hpp_includes: &mut Includes

fn archetype_serialize(type_ident: &Ident, obj: &Object, hpp_includes: &mut Includes) -> Method {
hpp_includes.insert_rerun("data_cell.hpp");
hpp_includes.insert_rerun("component_batch.hpp");
hpp_includes.insert_rerun("collection.hpp");
hpp_includes.insert_system("vector"); // std::vector

let num_fields = quote_integer(obj.fields.len());
let push_batches = obj.fields.iter().map(|field| {
let field_name = format_ident!("{}", field.name);
let field_accessor = quote!(archetype.#field_name);

// TODO(andreas): Introducing MonoComponentBatch will remove the need for this.
// TODO(andreas): Introducing MonoCollection will remove the need for this.
let wrapping_type = if field.typ.is_plural() {
quote!()
} else {
Expand All @@ -1361,7 +1361,7 @@ fn archetype_serialize(type_ident: &Ident, obj: &Object, hpp_includes: &mut Incl
.fqname()
.expect("Archetypes only have components and vectors of components."),
);
quote!(ComponentBatch<#field_type>)
quote!(Collection<#field_type>)
};

if field.is_nullable {
Expand Down Expand Up @@ -1399,7 +1399,7 @@ fn archetype_serialize(type_ident: &Ident, obj: &Object, hpp_includes: &mut Incl
#NEWLINE_TOKEN
#(#push_batches)*
{
auto result = ComponentBatch<#type_ident::IndicatorComponent>(#type_ident::IndicatorComponent()).serialize();
auto result = Collection<#type_ident::IndicatorComponent>(#type_ident::IndicatorComponent()).serialize();
RR_RETURN_NOT_OK(result.error);
cells.emplace_back(std::move(result.value));
}
Expand Down Expand Up @@ -1924,13 +1924,13 @@ fn are_types_disjoint(fields: &[ObjectField]) -> bool {
fn quote_archetype_field_type(hpp_includes: &mut Includes, obj_field: &ObjectField) -> TokenStream {
match &obj_field.typ {
Type::Vector { elem_type } => {
hpp_includes.insert_rerun("component_batch.hpp");
hpp_includes.insert_rerun("collection.hpp");
let elem_type = quote_element_type(hpp_includes, elem_type);
quote! { ComponentBatch<#elem_type> }
quote! { Collection<#elem_type> }
}
// TODO(andreas): This should emit `MonoComponentBatch` which will be a constrained version of `ComponentBatch`.
// (simply adapting `MonoComponentBatch` breaks some existing code, so this not entirely trivial to do.
// Designing constraints for `MonoComponentBatch` is harder still)
// TODO(andreas): This should emit `MonoCollection` which will be a constrained version of `Collection`.
// (simply adapting `MonoCollection` breaks some existing code, so this not entirely trivial to do.
// Designing constraints for `MonoCollection` is harder still)
Type::Object(fqname) => quote_fqname_as_type_path(hpp_includes, fqname),
_ => panic!("Only vectors and objects are allowed in archetypes."),
}
Expand Down
4 changes: 1 addition & 3 deletions docs/code-examples/asset3d_out_of_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ int main(int argc, char** argv) {
rerun::TranslationRotationScale3D({0.0, 0.0, static_cast<float>(i) - 10.0f});
rec.log(
"world/asset",
rerun::ComponentBatch<rerun::OutOfTreeTransform3D>(
rerun::OutOfTreeTransform3D(translation)
)
rerun::Collection<rerun::OutOfTreeTransform3D>(rerun::OutOfTreeTransform3D(translation))
);
}
}
16 changes: 8 additions & 8 deletions examples/cpp/custom_component_adapter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ struct MyVec3 {
float x, y, z;
};

/// Adapts `MyContainer<MyVec3>` to a `ComponentBatch<Position3D>`.
/// Adapts `MyContainer<MyVec3>` to a `Collection<Position3D>`.
///
/// With this in place, `ComponentBatch<Position3D>` can be constructed from a `MyContainer<MyVec3>`!
/// With this in place, `Collection<Position3D>` can be constructed from a `MyContainer<MyVec3>`!
template <>
struct rerun::ComponentBatchAdapter<rerun::Position3D, MyContainer<MyVec3>> {
// Creating a ComponentBatch from a non-temporary is done by casting & borrowing binary compatible data.
ComponentBatch<rerun::Position3D> operator()(const MyContainer<MyVec3>& container) {
return ComponentBatch<rerun::Position3D>::borrow(container.data, container.size);
struct rerun::CollectionAdapter<rerun::Position3D, MyContainer<MyVec3>> {
// Creating a Collection from a non-temporary is done by casting & borrowing binary compatible data.
Collection<rerun::Position3D> operator()(const MyContainer<MyVec3>& container) {
return Collection<rerun::Position3D>::borrow(container.data, container.size);
}

// For temporaries we have to do a copy since the pointer doesn't live long enough.
// If you don't implement this, the other overload may be used for temporaries and cause
// undefined behavior.
ComponentBatch<rerun::Position3D> operator()(MyContainer<MyVec3>&& container) {
Collection<rerun::Position3D> operator()(MyContainer<MyVec3>&& container) {
std::vector<rerun::Position3D> components(container.size);
for (size_t i = 0; i < container.size; ++i) {
components[i] =
rerun::Position3D(container.data[i].x, container.data[i].y, container.data[i].z);
}
return ComponentBatch<rerun::Position3D>::take_ownership(std::move(components));
return Collection<rerun::Position3D>::take_ownership(std::move(components));
}
};

Expand Down
6 changes: 3 additions & 3 deletions rerun_cpp/src/rerun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "rerun/datatypes.hpp"

// Rerun API.
#include "rerun/component_batch.hpp"
#include "rerun/component_batch_adapter.hpp"
#include "rerun/component_batch_adapter_builtins.hpp"
#include "rerun/collection.hpp"
#include "rerun/collection_adapter.hpp"
#include "rerun/collection_adapter_builtins.hpp"
#include "rerun/config.hpp"
#include "rerun/error.hpp"
#include "rerun/recording_stream.hpp"
Expand Down
6 changes: 3 additions & 3 deletions rerun_cpp/src/rerun/archetypes/annotation_context.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/archetypes/annotation_context.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions rerun_cpp/src/rerun/archetypes/arrows3d.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 15 additions & 16 deletions rerun_cpp/src/rerun/archetypes/arrows3d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/archetypes/arrows3d_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace rerun {

/// Creates new 3D arrows pointing in the given directions, with a base at the origin (0, 0,
/// 0).
static Arrows3D from_vectors(ComponentBatch<components::Vector3D> vectors_) {
static Arrows3D from_vectors(Collection<components::Vector3D> vectors_) {
Arrows3D arrows;
arrows.vectors = std::move(vectors_);
return arrows;
Expand Down
14 changes: 7 additions & 7 deletions rerun_cpp/src/rerun/archetypes/asset3d.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/archetypes/asset3d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions rerun_cpp/src/rerun/archetypes/bar_chart.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/archetypes/bar_chart.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading