diff --git a/crates/re_types/source_hash.txt b/crates/re_types/source_hash.txt index c680b670a13..90f1e7b8f6e 100644 --- a/crates/re_types/source_hash.txt +++ b/crates/re_types/source_hash.txt @@ -1,4 +1,4 @@ # This is a sha256 hash for all direct and indirect dependencies of this crate's build script. # It can be safely removed at anytime to force the build script to run again. # Check out build.rs to see how it's computed. -d824555b3e123065a3064a4f01e963f74f0f5d62a3dd96dfdffaa57c8033ca08 +193f517cba0adad129dff54dc9a19e0c6519c9c852cac586b7634447831e4819 diff --git a/crates/re_types_builder/src/codegen/cpp/mod.rs b/crates/re_types_builder/src/codegen/cpp/mod.rs index 27f922ac3f9..935096e204a 100644 --- a/crates/re_types_builder/src/codegen/cpp/mod.rs +++ b/crates/re_types_builder/src/codegen/cpp/mod.rs @@ -208,12 +208,12 @@ impl QuotedObject { fn from_struct( arrow_registry: &ArrowRegistry, - _objects: &Objects, + objects: &Objects, obj: &Object, ) -> QuotedObject { let namespace_ident = format_ident!("{}", obj.kind.plural_snake_case()); // `datatypes`, `components`, or `archetypes` - let pascal_case_name = &obj.name; - let pascal_case_ident = format_ident!("{pascal_case_name}"); // The PascalCase name of the object type. + let type_name = &obj.name; + let type_ident = format_ident!("{type_name}"); // The PascalCase name of the object type. let quoted_docs = quote_docstrings(&obj.docs); let mut hpp_includes = Includes::default(); @@ -230,7 +230,7 @@ impl QuotedObject { .fields .iter() .map(|obj_field| { - let declaration = quote_declaration_with_docstring( + let declaration = quote_variable_with_docstring( &mut hpp_includes, obj_field, &format_ident!("{}", obj_field.name), @@ -242,55 +242,150 @@ impl QuotedObject { }) .collect_vec(); + let (constants_hpp, constants_cpp) = + quote_constants_header_and_cpp(obj, objects, &type_ident); let mut methods = Vec::new(); - if obj.fields.len() == 1 { - // Single-field struct - it is a newtype wrapper. - // Create a implicit constructor from its own field-type. - let obj_field = &obj.fields[0]; - if let Type::Array { .. } = &obj_field.typ { - // TODO(emilk): implicit constructor for arrays - } else { - hpp_includes.system.insert("utility".to_owned()); // std::move - - let field_ident = format_ident!("{}", obj_field.name); - let parameter_declaration = - quote_declaration(&mut hpp_includes, obj_field, &field_ident); - - methods.push(Method { - declaration: MethodDeclaration::constructor(quote! { - #pascal_case_ident(#parameter_declaration) : #field_ident(std::move(#field_ident)) - }), - ..Method::default() - }); - } - }; - let datatype = arrow_registry.get(&obj.fqname); match obj.kind { ObjectKind::Datatype | ObjectKind::Component => { + if obj.fields.len() == 1 { + // Single-field struct - it is a newtype wrapper. + // Create a implicit constructor from its own field-type - do so by copy, and if meaningful by rvalue reference. + let obj_field = &obj.fields[0]; + if let Type::Array { .. } = &obj_field.typ { + // TODO(emilk): implicit constructor for arrays + } else { + // Pass by value: + // If it was a temporary it gets moved into the value and then moved again into the field. + // If it was a lvalue it gets copied into the value and then moved into the field. + let field_ident = format_ident!("{}", obj_field.name); + let parameter_declaration = + quote_variable(&mut hpp_includes, obj_field, &field_ident); + hpp_includes.system.insert("utility".to_owned()); // std::move + methods.push(Method { + declaration: MethodDeclaration::constructor(quote! { + #type_ident(#parameter_declaration) : #field_ident(std::move(#field_ident)) + }), + ..Method::default() + }); + } + }; + + // Arrow serialization methods. + // TODO(andreas): These are just utilities for to_data_cell. How do we hide them best from the public header? methods.push(arrow_data_type_method(&datatype, &mut cpp_includes)); methods.push(new_arrow_array_builder_method(&datatype, &mut cpp_includes)); methods.push(fill_arrow_array_builder_method( &datatype, obj, - &pascal_case_ident, + &type_ident, &mut cpp_includes, )); + + if obj.kind == ObjectKind::Component { + methods.push(component_to_data_cell_method( + &type_ident, + &mut hpp_includes, + &mut cpp_includes, + )); + } } ObjectKind::Archetype => { - // TODO(andreas): Should also be convertible to arrow? + hpp_includes.system.insert("utility".to_owned()); // std::move + + let required_component_fields = obj + .fields + .iter() + .filter(|field| !field.is_nullable) + .collect_vec(); + + // Constructor with all required components. + { + let (arguments, assignments): (Vec<_>, Vec<_>) = required_component_fields + .iter() + .map(|obj_field| { + let field_ident = format_ident!("{}", obj_field.name); + ( + quote_variable(&mut hpp_includes, obj_field, &field_ident), + quote! { #field_ident(std::move(#field_ident)) }, + ) + }) + .unzip(); + + methods.push(Method { + declaration: MethodDeclaration::constructor(quote! { + #type_ident(#(#arguments),*) : #(#assignments),* + }), + ..Method::default() + }); + } + // Builder methods for all optional components. + for obj_field in obj.fields.iter().filter(|field| field.is_nullable) { + let field_ident = format_ident!("{}", obj_field.name); + let method_ident = format_ident!("with_{}", obj_field.name); + let non_nullable = ObjectField { + is_nullable: false, + ..obj_field.clone() + }; + let parameter_declaration = + quote_variable(&mut hpp_includes, &non_nullable, &field_ident); + methods.push(Method { + docs: obj_field.docs.clone().into(), + declaration: MethodDeclaration { + is_static: false, + return_type: quote!(#type_ident&), + name_and_parameters: quote! { + #method_ident(#parameter_declaration) + }, + }, + definition_body: quote! { + this->#field_ident = std::move(#field_ident); + return *this; + }, + inline: true, + }); + } + + // Num instances gives the number of primary instances. + { + let first_required_field = required_component_fields.first().unwrap(); + let first_required_field_name = &format_ident!("{}", first_required_field.name); + let definition_body = if first_required_field.typ.is_plural() { + quote!(return #first_required_field_name.size();) + } else { + quote!(return 1;) + }; + methods.push(Method { + docs: "Returns the number of primary instances of this archetype.".into(), + declaration: MethodDeclaration { + is_static: false, + return_type: quote!(size_t), + name_and_parameters: quote! { + num_instances() const + }, + }, + definition_body, + inline: true, + }); + } + + methods.push(archetype_to_data_cells( + obj, + &mut hpp_includes, + &mut cpp_includes, + )); } }; let hpp_method_section = if methods.is_empty() { quote! {} } else { - let hpp_methods = methods.iter().map(|m| m.to_hpp_tokens()); + let methods_hpp = methods.iter().map(|m| m.to_hpp_tokens()); quote! { public: - #(#hpp_methods)* + #(#methods_hpp)* } }; let hpp = quote! { @@ -301,21 +396,26 @@ impl QuotedObject { namespace rr { namespace #namespace_ident { #quoted_docs - struct #pascal_case_ident { + struct #type_ident { #(#field_declarations;)* + + #(#constants_hpp;)* + #hpp_method_section }; } } }; - let cpp_methods = methods.iter().map(|m| m.to_cpp_tokens(&pascal_case_ident)); + let methods_cpp = methods.iter().map(|m| m.to_cpp_tokens(&type_ident)); let cpp = quote! { #cpp_includes namespace rr { namespace #namespace_ident { - #(#cpp_methods)* + #(#constants_cpp;)* + + #(#methods_cpp)* } } }; @@ -343,7 +443,12 @@ impl QuotedObject { // Rotation3DData _data; // }; - let namespace_ident = format_ident!("{}", obj.kind.plural_snake_case()); // `datatypes`, `components`, or `archetypes` + assert!( + obj.kind != ObjectKind::Archetype, + "Union archetypes are not supported {}", + obj.fqname + ); + let namespace_ident = format_ident!("{}", obj.kind.plural_snake_case()); // `datatypes` or `components` let pascal_case_name = &obj.name; let pascal_case_ident = format_ident!("{pascal_case_name}"); // The PascalCase name of the object type. let quoted_docs = quote_docstrings(&obj.docs); @@ -387,7 +492,7 @@ impl QuotedObject { .fields .iter() .map(|obj_field| { - let declaration = quote_declaration_with_docstring( + let declaration = quote_variable_with_docstring( &mut hpp_includes, obj_field, &format_ident!("{}", crate::to_snake_case(&obj_field.name)), @@ -399,6 +504,8 @@ impl QuotedObject { }) .collect_vec(); + let (constants_hpp, constants_cpp) = + quote_constants_header_and_cpp(obj, objects, &pascal_case_ident); let mut methods = Vec::new(); // Add one static constructor for every field. @@ -417,7 +524,7 @@ impl QuotedObject { for obj_field in &obj.fields { let snake_case_ident = format_ident!("{}", crate::to_snake_case(&obj_field.name)); let param_declaration = - quote_declaration(&mut hpp_includes, obj_field, &snake_case_ident); + quote_variable(&mut hpp_includes, obj_field, &snake_case_ident); methods.push(Method { docs: obj_field.docs.clone().into(), @@ -478,11 +585,8 @@ impl QuotedObject { } } } else { - let typedef_declaration = quote_declaration( - &mut hpp_includes, - obj_field, - &format_ident!("TypeAlias"), - ); + let typedef_declaration = + quote_variable(&mut hpp_includes, obj_field, &format_ident!("TypeAlias")); hpp_includes.system.insert("utility".to_owned()); // std::move quote! { case detail::#tag_typename::#tag_ident: { @@ -504,9 +608,46 @@ impl QuotedObject { } }; + let copy_constructor = { + let copy_match_arms = obj + .fields + .iter() + .filter_map(|obj_field| { + // Inferring from trivial destructability that we don't need to call the copy constructor is a little bit wonky, + // but is typically the reason why we need to do this in the first place - if we'd always memcpy we'd get double-free errors. + // (As with swap, we generously assume that objects are rellocatable) + (!obj_field.typ.has_default_destructor(objects)).then(|| { + let tag_ident = format_ident!("{}", obj_field.name); + let field_ident = + format_ident!("{}", crate::to_snake_case(&obj_field.name)); + Some(quote! { + case detail::#tag_typename::#tag_ident: { + _data.#field_ident = other._data.#field_ident; + break; + } + }) + }) + }) + .collect_vec(); + if copy_match_arms.is_empty() { + quote!(#pascal_case_ident(const #pascal_case_ident& other) : _tag(other._tag) { + memcpy(&this->_data, &other._data, sizeof(detail::#data_typename)); + }) + } else { + quote!(#pascal_case_ident(const #pascal_case_ident& other) : _tag(other._tag) { + switch (other._tag) { + #(#copy_match_arms)* + default: + memcpy(&this->_data, &other._data, sizeof(detail::#data_typename)); + break; + } + }) + } + }; + let swap_comment = quote_comment("This bitwise swap would fail for self-referential types, but we don't have any of those."); - let hpp_methods = methods.iter().map(|m| m.to_hpp_tokens()); + let methods_hpp = methods.iter().map(|m| m.to_hpp_tokens()); let hpp = quote! { #hpp_includes @@ -525,6 +666,8 @@ impl QuotedObject { #data_typename() { } // Required by static constructors ~#data_typename() { } + // Note that this type is *not* copyable unless all enum fields are trivially destructable. + void swap(#data_typename& other) noexcept { #NEWLINE_TOKEN #swap_comment @@ -539,14 +682,17 @@ impl QuotedObject { #quoted_docs struct #pascal_case_ident { - private: - detail::#tag_typename _tag; - detail::#data_typename _data; + #(#constants_hpp;)* - // Empty state required by static constructors: - #pascal_case_ident() : _tag(detail::#tag_typename::NONE) {} + #copy_constructor + + // Copy-assignment + #pascal_case_ident& operator=(const #pascal_case_ident& other) noexcept { + #pascal_case_ident tmp(other); + this->swap(tmp); + return *this; + } - public: // Move-constructor: #pascal_case_ident(#pascal_case_ident&& other) noexcept : _tag(detail::#tag_typename::NONE) { this->swap(other); @@ -560,9 +706,7 @@ impl QuotedObject { #destructor - #(#hpp_methods)* - - // This is useful for easily implementing the move constructor and move assignment operator: + // This is useful for easily implementing the move constructor and assignment operators: void swap(#pascal_case_ident& other) noexcept { // Swap tags: auto tag_temp = this->_tag; @@ -572,6 +716,16 @@ impl QuotedObject { // Swap data: this->_data.swap(other._data); } + + #(#methods_hpp)* + + private: + detail::#tag_typename _tag; + detail::#data_typename _data; + + // Empty state required by static constructors: + #pascal_case_ident() : _tag(detail::#tag_typename::NONE) {} + public: }; } } @@ -581,6 +735,8 @@ impl QuotedObject { let cpp = quote! { #cpp_includes + #(#constants_cpp;)* + namespace rr { namespace #namespace_ident { #(#cpp_methods)* @@ -601,15 +757,20 @@ fn arrow_data_type_method(datatype: &DataType, cpp_includes: &mut Includes) -> M docs: "Returns the arrow data type this type corresponds to.".into(), declaration: MethodDeclaration { is_static: true, - return_type: quote! { std::shared_ptr }, + return_type: quote! { const std::shared_ptr& }, name_and_parameters: quote! { to_arrow_datatype() }, }, - definition_body: quote! { return #quoted_datatype; }, + definition_body: quote! { + static const auto datatype = #quoted_datatype; + return datatype; + }, inline: false, } } fn new_arrow_array_builder_method(datatype: &DataType, cpp_includes: &mut Includes) -> Method { + cpp_includes.system.insert("arrow/api.h".to_owned()); + let arrow_builder_type = arrow_array_builder_type(datatype); let arrow_builder_type = format_ident!("{arrow_builder_type}"); let builder_instantiation = @@ -640,6 +801,8 @@ fn fill_arrow_array_builder_method( pascal_case_ident: &Ident, cpp_includes: &mut Includes, ) -> Method { + cpp_includes.system.insert("arrow/api.h".to_owned()); + let DataType::Extension(_fqname, logical_datatype, _metadata) = datatype else { panic!("Can only generate arrow serialization code for extension types. {}", obj.fqname); }; @@ -686,6 +849,133 @@ fn fill_arrow_array_builder_method( } } +fn component_to_data_cell_method( + type_ident: &Ident, + hpp_includes: &mut Includes, + cpp_includes: &mut Includes, +) -> Method { + hpp_includes.local.insert("../data_cell.hpp".to_owned()); + cpp_includes.local.insert("../rerun.hpp".to_owned()); // ipc_from_table + cpp_includes.system.insert("arrow/api.h".to_owned()); + + let todo_pool = quote_comment("TODO(andreas): Allow configuring the memory pool."); + + Method { + docs: format!("Creates a Rerun DataCell from an array of {type_ident} components.").into(), + declaration: MethodDeclaration { + is_static: true, + return_type: quote! { arrow::Result }, + name_and_parameters: quote! { + to_data_cell(const #type_ident* instances, size_t num_instances) + }, + }, + definition_body: quote! { + #NEWLINE_TOKEN + #todo_pool + arrow::MemoryPool* pool = arrow::default_memory_pool(); + #NEWLINE_TOKEN + #NEWLINE_TOKEN + ARROW_ASSIGN_OR_RAISE(auto builder, #type_ident::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK(#type_ident::fill_arrow_array_builder( + builder.get(), + instances, + num_instances + )); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + #NEWLINE_TOKEN + #NEWLINE_TOKEN + auto schema = arrow::schema({arrow::field( + #type_ident::NAME, // Unused, but should be the name of the field in the archetype if any. + #type_ident::to_arrow_datatype(), + false + )}); + #NEWLINE_TOKEN + #NEWLINE_TOKEN + rr::DataCell cell; + cell.component_name = #type_ident::NAME; + ARROW_ASSIGN_OR_RAISE(cell.buffer, rr::ipc_from_table(*arrow::Table::Make(schema, {array}))); + #NEWLINE_TOKEN + #NEWLINE_TOKEN + return cell; + }, + inline: false, + } +} + +fn archetype_to_data_cells( + obj: &Object, + hpp_includes: &mut Includes, + cpp_includes: &mut Includes, +) -> Method { + hpp_includes.local.insert("../data_cell.hpp".to_owned()); + cpp_includes.system.insert("arrow/api.h".to_owned()); + + // TODO(andreas): Splats need to be handled separately. + + let num_fields = quote_integer(obj.fields.len()); + let push_cells = obj.fields.iter().map(|field| { + let field_type_fqname = match &field.typ { + Type::Vector { elem_type } => elem_type.fqname().unwrap(), + Type::Object(fqname) => fqname, + _ => unreachable!( + "Archetypes are not expected to have any fields other than objects and vectors" + ), + }; + let field_type = quote_fqname_as_type_path(cpp_includes, field_type_fqname); + let field_name = format_ident!("{}", field.name); + + if field.is_nullable { + let to_data_cell = if field.typ.is_plural() { + quote!(#field_type::to_data_cell(value.data(), value.size())) + } else { + quote!(#field_type::to_data_cell(&value, 1)) + }; + quote! { + if (#field_name.has_value()) { + const auto& value = #field_name.value(); + ARROW_ASSIGN_OR_RAISE(const auto cell, #to_data_cell); + cells.push_back(cell); + } + } + } else { + let to_data_cell = if field.typ.is_plural() { + quote!(#field_type::to_data_cell(#field_name.data(), #field_name.size())) + } else { + quote!(#field_type::to_data_cell(&#field_name, 1)) + }; + quote! { + { + ARROW_ASSIGN_OR_RAISE(const auto cell, #to_data_cell); + cells.push_back(cell); + } + } + } + }); + + Method { + docs: "Creates a list of Rerun DataCell from this archetype.".into(), + declaration: MethodDeclaration { + is_static: false, + return_type: quote!(arrow::Result>), + name_and_parameters: quote!(to_data_cells() const), + }, + definition_body: quote! { + std::vector cells; + cells.reserve(#num_fields); + #NEWLINE_TOKEN + #NEWLINE_TOKEN + #(#push_cells)* + #NEWLINE_TOKEN + #NEWLINE_TOKEN + return cells; + }, + inline: false, + } +} + fn quote_fill_arrow_array_builder( pascal_case_ident: &Ident, datatype: &DataType, @@ -760,13 +1050,15 @@ fn quote_fill_arrow_array_builder( if field.is_nullable { let item_append = if trivial_batch_append(field.data_type()) { // `&expression[0]` is not pretty but works on both arrays and vectors! + let element_ptr_accessor = + quote_batch_append_cast(datatype, quote!(&element.#field_name.value()[0])); quote! { - ARROW_RETURN_NOT_OK(value_builder->AppendValues(&element.#field_name.value()[0], #num_items_per_element, nullptr)); + ARROW_RETURN_NOT_OK(value_builder->AppendValues(#element_ptr_accessor, #num_items_per_element, nullptr)); } } else { quote! { for (auto item_idx = 0; item_idx < #num_items_per_element; item_idx += 1) { - value_builder->Append(element.#field_name.value()[item_idx]); + ARROW_RETURN_NOT_OK(value_builder->Append(element.#field_name.value()[item_idx])); } } }; @@ -786,11 +1078,13 @@ fn quote_fill_arrow_array_builder( && trivial_batch_append(field.data_type()) { // Optimize common case: Trivial batch of transparent fixed size elements. + let element_ptr_accessor = + quote_batch_append_cast(datatype, quote!(elements[0].#field_name)); quote! { auto value_builder = static_cast(#builder->value_builder()); #NEWLINE_TOKEN #NEWLINE_TOKEN static_assert(sizeof(elements[0].#field_name) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues(elements[0].#field_name, num_elements * #num_items_per_element, nullptr)); + ARROW_RETURN_NOT_OK(value_builder->AppendValues(#element_ptr_accessor, num_elements * #num_items_per_element, nullptr)); ARROW_RETURN_NOT_OK(#builder->AppendValues(num_elements)); } } else { @@ -799,7 +1093,7 @@ fn quote_fill_arrow_array_builder( for (auto elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { const auto& element = elements[elem_idx]; for (auto item_idx = 0; item_idx < #num_items_per_element; item_idx += 1) { - value_builder->Append(element.#field_name[item_idx]); + ARROW_RETURN_NOT_OK(value_builder->Append(element.#field_name[item_idx])); } ARROW_RETURN_NOT_OK(#builder->Append()); } @@ -923,9 +1217,11 @@ fn quote_append_elements_to_builder( } else if is_transparent && trivial_batch_append(datatype) { // Trivial optimization: If this is the only field of this type and it's a trivial field (not array/string/blob), // we can just pass the whole array as-is! + let element_ptr_accessor = + quote_batch_append_cast(datatype, quote!(&elements->#field_name)); quote! { static_assert(sizeof(*elements) == sizeof(elements->#field_name)); - ARROW_RETURN_NOT_OK(#builder->AppendValues(&elements->#field_name, num_elements)); + ARROW_RETURN_NOT_OK(#builder->AppendValues(#element_ptr_accessor, num_elements)); } } else { quote! { @@ -937,6 +1233,15 @@ fn quote_append_elements_to_builder( } } +fn quote_batch_append_cast(datatype: &DataType, element_ptr_accessor: TokenStream) -> TokenStream { + if *datatype == DataType::Boolean { + // Bool needs a cast because it takes uint8_t. + quote!(reinterpret_cast(#element_ptr_accessor)) + } else { + element_ptr_accessor + } +} + fn arrow_array_builder_type(datatype: &DataType) -> &'static str { match datatype.to_logical_type() { DataType::Boolean => "BooleanBuilder", @@ -1073,7 +1378,7 @@ fn static_constructor_for_enum_type( let snake_case_ident = format_ident!("{}", crate::to_snake_case(&obj_field.name)); let docs = obj_field.docs.clone().into(); - let param_declaration = quote_declaration(hpp_includes, obj_field, &snake_case_ident); + let param_declaration = quote_variable(hpp_includes, obj_field, &snake_case_ident); let declaration = MethodDeclaration { is_static: true, return_type: quote!(#pascal_case_ident), @@ -1130,7 +1435,7 @@ fn static_constructor_for_enum_type( // We need to use placement-new since the union is in an uninitialized state here: hpp_includes.system.insert("new".to_owned()); // placement-new let typedef_declaration = - quote_declaration(hpp_includes, obj_field, &format_ident!("TypeAlias")); + quote_variable(hpp_includes, obj_field, &format_ident!("TypeAlias")); Method { docs, declaration, @@ -1146,17 +1451,45 @@ fn static_constructor_for_enum_type( } } +fn quote_constants_header_and_cpp( + obj: &Object, + objects: &Objects, + obj_type_ident: &Ident, +) -> (Vec, Vec) { + let mut hpp = Vec::new(); + let mut cpp = Vec::new(); + match &obj.kind { + ObjectKind::Component => { + let legacy_fqname = objects[&obj.fqname] + .try_get_attr::(crate::ATTR_RERUN_LEGACY_FQNAME) + .unwrap_or_else(|| obj.fqname.clone()); + + let comment = quote_doc_comment("Name of the component, used for serialization."); + hpp.push(quote! { + #NEWLINE_TOKEN + #NEWLINE_TOKEN + #comment + static const char* NAME + }); + cpp.push(quote!(const char* #obj_type_ident::NAME = #legacy_fqname)); + } + ObjectKind::Archetype | ObjectKind::Datatype => {} + } + + (hpp, cpp) +} + fn are_types_disjoint(fields: &[ObjectField]) -> bool { let type_set: std::collections::HashSet<&Type> = fields.iter().map(|f| &f.typ).collect(); type_set.len() == fields.len() } -fn quote_declaration_with_docstring( +fn quote_variable_with_docstring( includes: &mut Includes, obj_field: &ObjectField, name: &syn::Ident, ) -> TokenStream { - let quoted = quote_declaration(includes, obj_field, name); + let quoted = quote_variable(includes, obj_field, name); let docstring = quote_docstrings(&obj_field.docs); @@ -1168,7 +1501,7 @@ fn quote_declaration_with_docstring( quoted } -fn quote_declaration( +fn quote_variable( includes: &mut Includes, obj_field: &ObjectField, name: &syn::Ident, diff --git a/examples/cpp/minimal/main.cpp b/examples/cpp/minimal/main.cpp index 1a7e24b33c1..6da8b0763b1 100644 --- a/examples/cpp/minimal/main.cpp +++ b/examples/cpp/minimal/main.cpp @@ -1,29 +1,9 @@ #include #include +#include #include -arrow::Result> points2(size_t num_points, const float* xy) { - arrow::MemoryPool* pool = arrow::default_memory_pool(); - - ARROW_ASSIGN_OR_RAISE(auto builder, rr::components::Point2D::new_arrow_array_builder(pool)); - ARROW_RETURN_NOT_OK(rr::components::Point2D::fill_arrow_array_builder( - builder.get(), - (const rr::components::Point2D*) - xy, // TODO(andreas): Hack to get Points2D C-style array in an easy fashion - num_points - )); - - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); - - auto name = "points"; // Unused, but should be the name of the field in the archetype - auto schema = - arrow::schema({arrow::field(name, rr::components::Point2D::to_arrow_datatype(), false)}); - - return arrow::Table::Make(schema, {array}); -} - int main(int argc, char** argv) { loguru::g_preamble_uptime = false; loguru::g_preamble_thread = false; @@ -33,37 +13,39 @@ int main(int argc, char** argv) { auto rr_stream = rr::RecordingStream{"c-example-app", "127.0.0.1:9876"}; - // Points3D. - { - float xyz[9] = {0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 5.0, 5.0, 5.0}; - auto points = rr::points3(3, xyz).ValueOrDie(); // TODO(andreas): phase this out. - auto buffer = rr::ipc_from_table(*points).ValueOrDie(); - - const rr::DataCell data_cells[1] = {rr::DataCell{ - .component_name = "rerun.point3d", - .num_bytes = static_cast(buffer->size()), - .bytes = buffer->data(), - }}; - - uint32_t num_instances = 3; - rr_stream.log_data_row("3d/points", num_instances, 1, data_cells); - } - - // Points2D. - { - float xy[6] = {0.0, 0.0, 1.0, 3.0, 5.0, 5.0}; - auto points = points2(3, xy).ValueOrDie(); - auto buffer = rr::ipc_from_table(*points).ValueOrDie(); - - const rr::DataCell data_cells[1] = {rr::DataCell{ - .component_name = "rerun.point2d", - .num_bytes = static_cast(buffer->size()), - .bytes = buffer->data(), - }}; - - uint32_t num_instances = 3; - rr_stream.log_data_row("2d/points", num_instances, 1, data_cells); - } + rr_stream.log_archetype( + "3d/points", + rr::archetypes::Points3D({ + rr::datatypes::Point3D{1.0, 2.0, 3.0}, + rr::datatypes::Point3D{4.0, 5.0, 6.0}, + }) + .with_radii({0.42, 0.43}) + .with_colors({0xAA0000CC, 0x00BB00DD}) + .with_labels({std::string("hello"), std::string("friend")}) + .with_class_ids({126, 127}) + .with_keypoint_ids({2, 3}) + .with_instance_keys({66, 666}) + ); + + rr::components::Label c_style_array[3] = { + rr::components::Label("hello"), + rr::components::Label("friend"), + rr::components::Label("yo"), + }; + rr_stream.log_components( + "2d/points", + std::vector{ + rr::components::Point2D(rr::datatypes::Point2D{0.0, 0.0}), + rr::components::Point2D(rr::datatypes::Point2D{1.0, 3.0}), + rr::components::Point2D(rr::datatypes::Point2D{5.0, 5.0}), + }, + std::array{ + rr::components::Color(0xFF0000FF), + rr::components::Color(0x00FF00FF), + rr::components::Color(0x0000FFFF), + }, + c_style_array + ); // Test some type instantiation auto tls = rr::datatypes::TranslationRotationScale3D{}; diff --git a/rerun_cpp/src/archetypes/affix_fuzzer1.cpp b/rerun_cpp/src/archetypes/affix_fuzzer1.cpp index a4117d5bc89..cac74004c87 100644 --- a/rerun_cpp/src/archetypes/affix_fuzzer1.cpp +++ b/rerun_cpp/src/archetypes/affix_fuzzer1.cpp @@ -3,6 +3,583 @@ #include "affix_fuzzer1.hpp" +#include "../components/affix_fuzzer1.hpp" +#include "../components/affix_fuzzer10.hpp" +#include "../components/affix_fuzzer11.hpp" +#include "../components/affix_fuzzer12.hpp" +#include "../components/affix_fuzzer13.hpp" +#include "../components/affix_fuzzer14.hpp" +#include "../components/affix_fuzzer15.hpp" +#include "../components/affix_fuzzer16.hpp" +#include "../components/affix_fuzzer17.hpp" +#include "../components/affix_fuzzer18.hpp" +#include "../components/affix_fuzzer19.hpp" +#include "../components/affix_fuzzer2.hpp" +#include "../components/affix_fuzzer3.hpp" +#include "../components/affix_fuzzer4.hpp" +#include "../components/affix_fuzzer5.hpp" +#include "../components/affix_fuzzer6.hpp" +#include "../components/affix_fuzzer7.hpp" +#include "../components/affix_fuzzer8.hpp" +#include "../components/affix_fuzzer9.hpp" + +#include + namespace rr { - namespace archetypes {} + namespace archetypes { + arrow::Result> AffixFuzzer1::to_data_cells() const { + std::vector cells; + cells.reserve(73); + + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer1::to_data_cell(&fuzz1001, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer2::to_data_cell(&fuzz1002, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer3::to_data_cell(&fuzz1003, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer4::to_data_cell(&fuzz1004, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer5::to_data_cell(&fuzz1005, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer6::to_data_cell(&fuzz1006, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer7::to_data_cell(&fuzz1007, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer8::to_data_cell(&fuzz1008, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer9::to_data_cell(&fuzz1009, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer10::to_data_cell(&fuzz1010, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer11::to_data_cell(&fuzz1011, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer12::to_data_cell(&fuzz1012, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer13::to_data_cell(&fuzz1013, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer14::to_data_cell(&fuzz1014, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer15::to_data_cell(&fuzz1015, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer16::to_data_cell(&fuzz1016, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer17::to_data_cell(&fuzz1017, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer18::to_data_cell(&fuzz1018, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer19::to_data_cell(&fuzz1019, 1) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer1::to_data_cell(fuzz1101.data(), fuzz1101.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer2::to_data_cell(fuzz1102.data(), fuzz1102.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer3::to_data_cell(fuzz1103.data(), fuzz1103.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer4::to_data_cell(fuzz1104.data(), fuzz1104.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer5::to_data_cell(fuzz1105.data(), fuzz1105.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer6::to_data_cell(fuzz1106.data(), fuzz1106.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer7::to_data_cell(fuzz1107.data(), fuzz1107.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer8::to_data_cell(fuzz1108.data(), fuzz1108.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer9::to_data_cell(fuzz1109.data(), fuzz1109.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer10::to_data_cell(fuzz1110.data(), fuzz1110.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer11::to_data_cell(fuzz1111.data(), fuzz1111.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer12::to_data_cell(fuzz1112.data(), fuzz1112.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer13::to_data_cell(fuzz1113.data(), fuzz1113.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer14::to_data_cell(fuzz1114.data(), fuzz1114.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer15::to_data_cell(fuzz1115.data(), fuzz1115.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer16::to_data_cell(fuzz1116.data(), fuzz1116.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer17::to_data_cell(fuzz1117.data(), fuzz1117.size()) + ); + cells.push_back(cell); + } + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer18::to_data_cell(fuzz1118.data(), fuzz1118.size()) + ); + cells.push_back(cell); + } + if (fuzz2001.has_value()) { + const auto& value = fuzz2001.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer1::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2002.has_value()) { + const auto& value = fuzz2002.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer2::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2003.has_value()) { + const auto& value = fuzz2003.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer3::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2004.has_value()) { + const auto& value = fuzz2004.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer4::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2005.has_value()) { + const auto& value = fuzz2005.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer5::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2006.has_value()) { + const auto& value = fuzz2006.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer6::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2007.has_value()) { + const auto& value = fuzz2007.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer7::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2008.has_value()) { + const auto& value = fuzz2008.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer8::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2009.has_value()) { + const auto& value = fuzz2009.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer9::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2010.has_value()) { + const auto& value = fuzz2010.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer10::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2011.has_value()) { + const auto& value = fuzz2011.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer11::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2012.has_value()) { + const auto& value = fuzz2012.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer12::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2013.has_value()) { + const auto& value = fuzz2013.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer13::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2014.has_value()) { + const auto& value = fuzz2014.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer14::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2015.has_value()) { + const auto& value = fuzz2015.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer15::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2016.has_value()) { + const auto& value = fuzz2016.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer16::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2017.has_value()) { + const auto& value = fuzz2017.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer17::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2018.has_value()) { + const auto& value = fuzz2018.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer18::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (fuzz2101.has_value()) { + const auto& value = fuzz2101.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer1::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2102.has_value()) { + const auto& value = fuzz2102.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer2::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2103.has_value()) { + const auto& value = fuzz2103.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer3::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2104.has_value()) { + const auto& value = fuzz2104.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer4::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2105.has_value()) { + const auto& value = fuzz2105.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer5::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2106.has_value()) { + const auto& value = fuzz2106.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer6::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2107.has_value()) { + const auto& value = fuzz2107.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer7::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2108.has_value()) { + const auto& value = fuzz2108.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer8::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2109.has_value()) { + const auto& value = fuzz2109.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer9::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2110.has_value()) { + const auto& value = fuzz2110.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer10::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2111.has_value()) { + const auto& value = fuzz2111.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer11::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2112.has_value()) { + const auto& value = fuzz2112.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer12::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2113.has_value()) { + const auto& value = fuzz2113.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer13::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2114.has_value()) { + const auto& value = fuzz2114.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer14::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2115.has_value()) { + const auto& value = fuzz2115.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer15::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2116.has_value()) { + const auto& value = fuzz2116.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer16::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2117.has_value()) { + const auto& value = fuzz2117.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer17::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (fuzz2118.has_value()) { + const auto& value = fuzz2118.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::AffixFuzzer18::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + + return cells; + } + } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/affix_fuzzer1.hpp b/rerun_cpp/src/archetypes/affix_fuzzer1.hpp index a6396d0d2d0..1cbc03e1226 100644 --- a/rerun_cpp/src/archetypes/affix_fuzzer1.hpp +++ b/rerun_cpp/src/archetypes/affix_fuzzer1.hpp @@ -22,10 +22,12 @@ #include "../components/affix_fuzzer7.hpp" #include "../components/affix_fuzzer8.hpp" #include "../components/affix_fuzzer9.hpp" +#include "../data_cell.hpp" #include #include #include +#include #include namespace rr { @@ -176,6 +178,263 @@ namespace rr { std::optional> fuzz2117; std::optional> fuzz2118; + + public: + AffixFuzzer1( + rr::components::AffixFuzzer1 fuzz1001, rr::components::AffixFuzzer2 fuzz1002, + rr::components::AffixFuzzer3 fuzz1003, rr::components::AffixFuzzer4 fuzz1004, + rr::components::AffixFuzzer5 fuzz1005, rr::components::AffixFuzzer6 fuzz1006, + rr::components::AffixFuzzer7 fuzz1007, rr::components::AffixFuzzer8 fuzz1008, + rr::components::AffixFuzzer9 fuzz1009, rr::components::AffixFuzzer10 fuzz1010, + rr::components::AffixFuzzer11 fuzz1011, rr::components::AffixFuzzer12 fuzz1012, + rr::components::AffixFuzzer13 fuzz1013, rr::components::AffixFuzzer14 fuzz1014, + rr::components::AffixFuzzer15 fuzz1015, rr::components::AffixFuzzer16 fuzz1016, + rr::components::AffixFuzzer17 fuzz1017, rr::components::AffixFuzzer18 fuzz1018, + rr::components::AffixFuzzer19 fuzz1019, + std::vector fuzz1101, + std::vector fuzz1102, + std::vector fuzz1103, + std::vector fuzz1104, + std::vector fuzz1105, + std::vector fuzz1106, + std::vector fuzz1107, + std::vector fuzz1108, + std::vector fuzz1109, + std::vector fuzz1110, + std::vector fuzz1111, + std::vector fuzz1112, + std::vector fuzz1113, + std::vector fuzz1114, + std::vector fuzz1115, + std::vector fuzz1116, + std::vector fuzz1117, + std::vector fuzz1118 + ) + : fuzz1001(std::move(fuzz1001)), + fuzz1002(std::move(fuzz1002)), + fuzz1003(std::move(fuzz1003)), + fuzz1004(std::move(fuzz1004)), + fuzz1005(std::move(fuzz1005)), + fuzz1006(std::move(fuzz1006)), + fuzz1007(std::move(fuzz1007)), + fuzz1008(std::move(fuzz1008)), + fuzz1009(std::move(fuzz1009)), + fuzz1010(std::move(fuzz1010)), + fuzz1011(std::move(fuzz1011)), + fuzz1012(std::move(fuzz1012)), + fuzz1013(std::move(fuzz1013)), + fuzz1014(std::move(fuzz1014)), + fuzz1015(std::move(fuzz1015)), + fuzz1016(std::move(fuzz1016)), + fuzz1017(std::move(fuzz1017)), + fuzz1018(std::move(fuzz1018)), + fuzz1019(std::move(fuzz1019)), + fuzz1101(std::move(fuzz1101)), + fuzz1102(std::move(fuzz1102)), + fuzz1103(std::move(fuzz1103)), + fuzz1104(std::move(fuzz1104)), + fuzz1105(std::move(fuzz1105)), + fuzz1106(std::move(fuzz1106)), + fuzz1107(std::move(fuzz1107)), + fuzz1108(std::move(fuzz1108)), + fuzz1109(std::move(fuzz1109)), + fuzz1110(std::move(fuzz1110)), + fuzz1111(std::move(fuzz1111)), + fuzz1112(std::move(fuzz1112)), + fuzz1113(std::move(fuzz1113)), + fuzz1114(std::move(fuzz1114)), + fuzz1115(std::move(fuzz1115)), + fuzz1116(std::move(fuzz1116)), + fuzz1117(std::move(fuzz1117)), + fuzz1118(std::move(fuzz1118)) {} + + AffixFuzzer1& with_fuzz2001(rr::components::AffixFuzzer1 fuzz2001) { + this->fuzz2001 = std::move(fuzz2001); + return *this; + } + + AffixFuzzer1& with_fuzz2002(rr::components::AffixFuzzer2 fuzz2002) { + this->fuzz2002 = std::move(fuzz2002); + return *this; + } + + AffixFuzzer1& with_fuzz2003(rr::components::AffixFuzzer3 fuzz2003) { + this->fuzz2003 = std::move(fuzz2003); + return *this; + } + + AffixFuzzer1& with_fuzz2004(rr::components::AffixFuzzer4 fuzz2004) { + this->fuzz2004 = std::move(fuzz2004); + return *this; + } + + AffixFuzzer1& with_fuzz2005(rr::components::AffixFuzzer5 fuzz2005) { + this->fuzz2005 = std::move(fuzz2005); + return *this; + } + + AffixFuzzer1& with_fuzz2006(rr::components::AffixFuzzer6 fuzz2006) { + this->fuzz2006 = std::move(fuzz2006); + return *this; + } + + AffixFuzzer1& with_fuzz2007(rr::components::AffixFuzzer7 fuzz2007) { + this->fuzz2007 = std::move(fuzz2007); + return *this; + } + + AffixFuzzer1& with_fuzz2008(rr::components::AffixFuzzer8 fuzz2008) { + this->fuzz2008 = std::move(fuzz2008); + return *this; + } + + AffixFuzzer1& with_fuzz2009(rr::components::AffixFuzzer9 fuzz2009) { + this->fuzz2009 = std::move(fuzz2009); + return *this; + } + + AffixFuzzer1& with_fuzz2010(rr::components::AffixFuzzer10 fuzz2010) { + this->fuzz2010 = std::move(fuzz2010); + return *this; + } + + AffixFuzzer1& with_fuzz2011(rr::components::AffixFuzzer11 fuzz2011) { + this->fuzz2011 = std::move(fuzz2011); + return *this; + } + + AffixFuzzer1& with_fuzz2012(rr::components::AffixFuzzer12 fuzz2012) { + this->fuzz2012 = std::move(fuzz2012); + return *this; + } + + AffixFuzzer1& with_fuzz2013(rr::components::AffixFuzzer13 fuzz2013) { + this->fuzz2013 = std::move(fuzz2013); + return *this; + } + + AffixFuzzer1& with_fuzz2014(rr::components::AffixFuzzer14 fuzz2014) { + this->fuzz2014 = std::move(fuzz2014); + return *this; + } + + AffixFuzzer1& with_fuzz2015(rr::components::AffixFuzzer15 fuzz2015) { + this->fuzz2015 = std::move(fuzz2015); + return *this; + } + + AffixFuzzer1& with_fuzz2016(rr::components::AffixFuzzer16 fuzz2016) { + this->fuzz2016 = std::move(fuzz2016); + return *this; + } + + AffixFuzzer1& with_fuzz2017(rr::components::AffixFuzzer17 fuzz2017) { + this->fuzz2017 = std::move(fuzz2017); + return *this; + } + + AffixFuzzer1& with_fuzz2018(rr::components::AffixFuzzer18 fuzz2018) { + this->fuzz2018 = std::move(fuzz2018); + return *this; + } + + AffixFuzzer1& with_fuzz2101(std::vector fuzz2101) { + this->fuzz2101 = std::move(fuzz2101); + return *this; + } + + AffixFuzzer1& with_fuzz2102(std::vector fuzz2102) { + this->fuzz2102 = std::move(fuzz2102); + return *this; + } + + AffixFuzzer1& with_fuzz2103(std::vector fuzz2103) { + this->fuzz2103 = std::move(fuzz2103); + return *this; + } + + AffixFuzzer1& with_fuzz2104(std::vector fuzz2104) { + this->fuzz2104 = std::move(fuzz2104); + return *this; + } + + AffixFuzzer1& with_fuzz2105(std::vector fuzz2105) { + this->fuzz2105 = std::move(fuzz2105); + return *this; + } + + AffixFuzzer1& with_fuzz2106(std::vector fuzz2106) { + this->fuzz2106 = std::move(fuzz2106); + return *this; + } + + AffixFuzzer1& with_fuzz2107(std::vector fuzz2107) { + this->fuzz2107 = std::move(fuzz2107); + return *this; + } + + AffixFuzzer1& with_fuzz2108(std::vector fuzz2108) { + this->fuzz2108 = std::move(fuzz2108); + return *this; + } + + AffixFuzzer1& with_fuzz2109(std::vector fuzz2109) { + this->fuzz2109 = std::move(fuzz2109); + return *this; + } + + AffixFuzzer1& with_fuzz2110(std::vector fuzz2110) { + this->fuzz2110 = std::move(fuzz2110); + return *this; + } + + AffixFuzzer1& with_fuzz2111(std::vector fuzz2111) { + this->fuzz2111 = std::move(fuzz2111); + return *this; + } + + AffixFuzzer1& with_fuzz2112(std::vector fuzz2112) { + this->fuzz2112 = std::move(fuzz2112); + return *this; + } + + AffixFuzzer1& with_fuzz2113(std::vector fuzz2113) { + this->fuzz2113 = std::move(fuzz2113); + return *this; + } + + AffixFuzzer1& with_fuzz2114(std::vector fuzz2114) { + this->fuzz2114 = std::move(fuzz2114); + return *this; + } + + AffixFuzzer1& with_fuzz2115(std::vector fuzz2115) { + this->fuzz2115 = std::move(fuzz2115); + return *this; + } + + AffixFuzzer1& with_fuzz2116(std::vector fuzz2116) { + this->fuzz2116 = std::move(fuzz2116); + return *this; + } + + AffixFuzzer1& with_fuzz2117(std::vector fuzz2117) { + this->fuzz2117 = std::move(fuzz2117); + return *this; + } + + AffixFuzzer1& with_fuzz2118(std::vector fuzz2118) { + this->fuzz2118 = std::move(fuzz2118); + return *this; + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + + /// Creates a list of Rerun DataCell from this archetype. + arrow::Result> to_data_cells() const; }; } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/disconnected_space.cpp b/rerun_cpp/src/archetypes/disconnected_space.cpp index 0d07bf54360..9f9e9526314 100644 --- a/rerun_cpp/src/archetypes/disconnected_space.cpp +++ b/rerun_cpp/src/archetypes/disconnected_space.cpp @@ -3,6 +3,25 @@ #include "disconnected_space.hpp" +#include "../components/disconnected_space.hpp" + +#include + namespace rr { - namespace archetypes {} + namespace archetypes { + arrow::Result> DisconnectedSpace::to_data_cells() const { + std::vector cells; + cells.reserve(1); + + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::DisconnectedSpace::to_data_cell(&disconnected_space, 1) + ); + cells.push_back(cell); + } + + return cells; + } + } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/disconnected_space.hpp b/rerun_cpp/src/archetypes/disconnected_space.hpp index 24d2a3351bc..4035251054d 100644 --- a/rerun_cpp/src/archetypes/disconnected_space.hpp +++ b/rerun_cpp/src/archetypes/disconnected_space.hpp @@ -4,6 +4,7 @@ #pragma once #include "../components/disconnected_space.hpp" +#include "../data_cell.hpp" #include #include @@ -23,6 +24,14 @@ namespace rr { public: DisconnectedSpace(rr::components::DisconnectedSpace disconnected_space) : disconnected_space(std::move(disconnected_space)) {} + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + + /// Creates a list of Rerun DataCell from this archetype. + arrow::Result> to_data_cells() const; }; } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/points2d.cpp b/rerun_cpp/src/archetypes/points2d.cpp index adb742c229d..5e45ea29cd1 100644 --- a/rerun_cpp/src/archetypes/points2d.cpp +++ b/rerun_cpp/src/archetypes/points2d.cpp @@ -3,6 +3,88 @@ #include "points2d.hpp" +#include "../components/class_id.hpp" +#include "../components/color.hpp" +#include "../components/draw_order.hpp" +#include "../components/instance_key.hpp" +#include "../components/keypoint_id.hpp" +#include "../components/label.hpp" +#include "../components/point2d.hpp" +#include "../components/radius.hpp" + +#include + namespace rr { - namespace archetypes {} + namespace archetypes { + arrow::Result> Points2D::to_data_cells() const { + std::vector cells; + cells.reserve(8); + + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Point2D::to_data_cell(points.data(), points.size()) + ); + cells.push_back(cell); + } + if (radii.has_value()) { + const auto& value = radii.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Radius::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (colors.has_value()) { + const auto& value = colors.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Color::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (labels.has_value()) { + const auto& value = labels.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Label::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (draw_order.has_value()) { + const auto& value = draw_order.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::DrawOrder::to_data_cell(&value, 1) + ); + cells.push_back(cell); + } + if (class_ids.has_value()) { + const auto& value = class_ids.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::ClassId::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (keypoint_ids.has_value()) { + const auto& value = keypoint_ids.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::KeypointId::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (instance_keys.has_value()) { + const auto& value = instance_keys.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::InstanceKey::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + + return cells; + } + } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/points2d.hpp b/rerun_cpp/src/archetypes/points2d.hpp index 39fbbbd547c..f30c2645060 100644 --- a/rerun_cpp/src/archetypes/points2d.hpp +++ b/rerun_cpp/src/archetypes/points2d.hpp @@ -11,10 +11,12 @@ #include "../components/label.hpp" #include "../components/point2d.hpp" #include "../components/radius.hpp" +#include "../data_cell.hpp" #include #include #include +#include #include namespace rr { @@ -55,6 +57,70 @@ namespace rr { /// Unique identifiers for each individual point in the batch. std::optional> instance_keys; + + public: + Points2D(std::vector points) : points(std::move(points)) {} + + /// Optional radii for the points, effectively turning them into circles. + Points2D& with_radii(std::vector radii) { + this->radii = std::move(radii); + return *this; + } + + /// Optional colors for the points. + Points2D& with_colors(std::vector colors) { + this->colors = std::move(colors); + return *this; + } + + /// Optional text labels for the points. + Points2D& with_labels(std::vector labels) { + this->labels = std::move(labels); + return *this; + } + + /// An optional floating point value that specifies the 2D drawing order. + /// Objects with higher values are drawn on top of those with lower values. + /// + /// The default for 2D points is 30.0. + Points2D& with_draw_order(rr::components::DrawOrder draw_order) { + this->draw_order = std::move(draw_order); + return *this; + } + + /// Optional class Ids for the points. + /// + /// The class ID provides colors and labels if not specified explicitly. + Points2D& with_class_ids(std::vector class_ids) { + this->class_ids = std::move(class_ids); + return *this; + } + + /// Optional keypoint IDs for the points, identifying them within a class. + /// + /// If keypoint IDs are passed in but no class IDs were specified, the class ID will + /// default to 0. + /// This is useful to identify points within a single classification (which is + /// identified with `class_id`). E.g. the classification might be 'Person' and the + /// keypoints refer to joints on a detected skeleton. + Points2D& with_keypoint_ids(std::vector keypoint_ids) { + this->keypoint_ids = std::move(keypoint_ids); + return *this; + } + + /// Unique identifiers for each individual point in the batch. + Points2D& with_instance_keys(std::vector instance_keys) { + this->instance_keys = std::move(instance_keys); + return *this; + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return points.size(); + } + + /// Creates a list of Rerun DataCell from this archetype. + arrow::Result> to_data_cells() const; }; } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/points3d.cpp b/rerun_cpp/src/archetypes/points3d.cpp index c1830b732e5..4a1984eca37 100644 --- a/rerun_cpp/src/archetypes/points3d.cpp +++ b/rerun_cpp/src/archetypes/points3d.cpp @@ -3,6 +3,79 @@ #include "points3d.hpp" +#include "../components/class_id.hpp" +#include "../components/color.hpp" +#include "../components/instance_key.hpp" +#include "../components/keypoint_id.hpp" +#include "../components/label.hpp" +#include "../components/point3d.hpp" +#include "../components/radius.hpp" + +#include + namespace rr { - namespace archetypes {} + namespace archetypes { + arrow::Result> Points3D::to_data_cells() const { + std::vector cells; + cells.reserve(7); + + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Point3D::to_data_cell(points.data(), points.size()) + ); + cells.push_back(cell); + } + if (radii.has_value()) { + const auto& value = radii.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Radius::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (colors.has_value()) { + const auto& value = colors.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Color::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (labels.has_value()) { + const auto& value = labels.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Label::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (class_ids.has_value()) { + const auto& value = class_ids.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::ClassId::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (keypoint_ids.has_value()) { + const auto& value = keypoint_ids.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::KeypointId::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + if (instance_keys.has_value()) { + const auto& value = instance_keys.value(); + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::InstanceKey::to_data_cell(value.data(), value.size()) + ); + cells.push_back(cell); + } + + return cells; + } + } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/points3d.hpp b/rerun_cpp/src/archetypes/points3d.hpp index 21d4b54231c..7974b6324f7 100644 --- a/rerun_cpp/src/archetypes/points3d.hpp +++ b/rerun_cpp/src/archetypes/points3d.hpp @@ -10,10 +10,12 @@ #include "../components/label.hpp" #include "../components/point3d.hpp" #include "../components/radius.hpp" +#include "../data_cell.hpp" #include #include #include +#include #include namespace rr { @@ -48,6 +50,61 @@ namespace rr { /// Unique identifiers for each individual point in the batch. std::optional> instance_keys; + + public: + Points3D(std::vector points) : points(std::move(points)) {} + + /// Optional radii for the points, effectively turning them into circles. + Points3D& with_radii(std::vector radii) { + this->radii = std::move(radii); + return *this; + } + + /// Optional colors for the points. + Points3D& with_colors(std::vector colors) { + this->colors = std::move(colors); + return *this; + } + + /// Optional text labels for the points. + Points3D& with_labels(std::vector labels) { + this->labels = std::move(labels); + return *this; + } + + /// Optional class Ids for the points. + /// + /// The class ID provides colors and labels if not specified explicitly. + Points3D& with_class_ids(std::vector class_ids) { + this->class_ids = std::move(class_ids); + return *this; + } + + /// Optional keypoint IDs for the points, identifying them within a class. + /// + /// If keypoint IDs are passed in but no class IDs were specified, the class ID will + /// default to 0. + /// This is useful to identify points within a single classification (which is + /// identified with `class_id`). E.g. the classification might be 'Person' and the + /// keypoints refer to joints on a detected skeleton. + Points3D& with_keypoint_ids(std::vector keypoint_ids) { + this->keypoint_ids = std::move(keypoint_ids); + return *this; + } + + /// Unique identifiers for each individual point in the batch. + Points3D& with_instance_keys(std::vector instance_keys) { + this->instance_keys = std::move(instance_keys); + return *this; + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return points.size(); + } + + /// Creates a list of Rerun DataCell from this archetype. + arrow::Result> to_data_cells() const; }; } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/transform3d.cpp b/rerun_cpp/src/archetypes/transform3d.cpp index 539fdead8e9..25cc9befb75 100644 --- a/rerun_cpp/src/archetypes/transform3d.cpp +++ b/rerun_cpp/src/archetypes/transform3d.cpp @@ -3,6 +3,25 @@ #include "transform3d.hpp" +#include "../components/transform3d.hpp" + +#include + namespace rr { - namespace archetypes {} + namespace archetypes { + arrow::Result> Transform3D::to_data_cells() const { + std::vector cells; + cells.reserve(1); + + { + ARROW_ASSIGN_OR_RAISE( + const auto cell, + rr::components::Transform3D::to_data_cell(&transform, 1) + ); + cells.push_back(cell); + } + + return cells; + } + } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/archetypes/transform3d.hpp b/rerun_cpp/src/archetypes/transform3d.hpp index 82dda3cc1ed..2a5548807de 100644 --- a/rerun_cpp/src/archetypes/transform3d.hpp +++ b/rerun_cpp/src/archetypes/transform3d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../components/transform3d.hpp" +#include "../data_cell.hpp" #include #include @@ -18,6 +19,14 @@ namespace rr { public: Transform3D(rr::components::Transform3D transform) : transform(std::move(transform)) {} + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + + /// Creates a list of Rerun DataCell from this archetype. + arrow::Result> to_data_cells() const; }; } // namespace archetypes } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer1.cpp b/rerun_cpp/src/components/affix_fuzzer1.cpp index 5518fea03a4..e258eaadc92 100644 --- a/rerun_cpp/src/components/affix_fuzzer1.cpp +++ b/rerun_cpp/src/components/affix_fuzzer1.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer1.hpp" #include "../datatypes/affix_fuzzer1.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer1::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + const char *AffixFuzzer1::NAME = "rerun.testing.components.AffixFuzzer1"; + + const std::shared_ptr &AffixFuzzer1::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + return datatype; } arrow::Result> AffixFuzzer1::new_arrow_array_builder( @@ -44,5 +48,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer1::to_data_cell( + const AffixFuzzer1 *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer1::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer1::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer1::NAME, AffixFuzzer1::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer1::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer1.hpp b/rerun_cpp/src/components/affix_fuzzer1.hpp index a749a1ea4bb..d25df5dcf22 100644 --- a/rerun_cpp/src/components/affix_fuzzer1.hpp +++ b/rerun_cpp/src/components/affix_fuzzer1.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer1.hpp" #include @@ -14,12 +15,15 @@ namespace rr { struct AffixFuzzer1 { rr::datatypes::AffixFuzzer1 single_required; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer1(rr::datatypes::AffixFuzzer1 single_required) : single_required(std::move(single_required)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const AffixFuzzer1* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer1 components. + static arrow::Result to_data_cell( + const AffixFuzzer1* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer10.cpp b/rerun_cpp/src/components/affix_fuzzer10.cpp index 0c3a13d23e8..10375c4953f 100644 --- a/rerun_cpp/src/components/affix_fuzzer10.cpp +++ b/rerun_cpp/src/components/affix_fuzzer10.cpp @@ -3,12 +3,17 @@ #include "affix_fuzzer10.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer10::to_arrow_datatype() { - return arrow::utf8(); + const char* AffixFuzzer10::NAME = "rerun.testing.components.AffixFuzzer10"; + + const std::shared_ptr& AffixFuzzer10::to_arrow_datatype() { + static const auto datatype = arrow::utf8(); + return datatype; } arrow::Result> AffixFuzzer10::new_arrow_array_builder( @@ -43,5 +48,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer10::to_data_cell( + const AffixFuzzer10* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer10::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer10::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer10::NAME, AffixFuzzer10::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer10::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer10.hpp b/rerun_cpp/src/components/affix_fuzzer10.hpp index 1c3c951d971..f59db7f3388 100644 --- a/rerun_cpp/src/components/affix_fuzzer10.hpp +++ b/rerun_cpp/src/components/affix_fuzzer10.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -14,12 +16,15 @@ namespace rr { struct AffixFuzzer10 { std::optional single_string_optional; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer10(std::optional single_string_optional) : single_string_optional(std::move(single_string_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +35,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StringBuilder* builder, const AffixFuzzer10* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer10 components. + static arrow::Result to_data_cell( + const AffixFuzzer10* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer11.cpp b/rerun_cpp/src/components/affix_fuzzer11.cpp index 4e82609e9bc..6aff746c18b 100644 --- a/rerun_cpp/src/components/affix_fuzzer11.cpp +++ b/rerun_cpp/src/components/affix_fuzzer11.cpp @@ -3,12 +3,18 @@ #include "affix_fuzzer11.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer11::to_arrow_datatype() { - return arrow::list(arrow::field("item", arrow::float32(), true, nullptr)); + const char *AffixFuzzer11::NAME = "rerun.testing.components.AffixFuzzer11"; + + const std::shared_ptr &AffixFuzzer11::to_arrow_datatype() { + static const auto datatype = + arrow::list(arrow::field("item", arrow::float32(), true, nullptr)); + return datatype; } arrow::Result> AffixFuzzer11::new_arrow_array_builder( @@ -54,5 +60,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer11::to_data_cell( + const AffixFuzzer11 *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer11::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer11::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer11::NAME, AffixFuzzer11::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer11::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer11.hpp b/rerun_cpp/src/components/affix_fuzzer11.hpp index ad40ffa4036..7ef890603f2 100644 --- a/rerun_cpp/src/components/affix_fuzzer11.hpp +++ b/rerun_cpp/src/components/affix_fuzzer11.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -14,12 +16,15 @@ namespace rr { struct AffixFuzzer11 { std::optional> many_floats_optional; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer11(std::optional> many_floats_optional) : many_floats_optional(std::move(many_floats_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +35,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::ListBuilder* builder, const AffixFuzzer11* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer11 components. + static arrow::Result to_data_cell( + const AffixFuzzer11* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer12.cpp b/rerun_cpp/src/components/affix_fuzzer12.cpp index a3731669371..19a5becf7b8 100644 --- a/rerun_cpp/src/components/affix_fuzzer12.cpp +++ b/rerun_cpp/src/components/affix_fuzzer12.cpp @@ -3,12 +3,18 @@ #include "affix_fuzzer12.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer12::to_arrow_datatype() { - return arrow::list(arrow::field("item", arrow::utf8(), false, nullptr)); + const char *AffixFuzzer12::NAME = "rerun.testing.components.AffixFuzzer12"; + + const std::shared_ptr &AffixFuzzer12::to_arrow_datatype() { + static const auto datatype = + arrow::list(arrow::field("item", arrow::utf8(), false, nullptr)); + return datatype; } arrow::Result> AffixFuzzer12::new_arrow_array_builder( @@ -42,12 +48,43 @@ namespace rr { const auto &element = elements[elem_idx]; for (auto item_idx = 0; item_idx < element.many_strings_required.size(); item_idx += 1) { - value_builder->Append(element.many_strings_required[item_idx]); + ARROW_RETURN_NOT_OK( + value_builder->Append(element.many_strings_required[item_idx]) + ); } ARROW_RETURN_NOT_OK(builder->Append()); } return arrow::Status::OK(); } + + arrow::Result AffixFuzzer12::to_data_cell( + const AffixFuzzer12 *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer12::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer12::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer12::NAME, AffixFuzzer12::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer12::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer12.hpp b/rerun_cpp/src/components/affix_fuzzer12.hpp index d6e2761dc42..28acd83a99a 100644 --- a/rerun_cpp/src/components/affix_fuzzer12.hpp +++ b/rerun_cpp/src/components/affix_fuzzer12.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -14,12 +16,15 @@ namespace rr { struct AffixFuzzer12 { std::vector many_strings_required; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer12(std::vector many_strings_required) : many_strings_required(std::move(many_strings_required)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +35,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::ListBuilder* builder, const AffixFuzzer12* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer12 components. + static arrow::Result to_data_cell( + const AffixFuzzer12* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer13.cpp b/rerun_cpp/src/components/affix_fuzzer13.cpp index c2bdb9baa82..f05f2c02681 100644 --- a/rerun_cpp/src/components/affix_fuzzer13.cpp +++ b/rerun_cpp/src/components/affix_fuzzer13.cpp @@ -3,12 +3,18 @@ #include "affix_fuzzer13.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer13::to_arrow_datatype() { - return arrow::list(arrow::field("item", arrow::utf8(), true, nullptr)); + const char *AffixFuzzer13::NAME = "rerun.testing.components.AffixFuzzer13"; + + const std::shared_ptr &AffixFuzzer13::to_arrow_datatype() { + static const auto datatype = + arrow::list(arrow::field("item", arrow::utf8(), true, nullptr)); + return datatype; } arrow::Result> AffixFuzzer13::new_arrow_array_builder( @@ -43,7 +49,9 @@ namespace rr { if (element.many_strings_optional.has_value()) { for (auto item_idx = 0; item_idx < element.many_strings_optional.value().size(); item_idx += 1) { - value_builder->Append(element.many_strings_optional.value()[item_idx]); + ARROW_RETURN_NOT_OK( + value_builder->Append(element.many_strings_optional.value()[item_idx]) + ); } ARROW_RETURN_NOT_OK(builder->Append()); } else { @@ -53,5 +61,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer13::to_data_cell( + const AffixFuzzer13 *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer13::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer13::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer13::NAME, AffixFuzzer13::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer13::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer13.hpp b/rerun_cpp/src/components/affix_fuzzer13.hpp index 5ddd66ff404..4f509444485 100644 --- a/rerun_cpp/src/components/affix_fuzzer13.hpp +++ b/rerun_cpp/src/components/affix_fuzzer13.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -15,12 +17,15 @@ namespace rr { struct AffixFuzzer13 { std::optional> many_strings_optional; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer13(std::optional> many_strings_optional) : many_strings_optional(std::move(many_strings_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -31,6 +36,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::ListBuilder* builder, const AffixFuzzer13* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer13 components. + static arrow::Result to_data_cell( + const AffixFuzzer13* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer14.cpp b/rerun_cpp/src/components/affix_fuzzer14.cpp index 3a97ebed9e8..a7401b84788 100644 --- a/rerun_cpp/src/components/affix_fuzzer14.cpp +++ b/rerun_cpp/src/components/affix_fuzzer14.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer14.hpp" #include "../datatypes/affix_fuzzer3.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer14::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer3::to_arrow_datatype(); + const char *AffixFuzzer14::NAME = "rerun.testing.components.AffixFuzzer14"; + + const std::shared_ptr &AffixFuzzer14::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer3::to_arrow_datatype(); + return datatype; } arrow::Result> @@ -43,5 +47,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer14::to_data_cell( + const AffixFuzzer14 *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer14::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer14::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer14::NAME, AffixFuzzer14::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer14::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer14.hpp b/rerun_cpp/src/components/affix_fuzzer14.hpp index c7d4e8d345d..ac4e2bbc86c 100644 --- a/rerun_cpp/src/components/affix_fuzzer14.hpp +++ b/rerun_cpp/src/components/affix_fuzzer14.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer3.hpp" #include @@ -14,12 +15,15 @@ namespace rr { struct AffixFuzzer14 { rr::datatypes::AffixFuzzer3 single_required_union; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer14(rr::datatypes::AffixFuzzer3 single_required_union) : single_required_union(std::move(single_required_union)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -31,6 +35,11 @@ namespace rr { arrow::DenseUnionBuilder* builder, const AffixFuzzer14* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer14 components. + static arrow::Result to_data_cell( + const AffixFuzzer14* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer15.cpp b/rerun_cpp/src/components/affix_fuzzer15.cpp index c80eb365c0a..197cfbee89f 100644 --- a/rerun_cpp/src/components/affix_fuzzer15.cpp +++ b/rerun_cpp/src/components/affix_fuzzer15.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer15.hpp" #include "../datatypes/affix_fuzzer3.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer15::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer3::to_arrow_datatype(); + const char* AffixFuzzer15::NAME = "rerun.testing.components.AffixFuzzer15"; + + const std::shared_ptr& AffixFuzzer15::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer3::to_arrow_datatype(); + return datatype; } arrow::Result> @@ -38,5 +42,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer15::to_data_cell( + const AffixFuzzer15* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer15::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer15::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer15::NAME, AffixFuzzer15::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer15::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer15.hpp b/rerun_cpp/src/components/affix_fuzzer15.hpp index 3fdb1a83796..65d43628f4b 100644 --- a/rerun_cpp/src/components/affix_fuzzer15.hpp +++ b/rerun_cpp/src/components/affix_fuzzer15.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer3.hpp" #include @@ -15,12 +16,15 @@ namespace rr { struct AffixFuzzer15 { std::optional single_optional_union; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer15(std::optional single_optional_union) : single_optional_union(std::move(single_optional_union)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -32,6 +36,11 @@ namespace rr { arrow::DenseUnionBuilder* builder, const AffixFuzzer15* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer15 components. + static arrow::Result to_data_cell( + const AffixFuzzer15* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer16.cpp b/rerun_cpp/src/components/affix_fuzzer16.cpp index 10d40df328e..8dc8bd5cc49 100644 --- a/rerun_cpp/src/components/affix_fuzzer16.cpp +++ b/rerun_cpp/src/components/affix_fuzzer16.cpp @@ -4,18 +4,22 @@ #include "affix_fuzzer16.hpp" #include "../datatypes/affix_fuzzer3.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer16::to_arrow_datatype() { - return arrow::list(arrow::field( + const char* AffixFuzzer16::NAME = "rerun.testing.components.AffixFuzzer16"; + + const std::shared_ptr& AffixFuzzer16::to_arrow_datatype() { + static const auto datatype = arrow::list(arrow::field( "item", rr::datatypes::AffixFuzzer3::to_arrow_datatype(), false, nullptr )); + return datatype; } arrow::Result> AffixFuzzer16::new_arrow_array_builder( @@ -47,5 +51,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer16::to_data_cell( + const AffixFuzzer16* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer16::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer16::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer16::NAME, AffixFuzzer16::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer16::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer16.hpp b/rerun_cpp/src/components/affix_fuzzer16.hpp index 973b3d502cb..09f342cbf86 100644 --- a/rerun_cpp/src/components/affix_fuzzer16.hpp +++ b/rerun_cpp/src/components/affix_fuzzer16.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer3.hpp" #include @@ -15,12 +16,15 @@ namespace rr { struct AffixFuzzer16 { std::vector many_required_unions; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer16(std::vector many_required_unions) : many_required_unions(std::move(many_required_unions)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -31,6 +35,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::ListBuilder* builder, const AffixFuzzer16* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer16 components. + static arrow::Result to_data_cell( + const AffixFuzzer16* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer17.cpp b/rerun_cpp/src/components/affix_fuzzer17.cpp index 8e478c4e812..7a13d2eb358 100644 --- a/rerun_cpp/src/components/affix_fuzzer17.cpp +++ b/rerun_cpp/src/components/affix_fuzzer17.cpp @@ -4,18 +4,22 @@ #include "affix_fuzzer17.hpp" #include "../datatypes/affix_fuzzer3.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer17::to_arrow_datatype() { - return arrow::list(arrow::field( + const char* AffixFuzzer17::NAME = "rerun.testing.components.AffixFuzzer17"; + + const std::shared_ptr& AffixFuzzer17::to_arrow_datatype() { + static const auto datatype = arrow::list(arrow::field( "item", rr::datatypes::AffixFuzzer3::to_arrow_datatype(), true, nullptr )); + return datatype; } arrow::Result> AffixFuzzer17::new_arrow_array_builder( @@ -47,5 +51,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer17::to_data_cell( + const AffixFuzzer17* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer17::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer17::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer17::NAME, AffixFuzzer17::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer17::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer17.hpp b/rerun_cpp/src/components/affix_fuzzer17.hpp index 849774b2cf9..4fc7ed29fbf 100644 --- a/rerun_cpp/src/components/affix_fuzzer17.hpp +++ b/rerun_cpp/src/components/affix_fuzzer17.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer3.hpp" #include @@ -16,6 +17,9 @@ namespace rr { struct AffixFuzzer17 { std::optional> many_optional_unions; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer17( std::optional> many_optional_unions @@ -23,7 +27,7 @@ namespace rr { : many_optional_unions(std::move(many_optional_unions)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -34,6 +38,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::ListBuilder* builder, const AffixFuzzer17* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer17 components. + static arrow::Result to_data_cell( + const AffixFuzzer17* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer18.cpp b/rerun_cpp/src/components/affix_fuzzer18.cpp index 088de459769..2421ae52ca5 100644 --- a/rerun_cpp/src/components/affix_fuzzer18.cpp +++ b/rerun_cpp/src/components/affix_fuzzer18.cpp @@ -4,18 +4,22 @@ #include "affix_fuzzer18.hpp" #include "../datatypes/affix_fuzzer4.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer18::to_arrow_datatype() { - return arrow::list(arrow::field( + const char* AffixFuzzer18::NAME = "rerun.testing.components.AffixFuzzer18"; + + const std::shared_ptr& AffixFuzzer18::to_arrow_datatype() { + static const auto datatype = arrow::list(arrow::field( "item", rr::datatypes::AffixFuzzer4::to_arrow_datatype(), true, nullptr )); + return datatype; } arrow::Result> AffixFuzzer18::new_arrow_array_builder( @@ -47,5 +51,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer18::to_data_cell( + const AffixFuzzer18* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer18::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer18::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer18::NAME, AffixFuzzer18::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer18::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer18.hpp b/rerun_cpp/src/components/affix_fuzzer18.hpp index 825e29082b9..0abd843c313 100644 --- a/rerun_cpp/src/components/affix_fuzzer18.hpp +++ b/rerun_cpp/src/components/affix_fuzzer18.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer4.hpp" #include @@ -16,6 +17,9 @@ namespace rr { struct AffixFuzzer18 { std::optional> many_optional_unions; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer18( std::optional> many_optional_unions @@ -23,7 +27,7 @@ namespace rr { : many_optional_unions(std::move(many_optional_unions)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -34,6 +38,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::ListBuilder* builder, const AffixFuzzer18* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer18 components. + static arrow::Result to_data_cell( + const AffixFuzzer18* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer19.cpp b/rerun_cpp/src/components/affix_fuzzer19.cpp index b1630b37e40..79e130c1d9f 100644 --- a/rerun_cpp/src/components/affix_fuzzer19.cpp +++ b/rerun_cpp/src/components/affix_fuzzer19.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer19.hpp" #include "../datatypes/affix_fuzzer5.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer19::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer5::to_arrow_datatype(); + const char *AffixFuzzer19::NAME = "rerun.testing.components.AffixFuzzer19"; + + const std::shared_ptr &AffixFuzzer19::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer5::to_arrow_datatype(); + return datatype; } arrow::Result> AffixFuzzer19::new_arrow_array_builder( @@ -44,5 +48,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer19::to_data_cell( + const AffixFuzzer19 *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer19::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer19::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer19::NAME, AffixFuzzer19::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer19::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer19.hpp b/rerun_cpp/src/components/affix_fuzzer19.hpp index 089daef4598..8d742d6cbba 100644 --- a/rerun_cpp/src/components/affix_fuzzer19.hpp +++ b/rerun_cpp/src/components/affix_fuzzer19.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer5.hpp" #include @@ -14,12 +15,15 @@ namespace rr { struct AffixFuzzer19 { rr::datatypes::AffixFuzzer5 just_a_table_nothing_shady; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer19(rr::datatypes::AffixFuzzer5 just_a_table_nothing_shady) : just_a_table_nothing_shady(std::move(just_a_table_nothing_shady)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const AffixFuzzer19* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer19 components. + static arrow::Result to_data_cell( + const AffixFuzzer19* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer2.cpp b/rerun_cpp/src/components/affix_fuzzer2.cpp index 083d72529de..77e7ddaaf11 100644 --- a/rerun_cpp/src/components/affix_fuzzer2.cpp +++ b/rerun_cpp/src/components/affix_fuzzer2.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer2.hpp" #include "../datatypes/affix_fuzzer1.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer2::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + const char *AffixFuzzer2::NAME = "rerun.testing.components.AffixFuzzer2"; + + const std::shared_ptr &AffixFuzzer2::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + return datatype; } arrow::Result> AffixFuzzer2::new_arrow_array_builder( @@ -44,5 +48,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer2::to_data_cell( + const AffixFuzzer2 *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer2::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer2::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer2::NAME, AffixFuzzer2::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer2::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer2.hpp b/rerun_cpp/src/components/affix_fuzzer2.hpp index 4db325c8df8..7f7fe23f73f 100644 --- a/rerun_cpp/src/components/affix_fuzzer2.hpp +++ b/rerun_cpp/src/components/affix_fuzzer2.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer1.hpp" #include @@ -14,12 +15,15 @@ namespace rr { struct AffixFuzzer2 { rr::datatypes::AffixFuzzer1 single_required; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer2(rr::datatypes::AffixFuzzer1 single_required) : single_required(std::move(single_required)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const AffixFuzzer2* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer2 components. + static arrow::Result to_data_cell( + const AffixFuzzer2* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer3.cpp b/rerun_cpp/src/components/affix_fuzzer3.cpp index 9a9e36eb4e5..943e8fcff72 100644 --- a/rerun_cpp/src/components/affix_fuzzer3.cpp +++ b/rerun_cpp/src/components/affix_fuzzer3.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer3.hpp" #include "../datatypes/affix_fuzzer1.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer3::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + const char *AffixFuzzer3::NAME = "rerun.testing.components.AffixFuzzer3"; + + const std::shared_ptr &AffixFuzzer3::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + return datatype; } arrow::Result> AffixFuzzer3::new_arrow_array_builder( @@ -44,5 +48,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer3::to_data_cell( + const AffixFuzzer3 *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer3::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer3::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer3::NAME, AffixFuzzer3::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer3::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer3.hpp b/rerun_cpp/src/components/affix_fuzzer3.hpp index d0443ea19ad..de779c8d26f 100644 --- a/rerun_cpp/src/components/affix_fuzzer3.hpp +++ b/rerun_cpp/src/components/affix_fuzzer3.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer1.hpp" #include @@ -14,12 +15,15 @@ namespace rr { struct AffixFuzzer3 { rr::datatypes::AffixFuzzer1 single_required; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer3(rr::datatypes::AffixFuzzer1 single_required) : single_required(std::move(single_required)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const AffixFuzzer3* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer3 components. + static arrow::Result to_data_cell( + const AffixFuzzer3* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer4.cpp b/rerun_cpp/src/components/affix_fuzzer4.cpp index cb4c8d7a443..7a4473e438c 100644 --- a/rerun_cpp/src/components/affix_fuzzer4.cpp +++ b/rerun_cpp/src/components/affix_fuzzer4.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer4.hpp" #include "../datatypes/affix_fuzzer1.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer4::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + const char* AffixFuzzer4::NAME = "rerun.testing.components.AffixFuzzer4"; + + const std::shared_ptr& AffixFuzzer4::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + return datatype; } arrow::Result> AffixFuzzer4::new_arrow_array_builder( @@ -39,5 +43,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer4::to_data_cell( + const AffixFuzzer4* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer4::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer4::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer4::NAME, AffixFuzzer4::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer4::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer4.hpp b/rerun_cpp/src/components/affix_fuzzer4.hpp index 5ab17b0629b..86310c9a625 100644 --- a/rerun_cpp/src/components/affix_fuzzer4.hpp +++ b/rerun_cpp/src/components/affix_fuzzer4.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer1.hpp" #include @@ -15,12 +16,15 @@ namespace rr { struct AffixFuzzer4 { std::optional single_optional; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer4(std::optional single_optional) : single_optional(std::move(single_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -31,6 +35,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const AffixFuzzer4* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer4 components. + static arrow::Result to_data_cell( + const AffixFuzzer4* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer5.cpp b/rerun_cpp/src/components/affix_fuzzer5.cpp index f6080fafc63..fbb1337f360 100644 --- a/rerun_cpp/src/components/affix_fuzzer5.cpp +++ b/rerun_cpp/src/components/affix_fuzzer5.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer5.hpp" #include "../datatypes/affix_fuzzer1.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer5::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + const char* AffixFuzzer5::NAME = "rerun.testing.components.AffixFuzzer5"; + + const std::shared_ptr& AffixFuzzer5::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + return datatype; } arrow::Result> AffixFuzzer5::new_arrow_array_builder( @@ -39,5 +43,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer5::to_data_cell( + const AffixFuzzer5* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer5::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer5::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer5::NAME, AffixFuzzer5::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer5::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer5.hpp b/rerun_cpp/src/components/affix_fuzzer5.hpp index f6ed7ebb2bb..763045527ce 100644 --- a/rerun_cpp/src/components/affix_fuzzer5.hpp +++ b/rerun_cpp/src/components/affix_fuzzer5.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer1.hpp" #include @@ -15,12 +16,15 @@ namespace rr { struct AffixFuzzer5 { std::optional single_optional; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer5(std::optional single_optional) : single_optional(std::move(single_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -31,6 +35,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const AffixFuzzer5* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer5 components. + static arrow::Result to_data_cell( + const AffixFuzzer5* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer6.cpp b/rerun_cpp/src/components/affix_fuzzer6.cpp index f6eb36be291..d16c3035bba 100644 --- a/rerun_cpp/src/components/affix_fuzzer6.cpp +++ b/rerun_cpp/src/components/affix_fuzzer6.cpp @@ -4,13 +4,17 @@ #include "affix_fuzzer6.hpp" #include "../datatypes/affix_fuzzer1.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer6::to_arrow_datatype() { - return rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + const char* AffixFuzzer6::NAME = "rerun.testing.components.AffixFuzzer6"; + + const std::shared_ptr& AffixFuzzer6::to_arrow_datatype() { + static const auto datatype = rr::datatypes::AffixFuzzer1::to_arrow_datatype(); + return datatype; } arrow::Result> AffixFuzzer6::new_arrow_array_builder( @@ -39,5 +43,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer6::to_data_cell( + const AffixFuzzer6* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer6::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer6::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer6::NAME, AffixFuzzer6::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer6::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer6.hpp b/rerun_cpp/src/components/affix_fuzzer6.hpp index 78f27128c35..9893de3e12a 100644 --- a/rerun_cpp/src/components/affix_fuzzer6.hpp +++ b/rerun_cpp/src/components/affix_fuzzer6.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer1.hpp" #include @@ -15,12 +16,15 @@ namespace rr { struct AffixFuzzer6 { std::optional single_optional; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer6(std::optional single_optional) : single_optional(std::move(single_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -31,6 +35,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const AffixFuzzer6* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer6 components. + static arrow::Result to_data_cell( + const AffixFuzzer6* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer7.cpp b/rerun_cpp/src/components/affix_fuzzer7.cpp index 30d4bb200b1..570e242c2db 100644 --- a/rerun_cpp/src/components/affix_fuzzer7.cpp +++ b/rerun_cpp/src/components/affix_fuzzer7.cpp @@ -4,18 +4,22 @@ #include "affix_fuzzer7.hpp" #include "../datatypes/affix_fuzzer1.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer7::to_arrow_datatype() { - return arrow::list(arrow::field( + const char* AffixFuzzer7::NAME = "rerun.testing.components.AffixFuzzer7"; + + const std::shared_ptr& AffixFuzzer7::to_arrow_datatype() { + static const auto datatype = arrow::list(arrow::field( "item", rr::datatypes::AffixFuzzer1::to_arrow_datatype(), true, nullptr )); + return datatype; } arrow::Result> AffixFuzzer7::new_arrow_array_builder( @@ -47,5 +51,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer7::to_data_cell( + const AffixFuzzer7* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer7::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer7::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer7::NAME, AffixFuzzer7::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer7::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer7.hpp b/rerun_cpp/src/components/affix_fuzzer7.hpp index 1e9cd32bef9..526e45f1105 100644 --- a/rerun_cpp/src/components/affix_fuzzer7.hpp +++ b/rerun_cpp/src/components/affix_fuzzer7.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/affix_fuzzer1.hpp" #include @@ -16,12 +17,15 @@ namespace rr { struct AffixFuzzer7 { std::optional> many_optional; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer7(std::optional> many_optional) : many_optional(std::move(many_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -32,6 +36,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::ListBuilder* builder, const AffixFuzzer7* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer7 components. + static arrow::Result to_data_cell( + const AffixFuzzer7* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer8.cpp b/rerun_cpp/src/components/affix_fuzzer8.cpp index 2ac5850087c..8e1a0c4d3e2 100644 --- a/rerun_cpp/src/components/affix_fuzzer8.cpp +++ b/rerun_cpp/src/components/affix_fuzzer8.cpp @@ -3,12 +3,17 @@ #include "affix_fuzzer8.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer8::to_arrow_datatype() { - return arrow::float32(); + const char* AffixFuzzer8::NAME = "rerun.testing.components.AffixFuzzer8"; + + const std::shared_ptr& AffixFuzzer8::to_arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; } arrow::Result> AffixFuzzer8::new_arrow_array_builder( @@ -43,5 +48,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer8::to_data_cell( + const AffixFuzzer8* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer8::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer8::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer8::NAME, AffixFuzzer8::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer8::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer8.hpp b/rerun_cpp/src/components/affix_fuzzer8.hpp index 63a0925591f..6d60ef0f712 100644 --- a/rerun_cpp/src/components/affix_fuzzer8.hpp +++ b/rerun_cpp/src/components/affix_fuzzer8.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -13,12 +15,15 @@ namespace rr { struct AffixFuzzer8 { std::optional single_float_optional; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer8(std::optional single_float_optional) : single_float_optional(std::move(single_float_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -29,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::FloatBuilder* builder, const AffixFuzzer8* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer8 components. + static arrow::Result to_data_cell( + const AffixFuzzer8* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer9.cpp b/rerun_cpp/src/components/affix_fuzzer9.cpp index 815fb20a74d..4c56aeb4c33 100644 --- a/rerun_cpp/src/components/affix_fuzzer9.cpp +++ b/rerun_cpp/src/components/affix_fuzzer9.cpp @@ -3,12 +3,17 @@ #include "affix_fuzzer9.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr AffixFuzzer9::to_arrow_datatype() { - return arrow::utf8(); + const char* AffixFuzzer9::NAME = "rerun.testing.components.AffixFuzzer9"; + + const std::shared_ptr& AffixFuzzer9::to_arrow_datatype() { + static const auto datatype = arrow::utf8(); + return datatype; } arrow::Result> AffixFuzzer9::new_arrow_array_builder( @@ -38,5 +43,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result AffixFuzzer9::to_data_cell( + const AffixFuzzer9* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, AffixFuzzer9::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + AffixFuzzer9::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(AffixFuzzer9::NAME, AffixFuzzer9::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = AffixFuzzer9::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/affix_fuzzer9.hpp b/rerun_cpp/src/components/affix_fuzzer9.hpp index c65fb7d5f5a..e2f7c67855e 100644 --- a/rerun_cpp/src/components/affix_fuzzer9.hpp +++ b/rerun_cpp/src/components/affix_fuzzer9.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -13,12 +15,15 @@ namespace rr { struct AffixFuzzer9 { std::string single_string_required; + /// Name of the component, used for serialization. + static const char* NAME; + public: AffixFuzzer9(std::string single_string_required) : single_string_required(std::move(single_string_required)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -29,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StringBuilder* builder, const AffixFuzzer9* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer9 components. + static arrow::Result to_data_cell( + const AffixFuzzer9* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/class_id.cpp b/rerun_cpp/src/components/class_id.cpp index 91e5835cfc5..f2476762545 100644 --- a/rerun_cpp/src/components/class_id.cpp +++ b/rerun_cpp/src/components/class_id.cpp @@ -3,12 +3,17 @@ #include "class_id.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr ClassId::to_arrow_datatype() { - return arrow::uint16(); + const char* ClassId::NAME = "rerun.class_id"; + + const std::shared_ptr& ClassId::to_arrow_datatype() { + static const auto datatype = arrow::uint16(); + return datatype; } arrow::Result> ClassId::new_arrow_array_builder( @@ -36,5 +41,33 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result ClassId::to_data_cell( + const ClassId* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, ClassId::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + ClassId::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = + arrow::schema({arrow::field(ClassId::NAME, ClassId::to_arrow_datatype(), false)}); + + rr::DataCell cell; + cell.component_name = ClassId::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/class_id.hpp b/rerun_cpp/src/components/class_id.hpp index 7836c98f007..ec63ec3307b 100644 --- a/rerun_cpp/src/components/class_id.hpp +++ b/rerun_cpp/src/components/class_id.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -13,11 +15,14 @@ namespace rr { struct ClassId { uint16_t id; + /// Name of the component, used for serialization. + static const char* NAME; + public: ClassId(uint16_t id) : id(std::move(id)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -28,6 +33,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::UInt16Builder* builder, const ClassId* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of ClassId components. + static arrow::Result to_data_cell( + const ClassId* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/color.cpp b/rerun_cpp/src/components/color.cpp index a40b178607e..ce6084a19ac 100644 --- a/rerun_cpp/src/components/color.cpp +++ b/rerun_cpp/src/components/color.cpp @@ -3,12 +3,17 @@ #include "color.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr Color::to_arrow_datatype() { - return arrow::uint32(); + const char* Color::NAME = "rerun.colorrgba"; + + const std::shared_ptr& Color::to_arrow_datatype() { + static const auto datatype = arrow::uint32(); + return datatype; } arrow::Result> Color::new_arrow_array_builder( @@ -36,5 +41,33 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result Color::to_data_cell( + const Color* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, Color::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + Color::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = + arrow::schema({arrow::field(Color::NAME, Color::to_arrow_datatype(), false)}); + + rr::DataCell cell; + cell.component_name = Color::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/color.hpp b/rerun_cpp/src/components/color.hpp index 0210c902283..956c7d5cf00 100644 --- a/rerun_cpp/src/components/color.hpp +++ b/rerun_cpp/src/components/color.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -14,11 +16,14 @@ namespace rr { struct Color { uint32_t rgba; + /// Name of the component, used for serialization. + static const char* NAME; + public: Color(uint32_t rgba) : rgba(std::move(rgba)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -29,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::UInt32Builder* builder, const Color* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of Color components. + static arrow::Result to_data_cell( + const Color* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/disconnected_space.cpp b/rerun_cpp/src/components/disconnected_space.cpp index e637baf4dfa..a02676df0a2 100644 --- a/rerun_cpp/src/components/disconnected_space.cpp +++ b/rerun_cpp/src/components/disconnected_space.cpp @@ -3,16 +3,21 @@ #include "disconnected_space.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr DisconnectedSpace::to_arrow_datatype() { - return arrow::boolean(); + const char *DisconnectedSpace::NAME = "rerun.disconnected_space"; + + const std::shared_ptr &DisconnectedSpace::to_arrow_datatype() { + static const auto datatype = arrow::boolean(); + return datatype; } arrow::Result> - DisconnectedSpace::new_arrow_array_builder(arrow::MemoryPool* memory_pool) { + DisconnectedSpace::new_arrow_array_builder(arrow::MemoryPool *memory_pool) { if (!memory_pool) { return arrow::Status::Invalid("Memory pool is null."); } @@ -21,7 +26,7 @@ namespace rr { } arrow::Status DisconnectedSpace::fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const DisconnectedSpace* elements, size_t num_elements + arrow::BooleanBuilder *builder, const DisconnectedSpace *elements, size_t num_elements ) { if (!builder) { return arrow::Status::Invalid("Passed array builder is null."); @@ -31,9 +36,45 @@ namespace rr { } static_assert(sizeof(*elements) == sizeof(elements->is_disconnected)); - ARROW_RETURN_NOT_OK(builder->AppendValues(&elements->is_disconnected, num_elements)); + ARROW_RETURN_NOT_OK(builder->AppendValues( + reinterpret_cast(&elements->is_disconnected), + num_elements + )); return arrow::Status::OK(); } + + arrow::Result DisconnectedSpace::to_data_cell( + const DisconnectedSpace *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, DisconnectedSpace::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK(DisconnectedSpace::fill_arrow_array_builder( + builder.get(), + instances, + num_instances + )); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema({arrow::field( + DisconnectedSpace::NAME, + DisconnectedSpace::to_arrow_datatype(), + false + )}); + + rr::DataCell cell; + cell.component_name = DisconnectedSpace::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/disconnected_space.hpp b/rerun_cpp/src/components/disconnected_space.hpp index d91b3a00cea..dc40f87908c 100644 --- a/rerun_cpp/src/components/disconnected_space.hpp +++ b/rerun_cpp/src/components/disconnected_space.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -17,11 +19,14 @@ namespace rr { struct DisconnectedSpace { bool is_disconnected; + /// Name of the component, used for serialization. + static const char* NAME; + public: DisconnectedSpace(bool is_disconnected) : is_disconnected(std::move(is_disconnected)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -33,6 +38,11 @@ namespace rr { arrow::BooleanBuilder* builder, const DisconnectedSpace* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of DisconnectedSpace components. + static arrow::Result to_data_cell( + const DisconnectedSpace* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/draw_order.cpp b/rerun_cpp/src/components/draw_order.cpp index fdd4b8d7922..d220f0caf42 100644 --- a/rerun_cpp/src/components/draw_order.cpp +++ b/rerun_cpp/src/components/draw_order.cpp @@ -3,12 +3,17 @@ #include "draw_order.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr DrawOrder::to_arrow_datatype() { - return arrow::float32(); + const char* DrawOrder::NAME = "rerun.draw_order"; + + const std::shared_ptr& DrawOrder::to_arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; } arrow::Result> DrawOrder::new_arrow_array_builder( @@ -36,5 +41,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result DrawOrder::to_data_cell( + const DrawOrder* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, DrawOrder::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + DrawOrder::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = + arrow::schema({arrow::field(DrawOrder::NAME, DrawOrder::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = DrawOrder::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/draw_order.hpp b/rerun_cpp/src/components/draw_order.hpp index 417d4aad965..5be831d3d74 100644 --- a/rerun_cpp/src/components/draw_order.hpp +++ b/rerun_cpp/src/components/draw_order.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -19,11 +21,14 @@ namespace rr { struct DrawOrder { float value; + /// Name of the component, used for serialization. + static const char* NAME; + public: DrawOrder(float value) : value(std::move(value)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -34,6 +39,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::FloatBuilder* builder, const DrawOrder* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of DrawOrder components. + static arrow::Result to_data_cell( + const DrawOrder* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/instance_key.cpp b/rerun_cpp/src/components/instance_key.cpp index 1c428100087..52247445e3f 100644 --- a/rerun_cpp/src/components/instance_key.cpp +++ b/rerun_cpp/src/components/instance_key.cpp @@ -3,12 +3,17 @@ #include "instance_key.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr InstanceKey::to_arrow_datatype() { - return arrow::uint64(); + const char* InstanceKey::NAME = "rerun.instance_key"; + + const std::shared_ptr& InstanceKey::to_arrow_datatype() { + static const auto datatype = arrow::uint64(); + return datatype; } arrow::Result> InstanceKey::new_arrow_array_builder( @@ -36,5 +41,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result InstanceKey::to_data_cell( + const InstanceKey* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, InstanceKey::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + InstanceKey::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(InstanceKey::NAME, InstanceKey::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = InstanceKey::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/instance_key.hpp b/rerun_cpp/src/components/instance_key.hpp index fcae04055fe..e0c21a14cff 100644 --- a/rerun_cpp/src/components/instance_key.hpp +++ b/rerun_cpp/src/components/instance_key.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -13,11 +15,14 @@ namespace rr { struct InstanceKey { uint64_t value; + /// Name of the component, used for serialization. + static const char* NAME; + public: InstanceKey(uint64_t value) : value(std::move(value)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -28,6 +33,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::UInt64Builder* builder, const InstanceKey* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of InstanceKey components. + static arrow::Result to_data_cell( + const InstanceKey* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/keypoint_id.cpp b/rerun_cpp/src/components/keypoint_id.cpp index 6871f498936..32c3ab02bac 100644 --- a/rerun_cpp/src/components/keypoint_id.cpp +++ b/rerun_cpp/src/components/keypoint_id.cpp @@ -3,12 +3,17 @@ #include "keypoint_id.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr KeypointId::to_arrow_datatype() { - return arrow::uint16(); + const char* KeypointId::NAME = "rerun.keypoint_id"; + + const std::shared_ptr& KeypointId::to_arrow_datatype() { + static const auto datatype = arrow::uint16(); + return datatype; } arrow::Result> KeypointId::new_arrow_array_builder( @@ -36,5 +41,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result KeypointId::to_data_cell( + const KeypointId* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, KeypointId::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + KeypointId::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(KeypointId::NAME, KeypointId::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = KeypointId::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/keypoint_id.hpp b/rerun_cpp/src/components/keypoint_id.hpp index ff29000da45..1671ce04e05 100644 --- a/rerun_cpp/src/components/keypoint_id.hpp +++ b/rerun_cpp/src/components/keypoint_id.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -13,11 +15,14 @@ namespace rr { struct KeypointId { uint16_t id; + /// Name of the component, used for serialization. + static const char* NAME; + public: KeypointId(uint16_t id) : id(std::move(id)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -28,6 +33,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::UInt16Builder* builder, const KeypointId* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of KeypointId components. + static arrow::Result to_data_cell( + const KeypointId* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/label.cpp b/rerun_cpp/src/components/label.cpp index f2c1fb409f7..ff265434df4 100644 --- a/rerun_cpp/src/components/label.cpp +++ b/rerun_cpp/src/components/label.cpp @@ -3,12 +3,17 @@ #include "label.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr Label::to_arrow_datatype() { - return arrow::utf8(); + const char* Label::NAME = "rerun.label"; + + const std::shared_ptr& Label::to_arrow_datatype() { + static const auto datatype = arrow::utf8(); + return datatype; } arrow::Result> Label::new_arrow_array_builder( @@ -38,5 +43,33 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result Label::to_data_cell( + const Label* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, Label::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + Label::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = + arrow::schema({arrow::field(Label::NAME, Label::to_arrow_datatype(), false)}); + + rr::DataCell cell; + cell.component_name = Label::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/label.hpp b/rerun_cpp/src/components/label.hpp index 297343f68a6..84156e4e9f0 100644 --- a/rerun_cpp/src/components/label.hpp +++ b/rerun_cpp/src/components/label.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -14,11 +16,14 @@ namespace rr { struct Label { std::string value; + /// Name of the component, used for serialization. + static const char* NAME; + public: Label(std::string value) : value(std::move(value)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -29,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StringBuilder* builder, const Label* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of Label components. + static arrow::Result to_data_cell( + const Label* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/point2d.cpp b/rerun_cpp/src/components/point2d.cpp index d55ee379856..1948f23d7f9 100644 --- a/rerun_cpp/src/components/point2d.cpp +++ b/rerun_cpp/src/components/point2d.cpp @@ -4,13 +4,17 @@ #include "point2d.hpp" #include "../datatypes/point2d.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr Point2D::to_arrow_datatype() { - return rr::datatypes::Point2D::to_arrow_datatype(); + const char *Point2D::NAME = "rerun.point2d"; + + const std::shared_ptr &Point2D::to_arrow_datatype() { + static const auto datatype = rr::datatypes::Point2D::to_arrow_datatype(); + return datatype; } arrow::Result> Point2D::new_arrow_array_builder( @@ -44,5 +48,33 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result Point2D::to_data_cell( + const Point2D *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, Point2D::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + Point2D::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = + arrow::schema({arrow::field(Point2D::NAME, Point2D::to_arrow_datatype(), false)}); + + rr::DataCell cell; + cell.component_name = Point2D::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/point2d.hpp b/rerun_cpp/src/components/point2d.hpp index c729d8478b7..cb3b593943b 100644 --- a/rerun_cpp/src/components/point2d.hpp +++ b/rerun_cpp/src/components/point2d.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/point2d.hpp" #include @@ -15,11 +16,14 @@ namespace rr { struct Point2D { rr::datatypes::Point2D xy; + /// Name of the component, used for serialization. + static const char* NAME; + public: Point2D(rr::datatypes::Point2D xy) : xy(std::move(xy)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const Point2D* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of Point2D components. + static arrow::Result to_data_cell( + const Point2D* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/point3d.cpp b/rerun_cpp/src/components/point3d.cpp index 3566bac48ae..48432c37725 100644 --- a/rerun_cpp/src/components/point3d.cpp +++ b/rerun_cpp/src/components/point3d.cpp @@ -4,13 +4,17 @@ #include "point3d.hpp" #include "../datatypes/point3d.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr Point3D::to_arrow_datatype() { - return rr::datatypes::Point3D::to_arrow_datatype(); + const char *Point3D::NAME = "rerun.point3d"; + + const std::shared_ptr &Point3D::to_arrow_datatype() { + static const auto datatype = rr::datatypes::Point3D::to_arrow_datatype(); + return datatype; } arrow::Result> Point3D::new_arrow_array_builder( @@ -44,5 +48,33 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result Point3D::to_data_cell( + const Point3D *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, Point3D::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + Point3D::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = + arrow::schema({arrow::field(Point3D::NAME, Point3D::to_arrow_datatype(), false)}); + + rr::DataCell cell; + cell.component_name = Point3D::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/point3d.hpp b/rerun_cpp/src/components/point3d.hpp index 72e196ff194..092792dfa0a 100644 --- a/rerun_cpp/src/components/point3d.hpp +++ b/rerun_cpp/src/components/point3d.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/point3d.hpp" #include @@ -15,11 +16,14 @@ namespace rr { struct Point3D { rr::datatypes::Point3D xy; + /// Name of the component, used for serialization. + static const char* NAME; + public: Point3D(rr::datatypes::Point3D xy) : xy(std::move(xy)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -30,6 +34,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::StructBuilder* builder, const Point3D* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of Point3D components. + static arrow::Result to_data_cell( + const Point3D* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/radius.cpp b/rerun_cpp/src/components/radius.cpp index 30980e6119a..fe4902e31a6 100644 --- a/rerun_cpp/src/components/radius.cpp +++ b/rerun_cpp/src/components/radius.cpp @@ -3,12 +3,17 @@ #include "radius.hpp" +#include "../rerun.hpp" + #include namespace rr { namespace components { - std::shared_ptr Radius::to_arrow_datatype() { - return arrow::float32(); + const char* Radius::NAME = "rerun.radius"; + + const std::shared_ptr& Radius::to_arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; } arrow::Result> Radius::new_arrow_array_builder( @@ -36,5 +41,33 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result Radius::to_data_cell( + const Radius* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, Radius::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + Radius::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = + arrow::schema({arrow::field(Radius::NAME, Radius::to_arrow_datatype(), false)}); + + rr::DataCell cell; + cell.component_name = Radius::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/radius.hpp b/rerun_cpp/src/components/radius.hpp index 12841b6c524..df0d3cf509d 100644 --- a/rerun_cpp/src/components/radius.hpp +++ b/rerun_cpp/src/components/radius.hpp @@ -3,6 +3,8 @@ #pragma once +#include "../data_cell.hpp" + #include #include #include @@ -13,11 +15,14 @@ namespace rr { struct Radius { float value; + /// Name of the component, used for serialization. + static const char* NAME; + public: Radius(float value) : value(std::move(value)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -28,6 +33,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::FloatBuilder* builder, const Radius* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of Radius components. + static arrow::Result to_data_cell( + const Radius* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/transform3d.cpp b/rerun_cpp/src/components/transform3d.cpp index 8678683c86a..63faa7e7972 100644 --- a/rerun_cpp/src/components/transform3d.cpp +++ b/rerun_cpp/src/components/transform3d.cpp @@ -4,13 +4,17 @@ #include "transform3d.hpp" #include "../datatypes/transform3d.hpp" +#include "../rerun.hpp" #include namespace rr { namespace components { - std::shared_ptr Transform3D::to_arrow_datatype() { - return rr::datatypes::Transform3D::to_arrow_datatype(); + const char *Transform3D::NAME = "rerun.components.Transform3D"; + + const std::shared_ptr &Transform3D::to_arrow_datatype() { + static const auto datatype = rr::datatypes::Transform3D::to_arrow_datatype(); + return datatype; } arrow::Result> @@ -43,5 +47,34 @@ namespace rr { return arrow::Status::OK(); } + + arrow::Result Transform3D::to_data_cell( + const Transform3D *instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool *pool = arrow::default_memory_pool(); + + ARROW_ASSIGN_OR_RAISE(auto builder, Transform3D::new_arrow_array_builder(pool)); + if (instances && num_instances > 0) { + ARROW_RETURN_NOT_OK( + Transform3D::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); + } + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + auto schema = arrow::schema( + {arrow::field(Transform3D::NAME, Transform3D::to_arrow_datatype(), false)} + ); + + rr::DataCell cell; + cell.component_name = Transform3D::NAME; + ARROW_ASSIGN_OR_RAISE( + cell.buffer, + rr::ipc_from_table(*arrow::Table::Make(schema, {array})) + ); + + return cell; + } } // namespace components } // namespace rr diff --git a/rerun_cpp/src/components/transform3d.hpp b/rerun_cpp/src/components/transform3d.hpp index 0853d1bc7b2..797459098ab 100644 --- a/rerun_cpp/src/components/transform3d.hpp +++ b/rerun_cpp/src/components/transform3d.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../data_cell.hpp" #include "../datatypes/transform3d.hpp" #include @@ -16,11 +17,14 @@ namespace rr { /// Representation of the transform. rr::datatypes::Transform3D repr; + /// Name of the component, used for serialization. + static const char* NAME; + public: Transform3D(rr::datatypes::Transform3D repr) : repr(std::move(repr)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -31,6 +35,11 @@ namespace rr { static arrow::Status fill_arrow_array_builder( arrow::DenseUnionBuilder* builder, const Transform3D* elements, size_t num_elements ); + + /// Creates a Rerun DataCell from an array of Transform3D components. + static arrow::Result to_data_cell( + const Transform3D* instances, size_t num_instances + ); }; } // namespace components } // namespace rr diff --git a/rerun_cpp/src/data_cell.hpp b/rerun_cpp/src/data_cell.hpp new file mode 100644 index 00000000000..330167d938c --- /dev/null +++ b/rerun_cpp/src/data_cell.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include // shared_ptr + +namespace arrow { + class Buffer; +} + +namespace rr { + struct DataCell { + /// Name of the logged component. + const char* component_name; + + /// Data in the Arrow IPC encapsulated message format. + /// + /// There must be exactly one chunk of data. + /// + /// * + /// * + std::shared_ptr buffer; + }; +} // namespace rr diff --git a/rerun_cpp/src/datatypes/affix_fuzzer1.cpp b/rerun_cpp/src/datatypes/affix_fuzzer1.cpp index c5423b18c8b..56fc5782c18 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer1.cpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer1.cpp @@ -9,8 +9,8 @@ namespace rr { namespace datatypes { - std::shared_ptr AffixFuzzer1::to_arrow_datatype() { - return arrow::struct_({ + const std::shared_ptr &AffixFuzzer1::to_arrow_datatype() { + static const auto datatype = arrow::struct_({ arrow::field("single_float_optional", arrow::float32(), true, nullptr), arrow::field("single_string_required", arrow::utf8(), false, nullptr), arrow::field("single_string_optional", arrow::utf8(), true, nullptr), @@ -41,6 +41,7 @@ namespace rr { ), arrow::field("from_parent", arrow::boolean(), true, nullptr), }); + return datatype; } arrow::Result> AffixFuzzer1::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/affix_fuzzer1.hpp b/rerun_cpp/src/datatypes/affix_fuzzer1.hpp index 6626e3314f8..f825484dfff 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer1.hpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer1.hpp @@ -34,7 +34,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/affix_fuzzer2.cpp b/rerun_cpp/src/datatypes/affix_fuzzer2.cpp index 20a26bd384b..7029c0a5fb4 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer2.cpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer2.cpp @@ -7,8 +7,9 @@ namespace rr { namespace datatypes { - std::shared_ptr AffixFuzzer2::to_arrow_datatype() { - return arrow::float32(); + const std::shared_ptr& AffixFuzzer2::to_arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; } arrow::Result> AffixFuzzer2::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/affix_fuzzer2.hpp b/rerun_cpp/src/datatypes/affix_fuzzer2.hpp index b0c9d0ca3dd..a311944a3b4 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer2.hpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer2.hpp @@ -18,7 +18,7 @@ namespace rr { : single_float_optional(std::move(single_float_optional)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/affix_fuzzer3.cpp b/rerun_cpp/src/datatypes/affix_fuzzer3.cpp index d76727c7be3..98677d669a6 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer3.cpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer3.cpp @@ -9,8 +9,8 @@ namespace rr { namespace datatypes { - std::shared_ptr AffixFuzzer3::to_arrow_datatype() { - return arrow::dense_union({ + const std::shared_ptr& AffixFuzzer3::to_arrow_datatype() { + static const auto datatype = arrow::dense_union({ arrow::field("_null_markers", arrow::null(), true, nullptr), arrow::field("degrees", arrow::float32(), false, nullptr), arrow::field("radians", arrow::float32(), false, nullptr), @@ -35,6 +35,7 @@ namespace rr { nullptr ), }); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/affix_fuzzer3.hpp b/rerun_cpp/src/datatypes/affix_fuzzer3.hpp index fd12d4917c9..ff754db95af 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer3.hpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer3.hpp @@ -52,13 +52,24 @@ namespace rr { } // namespace detail struct AffixFuzzer3 { - private: - detail::AffixFuzzer3Tag _tag; - detail::AffixFuzzer3Data _data; + AffixFuzzer3(const AffixFuzzer3& other) : _tag(other._tag) { + switch (other._tag) { + case detail::AffixFuzzer3Tag::craziness: { + _data.craziness = other._data.craziness; + break; + } + default: + memcpy(&this->_data, &other._data, sizeof(detail::AffixFuzzer3Data)); + break; + } + } - AffixFuzzer3() : _tag(detail::AffixFuzzer3Tag::NONE) {} + AffixFuzzer3& operator=(const AffixFuzzer3& other) noexcept { + AffixFuzzer3 tmp(other); + this->swap(tmp); + return *this; + } - public: AffixFuzzer3(AffixFuzzer3&& other) noexcept : _tag(detail::AffixFuzzer3Tag::NONE) { this->swap(other); } @@ -90,6 +101,13 @@ namespace rr { } } + void swap(AffixFuzzer3& other) noexcept { + auto tag_temp = this->_tag; + this->_tag = other._tag; + other._tag = tag_temp; + this->_data.swap(other._data); + } + static AffixFuzzer3 degrees(float degrees) { AffixFuzzer3 self; self._tag = detail::AffixFuzzer3Tag::degrees; @@ -123,7 +141,7 @@ namespace rr { } /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -135,12 +153,13 @@ namespace rr { arrow::DenseUnionBuilder* builder, const AffixFuzzer3* elements, size_t num_elements ); - void swap(AffixFuzzer3& other) noexcept { - auto tag_temp = this->_tag; - this->_tag = other._tag; - other._tag = tag_temp; - this->_data.swap(other._data); - } + private: + detail::AffixFuzzer3Tag _tag; + detail::AffixFuzzer3Data _data; + + AffixFuzzer3() : _tag(detail::AffixFuzzer3Tag::NONE) {} + + public: }; } // namespace datatypes } // namespace rr diff --git a/rerun_cpp/src/datatypes/affix_fuzzer4.cpp b/rerun_cpp/src/datatypes/affix_fuzzer4.cpp index e39e3fbd3a9..bcd5c3a1dd3 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer4.cpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer4.cpp @@ -9,8 +9,8 @@ namespace rr { namespace datatypes { - std::shared_ptr AffixFuzzer4::to_arrow_datatype() { - return arrow::dense_union({ + const std::shared_ptr& AffixFuzzer4::to_arrow_datatype() { + static const auto datatype = arrow::dense_union({ arrow::field("_null_markers", arrow::null(), true, nullptr), arrow::field( "single_required", @@ -41,6 +41,7 @@ namespace rr { nullptr ), }); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/affix_fuzzer4.hpp b/rerun_cpp/src/datatypes/affix_fuzzer4.hpp index 2c1fc11f799..516fce54c65 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer4.hpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer4.hpp @@ -49,13 +49,32 @@ namespace rr { } // namespace detail struct AffixFuzzer4 { - private: - detail::AffixFuzzer4Tag _tag; - detail::AffixFuzzer4Data _data; + AffixFuzzer4(const AffixFuzzer4& other) : _tag(other._tag) { + switch (other._tag) { + case detail::AffixFuzzer4Tag::single_required: { + _data.single_required = other._data.single_required; + break; + } + case detail::AffixFuzzer4Tag::many_required: { + _data.many_required = other._data.many_required; + break; + } + case detail::AffixFuzzer4Tag::many_optional: { + _data.many_optional = other._data.many_optional; + break; + } + default: + memcpy(&this->_data, &other._data, sizeof(detail::AffixFuzzer4Data)); + break; + } + } - AffixFuzzer4() : _tag(detail::AffixFuzzer4Tag::NONE) {} + AffixFuzzer4& operator=(const AffixFuzzer4& other) noexcept { + AffixFuzzer4 tmp(other); + this->swap(tmp); + return *this; + } - public: AffixFuzzer4(AffixFuzzer4&& other) noexcept : _tag(detail::AffixFuzzer4Tag::NONE) { this->swap(other); } @@ -88,6 +107,13 @@ namespace rr { } } + void swap(AffixFuzzer4& other) noexcept { + auto tag_temp = this->_tag; + this->_tag = other._tag; + other._tag = tag_temp; + this->_data.swap(other._data); + } + static AffixFuzzer4 single_required(rr::datatypes::AffixFuzzer3 single_required) { typedef rr::datatypes::AffixFuzzer3 TypeAlias; AffixFuzzer4 self; @@ -116,7 +142,7 @@ namespace rr { } /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -128,12 +154,13 @@ namespace rr { arrow::DenseUnionBuilder* builder, const AffixFuzzer4* elements, size_t num_elements ); - void swap(AffixFuzzer4& other) noexcept { - auto tag_temp = this->_tag; - this->_tag = other._tag; - other._tag = tag_temp; - this->_data.swap(other._data); - } + private: + detail::AffixFuzzer4Tag _tag; + detail::AffixFuzzer4Data _data; + + AffixFuzzer4() : _tag(detail::AffixFuzzer4Tag::NONE) {} + + public: }; } // namespace datatypes } // namespace rr diff --git a/rerun_cpp/src/datatypes/affix_fuzzer5.cpp b/rerun_cpp/src/datatypes/affix_fuzzer5.cpp index bcf69f78142..6024daf25cb 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer5.cpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer5.cpp @@ -9,8 +9,8 @@ namespace rr { namespace datatypes { - std::shared_ptr AffixFuzzer5::to_arrow_datatype() { - return arrow::struct_({ + const std::shared_ptr& AffixFuzzer5::to_arrow_datatype() { + static const auto datatype = arrow::struct_({ arrow::field( "single_optional_union", rr::datatypes::AffixFuzzer4::to_arrow_datatype(), @@ -18,6 +18,7 @@ namespace rr { nullptr ), }); + return datatype; } arrow::Result> AffixFuzzer5::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/affix_fuzzer5.hpp b/rerun_cpp/src/datatypes/affix_fuzzer5.hpp index b68bcf48858..d0269ab142e 100644 --- a/rerun_cpp/src/datatypes/affix_fuzzer5.hpp +++ b/rerun_cpp/src/datatypes/affix_fuzzer5.hpp @@ -20,7 +20,7 @@ namespace rr { : single_optional_union(std::move(single_optional_union)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/angle.cpp b/rerun_cpp/src/datatypes/angle.cpp index 7371cebbc93..7740cd6ff62 100644 --- a/rerun_cpp/src/datatypes/angle.cpp +++ b/rerun_cpp/src/datatypes/angle.cpp @@ -7,12 +7,13 @@ namespace rr { namespace datatypes { - std::shared_ptr Angle::to_arrow_datatype() { - return arrow::dense_union({ + const std::shared_ptr& Angle::to_arrow_datatype() { + static const auto datatype = arrow::dense_union({ arrow::field("_null_markers", arrow::null(), true, nullptr), arrow::field("Radians", arrow::float32(), false, nullptr), arrow::field("Degrees", arrow::float32(), false, nullptr), }); + return datatype; } arrow::Result> Angle::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/angle.hpp b/rerun_cpp/src/datatypes/angle.hpp index 59bf5a92cd6..886a8e855b3 100644 --- a/rerun_cpp/src/datatypes/angle.hpp +++ b/rerun_cpp/src/datatypes/angle.hpp @@ -42,13 +42,16 @@ namespace rr { /// Angle in either radians or degrees. struct Angle { - private: - detail::AngleTag _tag; - detail::AngleData _data; + Angle(const Angle& other) : _tag(other._tag) { + memcpy(&this->_data, &other._data, sizeof(detail::AngleData)); + } - Angle() : _tag(detail::AngleTag::NONE) {} + Angle& operator=(const Angle& other) noexcept { + Angle tmp(other); + this->swap(tmp); + return *this; + } - public: Angle(Angle&& other) noexcept : _tag(detail::AngleTag::NONE) { this->swap(other); } @@ -58,6 +61,13 @@ namespace rr { return *this; } + void swap(Angle& other) noexcept { + auto tag_temp = this->_tag; + this->_tag = other._tag; + other._tag = tag_temp; + this->_data.swap(other._data); + } + static Angle radians(float radians) { Angle self; self._tag = detail::AngleTag::Radians; @@ -73,7 +83,7 @@ namespace rr { } /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -85,12 +95,13 @@ namespace rr { arrow::DenseUnionBuilder* builder, const Angle* elements, size_t num_elements ); - void swap(Angle& other) noexcept { - auto tag_temp = this->_tag; - this->_tag = other._tag; - other._tag = tag_temp; - this->_data.swap(other._data); - } + private: + detail::AngleTag _tag; + detail::AngleData _data; + + Angle() : _tag(detail::AngleTag::NONE) {} + + public: }; } // namespace datatypes } // namespace rr diff --git a/rerun_cpp/src/datatypes/flattened_scalar.cpp b/rerun_cpp/src/datatypes/flattened_scalar.cpp index 1fa7c7b7e03..bf00038de0b 100644 --- a/rerun_cpp/src/datatypes/flattened_scalar.cpp +++ b/rerun_cpp/src/datatypes/flattened_scalar.cpp @@ -7,10 +7,11 @@ namespace rr { namespace datatypes { - std::shared_ptr FlattenedScalar::to_arrow_datatype() { - return arrow::struct_({ + const std::shared_ptr &FlattenedScalar::to_arrow_datatype() { + static const auto datatype = arrow::struct_({ arrow::field("value", arrow::float32(), false, nullptr), }); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/flattened_scalar.hpp b/rerun_cpp/src/datatypes/flattened_scalar.hpp index 6dcd047a807..d51ad905ea3 100644 --- a/rerun_cpp/src/datatypes/flattened_scalar.hpp +++ b/rerun_cpp/src/datatypes/flattened_scalar.hpp @@ -16,7 +16,7 @@ namespace rr { FlattenedScalar(float value) : value(std::move(value)) {} /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/mat3x3.cpp b/rerun_cpp/src/datatypes/mat3x3.cpp index 4ef61f62651..02df0d149ce 100644 --- a/rerun_cpp/src/datatypes/mat3x3.cpp +++ b/rerun_cpp/src/datatypes/mat3x3.cpp @@ -7,11 +7,10 @@ namespace rr { namespace datatypes { - std::shared_ptr Mat3x3::to_arrow_datatype() { - return arrow::fixed_size_list( - arrow::field("item", arrow::float32(), false, nullptr), - 9 - ); + const std::shared_ptr &Mat3x3::to_arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false, nullptr), 9); + return datatype; } arrow::Result> Mat3x3::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/mat3x3.hpp b/rerun_cpp/src/datatypes/mat3x3.hpp index bc3ecee4913..03f32b8c7b0 100644 --- a/rerun_cpp/src/datatypes/mat3x3.hpp +++ b/rerun_cpp/src/datatypes/mat3x3.hpp @@ -14,7 +14,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> diff --git a/rerun_cpp/src/datatypes/mat4x4.cpp b/rerun_cpp/src/datatypes/mat4x4.cpp index 7d8454e3b43..38d8feccd50 100644 --- a/rerun_cpp/src/datatypes/mat4x4.cpp +++ b/rerun_cpp/src/datatypes/mat4x4.cpp @@ -7,11 +7,10 @@ namespace rr { namespace datatypes { - std::shared_ptr Mat4x4::to_arrow_datatype() { - return arrow::fixed_size_list( - arrow::field("item", arrow::float32(), false, nullptr), - 16 - ); + const std::shared_ptr &Mat4x4::to_arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false, nullptr), 16); + return datatype; } arrow::Result> Mat4x4::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/mat4x4.hpp b/rerun_cpp/src/datatypes/mat4x4.hpp index 43519801a0b..fed98466f10 100644 --- a/rerun_cpp/src/datatypes/mat4x4.hpp +++ b/rerun_cpp/src/datatypes/mat4x4.hpp @@ -14,7 +14,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> diff --git a/rerun_cpp/src/datatypes/point2d.cpp b/rerun_cpp/src/datatypes/point2d.cpp index 2835da471d5..3e81e0c2284 100644 --- a/rerun_cpp/src/datatypes/point2d.cpp +++ b/rerun_cpp/src/datatypes/point2d.cpp @@ -7,11 +7,12 @@ namespace rr { namespace datatypes { - std::shared_ptr Point2D::to_arrow_datatype() { - return arrow::struct_({ + const std::shared_ptr &Point2D::to_arrow_datatype() { + static const auto datatype = arrow::struct_({ arrow::field("x", arrow::float32(), false, nullptr), arrow::field("y", arrow::float32(), false, nullptr), }); + return datatype; } arrow::Result> Point2D::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/point2d.hpp b/rerun_cpp/src/datatypes/point2d.hpp index 0cf76ab2062..9d0dad73790 100644 --- a/rerun_cpp/src/datatypes/point2d.hpp +++ b/rerun_cpp/src/datatypes/point2d.hpp @@ -16,7 +16,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/point3d.cpp b/rerun_cpp/src/datatypes/point3d.cpp index bc24c2203cc..0113aac4e61 100644 --- a/rerun_cpp/src/datatypes/point3d.cpp +++ b/rerun_cpp/src/datatypes/point3d.cpp @@ -7,12 +7,13 @@ namespace rr { namespace datatypes { - std::shared_ptr Point3D::to_arrow_datatype() { - return arrow::struct_({ + const std::shared_ptr &Point3D::to_arrow_datatype() { + static const auto datatype = arrow::struct_({ arrow::field("x", arrow::float32(), false, nullptr), arrow::field("y", arrow::float32(), false, nullptr), arrow::field("z", arrow::float32(), false, nullptr), }); + return datatype; } arrow::Result> Point3D::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/point3d.hpp b/rerun_cpp/src/datatypes/point3d.hpp index 437c60ed84e..f3ff8d46fe7 100644 --- a/rerun_cpp/src/datatypes/point3d.hpp +++ b/rerun_cpp/src/datatypes/point3d.hpp @@ -18,7 +18,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/quaternion.cpp b/rerun_cpp/src/datatypes/quaternion.cpp index 6f2f7bd2d39..208cd362c98 100644 --- a/rerun_cpp/src/datatypes/quaternion.cpp +++ b/rerun_cpp/src/datatypes/quaternion.cpp @@ -7,11 +7,10 @@ namespace rr { namespace datatypes { - std::shared_ptr Quaternion::to_arrow_datatype() { - return arrow::fixed_size_list( - arrow::field("item", arrow::float32(), false, nullptr), - 4 - ); + const std::shared_ptr &Quaternion::to_arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false, nullptr), 4); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/quaternion.hpp b/rerun_cpp/src/datatypes/quaternion.hpp index 40a4587ec56..8c903173c79 100644 --- a/rerun_cpp/src/datatypes/quaternion.hpp +++ b/rerun_cpp/src/datatypes/quaternion.hpp @@ -14,7 +14,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> diff --git a/rerun_cpp/src/datatypes/rotation3d.cpp b/rerun_cpp/src/datatypes/rotation3d.cpp index 86980103a74..a0db3d9b446 100644 --- a/rerun_cpp/src/datatypes/rotation3d.cpp +++ b/rerun_cpp/src/datatypes/rotation3d.cpp @@ -10,8 +10,8 @@ namespace rr { namespace datatypes { - std::shared_ptr Rotation3D::to_arrow_datatype() { - return arrow::dense_union({ + const std::shared_ptr& Rotation3D::to_arrow_datatype() { + static const auto datatype = arrow::dense_union({ arrow::field("_null_markers", arrow::null(), true, nullptr), arrow::field( "Quaternion", @@ -26,6 +26,7 @@ namespace rr { nullptr ), }); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/rotation3d.hpp b/rerun_cpp/src/datatypes/rotation3d.hpp index 1852cdbdac8..f2ca517b5d3 100644 --- a/rerun_cpp/src/datatypes/rotation3d.hpp +++ b/rerun_cpp/src/datatypes/rotation3d.hpp @@ -47,13 +47,16 @@ namespace rr { /// A 3D rotation. struct Rotation3D { - private: - detail::Rotation3DTag _tag; - detail::Rotation3DData _data; + Rotation3D(const Rotation3D& other) : _tag(other._tag) { + memcpy(&this->_data, &other._data, sizeof(detail::Rotation3DData)); + } - Rotation3D() : _tag(detail::Rotation3DTag::NONE) {} + Rotation3D& operator=(const Rotation3D& other) noexcept { + Rotation3D tmp(other); + this->swap(tmp); + return *this; + } - public: Rotation3D(Rotation3D&& other) noexcept : _tag(detail::Rotation3DTag::NONE) { this->swap(other); } @@ -63,6 +66,13 @@ namespace rr { return *this; } + void swap(Rotation3D& other) noexcept { + auto tag_temp = this->_tag; + this->_tag = other._tag; + other._tag = tag_temp; + this->_data.swap(other._data); + } + /// Rotation defined by a quaternion. static Rotation3D quaternion(rr::datatypes::Quaternion quaternion) { Rotation3D self; @@ -90,7 +100,7 @@ namespace rr { } /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -102,12 +112,13 @@ namespace rr { arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements ); - void swap(Rotation3D& other) noexcept { - auto tag_temp = this->_tag; - this->_tag = other._tag; - other._tag = tag_temp; - this->_data.swap(other._data); - } + private: + detail::Rotation3DTag _tag; + detail::Rotation3DData _data; + + Rotation3D() : _tag(detail::Rotation3DTag::NONE) {} + + public: }; } // namespace datatypes } // namespace rr diff --git a/rerun_cpp/src/datatypes/rotation_axis_angle.cpp b/rerun_cpp/src/datatypes/rotation_axis_angle.cpp index f46caad3761..5972f267c9f 100644 --- a/rerun_cpp/src/datatypes/rotation_axis_angle.cpp +++ b/rerun_cpp/src/datatypes/rotation_axis_angle.cpp @@ -10,11 +10,12 @@ namespace rr { namespace datatypes { - std::shared_ptr RotationAxisAngle::to_arrow_datatype() { - return arrow::struct_({ + const std::shared_ptr& RotationAxisAngle::to_arrow_datatype() { + static const auto datatype = arrow::struct_({ arrow::field("axis", rr::datatypes::Vec3D::to_arrow_datatype(), false, nullptr), arrow::field("angle", rr::datatypes::Angle::to_arrow_datatype(), false, nullptr), }); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/rotation_axis_angle.hpp b/rerun_cpp/src/datatypes/rotation_axis_angle.hpp index b80e9870e57..4942a616e8f 100644 --- a/rerun_cpp/src/datatypes/rotation_axis_angle.hpp +++ b/rerun_cpp/src/datatypes/rotation_axis_angle.hpp @@ -25,7 +25,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/scale3d.cpp b/rerun_cpp/src/datatypes/scale3d.cpp index 0c839ea1189..d924ce9a329 100644 --- a/rerun_cpp/src/datatypes/scale3d.cpp +++ b/rerun_cpp/src/datatypes/scale3d.cpp @@ -9,12 +9,13 @@ namespace rr { namespace datatypes { - std::shared_ptr Scale3D::to_arrow_datatype() { - return arrow::dense_union({ + const std::shared_ptr& Scale3D::to_arrow_datatype() { + static const auto datatype = arrow::dense_union({ arrow::field("_null_markers", arrow::null(), true, nullptr), arrow::field("ThreeD", rr::datatypes::Vec3D::to_arrow_datatype(), false, nullptr), arrow::field("Uniform", arrow::float32(), false, nullptr), }); + return datatype; } arrow::Result> Scale3D::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/scale3d.hpp b/rerun_cpp/src/datatypes/scale3d.hpp index d18ba6f6c01..569c4c22376 100644 --- a/rerun_cpp/src/datatypes/scale3d.hpp +++ b/rerun_cpp/src/datatypes/scale3d.hpp @@ -46,13 +46,16 @@ namespace rr { /// 3D scaling factor, part of a transform representation. struct Scale3D { - private: - detail::Scale3DTag _tag; - detail::Scale3DData _data; + Scale3D(const Scale3D& other) : _tag(other._tag) { + memcpy(&this->_data, &other._data, sizeof(detail::Scale3DData)); + } - Scale3D() : _tag(detail::Scale3DTag::NONE) {} + Scale3D& operator=(const Scale3D& other) noexcept { + Scale3D tmp(other); + this->swap(tmp); + return *this; + } - public: Scale3D(Scale3D&& other) noexcept : _tag(detail::Scale3DTag::NONE) { this->swap(other); } @@ -62,6 +65,13 @@ namespace rr { return *this; } + void swap(Scale3D& other) noexcept { + auto tag_temp = this->_tag; + this->_tag = other._tag; + other._tag = tag_temp; + this->_data.swap(other._data); + } + /// Individual scaling factors for each axis, distorting the original object. static Scale3D three_d(rr::datatypes::Vec3D three_d) { Scale3D self; @@ -89,7 +99,7 @@ namespace rr { } /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -101,12 +111,13 @@ namespace rr { arrow::DenseUnionBuilder* builder, const Scale3D* elements, size_t num_elements ); - void swap(Scale3D& other) noexcept { - auto tag_temp = this->_tag; - this->_tag = other._tag; - other._tag = tag_temp; - this->_data.swap(other._data); - } + private: + detail::Scale3DTag _tag; + detail::Scale3DData _data; + + Scale3D() : _tag(detail::Scale3DTag::NONE) {} + + public: }; } // namespace datatypes } // namespace rr diff --git a/rerun_cpp/src/datatypes/transform3d.cpp b/rerun_cpp/src/datatypes/transform3d.cpp index 4943990e83d..08c6ef2f9b0 100644 --- a/rerun_cpp/src/datatypes/transform3d.cpp +++ b/rerun_cpp/src/datatypes/transform3d.cpp @@ -10,8 +10,8 @@ namespace rr { namespace datatypes { - std::shared_ptr Transform3D::to_arrow_datatype() { - return arrow::dense_union({ + const std::shared_ptr& Transform3D::to_arrow_datatype() { + static const auto datatype = arrow::dense_union({ arrow::field("_null_markers", arrow::null(), true, nullptr), arrow::field( "TranslationAndMat3x3", @@ -26,6 +26,7 @@ namespace rr { nullptr ), }); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/transform3d.hpp b/rerun_cpp/src/datatypes/transform3d.hpp index 302e366b116..646d0e69e92 100644 --- a/rerun_cpp/src/datatypes/transform3d.hpp +++ b/rerun_cpp/src/datatypes/transform3d.hpp @@ -45,13 +45,16 @@ namespace rr { /// Representation of a 3D affine transform. struct Transform3D { - private: - detail::Transform3DTag _tag; - detail::Transform3DData _data; + Transform3D(const Transform3D& other) : _tag(other._tag) { + memcpy(&this->_data, &other._data, sizeof(detail::Transform3DData)); + } - Transform3D() : _tag(detail::Transform3DTag::NONE) {} + Transform3D& operator=(const Transform3D& other) noexcept { + Transform3D tmp(other); + this->swap(tmp); + return *this; + } - public: Transform3D(Transform3D&& other) noexcept : _tag(detail::Transform3DTag::NONE) { this->swap(other); } @@ -61,6 +64,13 @@ namespace rr { return *this; } + void swap(Transform3D& other) noexcept { + auto tag_temp = this->_tag; + this->_tag = other._tag; + other._tag = tag_temp; + this->_data.swap(other._data); + } + static Transform3D translation_and_mat3x3( rr::datatypes::TranslationAndMat3x3 translation_and_mat3x3 ) { @@ -89,7 +99,7 @@ namespace rr { } /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( @@ -101,12 +111,13 @@ namespace rr { arrow::DenseUnionBuilder* builder, const Transform3D* elements, size_t num_elements ); - void swap(Transform3D& other) noexcept { - auto tag_temp = this->_tag; - this->_tag = other._tag; - other._tag = tag_temp; - this->_data.swap(other._data); - } + private: + detail::Transform3DTag _tag; + detail::Transform3DData _data; + + Transform3D() : _tag(detail::Transform3DTag::NONE) {} + + public: }; } // namespace datatypes } // namespace rr diff --git a/rerun_cpp/src/datatypes/translation_and_mat3x3.cpp b/rerun_cpp/src/datatypes/translation_and_mat3x3.cpp index 31b8eee2c8a..a384f52f9b4 100644 --- a/rerun_cpp/src/datatypes/translation_and_mat3x3.cpp +++ b/rerun_cpp/src/datatypes/translation_and_mat3x3.cpp @@ -10,8 +10,8 @@ namespace rr { namespace datatypes { - std::shared_ptr TranslationAndMat3x3::to_arrow_datatype() { - return arrow::struct_({ + const std::shared_ptr &TranslationAndMat3x3::to_arrow_datatype() { + static const auto datatype = arrow::struct_({ arrow::field( "translation", rr::datatypes::Vec3D::to_arrow_datatype(), @@ -21,6 +21,7 @@ namespace rr { arrow::field("matrix", rr::datatypes::Mat3x3::to_arrow_datatype(), true, nullptr), arrow::field("from_parent", arrow::boolean(), false, nullptr), }); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/translation_and_mat3x3.hpp b/rerun_cpp/src/datatypes/translation_and_mat3x3.hpp index 0abf367df8d..7b9c7f19857 100644 --- a/rerun_cpp/src/datatypes/translation_and_mat3x3.hpp +++ b/rerun_cpp/src/datatypes/translation_and_mat3x3.hpp @@ -28,7 +28,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/translation_rotation_scale3d.cpp b/rerun_cpp/src/datatypes/translation_rotation_scale3d.cpp index 3ba54c30e62..d15742fc5b5 100644 --- a/rerun_cpp/src/datatypes/translation_rotation_scale3d.cpp +++ b/rerun_cpp/src/datatypes/translation_rotation_scale3d.cpp @@ -11,8 +11,8 @@ namespace rr { namespace datatypes { - std::shared_ptr TranslationRotationScale3D::to_arrow_datatype() { - return arrow::struct_({ + const std::shared_ptr &TranslationRotationScale3D::to_arrow_datatype() { + static const auto datatype = arrow::struct_({ arrow::field( "translation", rr::datatypes::Vec3D::to_arrow_datatype(), @@ -28,6 +28,7 @@ namespace rr { arrow::field("scale", rr::datatypes::Scale3D::to_arrow_datatype(), true, nullptr), arrow::field("from_parent", arrow::boolean(), false, nullptr), }); + return datatype; } arrow::Result> diff --git a/rerun_cpp/src/datatypes/translation_rotation_scale3d.hpp b/rerun_cpp/src/datatypes/translation_rotation_scale3d.hpp index 8a8e11cadca..82b9c213493 100644 --- a/rerun_cpp/src/datatypes/translation_rotation_scale3d.hpp +++ b/rerun_cpp/src/datatypes/translation_rotation_scale3d.hpp @@ -30,7 +30,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/vec2d.cpp b/rerun_cpp/src/datatypes/vec2d.cpp index 7af078821fd..630df827dcb 100644 --- a/rerun_cpp/src/datatypes/vec2d.cpp +++ b/rerun_cpp/src/datatypes/vec2d.cpp @@ -7,11 +7,10 @@ namespace rr { namespace datatypes { - std::shared_ptr Vec2D::to_arrow_datatype() { - return arrow::fixed_size_list( - arrow::field("item", arrow::float32(), false, nullptr), - 2 - ); + const std::shared_ptr &Vec2D::to_arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false, nullptr), 2); + return datatype; } arrow::Result> Vec2D::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/vec2d.hpp b/rerun_cpp/src/datatypes/vec2d.hpp index 6f3438d3024..56c4e55fef5 100644 --- a/rerun_cpp/src/datatypes/vec2d.hpp +++ b/rerun_cpp/src/datatypes/vec2d.hpp @@ -14,7 +14,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> diff --git a/rerun_cpp/src/datatypes/vec3d.cpp b/rerun_cpp/src/datatypes/vec3d.cpp index be277e71829..4fc5c61f6ac 100644 --- a/rerun_cpp/src/datatypes/vec3d.cpp +++ b/rerun_cpp/src/datatypes/vec3d.cpp @@ -7,11 +7,10 @@ namespace rr { namespace datatypes { - std::shared_ptr Vec3D::to_arrow_datatype() { - return arrow::fixed_size_list( - arrow::field("item", arrow::float32(), false, nullptr), - 3 - ); + const std::shared_ptr &Vec3D::to_arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false, nullptr), 3); + return datatype; } arrow::Result> Vec3D::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/vec3d.hpp b/rerun_cpp/src/datatypes/vec3d.hpp index 92bd757db95..a8404536970 100644 --- a/rerun_cpp/src/datatypes/vec3d.hpp +++ b/rerun_cpp/src/datatypes/vec3d.hpp @@ -14,7 +14,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> diff --git a/rerun_cpp/src/datatypes/vec4d.cpp b/rerun_cpp/src/datatypes/vec4d.cpp index dff32d481cf..42ad8433ce2 100644 --- a/rerun_cpp/src/datatypes/vec4d.cpp +++ b/rerun_cpp/src/datatypes/vec4d.cpp @@ -7,11 +7,10 @@ namespace rr { namespace datatypes { - std::shared_ptr Vec4D::to_arrow_datatype() { - return arrow::fixed_size_list( - arrow::field("item", arrow::float32(), false, nullptr), - 4 - ); + const std::shared_ptr &Vec4D::to_arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false, nullptr), 4); + return datatype; } arrow::Result> Vec4D::new_arrow_array_builder( diff --git a/rerun_cpp/src/datatypes/vec4d.hpp b/rerun_cpp/src/datatypes/vec4d.hpp index 7ab3e76a228..f8b8dec3a12 100644 --- a/rerun_cpp/src/datatypes/vec4d.hpp +++ b/rerun_cpp/src/datatypes/vec4d.hpp @@ -14,7 +14,7 @@ namespace rr { public: /// Returns the arrow data type this type corresponds to. - static std::shared_ptr to_arrow_datatype(); + static const std::shared_ptr& to_arrow_datatype(); /// Creates a new array builder with an array of this type. static arrow::Result> diff --git a/rerun_cpp/src/recording_stream.cpp b/rerun_cpp/src/recording_stream.cpp index 74b40c0c41d..f072b58c3f2 100644 --- a/rerun_cpp/src/recording_stream.cpp +++ b/rerun_cpp/src/recording_stream.cpp @@ -1,7 +1,9 @@ #include "recording_stream.hpp" -#include +#include "data_cell.hpp" +#include "rerun.h" +#include #include #include @@ -50,8 +52,8 @@ namespace rr { for (size_t i = 0; i < num_data_cells; ++i) { c_data_cells.push_back({ .component_name = data_cells[i].component_name, - .num_bytes = data_cells[i].num_bytes, - .bytes = data_cells[i].bytes, + .num_bytes = static_cast(data_cells[i].buffer->size()), + .bytes = data_cells[i].buffer->data(), }); } diff --git a/rerun_cpp/src/recording_stream.hpp b/rerun_cpp/src/recording_stream.hpp index 30262b4f2d5..12732e3e933 100644 --- a/rerun_cpp/src/recording_stream.hpp +++ b/rerun_cpp/src/recording_stream.hpp @@ -2,19 +2,18 @@ #include // size_t #include // uint32_t etc +#include + +#include "data_cell.hpp" namespace rr { + struct DataCell; + enum StoreKind { Recording, Blueprint, }; - struct DataCell { - const char* component_name; - size_t num_bytes; - const uint8_t* bytes; - }; - class RecordingStream { public: RecordingStream( @@ -29,7 +28,43 @@ namespace rr { /// Aborts if `init_global` has not yet been called. static RecordingStream global(); - /// Logs raw data row to the recording stream. + /// Logs an archetype. + /// + /// Prefer this interface for ease of use over the more general `log_components` interface. + template + void log_archetype(const char* entity_path, const T& archetype) { + // TODO(andreas): Handle splats. + // TODO(andreas): Error handling. + const auto data_cells = archetype.to_data_cells().ValueOrDie(); + log_data_row( + entity_path, + archetype.num_instances(), + data_cells.size(), + data_cells.data() + ); + } + + /// Logs a list of component arrays. + /// + /// This forms the "medium level API", for easy to use high level api, prefer `log` to log + /// built-in archetypes. + /// + /// Expects component arrays as std::vector, std::array or C arrays. + /// + /// TODO(andreas): More documentation, examples etc. + template + void log_components(const char* entity_path, const Ts&... component_array) { + // TODO(andreas): Handle splats. + const size_t num_instances = size_of_first_collection(component_array...); + + std::vector data_cells; + data_cells.reserve(sizeof...(Ts)); + push_data_cells(data_cells, component_array...); + + log_data_row(entity_path, num_instances, data_cells.size(), data_cells.data()); + } + + /// Low level API that logs raw data cells to the recording stream. /// /// I.e. logs a number of components arrays (each with a same number of instances) to a /// single entity path. @@ -39,6 +74,53 @@ namespace rr { ); private: + template + static size_t size_of_first_collection(const std::vector& first, const Ts&... ts) { + return first.size(); + } + + template + static size_t size_of_first_collection(const std::array& first, const Ts&... ts) { + return first.size(); + } + + template + static size_t size_of_first_collection(const C (&first)[N], const Ts&... ts) { + return N; + } + + template + static void push_data_cells( + std::vector& data_cells, const std::vector& first, const Ts&... rest + ) { + // TODO(andreas): Error handling. + const auto cell = C::to_data_cell(first.data(), first.size()).ValueOrDie(); + data_cells.push_back(cell); + push_data_cells(data_cells, rest...); + } + + template + static void push_data_cells( + std::vector& data_cells, const std::array& first, const Ts&... rest + ) { + // TODO(andreas): Error handling. + const auto cell = C::to_data_cell(first.data(), N).ValueOrDie(); + data_cells.push_back(cell); + push_data_cells(data_cells, rest...); + } + + template + static void push_data_cells( + std::vector& data_cells, const C (&first)[N], const Ts&... rest + ) { + // TODO(andreas): Error handling. + const auto cell = C::to_data_cell(first, N).ValueOrDie(); + data_cells.push_back(cell); + push_data_cells(data_cells, rest...); + } + + static void push_data_cells(std::vector& data_cells) {} + RecordingStream() : _id{0} {} RecordingStream(uint32_t id) : _id{id} {} diff --git a/rerun_cpp/src/rerun.cpp b/rerun_cpp/src/rerun.cpp index 0136925b479..cf5f282bcf7 100644 --- a/rerun_cpp/src/rerun.cpp +++ b/rerun_cpp/src/rerun.cpp @@ -14,29 +14,6 @@ namespace rr { // ------------------------------------------------------------------------ - arrow::Result> points3(size_t num_points, const float* xyz) { - arrow::MemoryPool* pool = arrow::default_memory_pool(); - - auto nullable = false; - - ARROW_ASSIGN_OR_RAISE(auto builder, rr::components::Point3D::new_arrow_array_builder(pool)); - ARROW_RETURN_NOT_OK(rr::components::Point3D::fill_arrow_array_builder( - builder.get(), - (rr::components::Point3D*)xyz, - num_points - )); - - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); - - auto name = "points"; // Unused, but should be the name of the field in the archetype - auto schema = arrow::schema( - {arrow::field(name, rr::components::Point3D::to_arrow_datatype(), nullable)} - ); - - return arrow::Table::Make(schema, {array}); - } - arrow::Result> ipc_from_table(const arrow::Table& table) { ERROR_CONTEXT("ipc_from_table", ""); ARROW_ASSIGN_OR_RAISE(auto output, arrow::io::BufferOutputStream::Create()); diff --git a/rerun_cpp/src/rerun.hpp b/rerun_cpp/src/rerun.hpp index a8e8c27a99c..d3fbf4eadf3 100644 --- a/rerun_cpp/src/rerun.hpp +++ b/rerun_cpp/src/rerun.hpp @@ -20,8 +20,6 @@ namespace rr { #include namespace rr { - arrow::Result> points3(size_t num_points, const float* xyz); - /// Encode the given arrow table in the Arrow IPC encapsulated message format. /// /// *