Skip to content

Commit

Permalink
[C++] Rename rerun::ComponentBatch to rerun::Collection (and rela…
Browse files Browse the repository at this point in the history
…ted constructs) (#4236)

### What

Not much else has changed yet except some doc massaging. First step
towards solving

* #3794

`rerun::Collection` will evolve from here on and be the corner piece of
our zero copy & component adaptability strategy (just like
ComponentBatch is already!)


_This was originally opened on the wrong branch by accident:_
*  #4225

### 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 [demo.rerun.io](https://demo.rerun.io/pr/4225) (if
applicable)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4225)
- [Docs
preview](https://rerun.io/preview/3de46c8a5d294eb5ad68e5beb35a64d0610e992a/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/3de46c8a5d294eb5ad68e5beb35a64d0610e992a/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
  • Loading branch information
Wumpf authored Nov 15, 2023
1 parent c640da8 commit b3f0ff4
Show file tree
Hide file tree
Showing 74 changed files with 924 additions and 979 deletions.
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

0 comments on commit b3f0ff4

Please sign in to comment.