From dcdde90f6d14c88031f72791ef0982e5d9b7d56c Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Mon, 13 Nov 2023 12:53:35 +0100 Subject: [PATCH] C++ use nested namespaces for less right shift (#4213) ### What Changes codegen to use C++17 [nested namespaces](https://en.cppreference.com/w/cpp/language/namespace). ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/4213) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4213) - [Docs preview](https://rerun.io/preview/81288b0897c92c019187ad36de00df5d0764747a/docs) - [Examples preview](https://rerun.io/preview/81288b0897c92c019187ad36de00df5d0764747a/examples) - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/) --- .../re_types_builder/src/codegen/cpp/mod.rs | 202 ++-- .../rerun/archetypes/annotation_context.cpp | 9 +- .../rerun/archetypes/annotation_context.hpp | 132 +-- rerun_cpp/src/rerun/archetypes/arrows3d.cpp | 7 +- rerun_cpp/src/rerun/archetypes/arrows3d.hpp | 285 +++--- rerun_cpp/src/rerun/archetypes/asset3d.cpp | 7 +- rerun_cpp/src/rerun/archetypes/asset3d.hpp | 223 +++-- rerun_cpp/src/rerun/archetypes/bar_chart.cpp | 7 +- rerun_cpp/src/rerun/archetypes/bar_chart.hpp | 316 +++--- rerun_cpp/src/rerun/archetypes/boxes2d.cpp | 7 +- rerun_cpp/src/rerun/archetypes/boxes2d.hpp | 339 ++++--- rerun_cpp/src/rerun/archetypes/boxes3d.cpp | 7 +- rerun_cpp/src/rerun/archetypes/boxes3d.hpp | 359 ++++--- rerun_cpp/src/rerun/archetypes/clear.cpp | 7 +- rerun_cpp/src/rerun/archetypes/clear.hpp | 161 ++- .../src/rerun/archetypes/depth_image.cpp | 7 +- .../src/rerun/archetypes/depth_image.hpp | 218 ++-- .../rerun/archetypes/disconnected_space.cpp | 9 +- .../rerun/archetypes/disconnected_space.hpp | 94 +- rerun_cpp/src/rerun/archetypes/image.cpp | 7 +- rerun_cpp/src/rerun/archetypes/image.hpp | 170 ++-- .../src/rerun/archetypes/line_strips2d.cpp | 8 +- .../src/rerun/archetypes/line_strips2d.hpp | 244 ++--- .../src/rerun/archetypes/line_strips3d.cpp | 8 +- .../src/rerun/archetypes/line_strips3d.hpp | 240 ++--- rerun_cpp/src/rerun/archetypes/mesh3d.cpp | 7 +- rerun_cpp/src/rerun/archetypes/mesh3d.hpp | 259 +++-- rerun_cpp/src/rerun/archetypes/pinhole.cpp | 7 +- rerun_cpp/src/rerun/archetypes/pinhole.hpp | 346 +++---- rerun_cpp/src/rerun/archetypes/points2d.cpp | 7 +- rerun_cpp/src/rerun/archetypes/points2d.hpp | 316 +++--- rerun_cpp/src/rerun/archetypes/points3d.cpp | 7 +- rerun_cpp/src/rerun/archetypes/points3d.hpp | 286 +++--- .../rerun/archetypes/segmentation_image.cpp | 9 +- .../rerun/archetypes/segmentation_image.hpp | 182 ++-- rerun_cpp/src/rerun/archetypes/tensor.cpp | 7 +- rerun_cpp/src/rerun/archetypes/tensor.hpp | 134 +-- .../src/rerun/archetypes/text_document.cpp | 8 +- .../src/rerun/archetypes/text_document.hpp | 190 ++-- rerun_cpp/src/rerun/archetypes/text_log.cpp | 7 +- rerun_cpp/src/rerun/archetypes/text_log.hpp | 198 ++-- .../rerun/archetypes/time_series_scalar.cpp | 9 +- .../rerun/archetypes/time_series_scalar.hpp | 285 +++--- .../src/rerun/archetypes/transform3d.cpp | 8 +- .../src/rerun/archetypes/transform3d.hpp | 428 ++++---- .../src/rerun/archetypes/view_coordinates.cpp | 9 +- .../src/rerun/archetypes/view_coordinates.hpp | 231 +++-- .../src/rerun/blueprint/auto_space_views.cpp | 71 +- .../src/rerun/blueprint/auto_space_views.hpp | 64 +- rerun_cpp/src/rerun/blueprint/panel_view.cpp | 91 +- rerun_cpp/src/rerun/blueprint/panel_view.hpp | 64 +- .../rerun/blueprint/space_view_component.cpp | 120 ++- .../rerun/blueprint/space_view_component.hpp | 66 +- .../rerun/blueprint/space_view_maximized.cpp | 99 +- .../rerun/blueprint/space_view_maximized.hpp | 64 +- .../src/rerun/blueprint/viewport_layout.cpp | 179 ++-- .../src/rerun/blueprint/viewport_layout.hpp | 64 +- .../rerun/components/annotation_context.cpp | 144 ++- .../rerun/components/annotation_context.hpp | 98 +- rerun_cpp/src/rerun/components/blob.cpp | 118 ++- rerun_cpp/src/rerun/components/blob.hpp | 74 +- rerun_cpp/src/rerun/components/class_id.cpp | 107 +- rerun_cpp/src/rerun/components/class_id.hpp | 98 +- .../rerun/components/clear_is_recursive.cpp | 113 +-- .../rerun/components/clear_is_recursive.hpp | 79 +- rerun_cpp/src/rerun/components/color.cpp | 103 +- rerun_cpp/src/rerun/components/color.hpp | 148 ++- .../src/rerun/components/depth_meter.cpp | 107 +- .../src/rerun/components/depth_meter.hpp | 76 +- .../rerun/components/disconnected_space.cpp | 113 +-- .../rerun/components/disconnected_space.hpp | 87 +- rerun_cpp/src/rerun/components/draw_order.cpp | 107 +- rerun_cpp/src/rerun/components/draw_order.hpp | 72 +- .../src/rerun/components/half_sizes2d.cpp | 113 +-- .../src/rerun/components/half_sizes2d.hpp | 135 ++- .../src/rerun/components/half_sizes3d.cpp | 113 +-- .../src/rerun/components/half_sizes3d.hpp | 143 ++- .../src/rerun/components/instance_key.cpp | 107 +- .../src/rerun/components/instance_key.hpp | 76 +- .../src/rerun/components/keypoint_id.cpp | 113 +-- .../src/rerun/components/keypoint_id.hpp | 100 +- .../src/rerun/components/line_strip2d.cpp | 134 ++- .../src/rerun/components/line_strip2d.hpp | 99 +- .../src/rerun/components/line_strip3d.cpp | 134 ++- .../src/rerun/components/line_strip3d.hpp | 99 +- rerun_cpp/src/rerun/components/material.cpp | 113 +-- rerun_cpp/src/rerun/components/material.hpp | 116 ++- rerun_cpp/src/rerun/components/media_type.cpp | 113 +-- rerun_cpp/src/rerun/components/media_type.hpp | 188 ++-- .../src/rerun/components/mesh_properties.cpp | 115 +-- .../src/rerun/components/mesh_properties.hpp | 116 ++- .../components/out_of_tree_transform3d.cpp | 118 ++- .../components/out_of_tree_transform3d.hpp | 76 +- .../rerun/components/pinhole_projection.cpp | 115 +-- .../rerun/components/pinhole_projection.hpp | 141 ++- rerun_cpp/src/rerun/components/position2d.cpp | 113 +-- rerun_cpp/src/rerun/components/position2d.hpp | 129 ++- rerun_cpp/src/rerun/components/position3d.cpp | 113 +-- rerun_cpp/src/rerun/components/position3d.hpp | 137 ++- rerun_cpp/src/rerun/components/radius.cpp | 101 +- rerun_cpp/src/rerun/components/radius.hpp | 74 +- rerun_cpp/src/rerun/components/resolution.cpp | 113 +-- rerun_cpp/src/rerun/components/resolution.hpp | 129 ++- rerun_cpp/src/rerun/components/rotation3d.cpp | 113 +-- rerun_cpp/src/rerun/components/rotation3d.hpp | 110 +- rerun_cpp/src/rerun/components/scalar.cpp | 101 +- rerun_cpp/src/rerun/components/scalar.hpp | 78 +- .../rerun/components/scalar_scattering.cpp | 113 +-- .../rerun/components/scalar_scattering.hpp | 77 +- .../src/rerun/components/tensor_data.cpp | 113 +-- .../src/rerun/components/tensor_data.hpp | 106 +- rerun_cpp/src/rerun/components/text.cpp | 102 +- rerun_cpp/src/rerun/components/text.hpp | 118 ++- .../src/rerun/components/text_log_level.cpp | 113 +-- .../src/rerun/components/text_log_level.hpp | 172 ++-- .../src/rerun/components/transform3d.cpp | 112 +-- .../src/rerun/components/transform3d.hpp | 88 +- rerun_cpp/src/rerun/components/vector3d.cpp | 113 +-- rerun_cpp/src/rerun/components/vector3d.hpp | 142 ++- .../src/rerun/components/view_coordinates.cpp | 129 ++- .../src/rerun/components/view_coordinates.hpp | 276 +++--- rerun_cpp/src/rerun/datatypes/angle.cpp | 127 ++- rerun_cpp/src/rerun/datatypes/angle.hpp | 214 ++-- .../src/rerun/datatypes/annotation_info.cpp | 153 ++- .../src/rerun/datatypes/annotation_info.hpp | 90 +- .../src/rerun/datatypes/class_description.cpp | 199 ++-- .../src/rerun/datatypes/class_description.hpp | 92 +- .../datatypes/class_description_map_elem.cpp | 129 ++- .../datatypes/class_description_map_elem.hpp | 74 +- rerun_cpp/src/rerun/datatypes/class_id.cpp | 66 +- rerun_cpp/src/rerun/datatypes/class_id.hpp | 60 +- rerun_cpp/src/rerun/datatypes/float32.cpp | 67 +- rerun_cpp/src/rerun/datatypes/float32.hpp | 60 +- rerun_cpp/src/rerun/datatypes/keypoint_id.cpp | 66 +- rerun_cpp/src/rerun/datatypes/keypoint_id.hpp | 60 +- .../src/rerun/datatypes/keypoint_pair.cpp | 121 ++- .../src/rerun/datatypes/keypoint_pair.hpp | 72 +- rerun_cpp/src/rerun/datatypes/mat3x3.cpp | 91 +- rerun_cpp/src/rerun/datatypes/mat3x3.hpp | 126 ++- rerun_cpp/src/rerun/datatypes/mat4x4.cpp | 91 +- rerun_cpp/src/rerun/datatypes/mat4x4.hpp | 156 ++- rerun_cpp/src/rerun/datatypes/material.cpp | 105 +- rerun_cpp/src/rerun/datatypes/material.hpp | 78 +- .../src/rerun/datatypes/mesh_properties.cpp | 126 ++- .../src/rerun/datatypes/mesh_properties.hpp | 68 +- rerun_cpp/src/rerun/datatypes/quaternion.cpp | 91 +- rerun_cpp/src/rerun/datatypes/quaternion.hpp | 159 ++- rerun_cpp/src/rerun/datatypes/rgba32.cpp | 67 +- rerun_cpp/src/rerun/datatypes/rgba32.hpp | 124 ++- rerun_cpp/src/rerun/datatypes/rotation3d.cpp | 149 ++- rerun_cpp/src/rerun/datatypes/rotation3d.hpp | 251 +++-- .../rerun/datatypes/rotation_axis_angle.cpp | 124 ++- .../rerun/datatypes/rotation_axis_angle.hpp | 74 +- rerun_cpp/src/rerun/datatypes/scale3d.cpp | 135 ++- rerun_cpp/src/rerun/datatypes/scale3d.hpp | 240 +++-- .../src/rerun/datatypes/tensor_buffer.cpp | 543 +++++----- .../src/rerun/datatypes/tensor_buffer.hpp | 938 +++++++++--------- rerun_cpp/src/rerun/datatypes/tensor_data.cpp | 154 ++- rerun_cpp/src/rerun/datatypes/tensor_data.hpp | 84 +- .../src/rerun/datatypes/tensor_dimension.cpp | 113 +-- .../src/rerun/datatypes/tensor_dimension.hpp | 73 +- rerun_cpp/src/rerun/datatypes/transform3d.cpp | 172 ++-- rerun_cpp/src/rerun/datatypes/transform3d.hpp | 248 +++-- .../datatypes/translation_and_mat3x3.cpp | 157 ++- .../datatypes/translation_and_mat3x3.hpp | 137 ++- .../translation_rotation_scale3d.cpp | 189 ++-- .../translation_rotation_scale3d.hpp | 387 ++++---- rerun_cpp/src/rerun/datatypes/uint32.cpp | 67 +- rerun_cpp/src/rerun/datatypes/uint32.hpp | 60 +- rerun_cpp/src/rerun/datatypes/utf8.cpp | 67 +- rerun_cpp/src/rerun/datatypes/utf8.hpp | 80 +- rerun_cpp/src/rerun/datatypes/uvec2d.cpp | 91 +- rerun_cpp/src/rerun/datatypes/uvec2d.hpp | 60 +- rerun_cpp/src/rerun/datatypes/uvec3d.cpp | 91 +- rerun_cpp/src/rerun/datatypes/uvec3d.hpp | 60 +- rerun_cpp/src/rerun/datatypes/uvec4d.cpp | 91 +- rerun_cpp/src/rerun/datatypes/uvec4d.hpp | 60 +- rerun_cpp/src/rerun/datatypes/vec2d.cpp | 91 +- rerun_cpp/src/rerun/datatypes/vec2d.hpp | 94 +- rerun_cpp/src/rerun/datatypes/vec3d.cpp | 91 +- rerun_cpp/src/rerun/datatypes/vec3d.hpp | 102 +- rerun_cpp/src/rerun/datatypes/vec4d.cpp | 91 +- rerun_cpp/src/rerun/datatypes/vec4d.hpp | 110 +- .../generated/archetypes/affix_fuzzer1.cpp | 9 +- .../generated/archetypes/affix_fuzzer1.hpp | 154 ++- .../generated/archetypes/affix_fuzzer2.cpp | 9 +- .../generated/archetypes/affix_fuzzer2.hpp | 186 ++-- .../generated/archetypes/affix_fuzzer3.cpp | 9 +- .../generated/archetypes/affix_fuzzer3.hpp | 284 +++--- .../generated/archetypes/affix_fuzzer4.cpp | 9 +- .../generated/archetypes/affix_fuzzer4.hpp | 320 +++--- .../generated/components/affix_fuzzer1.cpp | 112 +-- .../generated/components/affix_fuzzer1.hpp | 86 +- .../generated/components/affix_fuzzer10.cpp | 115 +-- .../generated/components/affix_fuzzer10.hpp | 76 +- .../generated/components/affix_fuzzer11.cpp | 135 ++- .../generated/components/affix_fuzzer11.hpp | 76 +- .../generated/components/affix_fuzzer12.cpp | 127 ++- .../generated/components/affix_fuzzer12.hpp | 76 +- .../generated/components/affix_fuzzer13.cpp | 135 ++- .../generated/components/affix_fuzzer13.hpp | 77 +- .../generated/components/affix_fuzzer14.cpp | 112 +-- .../generated/components/affix_fuzzer14.hpp | 87 +- .../generated/components/affix_fuzzer15.cpp | 112 +-- .../generated/components/affix_fuzzer15.hpp | 73 +- .../generated/components/affix_fuzzer16.cpp | 135 ++- .../generated/components/affix_fuzzer16.hpp | 79 +- .../generated/components/affix_fuzzer17.cpp | 141 ++- .../generated/components/affix_fuzzer17.hpp | 84 +- .../generated/components/affix_fuzzer18.cpp | 141 ++- .../generated/components/affix_fuzzer18.hpp | 84 +- .../generated/components/affix_fuzzer19.cpp | 112 +-- .../generated/components/affix_fuzzer19.hpp | 106 +- .../generated/components/affix_fuzzer2.cpp | 112 +-- .../generated/components/affix_fuzzer2.hpp | 86 +- .../generated/components/affix_fuzzer20.cpp | 113 +-- .../generated/components/affix_fuzzer20.hpp | 86 +- .../generated/components/affix_fuzzer21.cpp | 113 +-- .../generated/components/affix_fuzzer21.hpp | 86 +- .../generated/components/affix_fuzzer3.cpp | 112 +-- .../generated/components/affix_fuzzer3.hpp | 86 +- .../generated/components/affix_fuzzer4.cpp | 112 +-- .../generated/components/affix_fuzzer4.hpp | 87 +- .../generated/components/affix_fuzzer5.cpp | 112 +-- .../generated/components/affix_fuzzer5.hpp | 87 +- .../generated/components/affix_fuzzer6.cpp | 112 +-- .../generated/components/affix_fuzzer6.hpp | 87 +- .../generated/components/affix_fuzzer7.cpp | 141 ++- .../generated/components/affix_fuzzer7.hpp | 80 +- .../generated/components/affix_fuzzer8.cpp | 115 +-- .../generated/components/affix_fuzzer8.hpp | 76 +- .../generated/components/affix_fuzzer9.cpp | 107 +- .../generated/components/affix_fuzzer9.hpp | 76 +- .../generated/datatypes/affix_fuzzer1.cpp | 363 ++++--- .../generated/datatypes/affix_fuzzer1.hpp | 52 +- .../generated/datatypes/affix_fuzzer2.cpp | 75 +- .../generated/datatypes/affix_fuzzer2.hpp | 60 +- .../generated/datatypes/affix_fuzzer20.cpp | 122 ++- .../generated/datatypes/affix_fuzzer20.hpp | 48 +- .../generated/datatypes/affix_fuzzer21.cpp | 142 ++- .../generated/datatypes/affix_fuzzer21.hpp | 48 +- .../generated/datatypes/affix_fuzzer3.cpp | 215 ++-- .../generated/datatypes/affix_fuzzer3.hpp | 347 ++++--- .../generated/datatypes/affix_fuzzer4.cpp | 209 ++-- .../generated/datatypes/affix_fuzzer4.hpp | 326 +++--- .../generated/datatypes/affix_fuzzer5.cpp | 114 +-- .../generated/datatypes/affix_fuzzer5.hpp | 63 +- .../generated/datatypes/flattened_scalar.cpp | 91 +- .../generated/datatypes/flattened_scalar.hpp | 58 +- .../datatypes/primitive_component.cpp | 67 +- .../datatypes/primitive_component.hpp | 59 +- .../generated/datatypes/string_component.cpp | 67 +- .../generated/datatypes/string_component.hpp | 58 +- 253 files changed, 14750 insertions(+), 15688 deletions(-) diff --git a/crates/re_types_builder/src/codegen/cpp/mod.rs b/crates/re_types_builder/src/codegen/cpp/mod.rs index cd5a1628512e..2f9ad5efdaaa 100644 --- a/crates/re_types_builder/src/codegen/cpp/mod.rs +++ b/crates/re_types_builder/src/codegen/cpp/mod.rs @@ -492,28 +492,26 @@ impl QuotedObject { let hpp = quote! { #hpp_includes - namespace rerun { - namespace archetypes { - #quoted_docs - struct #type_ident { - #(#field_declarations;)* + namespace rerun::archetypes { + #quoted_docs + struct #type_ident { + #(#field_declarations;)* - #(#constants_hpp;)* + #(#constants_hpp;)* - #NEWLINE_TOKEN - #indicator_comment - using IndicatorComponent = components::IndicatorComponent; + #NEWLINE_TOKEN + #indicator_comment + using IndicatorComponent = components::IndicatorComponent; - #hpp_type_extensions + #hpp_type_extensions - #hpp_method_section - }; - #NEWLINE_TOKEN - #NEWLINE_TOKEN - } + #hpp_method_section + }; #NEWLINE_TOKEN #NEWLINE_TOKEN + } + namespace rerun { // Instead of including as_components.hpp, simply re-declare the template since it's trivial #doc_hide_comment template @@ -533,12 +531,13 @@ impl QuotedObject { let cpp = quote! { #cpp_includes - namespace rerun { - namespace archetypes { - #(#constants_cpp;)* + namespace rerun::archetypes { + #(#constants_cpp;)* - #(#methods_cpp)* - } + #(#methods_cpp)* + } + + namespace rerun { #NEWLINE_TOKEN #NEWLINE_TOKEN #serialize_cpp @@ -663,19 +662,17 @@ impl QuotedObject { #hpp_declarations - namespace rerun { - namespace #namespace_ident { - #quoted_docs - struct #type_ident { - #(#field_declarations;)* + namespace rerun::#namespace_ident { + #quoted_docs + struct #type_ident { + #(#field_declarations;)* - #(#constants_hpp;)* + #(#constants_hpp;)* - #hpp_type_extensions + #hpp_type_extensions - #hpp_method_section - }; - } + #hpp_method_section + }; } }; @@ -685,12 +682,10 @@ impl QuotedObject { let cpp = quote! { #cpp_includes - namespace rerun { - namespace #namespace_ident { - #(#constants_cpp;)* + namespace rerun::#namespace_ident { + #(#constants_cpp;)* - #(#methods_cpp)* - } + #(#methods_cpp)* } }; @@ -1002,86 +997,83 @@ impl QuotedObject { #hpp_declarations - namespace rerun { - namespace #namespace_ident { - namespace detail { - #hide_from_docs_comment - enum class #tag_typename : uint8_t { - #(#tag_fields)* - }; - - #hide_from_docs_comment - union #data_typename { - #(#enum_data_declarations;)* - - // Required by static constructors - #data_typename() { - std::memset(reinterpret_cast(this), 0, sizeof(#data_typename)); - } - ~#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 - char temp[sizeof(#data_typename)]; - void* otherbytes = reinterpret_cast(&other); - void* thisbytes = reinterpret_cast(this); - std::memcpy(temp, thisbytes, sizeof(#data_typename)); - std::memcpy(thisbytes, otherbytes, sizeof(#data_typename)); - std::memcpy(otherbytes, temp, sizeof(#data_typename)); - } - }; - - } + namespace rerun::#namespace_ident { + namespace detail { + #hide_from_docs_comment + enum class #tag_typename : uint8_t { + #(#tag_fields)* + }; - #quoted_docs - struct #pascal_case_ident { - #(#constants_hpp;)* + #hide_from_docs_comment + union #data_typename { + #(#enum_data_declarations;)* - #pascal_case_ident() : _tag(detail::#tag_typename::None) {} + // Required by static constructors + #data_typename() { + std::memset(reinterpret_cast(this), 0, sizeof(#data_typename)); + } + ~#data_typename() { } - #copy_constructor + // Note that this type is *not* copyable unless all enum fields are trivially destructable. - // Copy-assignment - #pascal_case_ident& operator=(const #pascal_case_ident& other) noexcept { - #pascal_case_ident tmp(other); - this->swap(tmp); - return *this; + void swap(#data_typename& other) noexcept { + #NEWLINE_TOKEN + #swap_comment + char temp[sizeof(#data_typename)]; + void* otherbytes = reinterpret_cast(&other); + void* thisbytes = reinterpret_cast(this); + std::memcpy(temp, thisbytes, sizeof(#data_typename)); + std::memcpy(thisbytes, otherbytes, sizeof(#data_typename)); + std::memcpy(otherbytes, temp, sizeof(#data_typename)); } + }; + } - // Move-constructor: - #pascal_case_ident(#pascal_case_ident&& other) noexcept : #pascal_case_ident() { - this->swap(other); - } + #quoted_docs + struct #pascal_case_ident { + #(#constants_hpp;)* - // Move-assignment: - #pascal_case_ident& operator=(#pascal_case_ident&& other) noexcept { - this->swap(other); - return *this; - } + #pascal_case_ident() : _tag(detail::#tag_typename::None) {} - #destructor + #copy_constructor - #hpp_type_extensions + // Copy-assignment + #pascal_case_ident& operator=(const #pascal_case_ident& other) noexcept { + #pascal_case_ident tmp(other); + this->swap(tmp); + return *this; + } - // This is useful for easily implementing the move constructor and assignment operators: - void swap(#pascal_case_ident& other) noexcept { - // Swap tags: Not using std::swap here causes a warning for some gcc version about potentially uninitialized data. - std::swap(this->_tag, other._tag); + // Move-constructor: + #pascal_case_ident(#pascal_case_ident&& other) noexcept : #pascal_case_ident() { + this->swap(other); + } - // Swap data: - this->_data.swap(other._data); - } + // Move-assignment: + #pascal_case_ident& operator=(#pascal_case_ident&& other) noexcept { + this->swap(other); + return *this; + } - #(#methods_hpp)* + #destructor - private: - detail::#tag_typename _tag; - detail::#data_typename _data; - }; - } + #hpp_type_extensions + + // This is useful for easily implementing the move constructor and assignment operators: + void swap(#pascal_case_ident& other) noexcept { + // Swap tags: Not using std::swap here causes a warning for some gcc version about potentially uninitialized data. + std::swap(this->_tag, other._tag); + + // Swap data: + this->_data.swap(other._data); + } + + #(#methods_hpp)* + + private: + detail::#tag_typename _tag; + detail::#data_typename _data; + }; } }; @@ -1093,10 +1085,8 @@ impl QuotedObject { #(#constants_cpp;)* - namespace rerun { - namespace #namespace_ident { - #(#cpp_methods)* - } + namespace rerun::#namespace_ident { + #(#cpp_methods)* } }; diff --git a/rerun_cpp/src/rerun/archetypes/annotation_context.cpp b/rerun_cpp/src/rerun/archetypes/annotation_context.cpp index 4d1a90a18f25..c71a2c9c77d8 100644 --- a/rerun_cpp/src/rerun/archetypes/annotation_context.cpp +++ b/rerun_cpp/src/rerun/archetypes/annotation_context.cpp @@ -5,11 +5,12 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char AnnotationContext::INDICATOR_COMPONENT_NAME[] = + "rerun.components.AnnotationContextIndicator"; +} + namespace rerun { - namespace archetypes { - const char AnnotationContext::INDICATOR_COMPONENT_NAME[] = - "rerun.components.AnnotationContextIndicator"; - } Result> AsComponents< archetypes::AnnotationContext>::serialize(const archetypes::AnnotationContext& archetype) { diff --git a/rerun_cpp/src/rerun/archetypes/annotation_context.hpp b/rerun_cpp/src/rerun/archetypes/annotation_context.hpp index 456917688ae3..9648fd96f15f 100644 --- a/rerun_cpp/src/rerun/archetypes/annotation_context.hpp +++ b/rerun_cpp/src/rerun/archetypes/annotation_context.hpp @@ -13,78 +13,78 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: The `AnnotationContext` provides additional information on how to display entities. - /// - /// Entities can use `ClassId`s and `KeypointId`s to provide annotations, and - /// the labels and colors will be looked up in the appropriate - /// `AnnotationContext`. We use the *first* annotation context we find in the - /// path-hierarchy when searching up through the ancestors of a given entity - /// path. - /// - /// ## Example - /// - /// ### Segmentation - /// ![image](https://static.rerun.io/annotation_context_segmentation/0e21c0a04e456fec41d16b0deaa12c00cddf2d9b/full.png) - /// - /// ```cpp - /// #include - /// - /// #include // fill_n - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_annotation_context_connections"); - /// rec.spawn().exit_on_failure(); - /// - /// // create an annotation context to describe the classes - /// rec.log_timeless( - /// "segmentation", - /// rerun::AnnotationContext({ - /// rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)), - /// rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)), - /// }) - /// ); - /// - /// // create a segmentation image - /// const int HEIGHT = 200; - /// const int WIDTH = 300; - /// std::vector data(WIDTH * HEIGHT, 0); - /// for (auto y = 50; y <100; ++y) { - /// std::fill_n(data.begin() + y * WIDTH + 50, 70, static_cast(1)); - /// } - /// for (auto y = 100; y <180; ++y) { - /// std::fill_n(data.begin() + y * WIDTH + 130, 150, static_cast(2)); - /// } - /// - /// rec.log("segmentation/image", rerun::SegmentationImage({HEIGHT, WIDTH}, std::move(data))); - /// } - /// ``` - struct AnnotationContext { - /// List of class descriptions, mapping class indices to class names, colors etc. - rerun::components::AnnotationContext context; +namespace rerun::archetypes { + /// **Archetype**: The `AnnotationContext` provides additional information on how to display entities. + /// + /// Entities can use `ClassId`s and `KeypointId`s to provide annotations, and + /// the labels and colors will be looked up in the appropriate + /// `AnnotationContext`. We use the *first* annotation context we find in the + /// path-hierarchy when searching up through the ancestors of a given entity + /// path. + /// + /// ## Example + /// + /// ### Segmentation + /// ![image](https://static.rerun.io/annotation_context_segmentation/0e21c0a04e456fec41d16b0deaa12c00cddf2d9b/full.png) + /// + /// ```cpp + /// #include + /// + /// #include // fill_n + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_annotation_context_connections"); + /// rec.spawn().exit_on_failure(); + /// + /// // create an annotation context to describe the classes + /// rec.log_timeless( + /// "segmentation", + /// rerun::AnnotationContext({ + /// rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)), + /// rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)), + /// }) + /// ); + /// + /// // create a segmentation image + /// const int HEIGHT = 200; + /// const int WIDTH = 300; + /// std::vector data(WIDTH * HEIGHT, 0); + /// for (auto y = 50; y <100; ++y) { + /// std::fill_n(data.begin() + y * WIDTH + 50, 70, static_cast(1)); + /// } + /// for (auto y = 100; y <180; ++y) { + /// std::fill_n(data.begin() + y * WIDTH + 130, 150, static_cast(2)); + /// } + /// + /// rec.log("segmentation/image", rerun::SegmentationImage({HEIGHT, WIDTH}, std::move(data))); + /// } + /// ``` + struct AnnotationContext { + /// List of class descriptions, mapping class indices to class names, colors etc. + rerun::components::AnnotationContext context; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - AnnotationContext() = default; - AnnotationContext(AnnotationContext&& other) = default; + public: + AnnotationContext() = default; + AnnotationContext(AnnotationContext&& other) = default; - explicit AnnotationContext(rerun::components::AnnotationContext _context) - : context(std::move(_context)) {} + explicit AnnotationContext(rerun::components::AnnotationContext _context) + : context(std::move(_context)) {} - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/arrows3d.cpp b/rerun_cpp/src/rerun/archetypes/arrows3d.cpp index e07afb49df10..5d041010912d 100644 --- a/rerun_cpp/src/rerun/archetypes/arrows3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/arrows3d.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Arrows3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Arrows3DIndicator"; +} + namespace rerun { - namespace archetypes { - const char Arrows3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Arrows3DIndicator"; - } Result> AsComponents::serialize( const archetypes::Arrows3D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/arrows3d.hpp b/rerun_cpp/src/rerun/archetypes/arrows3d.hpp index 5fc4493814b0..c35f7b87f176 100644 --- a/rerun_cpp/src/rerun/archetypes/arrows3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/arrows3d.hpp @@ -21,156 +21,155 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: 3D arrows with optional colors, radii, labels, etc. - /// - /// ## Example - /// - /// ### Simple batch of 3D Arrows - /// ![image](https://static.rerun.io/arrow3d_simple/55e2f794a520bbf7527d7b828b0264732146c5d0/full.png) - /// - /// ```cpp - /// #include - /// - /// #include - /// #include +namespace rerun::archetypes { + /// **Archetype**: 3D arrows with optional colors, radii, labels, etc. + /// + /// ## Example + /// + /// ### Simple batch of 3D Arrows + /// ![image](https://static.rerun.io/arrow3d_simple/55e2f794a520bbf7527d7b828b0264732146c5d0/full.png) + /// + /// ```cpp + /// #include + /// + /// #include + /// #include + /// + /// constexpr float TAU = 6.28318530717958647692528676655900577f; + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_arrow3d"); + /// rec.spawn().exit_on_failure(); + /// + /// std::vector origins; + /// std::vector vectors; + /// std::vector colors; + /// + /// for (int i = 0; i <100; ++i) { + /// origins.push_back({0, 0, 0}); + /// + /// float angle = TAU * static_cast(i) * 0.01f; + /// float length = log2f(static_cast(i + 1)); + /// vectors.push_back({length * sinf(angle), 0.0, length * cosf(angle)}); + /// + /// uint8_t c = static_cast(round(angle / TAU * 255.0f)); + /// colors.push_back({static_cast(255 - c), c, 128, 128}); + /// } + /// + /// rec.log( + /// "arrows", + /// rerun::Arrows3D::from_vectors(vectors).with_origins(origins).with_colors(colors) + /// ); + /// } + /// ``` + struct Arrows3D { + /// All the vectors for each arrow in the batch. + ComponentBatch vectors; + + /// All the origin (base) positions for each arrow in the batch. /// - /// constexpr float TAU = 6.28318530717958647692528676655900577f; - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_arrow3d"); - /// rec.spawn().exit_on_failure(); + /// If no origins are set, (0, 0, 0) is used as the origin for each arrow. + std::optional> origins; + + /// Optional radii for the arrows. /// - /// std::vector origins; - /// std::vector vectors; - /// std::vector colors; + /// The shaft is rendered as a line with `radius = 0.5 * radius`. + /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`. + std::optional> radii; + + /// Optional colors for the points. + std::optional> colors; + + /// Optional text labels for the arrows. + std::optional> labels; + + /// Optional class Ids for the points. /// - /// for (int i = 0; i <100; ++i) { - /// origins.push_back({0, 0, 0}); + /// The class ID provides colors and labels if not specified explicitly. + std::optional> class_ids; + + /// Unique identifiers for each individual point in the batch. + std::optional> instance_keys; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + // Extensions to generated type defined in 'arrows3d_ext.cpp' + + /// Creates new 3D arrows pointing in the given directions, with a base at the origin (0, 0, + /// 0). + static Arrows3D from_vectors(ComponentBatch vectors_) { + Arrows3D arrows; + arrows.vectors = std::move(vectors_); + return arrows; + } + + public: + Arrows3D() = default; + Arrows3D(Arrows3D&& other) = default; + + /// All the origin (base) positions for each arrow in the batch. /// - /// float angle = TAU * static_cast(i) * 0.01f; - /// float length = log2f(static_cast(i + 1)); - /// vectors.push_back({length * sinf(angle), 0.0, length * cosf(angle)}); + /// If no origins are set, (0, 0, 0) is used as the origin for each arrow. + Arrows3D with_origins(ComponentBatch _origins) && { + origins = std::move(_origins); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional radii for the arrows. /// - /// uint8_t c = static_cast(round(angle / TAU * 255.0f)); - /// colors.push_back({static_cast(255 - c), c, 128, 128}); - /// } + /// The shaft is rendered as a line with `radius = 0.5 * radius`. + /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`. + Arrows3D with_radii(ComponentBatch _radii) && { + radii = std::move(_radii); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional colors for the points. + Arrows3D with_colors(ComponentBatch _colors) && { + colors = std::move(_colors); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional text labels for the arrows. + Arrows3D with_labels(ComponentBatch _labels) && { + labels = std::move(_labels); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional class Ids for the points. /// - /// rec.log( - /// "arrows", - /// rerun::Arrows3D::from_vectors(vectors).with_origins(origins).with_colors(colors) - /// ); - /// } - /// ``` - struct Arrows3D { - /// All the vectors for each arrow in the batch. - ComponentBatch vectors; - - /// All the origin (base) positions for each arrow in the batch. - /// - /// If no origins are set, (0, 0, 0) is used as the origin for each arrow. - std::optional> origins; - - /// Optional radii for the arrows. - /// - /// The shaft is rendered as a line with `radius = 0.5 * radius`. - /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`. - std::optional> radii; - - /// Optional colors for the points. - std::optional> colors; - - /// Optional text labels for the arrows. - std::optional> labels; - - /// Optional class Ids for the points. - /// - /// The class ID provides colors and labels if not specified explicitly. - std::optional> class_ids; - - /// Unique identifiers for each individual point in the batch. - std::optional> instance_keys; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - // Extensions to generated type defined in 'arrows3d_ext.cpp' - - /// Creates new 3D arrows pointing in the given directions, with a base at the origin (0, 0, - /// 0). - static Arrows3D from_vectors(ComponentBatch vectors_) { - Arrows3D arrows; - arrows.vectors = std::move(vectors_); - return arrows; - } - - public: - Arrows3D() = default; - Arrows3D(Arrows3D&& other) = default; - - /// All the origin (base) positions for each arrow in the batch. - /// - /// If no origins are set, (0, 0, 0) is used as the origin for each arrow. - Arrows3D with_origins(ComponentBatch _origins) && { - origins = std::move(_origins); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional radii for the arrows. - /// - /// The shaft is rendered as a line with `radius = 0.5 * radius`. - /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`. - Arrows3D with_radii(ComponentBatch _radii) && { - radii = std::move(_radii); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional colors for the points. - Arrows3D with_colors(ComponentBatch _colors) && { - colors = std::move(_colors); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional text labels for the arrows. - Arrows3D with_labels(ComponentBatch _labels) && { - labels = std::move(_labels); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional class Ids for the points. - /// - /// The class ID provides colors and labels if not specified explicitly. - Arrows3D with_class_ids(ComponentBatch _class_ids) && { - class_ids = std::move(_class_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Unique identifiers for each individual point in the batch. - Arrows3D with_instance_keys( - ComponentBatch _instance_keys - ) && { - instance_keys = std::move(_instance_keys); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return vectors.size(); - } - }; - - } // namespace archetypes + /// The class ID provides colors and labels if not specified explicitly. + Arrows3D with_class_ids(ComponentBatch _class_ids) && { + class_ids = std::move(_class_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Unique identifiers for each individual point in the batch. + Arrows3D with_instance_keys(ComponentBatch _instance_keys + ) && { + instance_keys = std::move(_instance_keys); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return vectors.size(); + } + }; +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/asset3d.cpp b/rerun_cpp/src/rerun/archetypes/asset3d.cpp index 0675c92e3f73..9739f395dbca 100644 --- a/rerun_cpp/src/rerun/archetypes/asset3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/asset3d.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Asset3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Asset3DIndicator"; +} + namespace rerun { - namespace archetypes { - const char Asset3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Asset3DIndicator"; - } Result> AsComponents::serialize( const archetypes::Asset3D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/asset3d.hpp b/rerun_cpp/src/rerun/archetypes/asset3d.hpp index d1847d2d1bb0..9d6ee57cced6 100644 --- a/rerun_cpp/src/rerun/archetypes/asset3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/asset3d.hpp @@ -18,127 +18,126 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A prepacked 3D asset (`.gltf`, `.glb`, `.obj`, etc.). +namespace rerun::archetypes { + /// **Archetype**: A prepacked 3D asset (`.gltf`, `.glb`, `.obj`, etc.). + /// + /// ## Example + /// + /// ### Simple 3D asset + /// ![image](https://static.rerun.io/asset3d_simple/af238578188d3fd0de3e330212120e2842a8ddb2/full.png) + /// + /// ```cpp + /// #include + /// + /// #include + /// #include + /// #include + /// + /// int main(int argc, char* argv[]) { + /// if (argc <2) { + /// std::cerr <<"Usage: " <" < media_type; + + /// An out-of-tree transform. /// - /// ### Simple 3D asset - /// ![image](https://static.rerun.io/asset3d_simple/af238578188d3fd0de3e330212120e2842a8ddb2/full.png) + /// Applies a transformation to the asset itself without impacting its children. + std::optional transform; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + // Extensions to generated type defined in 'asset3d_ext.cpp' + + static std::optional guess_media_type( + const std::filesystem::path& path + ); + + /// Creates a new `Asset3D` from the file contents at `path`. /// - /// ```cpp - /// #include + /// The `MediaType` will be guessed from the file extension. /// - /// #include - /// #include - /// #include + /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one + /// from the data at render-time. If it can't, rendering will fail with an error. + static Result from_file(const std::filesystem::path& path); + + /// Creates a new `Asset3D` from the given `bytes`. /// - /// int main(int argc, char* argv[]) { - /// if (argc <2) { - /// std::cerr <<"Usage: " <" < bytes, std::optional media_type + ) { + // TODO(cmc): we could try and guess using magic bytes here, like rust does. + Asset3D asset = Asset3D(bytes); + asset.media_type = media_type; + return asset; + } + + public: + Asset3D() = default; + Asset3D(Asset3D&& other) = default; + + explicit Asset3D(rerun::components::Blob _blob) : blob(std::move(_blob)) {} + + /// The Media Type of the asset. /// - /// const auto path = argv[1]; + /// Supported values: + /// * `model/gltf-binary` + /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored) /// - /// const auto rec = rerun::RecordingStream("rerun_example_asset3d_simple"); - /// rec.spawn().exit_on_failure(); + /// If omitted, the viewer will try to guess from the data blob. + /// If it cannot guess, it won't be able to render the asset. + Asset3D with_media_type(rerun::components::MediaType _media_type) && { + media_type = std::move(_media_type); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// An out-of-tree transform. /// - /// rec.log_timeless("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis - /// rec.log("world/asset", rerun::Asset3D::from_file(path).value_or_throw()); - /// } - /// ``` - struct Asset3D { - /// The asset's bytes. - rerun::components::Blob blob; - - /// The Media Type of the asset. - /// - /// Supported values: - /// * `model/gltf-binary` - /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored) - /// - /// If omitted, the viewer will try to guess from the data blob. - /// If it cannot guess, it won't be able to render the asset. - std::optional media_type; - - /// An out-of-tree transform. - /// - /// Applies a transformation to the asset itself without impacting its children. - std::optional transform; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - // Extensions to generated type defined in 'asset3d_ext.cpp' - - static std::optional guess_media_type( - const std::filesystem::path& path - ); - - /// Creates a new `Asset3D` from the file contents at `path`. - /// - /// The `MediaType` will be guessed from the file extension. - /// - /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one - /// from the data at render-time. If it can't, rendering will fail with an error. - static Result from_file(const std::filesystem::path& path); - - /// Creates a new `Asset3D` from the given `bytes`. - /// - /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data - /// at render-time. If it can't, rendering will fail with an error. - static Asset3D from_bytes( - const std::vector bytes, - std::optional media_type - ) { - // TODO(cmc): we could try and guess using magic bytes here, like rust does. - Asset3D asset = Asset3D(bytes); - asset.media_type = media_type; - return asset; - } - - public: - Asset3D() = default; - Asset3D(Asset3D&& other) = default; - - explicit Asset3D(rerun::components::Blob _blob) : blob(std::move(_blob)) {} - - /// The Media Type of the asset. - /// - /// Supported values: - /// * `model/gltf-binary` - /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored) - /// - /// If omitted, the viewer will try to guess from the data blob. - /// If it cannot guess, it won't be able to render the asset. - Asset3D with_media_type(rerun::components::MediaType _media_type) && { - media_type = std::move(_media_type); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// An out-of-tree transform. - /// - /// Applies a transformation to the asset itself without impacting its children. - Asset3D with_transform(rerun::components::OutOfTreeTransform3D _transform) && { - transform = std::move(_transform); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; - - } // namespace archetypes + /// Applies a transformation to the asset itself without impacting its children. + Asset3D with_transform(rerun::components::OutOfTreeTransform3D _transform) && { + transform = std::move(_transform); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; + +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/bar_chart.cpp b/rerun_cpp/src/rerun/archetypes/bar_chart.cpp index 7e2493499b8d..0eb91ee199bd 100644 --- a/rerun_cpp/src/rerun/archetypes/bar_chart.cpp +++ b/rerun_cpp/src/rerun/archetypes/bar_chart.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char BarChart::INDICATOR_COMPONENT_NAME[] = "rerun.components.BarChartIndicator"; +} + namespace rerun { - namespace archetypes { - const char BarChart::INDICATOR_COMPONENT_NAME[] = "rerun.components.BarChartIndicator"; - } Result> AsComponents::serialize( const archetypes::BarChart& archetype diff --git a/rerun_cpp/src/rerun/archetypes/bar_chart.hpp b/rerun_cpp/src/rerun/archetypes/bar_chart.hpp index 97681efe3538..bd601000b07e 100644 --- a/rerun_cpp/src/rerun/archetypes/bar_chart.hpp +++ b/rerun_cpp/src/rerun/archetypes/bar_chart.hpp @@ -13,165 +13,165 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A bar chart. - /// - /// The x values will be the indices of the array, and the bar heights will be the provided values. - /// - /// ## Example - /// - /// ### Simple bar chart - /// ![image](https://static.rerun.io/barchart_simple/cf6014b18265edfcaa562c06526c0716b296b193/full.png) - /// - /// ```cpp - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_bar_chart"); - /// rec.spawn().exit_on_failure(); - /// - /// rec.log("bar_chart", rerun::BarChart::i64({8, 4, 0, 9, 1, 4, 1, 6, 9, 0})); - /// } - /// ``` - struct BarChart { - /// The values. Should always be a rank-1 tensor. - rerun::components::TensorData values; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - // Extensions to generated type defined in 'bar_chart_ext.cpp' - - BarChart(rerun::datatypes::TensorBuffer buffer) { - auto num_elems = buffer.num_elems(); - this->values = rerun::components::TensorData({num_elems}, std::move(buffer)); - } - - // -------------------------------------------------------------------- - // Implicit constructors: - // TODO(#3794): don't use std::vector here - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u8) - : BarChart(rerun::datatypes::TensorBuffer::u8(std::move(u8))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u16) - : BarChart(rerun::datatypes::TensorBuffer::u16(std::move(u16))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u32) - : BarChart(rerun::datatypes::TensorBuffer::u32(std::move(u32))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u64) - : BarChart(rerun::datatypes::TensorBuffer::u64(std::move(u64))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i8) - : BarChart(rerun::datatypes::TensorBuffer::i8(std::move(i8))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i16) - : BarChart(rerun::datatypes::TensorBuffer::i16(std::move(i16))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i32) - : BarChart(rerun::datatypes::TensorBuffer::i32(std::move(i32))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i64) - : BarChart(rerun::datatypes::TensorBuffer::i64(std::move(i64))) {} - - /// Construct aBarChart` from a `std::vector`. - BarChart(std::vector f16) - : BarChart(rerun::datatypes::TensorBuffer::f16(std::move(f16))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector f32) - : BarChart(rerun::datatypes::TensorBuffer::f32(std::move(f32))) {} - - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector f64) - : BarChart(rerun::datatypes::TensorBuffer::f64(std::move(f64))) {} - - // -------------------------------------------------------------------- - // Explicit static constructors: - // TODO(#3794): don't use std::vector here - - /// Construct a `BarChart` from a `std::vector`. - static BarChart u8(std::vector u8) { - return BarChart(u8); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart u16(std::vector u16) { - return BarChart(u16); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart u32(std::vector u32) { - return BarChart(u32); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart u64(std::vector u64) { - return BarChart(u64); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart i8(std::vector i8) { - return BarChart(i8); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart i16(std::vector i16) { - return BarChart(i16); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart i32(std::vector i32) { - return BarChart(i32); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart i64(std::vector i64) { - return BarChart(i64); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart f16(std::vector f16) { - return BarChart(f16); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart f32(std::vector f32) { - return BarChart(f32); - } - - /// Construct a `BarChart` from a `std::vector`. - static BarChart f64(std::vector f64) { - return BarChart(f64); - } - - public: - BarChart() = default; - BarChart(BarChart&& other) = default; - - explicit BarChart(rerun::components::TensorData _values) : values(std::move(_values)) {} - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; - - } // namespace archetypes +namespace rerun::archetypes { + /// **Archetype**: A bar chart. + /// + /// The x values will be the indices of the array, and the bar heights will be the provided values. + /// + /// ## Example + /// + /// ### Simple bar chart + /// ![image](https://static.rerun.io/barchart_simple/cf6014b18265edfcaa562c06526c0716b296b193/full.png) + /// + /// ```cpp + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_bar_chart"); + /// rec.spawn().exit_on_failure(); + /// + /// rec.log("bar_chart", rerun::BarChart::i64({8, 4, 0, 9, 1, 4, 1, 6, 9, 0})); + /// } + /// ``` + struct BarChart { + /// The values. Should always be a rank-1 tensor. + rerun::components::TensorData values; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + // Extensions to generated type defined in 'bar_chart_ext.cpp' + + BarChart(rerun::datatypes::TensorBuffer buffer) { + auto num_elems = buffer.num_elems(); + this->values = rerun::components::TensorData({num_elems}, std::move(buffer)); + } + + // -------------------------------------------------------------------- + // Implicit constructors: + // TODO(#3794): don't use std::vector here + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector u8) + : BarChart(rerun::datatypes::TensorBuffer::u8(std::move(u8))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector u16) + : BarChart(rerun::datatypes::TensorBuffer::u16(std::move(u16))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector u32) + : BarChart(rerun::datatypes::TensorBuffer::u32(std::move(u32))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector u64) + : BarChart(rerun::datatypes::TensorBuffer::u64(std::move(u64))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector i8) + : BarChart(rerun::datatypes::TensorBuffer::i8(std::move(i8))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector i16) + : BarChart(rerun::datatypes::TensorBuffer::i16(std::move(i16))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector i32) + : BarChart(rerun::datatypes::TensorBuffer::i32(std::move(i32))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector i64) + : BarChart(rerun::datatypes::TensorBuffer::i64(std::move(i64))) {} + + /// Construct aBarChart` from a `std::vector`. + BarChart(std::vector f16) + : BarChart(rerun::datatypes::TensorBuffer::f16(std::move(f16))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector f32) + : BarChart(rerun::datatypes::TensorBuffer::f32(std::move(f32))) {} + + /// Construct a `BarChart` from a `std::vector`. + BarChart(std::vector f64) + : BarChart(rerun::datatypes::TensorBuffer::f64(std::move(f64))) {} + + // -------------------------------------------------------------------- + // Explicit static constructors: + // TODO(#3794): don't use std::vector here + + /// Construct a `BarChart` from a `std::vector`. + static BarChart u8(std::vector u8) { + return BarChart(u8); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart u16(std::vector u16) { + return BarChart(u16); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart u32(std::vector u32) { + return BarChart(u32); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart u64(std::vector u64) { + return BarChart(u64); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart i8(std::vector i8) { + return BarChart(i8); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart i16(std::vector i16) { + return BarChart(i16); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart i32(std::vector i32) { + return BarChart(i32); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart i64(std::vector i64) { + return BarChart(i64); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart f16(std::vector f16) { + return BarChart(f16); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart f32(std::vector f32) { + return BarChart(f32); + } + + /// Construct a `BarChart` from a `std::vector`. + static BarChart f64(std::vector f64) { + return BarChart(f64); + } + + public: + BarChart() = default; + BarChart(BarChart&& other) = default; + + explicit BarChart(rerun::components::TensorData _values) : values(std::move(_values)) {} + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/boxes2d.cpp b/rerun_cpp/src/rerun/archetypes/boxes2d.cpp index c2366f50884c..e2a7da255269 100644 --- a/rerun_cpp/src/rerun/archetypes/boxes2d.cpp +++ b/rerun_cpp/src/rerun/archetypes/boxes2d.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Boxes2D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Boxes2DIndicator"; +} + namespace rerun { - namespace archetypes { - const char Boxes2D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Boxes2DIndicator"; - } Result> AsComponents::serialize( const archetypes::Boxes2D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/boxes2d.hpp b/rerun_cpp/src/rerun/archetypes/boxes2d.hpp index d7fa8a5a64bf..c6bd8264ec3b 100644 --- a/rerun_cpp/src/rerun/archetypes/boxes2d.hpp +++ b/rerun_cpp/src/rerun/archetypes/boxes2d.hpp @@ -22,183 +22,182 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: 2D boxes with half-extents and optional center, rotations, rotations, colors etc. +namespace rerun::archetypes { + /// **Archetype**: 2D boxes with half-extents and optional center, rotations, rotations, colors etc. + /// + /// ## Example + /// + /// ### Simple 2D boxes + /// ![image](https://static.rerun.io/box2d_simple/ac4424f3cf747382867649610cbd749c45b2020b/full.png) + /// + /// ```cpp + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_box2d"); + /// rec.spawn().exit_on_failure(); + /// + /// rec.log("simple", rerun::Boxes2D::from_mins_and_sizes({{-1.f, -1.f}}, {{2.f, 2.f}})); + /// + /// // Log an extra rect to set the view bounds + /// rec.log("bounds", rerun::Boxes2D::from_sizes({{4.f, 3.f}})); + /// } + /// ``` + struct Boxes2D { + /// All half-extents that make up the batch of boxes. + ComponentBatch half_sizes; + + /// Optional center positions of the boxes. + std::optional> centers; + + /// Optional colors for the boxes. + std::optional> colors; + + /// Optional radii for the lines that make up the boxes. + std::optional> radii; + + /// Optional text labels for the boxes. + std::optional> labels; + + /// An optional floating point value that specifies the 2D drawing order. /// - /// ## Example + /// Objects with higher values are drawn on top of those with lower values. /// - /// ### Simple 2D boxes - /// ![image](https://static.rerun.io/box2d_simple/ac4424f3cf747382867649610cbd749c45b2020b/full.png) + /// The default for 2D boxes is 10.0. + std::optional draw_order; + + /// Optional `ClassId`s for the boxes. /// - /// ```cpp - /// #include + /// The class ID provides colors and labels if not specified explicitly. + std::optional> class_ids; + + /// Unique identifiers for each individual boxes in the batch. + std::optional> instance_keys; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + // Extensions to generated type defined in 'boxes2d_ext.cpp' + + /// Creates new `Boxes2D` with `half_sizes` centered around the local origin. + static Boxes2D from_half_sizes(ComponentBatch half_sizes) { + Boxes2D boxes; + boxes.half_sizes = std::move(half_sizes); + return boxes; + } + + /// Creates new `Boxes2D` with `centers` and `half_sizes`. + static Boxes2D from_centers_and_half_sizes( + ComponentBatch centers, + ComponentBatch half_sizes + ) { + Boxes2D boxes; + boxes.half_sizes = std::move(half_sizes); + boxes.centers = std::move(centers); + return boxes; + } + + /// Creates new `Boxes2D` with `half_sizes` created from (full) sizes. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_box2d"); - /// rec.spawn().exit_on_failure(); + /// TODO(#3285): Does *not* preserve data as-is and instead creates half-sizes from the + /// input data. + static Boxes2D from_sizes(const std::vector& sizes); + + /// Creates new `Boxes2D` with `centers` and `half_sizes` created from centers and (full) + /// sizes. /// - /// rec.log("simple", rerun::Boxes2D::from_mins_and_sizes({{-1.f, -1.f}}, {{2.f, 2.f}})); + /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes + /// from the input data. + static Boxes2D from_centers_and_sizes( + ComponentBatch centers, + const std::vector& sizes + ) { + Boxes2D boxes = from_sizes(std::move(sizes)); + boxes.centers = std::move(centers); + return boxes; + } + + /// Creates new `Boxes2D` with `half_sizes` and `centers` created from minimums and (full) + /// sizes. /// - /// // Log an extra rect to set the view bounds - /// rec.log("bounds", rerun::Boxes2D::from_sizes({{4.f, 3.f}})); - /// } - /// ``` - struct Boxes2D { - /// All half-extents that make up the batch of boxes. - ComponentBatch half_sizes; - - /// Optional center positions of the boxes. - std::optional> centers; - - /// Optional colors for the boxes. - std::optional> colors; - - /// Optional radii for the lines that make up the boxes. - std::optional> radii; - - /// Optional text labels for the boxes. - std::optional> labels; - - /// 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 boxes is 10.0. - std::optional draw_order; - - /// Optional `ClassId`s for the boxes. - /// - /// The class ID provides colors and labels if not specified explicitly. - std::optional> class_ids; - - /// Unique identifiers for each individual boxes in the batch. - std::optional> instance_keys; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - // Extensions to generated type defined in 'boxes2d_ext.cpp' - - /// Creates new `Boxes2D` with `half_sizes` centered around the local origin. - static Boxes2D from_half_sizes(ComponentBatch half_sizes) { - Boxes2D boxes; - boxes.half_sizes = std::move(half_sizes); - return boxes; - } - - /// Creates new `Boxes2D` with `centers` and `half_sizes`. - static Boxes2D from_centers_and_half_sizes( - ComponentBatch centers, - ComponentBatch half_sizes - ) { - Boxes2D boxes; - boxes.half_sizes = std::move(half_sizes); - boxes.centers = std::move(centers); - return boxes; - } - - /// Creates new `Boxes2D` with `half_sizes` created from (full) sizes. - /// - /// TODO(#3285): Does *not* preserve data as-is and instead creates half-sizes from the - /// input data. - static Boxes2D from_sizes(const std::vector& sizes); - - /// Creates new `Boxes2D` with `centers` and `half_sizes` created from centers and (full) - /// sizes. - /// - /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes - /// from the input data. - static Boxes2D from_centers_and_sizes( - ComponentBatch centers, - const std::vector& sizes - ) { - Boxes2D boxes = from_sizes(std::move(sizes)); - boxes.centers = std::move(centers); - return boxes; - } - - /// Creates new `Boxes2D` with `half_sizes` and `centers` created from minimums and (full) - /// sizes. - /// - /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes - /// from the input data. - static Boxes2D from_mins_and_sizes( - const std::vector& mins, - const std::vector& sizes - ); - - public: - Boxes2D() = default; - Boxes2D(Boxes2D&& other) = default; - - /// Optional center positions of the boxes. - Boxes2D with_centers(ComponentBatch _centers) && { - centers = std::move(_centers); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional colors for the boxes. - Boxes2D with_colors(ComponentBatch _colors) && { - colors = std::move(_colors); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional radii for the lines that make up the boxes. - Boxes2D with_radii(ComponentBatch _radii) && { - radii = std::move(_radii); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional text labels for the boxes. - Boxes2D with_labels(ComponentBatch _labels) && { - labels = std::move(_labels); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*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 boxes is 10.0. - Boxes2D with_draw_order(rerun::components::DrawOrder _draw_order) && { - draw_order = std::move(_draw_order); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional `ClassId`s for the boxes. - /// - /// The class ID provides colors and labels if not specified explicitly. - Boxes2D with_class_ids(ComponentBatch _class_ids) && { - class_ids = std::move(_class_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Unique identifiers for each individual boxes in the batch. - Boxes2D with_instance_keys(ComponentBatch _instance_keys - ) && { - instance_keys = std::move(_instance_keys); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return half_sizes.size(); - } - }; - - } // namespace archetypes + /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes + /// from the input data. + static Boxes2D from_mins_and_sizes( + const std::vector& mins, const std::vector& sizes + ); + public: + Boxes2D() = default; + Boxes2D(Boxes2D&& other) = default; + + /// Optional center positions of the boxes. + Boxes2D with_centers(ComponentBatch _centers) && { + centers = std::move(_centers); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional colors for the boxes. + Boxes2D with_colors(ComponentBatch _colors) && { + colors = std::move(_colors); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional radii for the lines that make up the boxes. + Boxes2D with_radii(ComponentBatch _radii) && { + radii = std::move(_radii); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional text labels for the boxes. + Boxes2D with_labels(ComponentBatch _labels) && { + labels = std::move(_labels); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*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 boxes is 10.0. + Boxes2D with_draw_order(rerun::components::DrawOrder _draw_order) && { + draw_order = std::move(_draw_order); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional `ClassId`s for the boxes. + /// + /// The class ID provides colors and labels if not specified explicitly. + Boxes2D with_class_ids(ComponentBatch _class_ids) && { + class_ids = std::move(_class_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Unique identifiers for each individual boxes in the batch. + Boxes2D with_instance_keys(ComponentBatch _instance_keys + ) && { + instance_keys = std::move(_instance_keys); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return half_sizes.size(); + } + }; + +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/boxes3d.cpp b/rerun_cpp/src/rerun/archetypes/boxes3d.cpp index cd7afe4fa23b..7b60f01cdfca 100644 --- a/rerun_cpp/src/rerun/archetypes/boxes3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/boxes3d.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Boxes3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Boxes3DIndicator"; +} + namespace rerun { - namespace archetypes { - const char Boxes3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Boxes3DIndicator"; - } Result> AsComponents::serialize( const archetypes::Boxes3D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/boxes3d.hpp b/rerun_cpp/src/rerun/archetypes/boxes3d.hpp index f8fab6b52c21..2e68fcae91ca 100644 --- a/rerun_cpp/src/rerun/archetypes/boxes3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/boxes3d.hpp @@ -22,192 +22,191 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: 3D boxes with half-extents and optional center, rotations, rotations, colors etc. +namespace rerun::archetypes { + /// **Archetype**: 3D boxes with half-extents and optional center, rotations, rotations, colors etc. + /// + /// ## Example + /// + /// ### Batch of 3D boxes + /// ![image](https://static.rerun.io/box3d_batch/6d3e453c3a0201ae42bbae9de941198513535f1d/full.png) + /// + /// ```cpp + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_box3d_batch"); + /// rec.spawn().exit_on_failure(); + /// + /// rec.log( + /// "batch", + /// rerun::Boxes3D::from_centers_and_half_sizes( + /// {{2.0f, 0.0f, 0.0f}, {-2.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 2.0f}}, + /// {{2.0f, 2.0f, 1.0f}, {1.0f, 1.0f, 0.5f}, {2.0f, 0.5f, 1.0f}} + /// ) + /// .with_rotations({ + /// rerun::Quaternion::IDENTITY, + /// // 45 degrees around Z + /// rerun::Quaternion::from_xyzw(0.0f, 0.0f, 0.382683f, 0.923880f), + /// rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::degrees(30.0f)), + /// }) + /// .with_radii({0.025f}) + /// .with_colors({ + /// rerun::Rgba32(255, 0, 0), + /// rerun::Rgba32(0, 255, 0), + /// rerun::Rgba32(0, 0, 255), + /// }) + /// .with_labels({"red", "green", "blue"}) + /// ); + /// } + /// ``` + struct Boxes3D { + /// All half-extents that make up the batch of boxes. + ComponentBatch half_sizes; + + /// Optional center positions of the boxes. + std::optional> centers; + + std::optional> rotations; + + /// Optional colors for the boxes. + std::optional> colors; + + /// Optional radii for the lines that make up the boxes. + std::optional> radii; + + /// Optional text labels for the boxes. + std::optional> labels; + + /// Optional `ClassId`s for the boxes. /// - /// ## Example + /// The class ID provides colors and labels if not specified explicitly. + std::optional> class_ids; + + /// Unique identifiers for each individual boxes in the batch. + std::optional> instance_keys; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + // Extensions to generated type defined in 'boxes3d_ext.cpp' + + /// Creates new `Boxes3D` with `half_sizes` centered around the local origin. + static Boxes3D from_half_sizes(ComponentBatch half_sizes) { + Boxes3D boxes; + boxes.half_sizes = std::move(half_sizes); + return boxes; + } + + /// Creates new `Boxes3D` with `centers` and `half_sizes`. + static Boxes3D from_centers_and_half_sizes( + ComponentBatch centers, + ComponentBatch half_sizes + ) { + Boxes3D boxes; + boxes.half_sizes = std::move(half_sizes); + boxes.centers = std::move(centers); + return boxes; + } + + /// Creates new `Boxes3D` with `half_sizes` created from (full) sizes. /// - /// ### Batch of 3D boxes - /// ![image](https://static.rerun.io/box3d_batch/6d3e453c3a0201ae42bbae9de941198513535f1d/full.png) + /// TODO(#3285): Does *not* preserve data as-is and instead creates half-sizes from the + /// input data. + /// TODO(#3794): This should not take an std::vector. + static Boxes3D from_sizes(const std::vector& sizes); + + /// Creates new `Boxes3D` with `centers` and `half_sizes` created from centers and (full) + /// sizes. /// - /// ```cpp - /// #include + /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes + /// from the input data. + /// TODO(#3794): This should not take an std::vector. + static Boxes3D from_centers_and_sizes( + ComponentBatch centers, + const std::vector& sizes + ) { + Boxes3D boxes = from_sizes(std::move(sizes)); + boxes.centers = std::move(centers); + return boxes; + } + + /// Creates new `Boxes3D` with `half_sizes` and `centers` created from minimums and (full) + /// sizes. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_box3d_batch"); - /// rec.spawn().exit_on_failure(); + /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes + /// from the input data. + /// TODO(#3794): This should not take an std::vector. + static Boxes3D from_mins_and_sizes( + const std::vector& mins, const std::vector& sizes + ); + + public: + Boxes3D() = default; + Boxes3D(Boxes3D&& other) = default; + + /// Optional center positions of the boxes. + Boxes3D with_centers(ComponentBatch _centers) && { + centers = std::move(_centers); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + Boxes3D with_rotations(ComponentBatch _rotations) && { + rotations = std::move(_rotations); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional colors for the boxes. + Boxes3D with_colors(ComponentBatch _colors) && { + colors = std::move(_colors); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional radii for the lines that make up the boxes. + Boxes3D with_radii(ComponentBatch _radii) && { + radii = std::move(_radii); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional text labels for the boxes. + Boxes3D with_labels(ComponentBatch _labels) && { + labels = std::move(_labels); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional `ClassId`s for the boxes. /// - /// rec.log( - /// "batch", - /// rerun::Boxes3D::from_centers_and_half_sizes( - /// {{2.0f, 0.0f, 0.0f}, {-2.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 2.0f}}, - /// {{2.0f, 2.0f, 1.0f}, {1.0f, 1.0f, 0.5f}, {2.0f, 0.5f, 1.0f}} - /// ) - /// .with_rotations({ - /// rerun::Quaternion::IDENTITY, - /// // 45 degrees around Z - /// rerun::Quaternion::from_xyzw(0.0f, 0.0f, 0.382683f, 0.923880f), - /// rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::degrees(30.0f)), - /// }) - /// .with_radii({0.025f}) - /// .with_colors({ - /// rerun::Rgba32(255, 0, 0), - /// rerun::Rgba32(0, 255, 0), - /// rerun::Rgba32(0, 0, 255), - /// }) - /// .with_labels({"red", "green", "blue"}) - /// ); - /// } - /// ``` - struct Boxes3D { - /// All half-extents that make up the batch of boxes. - ComponentBatch half_sizes; - - /// Optional center positions of the boxes. - std::optional> centers; - - std::optional> rotations; - - /// Optional colors for the boxes. - std::optional> colors; - - /// Optional radii for the lines that make up the boxes. - std::optional> radii; - - /// Optional text labels for the boxes. - std::optional> labels; - - /// Optional `ClassId`s for the boxes. - /// - /// The class ID provides colors and labels if not specified explicitly. - std::optional> class_ids; - - /// Unique identifiers for each individual boxes in the batch. - std::optional> instance_keys; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - // Extensions to generated type defined in 'boxes3d_ext.cpp' - - /// Creates new `Boxes3D` with `half_sizes` centered around the local origin. - static Boxes3D from_half_sizes(ComponentBatch half_sizes) { - Boxes3D boxes; - boxes.half_sizes = std::move(half_sizes); - return boxes; - } - - /// Creates new `Boxes3D` with `centers` and `half_sizes`. - static Boxes3D from_centers_and_half_sizes( - ComponentBatch centers, - ComponentBatch half_sizes - ) { - Boxes3D boxes; - boxes.half_sizes = std::move(half_sizes); - boxes.centers = std::move(centers); - return boxes; - } - - /// Creates new `Boxes3D` with `half_sizes` created from (full) sizes. - /// - /// TODO(#3285): Does *not* preserve data as-is and instead creates half-sizes from the - /// input data. - /// TODO(#3794): This should not take an std::vector. - static Boxes3D from_sizes(const std::vector& sizes); - - /// Creates new `Boxes3D` with `centers` and `half_sizes` created from centers and (full) - /// sizes. - /// - /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes - /// from the input data. - /// TODO(#3794): This should not take an std::vector. - static Boxes3D from_centers_and_sizes( - ComponentBatch centers, - const std::vector& sizes - ) { - Boxes3D boxes = from_sizes(std::move(sizes)); - boxes.centers = std::move(centers); - return boxes; - } - - /// Creates new `Boxes3D` with `half_sizes` and `centers` created from minimums and (full) - /// sizes. - /// - /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes - /// from the input data. - /// TODO(#3794): This should not take an std::vector. - static Boxes3D from_mins_and_sizes( - const std::vector& mins, - const std::vector& sizes - ); - - public: - Boxes3D() = default; - Boxes3D(Boxes3D&& other) = default; - - /// Optional center positions of the boxes. - Boxes3D with_centers(ComponentBatch _centers) && { - centers = std::move(_centers); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - Boxes3D with_rotations(ComponentBatch _rotations) && { - rotations = std::move(_rotations); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional colors for the boxes. - Boxes3D with_colors(ComponentBatch _colors) && { - colors = std::move(_colors); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional radii for the lines that make up the boxes. - Boxes3D with_radii(ComponentBatch _radii) && { - radii = std::move(_radii); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional text labels for the boxes. - Boxes3D with_labels(ComponentBatch _labels) && { - labels = std::move(_labels); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional `ClassId`s for the boxes. - /// - /// The class ID provides colors and labels if not specified explicitly. - Boxes3D with_class_ids(ComponentBatch _class_ids) && { - class_ids = std::move(_class_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Unique identifiers for each individual boxes in the batch. - Boxes3D with_instance_keys(ComponentBatch _instance_keys - ) && { - instance_keys = std::move(_instance_keys); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return half_sizes.size(); - } - }; - - } // namespace archetypes + /// The class ID provides colors and labels if not specified explicitly. + Boxes3D with_class_ids(ComponentBatch _class_ids) && { + class_ids = std::move(_class_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Unique identifiers for each individual boxes in the batch. + Boxes3D with_instance_keys(ComponentBatch _instance_keys + ) && { + instance_keys = std::move(_instance_keys); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return half_sizes.size(); + } + }; + +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/clear.cpp b/rerun_cpp/src/rerun/archetypes/clear.cpp index e101f2a19b97..5f15499351f4 100644 --- a/rerun_cpp/src/rerun/archetypes/clear.cpp +++ b/rerun_cpp/src/rerun/archetypes/clear.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Clear::INDICATOR_COMPONENT_NAME[] = "rerun.components.ClearIndicator"; +} + namespace rerun { - namespace archetypes { - const char Clear::INDICATOR_COMPONENT_NAME[] = "rerun.components.ClearIndicator"; - } Result> AsComponents::serialize( const archetypes::Clear& archetype diff --git a/rerun_cpp/src/rerun/archetypes/clear.hpp b/rerun_cpp/src/rerun/archetypes/clear.hpp index d712db2fa2dd..c16183ef3014 100644 --- a/rerun_cpp/src/rerun/archetypes/clear.hpp +++ b/rerun_cpp/src/rerun/archetypes/clear.hpp @@ -13,97 +13,96 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: Empties all the components of an entity. - /// - /// ## Example - /// - /// ### Flat - /// ![image](https://static.rerun.io/clear_simple/2f5df95fcc53e9f0552f65670aef7f94830c5c1a/full.png) - /// - /// ```cpp - /// #include - /// - /// #include - /// #include - /// #include // to_string - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_clear_simple"); - /// rec.spawn().exit_on_failure(); - /// - /// std::vector vectors = { - /// {1.0, 0.0, 0.0}, - /// {0.0, -1.0, 0.0}, - /// {-1.0, 0.0, 0.0}, - /// {0.0, 1.0, 0.0}, - /// }; - /// std::vector origins = { - /// {-0.5, 0.5, 0.0}, - /// {0.5, 0.5, 0.0}, - /// {0.5, -0.5, 0.0}, - /// {-0.5, -0.5, 0.0}, - /// }; - /// std::vector colors = { - /// {200, 0, 0}, - /// {0, 200, 0}, - /// {0, 0, 200}, - /// {200, 0, 200}, - /// }; - /// - /// // Log a handful of arrows. - /// for (size_t i = 0; i + /// + /// #include + /// #include + /// #include // to_string + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_clear_simple"); + /// rec.spawn().exit_on_failure(); + /// + /// std::vector vectors = { + /// {1.0, 0.0, 0.0}, + /// {0.0, -1.0, 0.0}, + /// {-1.0, 0.0, 0.0}, + /// {0.0, 1.0, 0.0}, + /// }; + /// std::vector origins = { + /// {-0.5, 0.5, 0.0}, + /// {0.5, 0.5, 0.0}, + /// {0.5, -0.5, 0.0}, + /// {-0.5, -0.5, 0.0}, + /// }; + /// std::vector colors = { + /// {200, 0, 0}, + /// {0, 200, 0}, + /// {0, 0, 200}, + /// {200, 0, 200}, + /// }; + /// + /// // Log a handful of arrows. + /// for (size_t i = 0; i ; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - // Extensions to generated type defined in 'clear_ext.cpp' + public: + // Extensions to generated type defined in 'clear_ext.cpp' - static const Clear FLAT; + static const Clear FLAT; - static const Clear RECURSIVE; + static const Clear RECURSIVE; - Clear(bool _is_recursive = false) - : Clear(components::ClearIsRecursive(_is_recursive)) {} + Clear(bool _is_recursive = false) : Clear(components::ClearIsRecursive(_is_recursive)) {} - public: - Clear() = default; - Clear(Clear&& other) = default; + public: + Clear() = default; + Clear(Clear&& other) = default; - explicit Clear(rerun::components::ClearIsRecursive _is_recursive) - : is_recursive(std::move(_is_recursive)) {} + explicit Clear(rerun::components::ClearIsRecursive _is_recursive) + : is_recursive(std::move(_is_recursive)) {} - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/depth_image.cpp b/rerun_cpp/src/rerun/archetypes/depth_image.cpp index d900d55da17e..7c4e9a6433b3 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image.cpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char DepthImage::INDICATOR_COMPONENT_NAME[] = "rerun.components.DepthImageIndicator"; +} + namespace rerun { - namespace archetypes { - const char DepthImage::INDICATOR_COMPONENT_NAME[] = "rerun.components.DepthImageIndicator"; - } Result> AsComponents::serialize( const archetypes::DepthImage& archetype diff --git a/rerun_cpp/src/rerun/archetypes/depth_image.hpp b/rerun_cpp/src/rerun/archetypes/depth_image.hpp index ec522615464a..6e1b2be6e935 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image.hpp @@ -17,123 +17,121 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A depth image. - /// - /// The shape of the `TensorData` must be mappable to an `HxW` tensor. - /// Each pixel corresponds to a depth value in units specified by `meter`. - /// - /// ## Example - /// - /// ### Depth to 3D example - /// ![image](https://static.rerun.io/depth_image_3d/f78674bdae0eb25786c6173307693c5338f38b87/full.png) +namespace rerun::archetypes { + /// **Archetype**: A depth image. + /// + /// The shape of the `TensorData` must be mappable to an `HxW` tensor. + /// Each pixel corresponds to a depth value in units specified by `meter`. + /// + /// ## Example + /// + /// ### Depth to 3D example + /// ![image](https://static.rerun.io/depth_image_3d/f78674bdae0eb25786c6173307693c5338f38b87/full.png) + /// + /// ```cpp + /// #include + /// + /// #include // fill_n + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_depth_image"); + /// rec.spawn().exit_on_failure(); + /// + /// // Create a synthetic depth image. + /// const int HEIGHT = 200; + /// const int WIDTH = 300; + /// std::vector data(WIDTH * HEIGHT, 65535); + /// for (auto y = 50; y <150; ++y) { + /// std::fill_n(data.begin() + y * WIDTH + 50, 100, static_cast(20000)); + /// } + /// for (auto y = 130; y <180; ++y) { + /// std::fill_n(data.begin() + y * WIDTH + 100, 180, static_cast(45000)); + /// } + /// + /// // If we log a pinhole camera model, the depth gets automatically back-projected to 3D + /// rec.log( + /// "world/camera", + /// rerun::Pinhole::from_focal_length_and_resolution( + /// 200.0f, + /// {static_cast(WIDTH), static_cast(HEIGHT)} + /// ) + /// ); + /// + /// rec.log( + /// "world/camera/depth", + /// rerun::DepthImage({HEIGHT, WIDTH}, std::move(data)).with_meter(10000.0) + /// ); + /// } + /// ``` + struct DepthImage { + /// The depth-image data. Should always be a rank-2 tensor. + rerun::components::TensorData data; + + /// An optional floating point value that specifies how long a meter is in the native depth units. /// - /// ```cpp - /// #include + /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision + /// and a range of up to ~65 meters (2^16 / 1000). + std::optional meter; + + /// An optional floating point value that specifies the 2D drawing order. /// - /// #include // fill_n - /// #include + /// Objects with higher values are drawn on top of those with lower values. + std::optional draw_order; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + // Extensions to generated type defined in 'depth_image_ext.cpp' + + /// New depth image from height/width and tensor buffer. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_depth_image"); - /// rec.spawn().exit_on_failure(); + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + DepthImage(std::vector shape, datatypes::TensorBuffer buffer) + : DepthImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} + + /// New depth image from tensor data. /// - /// // Create a synthetic depth image. - /// const int HEIGHT = 200; - /// const int WIDTH = 300; - /// std::vector data(WIDTH * HEIGHT, 65535); - /// for (auto y = 50; y <150; ++y) { - /// std::fill_n(data.begin() + y * WIDTH + 50, 100, static_cast(20000)); - /// } - /// for (auto y = 130; y <180; ++y) { - /// std::fill_n(data.begin() + y * WIDTH + 100, 180, static_cast(45000)); - /// } + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + explicit DepthImage(components::TensorData _data); + + public: + DepthImage() = default; + DepthImage(DepthImage&& other) = default; + + /// An optional floating point value that specifies how long a meter is in the native depth units. /// - /// // If we log a pinhole camera model, the depth gets automatically back-projected to 3D - /// rec.log( - /// "world/camera", - /// rerun::Pinhole::from_focal_length_and_resolution( - /// 200.0f, - /// {static_cast(WIDTH), static_cast(HEIGHT)} - /// ) - /// ); + /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision + /// and a range of up to ~65 meters (2^16 / 1000). + DepthImage with_meter(rerun::components::DepthMeter _meter) && { + meter = std::move(_meter); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// An optional floating point value that specifies the 2D drawing order. /// - /// rec.log( - /// "world/camera/depth", - /// rerun::DepthImage({HEIGHT, WIDTH}, std::move(data)).with_meter(10000.0) - /// ); - /// } - /// ``` - struct DepthImage { - /// The depth-image data. Should always be a rank-2 tensor. - rerun::components::TensorData data; - - /// An optional floating point value that specifies how long a meter is in the native depth units. - /// - /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision - /// and a range of up to ~65 meters (2^16 / 1000). - std::optional meter; - - /// An optional floating point value that specifies the 2D drawing order. - /// - /// Objects with higher values are drawn on top of those with lower values. - std::optional draw_order; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - // Extensions to generated type defined in 'depth_image_ext.cpp' - - /// New depth image from height/width and tensor buffer. - /// - /// Sets the dimension names to "height" and "width" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2. - DepthImage( - std::vector shape, datatypes::TensorBuffer buffer - ) - : DepthImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} - - /// New depth image from tensor data. - /// - /// Sets the dimension names to "height" and "width" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2. - explicit DepthImage(components::TensorData _data); - - public: - DepthImage() = default; - DepthImage(DepthImage&& other) = default; - - /// An optional floating point value that specifies how long a meter is in the native depth units. - /// - /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision - /// and a range of up to ~65 meters (2^16 / 1000). - DepthImage with_meter(rerun::components::DepthMeter _meter) && { - meter = std::move(_meter); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*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. - DepthImage with_draw_order(rerun::components::DrawOrder _draw_order) && { - draw_order = std::move(_draw_order); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; - - } // namespace archetypes + /// Objects with higher values are drawn on top of those with lower values. + DepthImage with_draw_order(rerun::components::DrawOrder _draw_order) && { + draw_order = std::move(_draw_order); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; + +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/disconnected_space.cpp b/rerun_cpp/src/rerun/archetypes/disconnected_space.cpp index af2082fb0715..4b343257f1b1 100644 --- a/rerun_cpp/src/rerun/archetypes/disconnected_space.cpp +++ b/rerun_cpp/src/rerun/archetypes/disconnected_space.cpp @@ -5,11 +5,12 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char DisconnectedSpace::INDICATOR_COMPONENT_NAME[] = + "rerun.components.DisconnectedSpaceIndicator"; +} + namespace rerun { - namespace archetypes { - const char DisconnectedSpace::INDICATOR_COMPONENT_NAME[] = - "rerun.components.DisconnectedSpaceIndicator"; - } Result> AsComponents< archetypes::DisconnectedSpace>::serialize(const archetypes::DisconnectedSpace& archetype) { diff --git a/rerun_cpp/src/rerun/archetypes/disconnected_space.hpp b/rerun_cpp/src/rerun/archetypes/disconnected_space.hpp index b511122a8127..f86d7b7bf343 100644 --- a/rerun_cpp/src/rerun/archetypes/disconnected_space.hpp +++ b/rerun_cpp/src/rerun/archetypes/disconnected_space.hpp @@ -13,59 +13,59 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: Specifies that the entity path at which this is logged is disconnected from its parent. - /// - /// This is useful for specifying that a subgraph is independent of the rest of the scene. - /// - /// If a transform or pinhole is logged on the same path, this archetype's components - /// will be ignored. - /// - /// ## Example - /// - /// ### Disconnected Space - /// ![image](https://static.rerun.io/disconnected_space/b8f95b0e32359de625a765247c84935146c1fba9/full.png) - /// - /// ```cpp - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_disconnected_space"); - /// rec.spawn().exit_on_failure(); - /// - /// // These two points can be projected into the same space.. - /// rec.log("world/room1/point", rerun::Points3D({{0.0f, 0.0f, 0.0f}})); - /// rec.log("world/room2/point", rerun::Points3D({{1.0f, 1.0f, 1.0f}})); - /// - /// // ..but this one lives in a completely separate space! - /// rec.log("world/wormhole", rerun::DisconnectedSpace(true)); - /// rec.log("world/wormhole/point", rerun::Points3D({{2.0f, 2.0f, 2.0f}})); - /// } - /// ``` - struct DisconnectedSpace { - rerun::components::DisconnectedSpace disconnected_space; +namespace rerun::archetypes { + /// **Archetype**: Specifies that the entity path at which this is logged is disconnected from its parent. + /// + /// This is useful for specifying that a subgraph is independent of the rest of the scene. + /// + /// If a transform or pinhole is logged on the same path, this archetype's components + /// will be ignored. + /// + /// ## Example + /// + /// ### Disconnected Space + /// ![image](https://static.rerun.io/disconnected_space/b8f95b0e32359de625a765247c84935146c1fba9/full.png) + /// + /// ```cpp + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_disconnected_space"); + /// rec.spawn().exit_on_failure(); + /// + /// // These two points can be projected into the same space.. + /// rec.log("world/room1/point", rerun::Points3D({{0.0f, 0.0f, 0.0f}})); + /// rec.log("world/room2/point", rerun::Points3D({{1.0f, 1.0f, 1.0f}})); + /// + /// // ..but this one lives in a completely separate space! + /// rec.log("world/wormhole", rerun::DisconnectedSpace(true)); + /// rec.log("world/wormhole/point", rerun::Points3D({{2.0f, 2.0f, 2.0f}})); + /// } + /// ``` + struct DisconnectedSpace { + rerun::components::DisconnectedSpace disconnected_space; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - DisconnectedSpace() = default; - DisconnectedSpace(DisconnectedSpace&& other) = default; + public: + DisconnectedSpace() = default; + DisconnectedSpace(DisconnectedSpace&& other) = default; - explicit DisconnectedSpace(rerun::components::DisconnectedSpace _disconnected_space) - : disconnected_space(std::move(_disconnected_space)) {} + explicit DisconnectedSpace(rerun::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; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/image.cpp b/rerun_cpp/src/rerun/archetypes/image.cpp index 1e2999277202..cdc5c23a1446 100644 --- a/rerun_cpp/src/rerun/archetypes/image.cpp +++ b/rerun_cpp/src/rerun/archetypes/image.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Image::INDICATOR_COMPONENT_NAME[] = "rerun.components.ImageIndicator"; +} + namespace rerun { - namespace archetypes { - const char Image::INDICATOR_COMPONENT_NAME[] = "rerun.components.ImageIndicator"; - } Result> AsComponents::serialize( const archetypes::Image& archetype diff --git a/rerun_cpp/src/rerun/archetypes/image.hpp b/rerun_cpp/src/rerun/archetypes/image.hpp index 3464aec4686c..8e50bad30cde 100644 --- a/rerun_cpp/src/rerun/archetypes/image.hpp +++ b/rerun_cpp/src/rerun/archetypes/image.hpp @@ -16,101 +16,101 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A monochrome or color image. - /// - /// The shape of the `TensorData` must be mappable to: - /// - A `HxW` tensor, treated as a grayscale image. - /// - A `HxWx3` tensor, treated as an RGB image. - /// - A `HxWx4` tensor, treated as an RGBA image. - /// - /// Leading and trailing unit-dimensions are ignored, so that - /// `1x640x480x3x1` is treated as a `640x480x3` RGB image. - /// - /// ## Example - /// - /// ### `image_simple`: - /// ![image](https://static.rerun.io/image_simple/06ba7f8582acc1ffb42a7fd0006fad7816f3e4e4/full.png) - /// - /// ```cpp - /// #include - /// - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_image_simple"); - /// rec.spawn().exit_on_failure(); - /// - /// // Create a synthetic image. - /// const int HEIGHT = 200; - /// const int WIDTH = 300; - /// std::vector data(WIDTH * HEIGHT * 3, 0); - /// for (size_t i = 0; i + /// + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_image_simple"); + /// rec.spawn().exit_on_failure(); + /// + /// // Create a synthetic image. + /// const int HEIGHT = 200; + /// const int WIDTH = 300; + /// std::vector data(WIDTH * HEIGHT * 3, 0); + /// for (size_t i = 0; i draw_order; + /// An optional floating point value that specifies the 2D drawing order. + /// + /// Objects with higher values are drawn on top of those with lower values. + std::optional draw_order; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - // Extensions to generated type defined in 'image_ext.cpp' + public: + // Extensions to generated type defined in 'image_ext.cpp' - /// New Image from height/width/channel and tensor buffer. - /// - /// Sets the dimension names to "height", "width" and "channel" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2 or 3. - Image(std::vector shape, datatypes::TensorBuffer buffer) - : Image(datatypes::TensorData(std::move(shape), std::move(buffer))) {} + /// New Image from height/width/channel and tensor buffer. + /// + /// Sets the dimension names to "height", "width" and "channel" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2 or 3. + Image(std::vector shape, datatypes::TensorBuffer buffer) + : Image(datatypes::TensorData(std::move(shape), std::move(buffer))) {} - /// New depth image from tensor data. - /// - /// Sets the dimension names to "height", "width" and "channel" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2 or 3. - explicit Image(rerun::components::TensorData _data); + /// New depth image from tensor data. + /// + /// Sets the dimension names to "height", "width" and "channel" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2 or 3. + explicit Image(rerun::components::TensorData _data); - public: - Image() = default; - Image(Image&& other) = default; + public: + Image() = default; + Image(Image&& other) = default; - /// An optional floating point value that specifies the 2D drawing order. - /// - /// Objects with higher values are drawn on top of those with lower values. - Image with_draw_order(rerun::components::DrawOrder _draw_order) && { - draw_order = std::move(_draw_order); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*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. + Image with_draw_order(rerun::components::DrawOrder _draw_order) && { + draw_order = std::move(_draw_order); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/line_strips2d.cpp b/rerun_cpp/src/rerun/archetypes/line_strips2d.cpp index 3160c1a96391..ad4d31896592 100644 --- a/rerun_cpp/src/rerun/archetypes/line_strips2d.cpp +++ b/rerun_cpp/src/rerun/archetypes/line_strips2d.cpp @@ -5,11 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char LineStrips2D::INDICATOR_COMPONENT_NAME[] = "rerun.components.LineStrips2DIndicator"; +} + namespace rerun { - namespace archetypes { - const char LineStrips2D::INDICATOR_COMPONENT_NAME[] = - "rerun.components.LineStrips2DIndicator"; - } Result> AsComponents::serialize( const archetypes::LineStrips2D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/line_strips2d.hpp b/rerun_cpp/src/rerun/archetypes/line_strips2d.hpp index eb74f7d1e58c..38bcd70ca533 100644 --- a/rerun_cpp/src/rerun/archetypes/line_strips2d.hpp +++ b/rerun_cpp/src/rerun/archetypes/line_strips2d.hpp @@ -21,133 +21,133 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: 2D line strips with positions and optional colors, radii, labels, etc. - /// - /// ## Example - /// - /// ### `line_strip2d_batch`: - /// ![image](https://static.rerun.io/line_strip2d_batch/d8aae7ca3d6c3b0e3b636de60b8067fa2f0b6db9/full.png) - /// - /// ```cpp - /// #include +namespace rerun::archetypes { + /// **Archetype**: 2D line strips with positions and optional colors, radii, labels, etc. + /// + /// ## Example + /// + /// ### `line_strip2d_batch`: + /// ![image](https://static.rerun.io/line_strip2d_batch/d8aae7ca3d6c3b0e3b636de60b8067fa2f0b6db9/full.png) + /// + /// ```cpp + /// #include + /// + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_line_strip2d"); + /// rec.spawn().exit_on_failure(); + /// + /// std::vector strip1 = {{0.f, 0.f}, {2.f, 1.f}, {4.f, -1.f}, {6.f, 0.f}}; + /// std::vector strip2 = + /// {{0.f, 3.f}, {1.f, 4.f}, {2.f, 2.f}, {3.f, 4.f}, {4.f, 2.f}, {5.f, 4.f}, {6.f, 3.f}}; + /// rec.log( + /// "strips", + /// rerun::LineStrips2D({strip1, strip2}) + /// .with_colors({0xFF0000FF, 0x00FF00FF}) + /// .with_radii({0.025f, 0.005f}) + /// .with_labels({"one strip here", "and one strip there"}) + /// ); + /// + /// // Log an extra rect to set the view bounds + /// rec.log("bounds", rerun::Boxes2D::from_centers_and_sizes({{3.0f, 1.5f}}, {{8.0f, 9.0f}})); + /// } + /// ``` + struct LineStrips2D { + /// All the actual 2D line strips that make up the batch. + ComponentBatch strips; + + /// Optional radii for the line strips. + std::optional> radii; + + /// Optional colors for the line strips. + std::optional> colors; + + /// Optional text labels for the line strips. + std::optional> labels; + + /// An optional floating point value that specifies the 2D drawing order of each line strip. /// - /// #include + /// Objects with higher values are drawn on top of those with lower values. + std::optional draw_order; + + /// Optional `ClassId`s for the lines. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_line_strip2d"); - /// rec.spawn().exit_on_failure(); + /// The class ID provides colors and labels if not specified explicitly. + std::optional> class_ids; + + /// Unique identifiers for each individual line strip in the batch. + std::optional> instance_keys; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + LineStrips2D() = default; + LineStrips2D(LineStrips2D&& other) = default; + + explicit LineStrips2D(ComponentBatch _strips) + : strips(std::move(_strips)) {} + + /// Optional radii for the line strips. + LineStrips2D with_radii(ComponentBatch _radii) && { + radii = std::move(_radii); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional colors for the line strips. + LineStrips2D with_colors(ComponentBatch _colors) && { + colors = std::move(_colors); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional text labels for the line strips. + LineStrips2D with_labels(ComponentBatch _labels) && { + labels = std::move(_labels); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// An optional floating point value that specifies the 2D drawing order of each line strip. /// - /// std::vector strip1 = {{0.f, 0.f}, {2.f, 1.f}, {4.f, -1.f}, {6.f, 0.f}}; - /// std::vector strip2 = - /// {{0.f, 3.f}, {1.f, 4.f}, {2.f, 2.f}, {3.f, 4.f}, {4.f, 2.f}, {5.f, 4.f}, {6.f, 3.f}}; - /// rec.log( - /// "strips", - /// rerun::LineStrips2D({strip1, strip2}) - /// .with_colors({0xFF0000FF, 0x00FF00FF}) - /// .with_radii({0.025f, 0.005f}) - /// .with_labels({"one strip here", "and one strip there"}) - /// ); + /// Objects with higher values are drawn on top of those with lower values. + LineStrips2D with_draw_order(rerun::components::DrawOrder _draw_order) && { + draw_order = std::move(_draw_order); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional `ClassId`s for the lines. /// - /// // Log an extra rect to set the view bounds - /// rec.log("bounds", rerun::Boxes2D::from_centers_and_sizes({{3.0f, 1.5f}}, {{8.0f, 9.0f}})); - /// } - /// ``` - struct LineStrips2D { - /// All the actual 2D line strips that make up the batch. - ComponentBatch strips; - - /// Optional radii for the line strips. - std::optional> radii; - - /// Optional colors for the line strips. - std::optional> colors; - - /// Optional text labels for the line strips. - std::optional> labels; - - /// An optional floating point value that specifies the 2D drawing order of each line strip. - /// - /// Objects with higher values are drawn on top of those with lower values. - std::optional draw_order; - - /// Optional `ClassId`s for the lines. - /// - /// The class ID provides colors and labels if not specified explicitly. - std::optional> class_ids; - - /// Unique identifiers for each individual line strip in the batch. - std::optional> instance_keys; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - LineStrips2D() = default; - LineStrips2D(LineStrips2D&& other) = default; - - explicit LineStrips2D(ComponentBatch _strips) - : strips(std::move(_strips)) {} - - /// Optional radii for the line strips. - LineStrips2D with_radii(ComponentBatch _radii) && { - radii = std::move(_radii); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional colors for the line strips. - LineStrips2D with_colors(ComponentBatch _colors) && { - colors = std::move(_colors); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional text labels for the line strips. - LineStrips2D with_labels(ComponentBatch _labels) && { - labels = std::move(_labels); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// An optional floating point value that specifies the 2D drawing order of each line strip. - /// - /// Objects with higher values are drawn on top of those with lower values. - LineStrips2D with_draw_order(rerun::components::DrawOrder _draw_order) && { - draw_order = std::move(_draw_order); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional `ClassId`s for the lines. - /// - /// The class ID provides colors and labels if not specified explicitly. - LineStrips2D with_class_ids(ComponentBatch _class_ids) && { - class_ids = std::move(_class_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Unique identifiers for each individual line strip in the batch. - LineStrips2D with_instance_keys( - ComponentBatch _instance_keys - ) && { - instance_keys = std::move(_instance_keys); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return strips.size(); - } - }; - - } // namespace archetypes + /// The class ID provides colors and labels if not specified explicitly. + LineStrips2D with_class_ids(ComponentBatch _class_ids) && { + class_ids = std::move(_class_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Unique identifiers for each individual line strip in the batch. + LineStrips2D with_instance_keys( + ComponentBatch _instance_keys + ) && { + instance_keys = std::move(_instance_keys); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return strips.size(); + } + }; +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/line_strips3d.cpp b/rerun_cpp/src/rerun/archetypes/line_strips3d.cpp index 458592690824..e87461e60e65 100644 --- a/rerun_cpp/src/rerun/archetypes/line_strips3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/line_strips3d.cpp @@ -5,11 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char LineStrips3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.LineStrips3DIndicator"; +} + namespace rerun { - namespace archetypes { - const char LineStrips3D::INDICATOR_COMPONENT_NAME[] = - "rerun.components.LineStrips3DIndicator"; - } Result> AsComponents::serialize( const archetypes::LineStrips3D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/line_strips3d.hpp b/rerun_cpp/src/rerun/archetypes/line_strips3d.hpp index e58711b3fb7d..cca603ba4ea3 100644 --- a/rerun_cpp/src/rerun/archetypes/line_strips3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/line_strips3d.hpp @@ -20,129 +20,129 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: 3D line strips with positions and optional colors, radii, labels, etc. - /// - /// ## Example - /// - /// ### Many strips - /// ![image](https://static.rerun.io/line_strip3d_batch/102e5ec5271475657fbc76b469267e4ec8e84337/full.png) - /// - /// ```cpp - /// #include +namespace rerun::archetypes { + /// **Archetype**: 3D line strips with positions and optional colors, radii, labels, etc. + /// + /// ## Example + /// + /// ### Many strips + /// ![image](https://static.rerun.io/line_strip3d_batch/102e5ec5271475657fbc76b469267e4ec8e84337/full.png) + /// + /// ```cpp + /// #include + /// + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_line_strip3d"); + /// rec.spawn().exit_on_failure(); + /// + /// std::vector strip1 = { + /// {0.f, 0.f, 2.f}, + /// {1.f, 0.f, 2.f}, + /// {1.f, 1.f, 2.f}, + /// {0.f, 1.f, 2.f}, + /// }; + /// std::vector strip2 = { + /// {0.f, 0.f, 0.f}, + /// {0.f, 0.f, 1.f}, + /// {1.f, 0.f, 0.f}, + /// {1.f, 0.f, 1.f}, + /// {1.f, 1.f, 0.f}, + /// {1.f, 1.f, 1.f}, + /// {0.f, 1.f, 0.f}, + /// {0.f, 1.f, 1.f}, + /// }; + /// rec.log( + /// "strips", + /// rerun::LineStrips3D({strip1, strip2}) + /// .with_colors({0xFF0000FF, 0x00FF00FF}) + /// .with_radii({0.025f, 0.005f}) + /// .with_labels({"one strip here", "and one strip there"}) + /// ); + /// } + /// ``` + struct LineStrips3D { + /// All the actual 3D line strips that make up the batch. + ComponentBatch strips; + + /// Optional radii for the line strips. + std::optional> radii; + + /// Optional colors for the line strips. + std::optional> colors; + + /// Optional text labels for the line strips. + std::optional> labels; + + /// Optional `ClassId`s for the lines. /// - /// #include + /// The class ID provides colors and labels if not specified explicitly. + std::optional> class_ids; + + /// Unique identifiers for each individual line strip in the batch. + std::optional> instance_keys; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + LineStrips3D() = default; + LineStrips3D(LineStrips3D&& other) = default; + + explicit LineStrips3D(ComponentBatch _strips) + : strips(std::move(_strips)) {} + + /// Optional radii for the line strips. + LineStrips3D with_radii(ComponentBatch _radii) && { + radii = std::move(_radii); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional colors for the line strips. + LineStrips3D with_colors(ComponentBatch _colors) && { + colors = std::move(_colors); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional text labels for the line strips. + LineStrips3D with_labels(ComponentBatch _labels) && { + labels = std::move(_labels); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional `ClassId`s for the lines. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_line_strip3d"); - /// rec.spawn().exit_on_failure(); - /// - /// std::vector strip1 = { - /// {0.f, 0.f, 2.f}, - /// {1.f, 0.f, 2.f}, - /// {1.f, 1.f, 2.f}, - /// {0.f, 1.f, 2.f}, - /// }; - /// std::vector strip2 = { - /// {0.f, 0.f, 0.f}, - /// {0.f, 0.f, 1.f}, - /// {1.f, 0.f, 0.f}, - /// {1.f, 0.f, 1.f}, - /// {1.f, 1.f, 0.f}, - /// {1.f, 1.f, 1.f}, - /// {0.f, 1.f, 0.f}, - /// {0.f, 1.f, 1.f}, - /// }; - /// rec.log( - /// "strips", - /// rerun::LineStrips3D({strip1, strip2}) - /// .with_colors({0xFF0000FF, 0x00FF00FF}) - /// .with_radii({0.025f, 0.005f}) - /// .with_labels({"one strip here", "and one strip there"}) - /// ); - /// } - /// ``` - struct LineStrips3D { - /// All the actual 3D line strips that make up the batch. - ComponentBatch strips; - - /// Optional radii for the line strips. - std::optional> radii; - - /// Optional colors for the line strips. - std::optional> colors; - - /// Optional text labels for the line strips. - std::optional> labels; - - /// Optional `ClassId`s for the lines. - /// - /// The class ID provides colors and labels if not specified explicitly. - std::optional> class_ids; - - /// Unique identifiers for each individual line strip in the batch. - std::optional> instance_keys; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - LineStrips3D() = default; - LineStrips3D(LineStrips3D&& other) = default; - - explicit LineStrips3D(ComponentBatch _strips) - : strips(std::move(_strips)) {} - - /// Optional radii for the line strips. - LineStrips3D with_radii(ComponentBatch _radii) && { - radii = std::move(_radii); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional colors for the line strips. - LineStrips3D with_colors(ComponentBatch _colors) && { - colors = std::move(_colors); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional text labels for the line strips. - LineStrips3D with_labels(ComponentBatch _labels) && { - labels = std::move(_labels); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional `ClassId`s for the lines. - /// - /// The class ID provides colors and labels if not specified explicitly. - LineStrips3D with_class_ids(ComponentBatch _class_ids) && { - class_ids = std::move(_class_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Unique identifiers for each individual line strip in the batch. - LineStrips3D with_instance_keys( - ComponentBatch _instance_keys - ) && { - instance_keys = std::move(_instance_keys); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return strips.size(); - } - }; - - } // namespace archetypes + /// The class ID provides colors and labels if not specified explicitly. + LineStrips3D with_class_ids(ComponentBatch _class_ids) && { + class_ids = std::move(_class_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Unique identifiers for each individual line strip in the batch. + LineStrips3D with_instance_keys( + ComponentBatch _instance_keys + ) && { + instance_keys = std::move(_instance_keys); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return strips.size(); + } + }; +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/mesh3d.cpp b/rerun_cpp/src/rerun/archetypes/mesh3d.cpp index fe6380b3282b..4e7403e486cf 100644 --- a/rerun_cpp/src/rerun/archetypes/mesh3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/mesh3d.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Mesh3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Mesh3DIndicator"; +} + namespace rerun { - namespace archetypes { - const char Mesh3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Mesh3DIndicator"; - } Result> AsComponents::serialize( const archetypes::Mesh3D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/mesh3d.hpp b/rerun_cpp/src/rerun/archetypes/mesh3d.hpp index 29dbc1da509c..5d66be7e870e 100644 --- a/rerun_cpp/src/rerun/archetypes/mesh3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/mesh3d.hpp @@ -21,142 +21,141 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A 3D triangle mesh as specified by its per-mesh and per-vertex properties. - /// - /// ## Example - /// - /// ### Simple indexed 3D mesh - /// ![image](https://static.rerun.io/mesh3d_simple/e1e5fd97265daf0d0bc7b782d862f19086fd6975/full.png) +namespace rerun::archetypes { + /// **Archetype**: A 3D triangle mesh as specified by its per-mesh and per-vertex properties. + /// + /// ## Example + /// + /// ### Simple indexed 3D mesh + /// ![image](https://static.rerun.io/mesh3d_simple/e1e5fd97265daf0d0bc7b782d862f19086fd6975/full.png) + /// + /// ```cpp + /// #include + /// + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_mesh3d_indexed"); + /// rec.spawn().exit_on_failure(); + /// + /// const rerun::Position3D vertex_positions[3] = { + /// {0.0f, 1.0f, 0.0f}, + /// {1.0f, 0.0f, 0.0f}, + /// {0.0f, 0.0f, 0.0f}, + /// }; + /// const rerun::Color vertex_colors[3] = { + /// {0, 0, 255}, + /// {0, 255, 0}, + /// {255, 0, 0}, + /// }; + /// const std::vector indices = {2, 1, 0}; + /// + /// rec.log( + /// "triangle", + /// rerun::Mesh3D(vertex_positions) + /// .with_vertex_normals({{0.0, 0.0, 1.0}}) + /// .with_vertex_colors(vertex_colors) + /// .with_mesh_properties(rerun::components::MeshProperties::from_triangle_indices(indices)) + /// .with_mesh_material(rerun::components::Material::from_albedo_factor(0xCC00CCFF)) + /// ); + /// } + /// ``` + struct Mesh3D { + /// The positions of each vertex. /// - /// ```cpp - /// #include + /// If no `indices` are specified, then each triplet of positions is interpreted as a triangle. + ComponentBatch vertex_positions; + + /// Optional properties for the mesh as a whole (including indexed drawing). + std::optional mesh_properties; + + /// An optional normal for each vertex. /// - /// #include + /// If specified, this must have as many elements as `vertex_positions`. + std::optional> vertex_normals; + + /// An optional color for each vertex. + std::optional> vertex_colors; + + /// Optional material properties for the mesh as a whole. + std::optional mesh_material; + + /// Optional class Ids for the vertices. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_mesh3d_indexed"); - /// rec.spawn().exit_on_failure(); + /// The class ID provides colors and labels if not specified explicitly. + std::optional> class_ids; + + /// Unique identifiers for each individual vertex in the mesh. + std::optional> instance_keys; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + Mesh3D() = default; + Mesh3D(Mesh3D&& other) = default; + + explicit Mesh3D(ComponentBatch _vertex_positions) + : vertex_positions(std::move(_vertex_positions)) {} + + /// Optional properties for the mesh as a whole (including indexed drawing). + Mesh3D with_mesh_properties(rerun::components::MeshProperties _mesh_properties) && { + mesh_properties = std::move(_mesh_properties); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// An optional normal for each vertex. /// - /// const rerun::Position3D vertex_positions[3] = { - /// {0.0f, 1.0f, 0.0f}, - /// {1.0f, 0.0f, 0.0f}, - /// {0.0f, 0.0f, 0.0f}, - /// }; - /// const rerun::Color vertex_colors[3] = { - /// {0, 0, 255}, - /// {0, 255, 0}, - /// {255, 0, 0}, - /// }; - /// const std::vector indices = {2, 1, 0}; + /// If specified, this must have as many elements as `vertex_positions`. + Mesh3D with_vertex_normals(ComponentBatch _vertex_normals) && { + vertex_normals = std::move(_vertex_normals); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// An optional color for each vertex. + Mesh3D with_vertex_colors(ComponentBatch _vertex_colors) && { + vertex_colors = std::move(_vertex_colors); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional material properties for the mesh as a whole. + Mesh3D with_mesh_material(rerun::components::Material _mesh_material) && { + mesh_material = std::move(_mesh_material); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional class Ids for the vertices. /// - /// rec.log( - /// "triangle", - /// rerun::Mesh3D(vertex_positions) - /// .with_vertex_normals({{0.0, 0.0, 1.0}}) - /// .with_vertex_colors(vertex_colors) - /// .with_mesh_properties(rerun::components::MeshProperties::from_triangle_indices(indices)) - /// .with_mesh_material(rerun::components::Material::from_albedo_factor(0xCC00CCFF)) - /// ); - /// } - /// ``` - struct Mesh3D { - /// The positions of each vertex. - /// - /// If no `indices` are specified, then each triplet of positions is interpreted as a triangle. - ComponentBatch vertex_positions; - - /// Optional properties for the mesh as a whole (including indexed drawing). - std::optional mesh_properties; - - /// An optional normal for each vertex. - /// - /// If specified, this must have as many elements as `vertex_positions`. - std::optional> vertex_normals; - - /// An optional color for each vertex. - std::optional> vertex_colors; - - /// Optional material properties for the mesh as a whole. - std::optional mesh_material; - - /// Optional class Ids for the vertices. - /// - /// The class ID provides colors and labels if not specified explicitly. - std::optional> class_ids; - - /// Unique identifiers for each individual vertex in the mesh. - std::optional> instance_keys; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - Mesh3D() = default; - Mesh3D(Mesh3D&& other) = default; - - explicit Mesh3D(ComponentBatch _vertex_positions) - : vertex_positions(std::move(_vertex_positions)) {} - - /// Optional properties for the mesh as a whole (including indexed drawing). - Mesh3D with_mesh_properties(rerun::components::MeshProperties _mesh_properties) && { - mesh_properties = std::move(_mesh_properties); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// An optional normal for each vertex. - /// - /// If specified, this must have as many elements as `vertex_positions`. - Mesh3D with_vertex_normals(ComponentBatch _vertex_normals - ) && { - vertex_normals = std::move(_vertex_normals); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// An optional color for each vertex. - Mesh3D with_vertex_colors(ComponentBatch _vertex_colors) && { - vertex_colors = std::move(_vertex_colors); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional material properties for the mesh as a whole. - Mesh3D with_mesh_material(rerun::components::Material _mesh_material) && { - mesh_material = std::move(_mesh_material); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional class Ids for the vertices. - /// - /// The class ID provides colors and labels if not specified explicitly. - Mesh3D with_class_ids(ComponentBatch _class_ids) && { - class_ids = std::move(_class_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Unique identifiers for each individual vertex in the mesh. - Mesh3D with_instance_keys(ComponentBatch _instance_keys - ) && { - instance_keys = std::move(_instance_keys); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return vertex_positions.size(); - } - }; - - } // namespace archetypes + /// The class ID provides colors and labels if not specified explicitly. + Mesh3D with_class_ids(ComponentBatch _class_ids) && { + class_ids = std::move(_class_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Unique identifiers for each individual vertex in the mesh. + Mesh3D with_instance_keys(ComponentBatch _instance_keys + ) && { + instance_keys = std::move(_instance_keys); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return vertex_positions.size(); + } + }; +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/pinhole.cpp b/rerun_cpp/src/rerun/archetypes/pinhole.cpp index bad19f2574b5..be5ef60144c4 100644 --- a/rerun_cpp/src/rerun/archetypes/pinhole.cpp +++ b/rerun_cpp/src/rerun/archetypes/pinhole.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Pinhole::INDICATOR_COMPONENT_NAME[] = "rerun.components.PinholeIndicator"; +} + namespace rerun { - namespace archetypes { - const char Pinhole::INDICATOR_COMPONENT_NAME[] = "rerun.components.PinholeIndicator"; - } Result> AsComponents::serialize( const archetypes::Pinhole& archetype diff --git a/rerun_cpp/src/rerun/archetypes/pinhole.hpp b/rerun_cpp/src/rerun/archetypes/pinhole.hpp index 53491422fa2c..6d0aaae19d97 100644 --- a/rerun_cpp/src/rerun/archetypes/pinhole.hpp +++ b/rerun_cpp/src/rerun/archetypes/pinhole.hpp @@ -17,189 +17,189 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: Camera perspective projection (a.k.a. intrinsics). +namespace rerun::archetypes { + /// **Archetype**: Camera perspective projection (a.k.a. intrinsics). + /// + /// ## Example + /// + /// ### Simple Pinhole Camera + /// ![image](https://static.rerun.io/pinhole_simple/9af9441a94bcd9fd54e1fea44fb0c59ff381a7f2/full.png) + /// + /// ```cpp + /// #include + /// + /// #include // std::generate + /// #include // std::rand + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_line_strip3d"); + /// rec.spawn().exit_on_failure(); + /// + /// rec.log("world/image", rerun::Pinhole::from_focal_length_and_resolution(3.0f, {3.0f, 3.0f})); + /// + /// std::vector random_data(3 * 3 * 3); + /// std::generate(random_data.begin(), random_data.end(), [] { + /// return static_cast(std::rand()); + /// }); + /// + /// const auto tensor = rerun::datatypes::TensorData({3, 3, 3}, random_data); + /// rec.log("world/image", rerun::Image(tensor)); + /// } + /// ``` + struct Pinhole { + /// Camera projection, from image coordinates to view coordinates. + rerun::components::PinholeProjection image_from_camera; + + /// Pixel resolution (usually integers) of child image space. Width and height. + /// + /// Example: + /// ```text + /// [1920.0, 1440.0] + /// ``` + /// + /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`. + std::optional resolution; + + /// Sets the view coordinates for the camera. /// - /// ## Example + /// All common values are available as constants on the `components.ViewCoordinates` class. /// - /// ### Simple Pinhole Camera - /// ![image](https://static.rerun.io/pinhole_simple/9af9441a94bcd9fd54e1fea44fb0c59ff381a7f2/full.png) + /// The default is `ViewCoordinates::RDF`, i.e. X=Right, Y=Down, Z=Forward, and this is also the recommended setting. + /// This means that the camera frustum will point along the positive Z axis of the parent space, + /// and the cameras "up" direction will be along the negative Y axis of the parent space. /// - /// ```cpp - /// #include + /// The camera frustum will point whichever axis is set to `F` (or the opposite of `B`). + /// When logging a depth image under this entity, this is the direction the point cloud will be projected. + /// With `RDF`, the default forward is +Z. /// - /// #include // std::generate - /// #include // std::rand - /// #include + /// The frustum's "up" direction will be whichever axis is set to `U` (or the opposite of `D`). + /// This will match the negative Y direction of pixel space (all images are assumed to have xyz=RDF). + /// With `RDF`, the default is up is -Y. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_line_strip3d"); - /// rec.spawn().exit_on_failure(); + /// The frustum's "right" direction will be whichever axis is set to `R` (or the opposite of `L`). + /// This will match the positive X direction of pixel space (all images are assumed to have xyz=RDF). + /// With `RDF`, the default right is +x. /// - /// rec.log("world/image", rerun::Pinhole::from_focal_length_and_resolution(3.0f, {3.0f, 3.0f})); + /// Other common formats are `RUB` (X=Right, Y=Up, Z=Back) and `FLU` (X=Forward, Y=Left, Z=Up). /// - /// std::vector random_data(3 * 3 * 3); - /// std::generate(random_data.begin(), random_data.end(), [] { - /// return static_cast(std::rand()); - /// }); + /// NOTE: setting this to something else than `RDF` (the default) will change the orientation of the camera frustum, + /// and make the pinhole matrix not match up with the coordinate system of the pinhole entity. + /// + /// The pinhole matrix (the `image_from_camera` argument) always project along the third (Z) axis, + /// but will be re-oriented to project along the forward axis of the `camera_xyz` argument. + std::optional camera_xyz; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + // Extensions to generated type defined in 'pinhole_ext.cpp' + + /// Creates a pinhole from the camera focal length and resolution, both specified in pixels. + /// + /// The focal length is the diagonal of the projection matrix. + /// Set the same value for x & y value for symmetric cameras, or two values for anamorphic + /// cameras. + /// + /// Assumes the principal point to be in the middle of the sensor. + static Pinhole from_focal_length_and_resolution( + const datatypes::Vec2D& focal_length, const datatypes::Vec2D& resolution + ); + + /// Creates a symmetric pinhole from the camera focal length and resolution, both specified + /// in pixels. + /// + /// The focal length is the diagonal of the projection matrix. + /// + /// Assumes the principal point to be in the middle of the sensor. + static Pinhole from_focal_length_and_resolution( + float focal_length, const datatypes::Vec2D& resolution + ) { + return from_focal_length_and_resolution({focal_length, focal_length}, resolution); + } + + /// Pixel resolution (usually integers) of child image space. Width and height. + /// + /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`. + Pinhole with_resolution(float width, float height) && { + resolution = rerun::components::Resolution(width, height); + return std::move(*this); + } + + /// Pixel resolution (usually integers) of child image space. Width and height. /// - /// const auto tensor = rerun::datatypes::TensorData({3, 3, 3}, random_data); - /// rec.log("world/image", rerun::Image(tensor)); - /// } + /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`. + Pinhole with_resolution(int width, int height) && { + resolution = rerun::components::Resolution(width, height); + return std::move(*this); + } + + public: + Pinhole() = default; + Pinhole(Pinhole&& other) = default; + + explicit Pinhole(rerun::components::PinholeProjection _image_from_camera) + : image_from_camera(std::move(_image_from_camera)) {} + + /// Pixel resolution (usually integers) of child image space. Width and height. + /// + /// Example: + /// ```text + /// [1920.0, 1440.0] /// ``` - struct Pinhole { - /// Camera projection, from image coordinates to view coordinates. - rerun::components::PinholeProjection image_from_camera; - - /// Pixel resolution (usually integers) of child image space. Width and height. - /// - /// Example: - /// ```text - /// [1920.0, 1440.0] - /// ``` - /// - /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`. - std::optional resolution; - - /// Sets the view coordinates for the camera. - /// - /// All common values are available as constants on the `components.ViewCoordinates` class. - /// - /// The default is `ViewCoordinates::RDF`, i.e. X=Right, Y=Down, Z=Forward, and this is also the recommended setting. - /// This means that the camera frustum will point along the positive Z axis of the parent space, - /// and the cameras "up" direction will be along the negative Y axis of the parent space. - /// - /// The camera frustum will point whichever axis is set to `F` (or the opposite of `B`). - /// When logging a depth image under this entity, this is the direction the point cloud will be projected. - /// With `RDF`, the default forward is +Z. - /// - /// The frustum's "up" direction will be whichever axis is set to `U` (or the opposite of `D`). - /// This will match the negative Y direction of pixel space (all images are assumed to have xyz=RDF). - /// With `RDF`, the default is up is -Y. - /// - /// The frustum's "right" direction will be whichever axis is set to `R` (or the opposite of `L`). - /// This will match the positive X direction of pixel space (all images are assumed to have xyz=RDF). - /// With `RDF`, the default right is +x. - /// - /// Other common formats are `RUB` (X=Right, Y=Up, Z=Back) and `FLU` (X=Forward, Y=Left, Z=Up). - /// - /// NOTE: setting this to something else than `RDF` (the default) will change the orientation of the camera frustum, - /// and make the pinhole matrix not match up with the coordinate system of the pinhole entity. - /// - /// The pinhole matrix (the `image_from_camera` argument) always project along the third (Z) axis, - /// but will be re-oriented to project along the forward axis of the `camera_xyz` argument. - std::optional camera_xyz; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - // Extensions to generated type defined in 'pinhole_ext.cpp' - - /// Creates a pinhole from the camera focal length and resolution, both specified in pixels. - /// - /// The focal length is the diagonal of the projection matrix. - /// Set the same value for x & y value for symmetric cameras, or two values for anamorphic - /// cameras. - /// - /// Assumes the principal point to be in the middle of the sensor. - static Pinhole from_focal_length_and_resolution( - const datatypes::Vec2D& focal_length, const datatypes::Vec2D& resolution - ); - - /// Creates a symmetric pinhole from the camera focal length and resolution, both specified - /// in pixels. - /// - /// The focal length is the diagonal of the projection matrix. - /// - /// Assumes the principal point to be in the middle of the sensor. - static Pinhole from_focal_length_and_resolution( - float focal_length, const datatypes::Vec2D& resolution - ) { - return from_focal_length_and_resolution({focal_length, focal_length}, resolution); - } - - /// Pixel resolution (usually integers) of child image space. Width and height. - /// - /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`. - Pinhole with_resolution(float width, float height) && { - resolution = rerun::components::Resolution(width, height); - return std::move(*this); - } - - /// Pixel resolution (usually integers) of child image space. Width and height. - /// - /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`. - Pinhole with_resolution(int width, int height) && { - resolution = rerun::components::Resolution(width, height); - return std::move(*this); - } - - public: - Pinhole() = default; - Pinhole(Pinhole&& other) = default; - - explicit Pinhole(rerun::components::PinholeProjection _image_from_camera) - : image_from_camera(std::move(_image_from_camera)) {} - - /// Pixel resolution (usually integers) of child image space. Width and height. - /// - /// Example: - /// ```text - /// [1920.0, 1440.0] - /// ``` - /// - /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`. - Pinhole with_resolution(rerun::components::Resolution _resolution) && { - resolution = std::move(_resolution); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Sets the view coordinates for the camera. - /// - /// All common values are available as constants on the `components.ViewCoordinates` class. - /// - /// The default is `ViewCoordinates::RDF`, i.e. X=Right, Y=Down, Z=Forward, and this is also the recommended setting. - /// This means that the camera frustum will point along the positive Z axis of the parent space, - /// and the cameras "up" direction will be along the negative Y axis of the parent space. - /// - /// The camera frustum will point whichever axis is set to `F` (or the opposite of `B`). - /// When logging a depth image under this entity, this is the direction the point cloud will be projected. - /// With `RDF`, the default forward is +Z. - /// - /// The frustum's "up" direction will be whichever axis is set to `U` (or the opposite of `D`). - /// This will match the negative Y direction of pixel space (all images are assumed to have xyz=RDF). - /// With `RDF`, the default is up is -Y. - /// - /// The frustum's "right" direction will be whichever axis is set to `R` (or the opposite of `L`). - /// This will match the positive X direction of pixel space (all images are assumed to have xyz=RDF). - /// With `RDF`, the default right is +x. - /// - /// Other common formats are `RUB` (X=Right, Y=Up, Z=Back) and `FLU` (X=Forward, Y=Left, Z=Up). - /// - /// NOTE: setting this to something else than `RDF` (the default) will change the orientation of the camera frustum, - /// and make the pinhole matrix not match up with the coordinate system of the pinhole entity. - /// - /// The pinhole matrix (the `image_from_camera` argument) always project along the third (Z) axis, - /// but will be re-oriented to project along the forward axis of the `camera_xyz` argument. - Pinhole with_camera_xyz(rerun::components::ViewCoordinates _camera_xyz) && { - camera_xyz = std::move(_camera_xyz); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; - - } // namespace archetypes + /// + /// `image_from_camera` project onto the space spanned by `(0,0)` and `resolution - 1`. + Pinhole with_resolution(rerun::components::Resolution _resolution) && { + resolution = std::move(_resolution); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Sets the view coordinates for the camera. + /// + /// All common values are available as constants on the `components.ViewCoordinates` class. + /// + /// The default is `ViewCoordinates::RDF`, i.e. X=Right, Y=Down, Z=Forward, and this is also the recommended setting. + /// This means that the camera frustum will point along the positive Z axis of the parent space, + /// and the cameras "up" direction will be along the negative Y axis of the parent space. + /// + /// The camera frustum will point whichever axis is set to `F` (or the opposite of `B`). + /// When logging a depth image under this entity, this is the direction the point cloud will be projected. + /// With `RDF`, the default forward is +Z. + /// + /// The frustum's "up" direction will be whichever axis is set to `U` (or the opposite of `D`). + /// This will match the negative Y direction of pixel space (all images are assumed to have xyz=RDF). + /// With `RDF`, the default is up is -Y. + /// + /// The frustum's "right" direction will be whichever axis is set to `R` (or the opposite of `L`). + /// This will match the positive X direction of pixel space (all images are assumed to have xyz=RDF). + /// With `RDF`, the default right is +x. + /// + /// Other common formats are `RUB` (X=Right, Y=Up, Z=Back) and `FLU` (X=Forward, Y=Left, Z=Up). + /// + /// NOTE: setting this to something else than `RDF` (the default) will change the orientation of the camera frustum, + /// and make the pinhole matrix not match up with the coordinate system of the pinhole entity. + /// + /// The pinhole matrix (the `image_from_camera` argument) always project along the third (Z) axis, + /// but will be re-oriented to project along the forward axis of the `camera_xyz` argument. + Pinhole with_camera_xyz(rerun::components::ViewCoordinates _camera_xyz) && { + camera_xyz = std::move(_camera_xyz); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/points2d.cpp b/rerun_cpp/src/rerun/archetypes/points2d.cpp index d91e69ec5d11..541971e1919f 100644 --- a/rerun_cpp/src/rerun/archetypes/points2d.cpp +++ b/rerun_cpp/src/rerun/archetypes/points2d.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Points2D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Points2DIndicator"; +} + namespace rerun { - namespace archetypes { - const char Points2D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Points2DIndicator"; - } Result> AsComponents::serialize( const archetypes::Points2D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/points2d.hpp b/rerun_cpp/src/rerun/archetypes/points2d.hpp index c5bbd9690c9a..8328bbbb8a13 100644 --- a/rerun_cpp/src/rerun/archetypes/points2d.hpp +++ b/rerun_cpp/src/rerun/archetypes/points2d.hpp @@ -22,172 +22,170 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A 2D point cloud with positions and optional colors, radii, labels, etc. - /// - /// ## Example - /// - /// ### Randomly distributed 2D points with varying color and radius - /// ![image](https://static.rerun.io/point2d_random/8e8ac75373677bd72bd3f56a15e44fcab309a168/full.png) +namespace rerun::archetypes { + /// **Archetype**: A 2D point cloud with positions and optional colors, radii, labels, etc. + /// + /// ## Example + /// + /// ### Randomly distributed 2D points with varying color and radius + /// ![image](https://static.rerun.io/point2d_random/8e8ac75373677bd72bd3f56a15e44fcab309a168/full.png) + /// + /// ```cpp + /// #include + /// + /// #include + /// #include + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_points2d_simple"); + /// rec.spawn().exit_on_failure(); + /// + /// std::default_random_engine gen; + /// std::uniform_real_distribution dist_pos(-5.0f, 5.0f); + /// std::uniform_real_distribution dist_radius(0.1f, 1.0f); + /// // On MSVC uint8_t distributions are not supported. + /// std::uniform_int_distribution dist_color(0, 255); + /// + /// std::vector points2d(10); + /// std::generate(points2d.begin(), points2d.end(), [&] { + /// return rerun::Position2D(dist_pos(gen), dist_pos(gen)); + /// }); + /// std::vector colors(10); + /// std::generate(colors.begin(), colors.end(), [&] { + /// return rerun::Color( + /// static_cast(dist_color(gen)), + /// static_cast(dist_color(gen)), + /// static_cast(dist_color(gen)) + /// ); + /// }); + /// std::vector radii(10); + /// std::generate(radii.begin(), radii.end(), [&] { return dist_radius(gen); }); + /// + /// rec.log("random", rerun::Points2D(points2d).with_colors(colors).with_radii(radii)); + /// + /// // Log an extra rect to set the view bounds + /// rec.log("bounds", rerun::Boxes2D::from_half_sizes({{2.0f, 1.5f}})); + /// } + /// ``` + struct Points2D { + /// All the 2D positions at which the point cloud shows points. + ComponentBatch positions; + + /// Optional radii for the points, effectively turning them into circles. + std::optional> radii; + + /// Optional colors for the points. + std::optional> colors; + + /// Optional text labels for the points. + std::optional> labels; + + /// An optional floating point value that specifies the 2D drawing order. /// - /// ```cpp - /// #include - /// - /// #include - /// #include - /// #include + /// Objects with higher values are drawn on top of those with lower values. + std::optional draw_order; + + /// Optional class Ids for the points. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_points2d_simple"); - /// rec.spawn().exit_on_failure(); + /// The class ID provides colors and labels if not specified explicitly. + std::optional> class_ids; + + /// Optional keypoint IDs for the points, identifying them within a class. /// - /// std::default_random_engine gen; - /// std::uniform_real_distribution dist_pos(-5.0f, 5.0f); - /// std::uniform_real_distribution dist_radius(0.1f, 1.0f); - /// // On MSVC uint8_t distributions are not supported. - /// std::uniform_int_distribution dist_color(0, 255); + /// 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. + std::optional> keypoint_ids; + + /// Unique identifiers for each individual point in the batch. + std::optional> instance_keys; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + Points2D() = default; + Points2D(Points2D&& other) = default; + + explicit Points2D(ComponentBatch _positions) + : positions(std::move(_positions)) {} + + /// Optional radii for the points, effectively turning them into circles. + Points2D with_radii(ComponentBatch _radii) && { + radii = std::move(_radii); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional colors for the points. + Points2D with_colors(ComponentBatch _colors) && { + colors = std::move(_colors); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional text labels for the points. + Points2D with_labels(ComponentBatch _labels) && { + labels = std::move(_labels); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// An optional floating point value that specifies the 2D drawing order. /// - /// std::vector points2d(10); - /// std::generate(points2d.begin(), points2d.end(), [&] { - /// return rerun::Position2D(dist_pos(gen), dist_pos(gen)); - /// }); - /// std::vector colors(10); - /// std::generate(colors.begin(), colors.end(), [&] { - /// return rerun::Color( - /// static_cast(dist_color(gen)), - /// static_cast(dist_color(gen)), - /// static_cast(dist_color(gen)) - /// ); - /// }); - /// std::vector radii(10); - /// std::generate(radii.begin(), radii.end(), [&] { return dist_radius(gen); }); + /// Objects with higher values are drawn on top of those with lower values. + Points2D with_draw_order(rerun::components::DrawOrder _draw_order) && { + draw_order = std::move(_draw_order); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional class Ids for the points. /// - /// rec.log("random", rerun::Points2D(points2d).with_colors(colors).with_radii(radii)); + /// The class ID provides colors and labels if not specified explicitly. + Points2D with_class_ids(ComponentBatch _class_ids) && { + class_ids = std::move(_class_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional keypoint IDs for the points, identifying them within a class. /// - /// // Log an extra rect to set the view bounds - /// rec.log("bounds", rerun::Boxes2D::from_half_sizes({{2.0f, 1.5f}})); - /// } - /// ``` - struct Points2D { - /// All the 2D positions at which the point cloud shows points. - ComponentBatch positions; - - /// Optional radii for the points, effectively turning them into circles. - std::optional> radii; - - /// Optional colors for the points. - std::optional> colors; - - /// Optional text labels for the points. - std::optional> labels; - - /// An optional floating point value that specifies the 2D drawing order. - /// - /// Objects with higher values are drawn on top of those with lower values. - std::optional draw_order; - - /// Optional class Ids for the points. - /// - /// The class ID provides colors and labels if not specified explicitly. - std::optional> class_ids; - - /// 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. - std::optional> keypoint_ids; - - /// Unique identifiers for each individual point in the batch. - std::optional> instance_keys; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - Points2D() = default; - Points2D(Points2D&& other) = default; - - explicit Points2D(ComponentBatch _positions) - : positions(std::move(_positions)) {} - - /// Optional radii for the points, effectively turning them into circles. - Points2D with_radii(ComponentBatch _radii) && { - radii = std::move(_radii); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional colors for the points. - Points2D with_colors(ComponentBatch _colors) && { - colors = std::move(_colors); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional text labels for the points. - Points2D with_labels(ComponentBatch _labels) && { - labels = std::move(_labels); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*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. - Points2D with_draw_order(rerun::components::DrawOrder _draw_order) && { - draw_order = std::move(_draw_order); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional class Ids for the points. - /// - /// The class ID provides colors and labels if not specified explicitly. - Points2D with_class_ids(ComponentBatch _class_ids) && { - class_ids = std::move(_class_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*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(ComponentBatch _keypoint_ids - ) && { - keypoint_ids = std::move(_keypoint_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Unique identifiers for each individual point in the batch. - Points2D with_instance_keys( - ComponentBatch _instance_keys - ) && { - instance_keys = std::move(_instance_keys); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return positions.size(); - } - }; - - } // namespace archetypes + /// 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(ComponentBatch _keypoint_ids) && { + keypoint_ids = std::move(_keypoint_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Unique identifiers for each individual point in the batch. + Points2D with_instance_keys(ComponentBatch _instance_keys + ) && { + instance_keys = std::move(_instance_keys); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return positions.size(); + } + }; +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/points3d.cpp b/rerun_cpp/src/rerun/archetypes/points3d.cpp index 6df94e268617..aa13006131f5 100644 --- a/rerun_cpp/src/rerun/archetypes/points3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/points3d.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Points3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Points3DIndicator"; +} + namespace rerun { - namespace archetypes { - const char Points3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Points3DIndicator"; - } Result> AsComponents::serialize( const archetypes::Points3D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/points3d.hpp b/rerun_cpp/src/rerun/archetypes/points3d.hpp index ffc9b878e065..a4222423fa00 100644 --- a/rerun_cpp/src/rerun/archetypes/points3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/points3d.hpp @@ -21,155 +21,153 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A 3D point cloud with positions and optional colors, radii, labels, etc. - /// - /// ## Example - /// - /// ### Randomly distributed 3D points with varying color and radius - /// ![image](https://static.rerun.io/point3d_random/7e94e1806d2c381943748abbb3bedb68d564de24/full.png) - /// - /// ```cpp - /// #include - /// - /// #include - /// #include - /// #include +namespace rerun::archetypes { + /// **Archetype**: A 3D point cloud with positions and optional colors, radii, labels, etc. + /// + /// ## Example + /// + /// ### Randomly distributed 3D points with varying color and radius + /// ![image](https://static.rerun.io/point3d_random/7e94e1806d2c381943748abbb3bedb68d564de24/full.png) + /// + /// ```cpp + /// #include + /// + /// #include + /// #include + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_points3d_random"); + /// rec.spawn().exit_on_failure(); + /// + /// std::default_random_engine gen; + /// std::uniform_real_distribution dist_pos(-5.0f, 5.0f); + /// std::uniform_real_distribution dist_radius(0.1f, 1.0f); + /// // On MSVC uint8_t distributions are not supported. + /// std::uniform_int_distribution dist_color(0, 255); + /// + /// std::vector points3d(10); + /// std::generate(points3d.begin(), points3d.end(), [&] { + /// return rerun::Position3D(dist_pos(gen), dist_pos(gen), dist_pos(gen)); + /// }); + /// std::vector colors(10); + /// std::generate(colors.begin(), colors.end(), [&] { + /// return rerun::Color( + /// static_cast(dist_color(gen)), + /// static_cast(dist_color(gen)), + /// static_cast(dist_color(gen)) + /// ); + /// }); + /// std::vector radii(10); + /// std::generate(radii.begin(), radii.end(), [&] { return dist_radius(gen); }); + /// + /// rec.log("random", rerun::Points3D(points3d).with_colors(colors).with_radii(radii)); + /// } + /// ``` + struct Points3D { + /// All the 3D positions at which the point cloud shows points. + ComponentBatch positions; + + /// Optional radii for the points, effectively turning them into circles. + std::optional> radii; + + /// Optional colors for the points. + std::optional> colors; + + /// Optional text labels for the points. + std::optional> labels; + + /// Optional class Ids for the points. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_points3d_random"); - /// rec.spawn().exit_on_failure(); + /// The class ID provides colors and labels if not specified explicitly. + std::optional> class_ids; + + /// Optional keypoint IDs for the points, identifying them within a class. /// - /// std::default_random_engine gen; - /// std::uniform_real_distribution dist_pos(-5.0f, 5.0f); - /// std::uniform_real_distribution dist_radius(0.1f, 1.0f); - /// // On MSVC uint8_t distributions are not supported. - /// std::uniform_int_distribution dist_color(0, 255); + /// 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. + std::optional> keypoint_ids; + + /// Unique identifiers for each individual point in the batch. + std::optional> instance_keys; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + Points3D() = default; + Points3D(Points3D&& other) = default; + + explicit Points3D(ComponentBatch _positions) + : positions(std::move(_positions)) {} + + /// Optional radii for the points, effectively turning them into circles. + Points3D with_radii(ComponentBatch _radii) && { + radii = std::move(_radii); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional colors for the points. + Points3D with_colors(ComponentBatch _colors) && { + colors = std::move(_colors); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional text labels for the points. + Points3D with_labels(ComponentBatch _labels) && { + labels = std::move(_labels); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional class Ids for the points. /// - /// std::vector points3d(10); - /// std::generate(points3d.begin(), points3d.end(), [&] { - /// return rerun::Position3D(dist_pos(gen), dist_pos(gen), dist_pos(gen)); - /// }); - /// std::vector colors(10); - /// std::generate(colors.begin(), colors.end(), [&] { - /// return rerun::Color( - /// static_cast(dist_color(gen)), - /// static_cast(dist_color(gen)), - /// static_cast(dist_color(gen)) - /// ); - /// }); - /// std::vector radii(10); - /// std::generate(radii.begin(), radii.end(), [&] { return dist_radius(gen); }); + /// The class ID provides colors and labels if not specified explicitly. + Points3D with_class_ids(ComponentBatch _class_ids) && { + class_ids = std::move(_class_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional keypoint IDs for the points, identifying them within a class. /// - /// rec.log("random", rerun::Points3D(points3d).with_colors(colors).with_radii(radii)); - /// } - /// ``` - struct Points3D { - /// All the 3D positions at which the point cloud shows points. - ComponentBatch positions; - - /// Optional radii for the points, effectively turning them into circles. - std::optional> radii; - - /// Optional colors for the points. - std::optional> colors; - - /// Optional text labels for the points. - std::optional> labels; - - /// Optional class Ids for the points. - /// - /// The class ID provides colors and labels if not specified explicitly. - std::optional> class_ids; - - /// 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. - std::optional> keypoint_ids; - - /// Unique identifiers for each individual point in the batch. - std::optional> instance_keys; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - Points3D() = default; - Points3D(Points3D&& other) = default; - - explicit Points3D(ComponentBatch _positions) - : positions(std::move(_positions)) {} - - /// Optional radii for the points, effectively turning them into circles. - Points3D with_radii(ComponentBatch _radii) && { - radii = std::move(_radii); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional colors for the points. - Points3D with_colors(ComponentBatch _colors) && { - colors = std::move(_colors); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional text labels for the points. - Points3D with_labels(ComponentBatch _labels) && { - labels = std::move(_labels); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional class Ids for the points. - /// - /// The class ID provides colors and labels if not specified explicitly. - Points3D with_class_ids(ComponentBatch _class_ids) && { - class_ids = std::move(_class_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*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(ComponentBatch _keypoint_ids - ) && { - keypoint_ids = std::move(_keypoint_ids); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Unique identifiers for each individual point in the batch. - Points3D with_instance_keys( - ComponentBatch _instance_keys - ) && { - instance_keys = std::move(_instance_keys); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return positions.size(); - } - }; - - } // namespace archetypes + /// 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(ComponentBatch _keypoint_ids) && { + keypoint_ids = std::move(_keypoint_ids); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Unique identifiers for each individual point in the batch. + Points3D with_instance_keys(ComponentBatch _instance_keys + ) && { + instance_keys = std::move(_instance_keys); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return positions.size(); + } + }; +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp b/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp index 84c8d08860b9..39430a8c1113 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp @@ -5,11 +5,12 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char SegmentationImage::INDICATOR_COMPONENT_NAME[] = + "rerun.components.SegmentationImageIndicator"; +} + namespace rerun { - namespace archetypes { - const char SegmentationImage::INDICATOR_COMPONENT_NAME[] = - "rerun.components.SegmentationImageIndicator"; - } Result> AsComponents< archetypes::SegmentationImage>::serialize(const archetypes::SegmentationImage& archetype) { diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp index 2277c9ac04d2..2d6a7ead8006 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp @@ -16,107 +16,107 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: An image made up of integer class-ids. - /// - /// The shape of the `TensorData` must be mappable to an `HxW` tensor. - /// Each pixel corresponds to a depth value in units specified by meter. - /// - /// Leading and trailing unit-dimensions are ignored, so that - /// `1x640x480x1` is treated as a `640x480` image. - /// - /// ## Example - /// - /// ### Simple segmentation image - /// ![image](https://static.rerun.io/segmentation_image_simple/eb49e0b8cb870c75a69e2a47a2d202e5353115f6/full.png) - /// - /// ```cpp - /// #include - /// - /// #include // std::fill_n - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_annotation_context_connections"); - /// rec.spawn().exit_on_failure(); - /// - /// // Create a segmentation image - /// const int HEIGHT = 8; - /// const int WIDTH = 12; - /// std::vector data(WIDTH * HEIGHT, 0); - /// for (auto y = 0; y <4; ++y) { // top half - /// std::fill_n(data.begin() + y * WIDTH, 6, static_cast(1)); // left half - /// } - /// for (auto y = 4; y <8; ++y) { // bottom half - /// std::fill_n(data.begin() + y * WIDTH + 6, 6, static_cast(2)); // right half - /// } - /// - /// // create an annotation context to describe the classes - /// rec.log_timeless( - /// "/", - /// rerun::AnnotationContext({ - /// rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)), - /// rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)), - /// }) - /// ); - /// - /// rec.log("image", rerun::SegmentationImage({HEIGHT, WIDTH}, std::move(data))); - /// } - /// ``` - struct SegmentationImage { - /// The image data. Should always be a rank-2 tensor. - rerun::components::TensorData data; +namespace rerun::archetypes { + /// **Archetype**: An image made up of integer class-ids. + /// + /// The shape of the `TensorData` must be mappable to an `HxW` tensor. + /// Each pixel corresponds to a depth value in units specified by meter. + /// + /// Leading and trailing unit-dimensions are ignored, so that + /// `1x640x480x1` is treated as a `640x480` image. + /// + /// ## Example + /// + /// ### Simple segmentation image + /// ![image](https://static.rerun.io/segmentation_image_simple/eb49e0b8cb870c75a69e2a47a2d202e5353115f6/full.png) + /// + /// ```cpp + /// #include + /// + /// #include // std::fill_n + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_annotation_context_connections"); + /// rec.spawn().exit_on_failure(); + /// + /// // Create a segmentation image + /// const int HEIGHT = 8; + /// const int WIDTH = 12; + /// std::vector data(WIDTH * HEIGHT, 0); + /// for (auto y = 0; y <4; ++y) { // top half + /// std::fill_n(data.begin() + y * WIDTH, 6, static_cast(1)); // left half + /// } + /// for (auto y = 4; y <8; ++y) { // bottom half + /// std::fill_n(data.begin() + y * WIDTH + 6, 6, static_cast(2)); // right half + /// } + /// + /// // create an annotation context to describe the classes + /// rec.log_timeless( + /// "/", + /// rerun::AnnotationContext({ + /// rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)), + /// rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)), + /// }) + /// ); + /// + /// rec.log("image", rerun::SegmentationImage({HEIGHT, WIDTH}, std::move(data))); + /// } + /// ``` + struct SegmentationImage { + /// The image data. Should always be a rank-2 tensor. + rerun::components::TensorData data; - /// An optional floating point value that specifies the 2D drawing order. - /// - /// Objects with higher values are drawn on top of those with lower values. - std::optional draw_order; + /// An optional floating point value that specifies the 2D drawing order. + /// + /// Objects with higher values are drawn on top of those with lower values. + std::optional draw_order; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - // Extensions to generated type defined in 'segmentation_image_ext.cpp' + public: + // Extensions to generated type defined in 'segmentation_image_ext.cpp' - /// New segmentation image from height/width and tensor buffer. - /// - /// Sets the dimension names to "height" and "width" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2. - SegmentationImage( - std::vector shape, datatypes::TensorBuffer buffer - ) - : SegmentationImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} + /// New segmentation image from height/width and tensor buffer. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + SegmentationImage( + std::vector shape, datatypes::TensorBuffer buffer + ) + : SegmentationImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} - /// New segmentation image from tensor data. - /// - /// Sets the dimension names to "height" and "width" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2. - explicit SegmentationImage(components::TensorData _data); + /// New segmentation image from tensor data. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + explicit SegmentationImage(components::TensorData _data); - public: - SegmentationImage() = default; - SegmentationImage(SegmentationImage&& other) = default; + public: + SegmentationImage() = default; + SegmentationImage(SegmentationImage&& other) = default; - /// An optional floating point value that specifies the 2D drawing order. - /// - /// Objects with higher values are drawn on top of those with lower values. - SegmentationImage with_draw_order(rerun::components::DrawOrder _draw_order) && { - draw_order = std::move(_draw_order); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*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. + SegmentationImage with_draw_order(rerun::components::DrawOrder _draw_order) && { + draw_order = std::move(_draw_order); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/tensor.cpp b/rerun_cpp/src/rerun/archetypes/tensor.cpp index 221e6b1a6461..e181f67a3c13 100644 --- a/rerun_cpp/src/rerun/archetypes/tensor.cpp +++ b/rerun_cpp/src/rerun/archetypes/tensor.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Tensor::INDICATOR_COMPONENT_NAME[] = "rerun.components.TensorIndicator"; +} + namespace rerun { - namespace archetypes { - const char Tensor::INDICATOR_COMPONENT_NAME[] = "rerun.components.TensorIndicator"; - } Result> AsComponents::serialize( const archetypes::Tensor& archetype diff --git a/rerun_cpp/src/rerun/archetypes/tensor.hpp b/rerun_cpp/src/rerun/archetypes/tensor.hpp index 36ee33c2f053..527c6b6c3e89 100644 --- a/rerun_cpp/src/rerun/archetypes/tensor.hpp +++ b/rerun_cpp/src/rerun/archetypes/tensor.hpp @@ -13,82 +13,82 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A generic n-dimensional Tensor. - /// - /// ## Example - /// - /// ### Simple Tensor - /// ![image](https://static.rerun.io/tensor_simple/baacb07712f7b706e3c80e696f70616c6c20b367/full.png) - /// - /// ```cpp - /// #include - /// - /// #include // std::generate - /// #include - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_tensor_simple"); - /// rec.spawn().exit_on_failure(); - /// - /// std::default_random_engine gen; - /// // On MSVC uint8_t distributions are not supported. - /// std::uniform_int_distribution dist(0, 255); - /// - /// std::vector data(8 * 6 * 3 * 5); - /// std::generate(data.begin(), data.end(), [&] { return static_cast(dist(gen)); }); - /// - /// rec.log( - /// "tensor", - /// rerun::Tensor({8, 6, 3, 5}, data).with_dim_names({"width", "height", "channel", "batch"}) - /// ); - /// } - /// ``` - struct Tensor { - /// The tensor data - rerun::components::TensorData data; +namespace rerun::archetypes { + /// **Archetype**: A generic n-dimensional Tensor. + /// + /// ## Example + /// + /// ### Simple Tensor + /// ![image](https://static.rerun.io/tensor_simple/baacb07712f7b706e3c80e696f70616c6c20b367/full.png) + /// + /// ```cpp + /// #include + /// + /// #include // std::generate + /// #include + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_tensor_simple"); + /// rec.spawn().exit_on_failure(); + /// + /// std::default_random_engine gen; + /// // On MSVC uint8_t distributions are not supported. + /// std::uniform_int_distribution dist(0, 255); + /// + /// std::vector data(8 * 6 * 3 * 5); + /// std::generate(data.begin(), data.end(), [&] { return static_cast(dist(gen)); }); + /// + /// rec.log( + /// "tensor", + /// rerun::Tensor({8, 6, 3, 5}, data).with_dim_names({"width", "height", "channel", "batch"}) + /// ); + /// } + /// ``` + struct Tensor { + /// The tensor data + rerun::components::TensorData data; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - // Extensions to generated type defined in 'tensor_ext.cpp' + public: + // Extensions to generated type defined in 'tensor_ext.cpp' - /// New Tensor from dimensions and tensor buffer. - Tensor( - std::vector shape, - rerun::datatypes::TensorBuffer buffer - ) - : Tensor(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} + /// New Tensor from dimensions and tensor buffer. + Tensor( + std::vector shape, + rerun::datatypes::TensorBuffer buffer + ) + : Tensor(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} - /// Update the `names` of the contained `TensorData` dimensions. - /// - /// Any existing Dimension names will be overwritten. - /// - /// If too many, or too few names are provided, this function will call - /// Error::handle and then proceed to only update the subset of names that it can. - /// - /// TODO(#3794): don't use std::vector here. - Tensor with_dim_names(std::vector names) &&; + /// Update the `names` of the contained `TensorData` dimensions. + /// + /// Any existing Dimension names will be overwritten. + /// + /// If too many, or too few names are provided, this function will call + /// Error::handle and then proceed to only update the subset of names that it can. + /// + /// TODO(#3794): don't use std::vector here. + Tensor with_dim_names(std::vector names) &&; - public: - Tensor() = default; - Tensor(Tensor&& other) = default; + public: + Tensor() = default; + Tensor(Tensor&& other) = default; - explicit Tensor(rerun::components::TensorData _data) : data(std::move(_data)) {} + explicit Tensor(rerun::components::TensorData _data) : data(std::move(_data)) {} - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/text_document.cpp b/rerun_cpp/src/rerun/archetypes/text_document.cpp index 128849e5036c..7f7cd0418094 100644 --- a/rerun_cpp/src/rerun/archetypes/text_document.cpp +++ b/rerun_cpp/src/rerun/archetypes/text_document.cpp @@ -5,11 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char TextDocument::INDICATOR_COMPONENT_NAME[] = "rerun.components.TextDocumentIndicator"; +} + namespace rerun { - namespace archetypes { - const char TextDocument::INDICATOR_COMPONENT_NAME[] = - "rerun.components.TextDocumentIndicator"; - } Result> AsComponents::serialize( const archetypes::TextDocument& archetype diff --git a/rerun_cpp/src/rerun/archetypes/text_document.hpp b/rerun_cpp/src/rerun/archetypes/text_document.hpp index c6a4f12ddc41..3aa994689cc9 100644 --- a/rerun_cpp/src/rerun/archetypes/text_document.hpp +++ b/rerun_cpp/src/rerun/archetypes/text_document.hpp @@ -16,110 +16,110 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A text element intended to be displayed in its own text-box. - /// - /// Supports raw text and markdown. - /// - /// ## Example - /// - /// ### Markdown text document - /// ![image](https://static.rerun.io/textdocument/babda19558ee32ed8d730495b595aee7a5e2c174/full.png) - /// - /// ```cpp - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_text_document"); - /// rec.spawn().exit_on_failure(); - /// - /// rec.log("text_document", rerun::TextDocument("Hello, TextDocument!")); - /// - /// rec.log( - /// "markdown", - /// rerun::TextDocument(R"#(# Hello Markdown! - /// [Click here to see the raw text](recording://markdown.Text). - /// - /// Basic formatting: - /// - /// | **Feature** | **Alternative** | - /// | ----------------- | --------------- | - /// | Plain | | - /// | *italics* | _italics_ | - /// | **bold** | __bold__ | - /// | ~~strikethrough~~ | | - /// | `inline code` | | - /// - /// ---------------------------------- - /// - /// ## Support - /// - [x] [Commonmark](https://commonmark.org/help/) support - /// - [x] GitHub-style strikethrough, tables, and checkboxes - /// - Basic syntax highlighting for: - /// - [x] C and C++ - /// - [x] Python - /// - [x] Rust - /// - [ ] Other languages - /// - /// ## Links - /// You can link to [an entity](recording://markdown), - /// a [specific instance of an entity](recording://markdown[#0]), - /// or a [specific component](recording://markdown.Text). +namespace rerun::archetypes { + /// **Archetype**: A text element intended to be displayed in its own text-box. + /// + /// Supports raw text and markdown. + /// + /// ## Example + /// + /// ### Markdown text document + /// ![image](https://static.rerun.io/textdocument/babda19558ee32ed8d730495b595aee7a5e2c174/full.png) + /// + /// ```cpp + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_text_document"); + /// rec.spawn().exit_on_failure(); + /// + /// rec.log("text_document", rerun::TextDocument("Hello, TextDocument!")); + /// + /// rec.log( + /// "markdown", + /// rerun::TextDocument(R"#(# Hello Markdown! + /// [Click here to see the raw text](recording://markdown.Text). + /// + /// Basic formatting: + /// + /// | **Feature** | **Alternative** | + /// | ----------------- | --------------- | + /// | Plain | | + /// | *italics* | _italics_ | + /// | **bold** | __bold__ | + /// | ~~strikethrough~~ | | + /// | `inline code` | | + /// + /// ---------------------------------- + /// + /// ## Support + /// - [x] [Commonmark](https://commonmark.org/help/) support + /// - [x] GitHub-style strikethrough, tables, and checkboxes + /// - Basic syntax highlighting for: + /// - [x] C and C++ + /// - [x] Python + /// - [x] Rust + /// - [ ] Other languages + /// + /// ## Links + /// You can link to [an entity](recording://markdown), + /// a [specific instance of an entity](recording://markdown[#0]), + /// or a [specific component](recording://markdown.Text). + /// + /// Of course you can also have [normal https links](https://github.com/rerun-io/rerun), e.g. . + /// + /// ## Image + /// ![A random image](https://picsum.photos/640/480))#") + /// .with_media_type(rerun::MediaType::markdown()) + /// ); + /// } + /// ``` + struct TextDocument { + /// Contents of the text document. + rerun::components::Text text; + + /// The Media Type of the text. /// - /// Of course you can also have [normal https links](https://github.com/rerun-io/rerun), e.g. . + /// For instance: + /// * `text/plain` + /// * `text/markdown` /// - /// ## Image - /// ![A random image](https://picsum.photos/640/480))#") - /// .with_media_type(rerun::MediaType::markdown()) - /// ); - /// } - /// ``` - struct TextDocument { - /// Contents of the text document. - rerun::components::Text text; - - /// The Media Type of the text. - /// - /// For instance: - /// * `text/plain` - /// * `text/markdown` - /// - /// If omitted, `text/plain` is assumed. - std::optional media_type; + /// If omitted, `text/plain` is assumed. + std::optional media_type; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - TextDocument() = default; - TextDocument(TextDocument&& other) = default; + public: + TextDocument() = default; + TextDocument(TextDocument&& other) = default; - explicit TextDocument(rerun::components::Text _text) : text(std::move(_text)) {} + explicit TextDocument(rerun::components::Text _text) : text(std::move(_text)) {} - /// The Media Type of the text. - /// - /// For instance: - /// * `text/plain` - /// * `text/markdown` - /// - /// If omitted, `text/plain` is assumed. - TextDocument with_media_type(rerun::components::MediaType _media_type) && { - media_type = std::move(_media_type); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } + /// The Media Type of the text. + /// + /// For instance: + /// * `text/plain` + /// * `text/markdown` + /// + /// If omitted, `text/plain` is assumed. + TextDocument with_media_type(rerun::components::MediaType _media_type) && { + media_type = std::move(_media_type); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/text_log.cpp b/rerun_cpp/src/rerun/archetypes/text_log.cpp index 6f6bcce74304..da87f5afb195 100644 --- a/rerun_cpp/src/rerun/archetypes/text_log.cpp +++ b/rerun_cpp/src/rerun/archetypes/text_log.cpp @@ -5,10 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char TextLog::INDICATOR_COMPONENT_NAME[] = "rerun.components.TextLogIndicator"; +} + namespace rerun { - namespace archetypes { - const char TextLog::INDICATOR_COMPONENT_NAME[] = "rerun.components.TextLogIndicator"; - } Result> AsComponents::serialize( const archetypes::TextLog& archetype diff --git a/rerun_cpp/src/rerun/archetypes/text_log.hpp b/rerun_cpp/src/rerun/archetypes/text_log.hpp index 9dac48f46479..ee7219e33f1d 100644 --- a/rerun_cpp/src/rerun/archetypes/text_log.hpp +++ b/rerun_cpp/src/rerun/archetypes/text_log.hpp @@ -17,115 +17,115 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A log entry in a text log, comprised of a text body and its log level. - /// - /// ## Example - /// - /// ### `text_log_integration`: - /// ![image](https://static.rerun.io/text_log_integration/9737d0c986325802a9885499d6fcc773b1736488/full.png) - /// - /// ```cpp - /// #include - /// #include - /// - /// void loguru_to_rerun(void* user_data, const loguru::Message& message) { - /// // NOTE: `rerun::RecordingStream` is thread-safe. - /// const rerun::RecordingStream* rec = reinterpret_cast(user_data); - /// - /// rerun::TextLogLevel level; - /// if (message.verbosity == loguru::Verbosity_FATAL) { - /// level = rerun::TextLogLevel::Critical; - /// } else if (message.verbosity == loguru::Verbosity_ERROR) { - /// level = rerun::TextLogLevel::Error; - /// } else if (message.verbosity == loguru::Verbosity_WARNING) { - /// level = rerun::TextLogLevel::Warning; - /// } else if (message.verbosity == loguru::Verbosity_INFO) { - /// level = rerun::TextLogLevel::Info; - /// } else if (message.verbosity == loguru::Verbosity_1) { - /// level = rerun::TextLogLevel::Debug; - /// } else if (message.verbosity == loguru::Verbosity_2) { - /// level = rerun::TextLogLevel::Trace; - /// } else { - /// level = rerun::TextLogLevel(std::to_string(message.verbosity)); - /// } - /// - /// rec->log( - /// "logs/handler/text_log_integration", - /// rerun::TextLog(message.message).with_level(level) - /// ); - /// } - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_text_log_integration"); - /// rec.spawn().exit_on_failure(); - /// - /// // Log a text entry directly: - /// rec.log( - /// "logs", - /// rerun::TextLog("this entry has loglevel TRACE").with_level(rerun::TextLogLevel::Trace) - /// ); - /// - /// loguru::add_callback( - /// "rerun", - /// loguru_to_rerun, - /// const_cast(reinterpret_cast(&rec)), - /// loguru::Verbosity_INFO - /// ); - /// - /// LOG_F(INFO, "This INFO log got added through the standard logging interface"); - /// - /// loguru::remove_callback("rerun"); // we need to do this before `rec` goes out of scope - /// } - /// ``` - struct TextLog { - /// The body of the message. - rerun::components::Text text; +namespace rerun::archetypes { + /// **Archetype**: A log entry in a text log, comprised of a text body and its log level. + /// + /// ## Example + /// + /// ### `text_log_integration`: + /// ![image](https://static.rerun.io/text_log_integration/9737d0c986325802a9885499d6fcc773b1736488/full.png) + /// + /// ```cpp + /// #include + /// #include + /// + /// void loguru_to_rerun(void* user_data, const loguru::Message& message) { + /// // NOTE: `rerun::RecordingStream` is thread-safe. + /// const rerun::RecordingStream* rec = reinterpret_cast(user_data); + /// + /// rerun::TextLogLevel level; + /// if (message.verbosity == loguru::Verbosity_FATAL) { + /// level = rerun::TextLogLevel::Critical; + /// } else if (message.verbosity == loguru::Verbosity_ERROR) { + /// level = rerun::TextLogLevel::Error; + /// } else if (message.verbosity == loguru::Verbosity_WARNING) { + /// level = rerun::TextLogLevel::Warning; + /// } else if (message.verbosity == loguru::Verbosity_INFO) { + /// level = rerun::TextLogLevel::Info; + /// } else if (message.verbosity == loguru::Verbosity_1) { + /// level = rerun::TextLogLevel::Debug; + /// } else if (message.verbosity == loguru::Verbosity_2) { + /// level = rerun::TextLogLevel::Trace; + /// } else { + /// level = rerun::TextLogLevel(std::to_string(message.verbosity)); + /// } + /// + /// rec->log( + /// "logs/handler/text_log_integration", + /// rerun::TextLog(message.message).with_level(level) + /// ); + /// } + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_text_log_integration"); + /// rec.spawn().exit_on_failure(); + /// + /// // Log a text entry directly: + /// rec.log( + /// "logs", + /// rerun::TextLog("this entry has loglevel TRACE").with_level(rerun::TextLogLevel::Trace) + /// ); + /// + /// loguru::add_callback( + /// "rerun", + /// loguru_to_rerun, + /// const_cast(reinterpret_cast(&rec)), + /// loguru::Verbosity_INFO + /// ); + /// + /// LOG_F(INFO, "This INFO log got added through the standard logging interface"); + /// + /// loguru::remove_callback("rerun"); // we need to do this before `rec` goes out of scope + /// } + /// ``` + struct TextLog { + /// The body of the message. + rerun::components::Text text; - /// The verbosity level of the message. - /// - /// This can be used to filter the log messages in the Rerun Viewer. - std::optional level; + /// The verbosity level of the message. + /// + /// This can be used to filter the log messages in the Rerun Viewer. + std::optional level; - /// Optional color to use for the log line in the Rerun Viewer. - std::optional color; + /// Optional color to use for the log line in the Rerun Viewer. + std::optional color; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - TextLog() = default; - TextLog(TextLog&& other) = default; + public: + TextLog() = default; + TextLog(TextLog&& other) = default; - explicit TextLog(rerun::components::Text _text) : text(std::move(_text)) {} + explicit TextLog(rerun::components::Text _text) : text(std::move(_text)) {} - /// The verbosity level of the message. - /// - /// This can be used to filter the log messages in the Rerun Viewer. - TextLog with_level(rerun::components::TextLogLevel _level) && { - level = std::move(_level); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } + /// The verbosity level of the message. + /// + /// This can be used to filter the log messages in the Rerun Viewer. + TextLog with_level(rerun::components::TextLogLevel _level) && { + level = std::move(_level); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } - /// Optional color to use for the log line in the Rerun Viewer. - TextLog with_color(rerun::components::Color _color) && { - color = std::move(_color); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } + /// Optional color to use for the log line in the Rerun Viewer. + TextLog with_color(rerun::components::Color _color) && { + color = std::move(_color); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/time_series_scalar.cpp b/rerun_cpp/src/rerun/archetypes/time_series_scalar.cpp index 59945b32d9bc..0e484ce991d7 100644 --- a/rerun_cpp/src/rerun/archetypes/time_series_scalar.cpp +++ b/rerun_cpp/src/rerun/archetypes/time_series_scalar.cpp @@ -5,11 +5,12 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char TimeSeriesScalar::INDICATOR_COMPONENT_NAME[] = + "rerun.components.TimeSeriesScalarIndicator"; +} + namespace rerun { - namespace archetypes { - const char TimeSeriesScalar::INDICATOR_COMPONENT_NAME[] = - "rerun.components.TimeSeriesScalarIndicator"; - } Result> AsComponents< archetypes::TimeSeriesScalar>::serialize(const archetypes::TimeSeriesScalar& archetype) { diff --git a/rerun_cpp/src/rerun/archetypes/time_series_scalar.hpp b/rerun_cpp/src/rerun/archetypes/time_series_scalar.hpp index a85e2b6028d3..11ac994d726c 100644 --- a/rerun_cpp/src/rerun/archetypes/time_series_scalar.hpp +++ b/rerun_cpp/src/rerun/archetypes/time_series_scalar.hpp @@ -19,157 +19,156 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: Log a double-precision scalar that will be visualized as a time-series plot. +namespace rerun::archetypes { + /// **Archetype**: Log a double-precision scalar that will be visualized as a time-series plot. + /// + /// The current simulation time will be used for the time/X-axis, hence scalars + /// cannot be timeless! + /// + /// ## Example + /// + /// ### Simple line plot + /// ![image](https://static.rerun.io/scalar_simple/8bcc92f56268739f8cd24d60d1fe72a655f62a46/full.png) + /// + /// ```cpp + /// #include + /// + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_scalar"); + /// rec.spawn().exit_on_failure(); + /// + /// for (int step = 0; step <64; ++step) { + /// rec.set_time_sequence("step", step); + /// rec.log("scalar", rerun::TimeSeriesScalar(std::sin(static_cast(step) / 10.0))); + /// } + /// } + /// ``` + struct TimeSeriesScalar { + /// The scalar value to log. + rerun::components::Scalar scalar; + + /// An optional radius for the point. + /// + /// Points within a single line do not have to share the same radius, the line + /// will have differently sized segments as appropriate. + /// + /// If all points within a single entity path (i.e. a line) share the same + /// radius, then this radius will be used as the line width too. Otherwise, the + /// line will use the default width of `1.0`. + std::optional radius; + + /// Optional color for the scalar entry. + /// + /// If left unspecified, a pseudo-random color will be used instead. That + /// same color will apply to all points residing in the same entity path + /// that don't have a color specified. + /// + /// Points within a single line do not have to share the same color, the line + /// will have differently colored segments as appropriate. + /// If all points within a single entity path (i.e. a line) share the same + /// color, then this color will be used as the line color in the plot legend. + /// Otherwise, the line will appear gray in the legend. + std::optional color; + + /// An optional label for the point. + /// + /// TODO(#1289): This won't show up on points at the moment, as our plots don't yet + /// support displaying labels for individual points. + /// If all points within a single entity path (i.e. a line) share the same label, then + /// this label will be used as the label for the line itself. Otherwise, the + /// line will be named after the entity path. The plot itself is named after + /// the space it's in. + std::optional label; + + /// Specifies whether a point in a scatter plot should form a continuous line. /// - /// The current simulation time will be used for the time/X-axis, hence scalars - /// cannot be timeless! + /// If set to true, this scalar will be drawn as a point, akin to a scatterplot. + /// Otherwise, it will form a continuous line with its neighbors. + /// Points within a single line do not have to all share the same scatteredness: + /// the line will switch between a scattered and a continuous representation as + /// required. + std::optional scattered; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + TimeSeriesScalar() = default; + TimeSeriesScalar(TimeSeriesScalar&& other) = default; + + explicit TimeSeriesScalar(rerun::components::Scalar _scalar) : scalar(std::move(_scalar)) {} + + /// An optional radius for the point. /// - /// ## Example + /// Points within a single line do not have to share the same radius, the line + /// will have differently sized segments as appropriate. /// - /// ### Simple line plot - /// ![image](https://static.rerun.io/scalar_simple/8bcc92f56268739f8cd24d60d1fe72a655f62a46/full.png) + /// If all points within a single entity path (i.e. a line) share the same + /// radius, then this radius will be used as the line width too. Otherwise, the + /// line will use the default width of `1.0`. + TimeSeriesScalar with_radius(rerun::components::Radius _radius) && { + radius = std::move(_radius); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Optional color for the scalar entry. /// - /// ```cpp - /// #include + /// If left unspecified, a pseudo-random color will be used instead. That + /// same color will apply to all points residing in the same entity path + /// that don't have a color specified. /// - /// #include + /// Points within a single line do not have to share the same color, the line + /// will have differently colored segments as appropriate. + /// If all points within a single entity path (i.e. a line) share the same + /// color, then this color will be used as the line color in the plot legend. + /// Otherwise, the line will appear gray in the legend. + TimeSeriesScalar with_color(rerun::components::Color _color) && { + color = std::move(_color); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// An optional label for the point. /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_scalar"); - /// rec.spawn().exit_on_failure(); + /// TODO(#1289): This won't show up on points at the moment, as our plots don't yet + /// support displaying labels for individual points. + /// If all points within a single entity path (i.e. a line) share the same label, then + /// this label will be used as the label for the line itself. Otherwise, the + /// line will be named after the entity path. The plot itself is named after + /// the space it's in. + TimeSeriesScalar with_label(rerun::components::Text _label) && { + label = std::move(_label); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Specifies whether a point in a scatter plot should form a continuous line. /// - /// for (int step = 0; step <64; ++step) { - /// rec.set_time_sequence("step", step); - /// rec.log("scalar", rerun::TimeSeriesScalar(std::sin(static_cast(step) / 10.0))); - /// } - /// } - /// ``` - struct TimeSeriesScalar { - /// The scalar value to log. - rerun::components::Scalar scalar; - - /// An optional radius for the point. - /// - /// Points within a single line do not have to share the same radius, the line - /// will have differently sized segments as appropriate. - /// - /// If all points within a single entity path (i.e. a line) share the same - /// radius, then this radius will be used as the line width too. Otherwise, the - /// line will use the default width of `1.0`. - std::optional radius; - - /// Optional color for the scalar entry. - /// - /// If left unspecified, a pseudo-random color will be used instead. That - /// same color will apply to all points residing in the same entity path - /// that don't have a color specified. - /// - /// Points within a single line do not have to share the same color, the line - /// will have differently colored segments as appropriate. - /// If all points within a single entity path (i.e. a line) share the same - /// color, then this color will be used as the line color in the plot legend. - /// Otherwise, the line will appear gray in the legend. - std::optional color; - - /// An optional label for the point. - /// - /// TODO(#1289): This won't show up on points at the moment, as our plots don't yet - /// support displaying labels for individual points. - /// If all points within a single entity path (i.e. a line) share the same label, then - /// this label will be used as the label for the line itself. Otherwise, the - /// line will be named after the entity path. The plot itself is named after - /// the space it's in. - std::optional label; - - /// Specifies whether a point in a scatter plot should form a continuous line. - /// - /// If set to true, this scalar will be drawn as a point, akin to a scatterplot. - /// Otherwise, it will form a continuous line with its neighbors. - /// Points within a single line do not have to all share the same scatteredness: - /// the line will switch between a scattered and a continuous representation as - /// required. - std::optional scattered; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - TimeSeriesScalar() = default; - TimeSeriesScalar(TimeSeriesScalar&& other) = default; - - explicit TimeSeriesScalar(rerun::components::Scalar _scalar) - : scalar(std::move(_scalar)) {} - - /// An optional radius for the point. - /// - /// Points within a single line do not have to share the same radius, the line - /// will have differently sized segments as appropriate. - /// - /// If all points within a single entity path (i.e. a line) share the same - /// radius, then this radius will be used as the line width too. Otherwise, the - /// line will use the default width of `1.0`. - TimeSeriesScalar with_radius(rerun::components::Radius _radius) && { - radius = std::move(_radius); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Optional color for the scalar entry. - /// - /// If left unspecified, a pseudo-random color will be used instead. That - /// same color will apply to all points residing in the same entity path - /// that don't have a color specified. - /// - /// Points within a single line do not have to share the same color, the line - /// will have differently colored segments as appropriate. - /// If all points within a single entity path (i.e. a line) share the same - /// color, then this color will be used as the line color in the plot legend. - /// Otherwise, the line will appear gray in the legend. - TimeSeriesScalar with_color(rerun::components::Color _color) && { - color = std::move(_color); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// An optional label for the point. - /// - /// TODO(#1289): This won't show up on points at the moment, as our plots don't yet - /// support displaying labels for individual points. - /// If all points within a single entity path (i.e. a line) share the same label, then - /// this label will be used as the label for the line itself. Otherwise, the - /// line will be named after the entity path. The plot itself is named after - /// the space it's in. - TimeSeriesScalar with_label(rerun::components::Text _label) && { - label = std::move(_label); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Specifies whether a point in a scatter plot should form a continuous line. - /// - /// If set to true, this scalar will be drawn as a point, akin to a scatterplot. - /// Otherwise, it will form a continuous line with its neighbors. - /// Points within a single line do not have to all share the same scatteredness: - /// the line will switch between a scattered and a continuous representation as - /// required. - TimeSeriesScalar with_scattered(rerun::components::ScalarScattering _scattered) && { - scattered = std::move(_scattered); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; - - } // namespace archetypes + /// If set to true, this scalar will be drawn as a point, akin to a scatterplot. + /// Otherwise, it will form a continuous line with its neighbors. + /// Points within a single line do not have to all share the same scatteredness: + /// the line will switch between a scattered and a continuous representation as + /// required. + TimeSeriesScalar with_scattered(rerun::components::ScalarScattering _scattered) && { + scattered = std::move(_scattered); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; + +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/transform3d.cpp b/rerun_cpp/src/rerun/archetypes/transform3d.cpp index dde1daed14a0..16b8e1ed3d16 100644 --- a/rerun_cpp/src/rerun/archetypes/transform3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/transform3d.cpp @@ -5,11 +5,11 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char Transform3D::INDICATOR_COMPONENT_NAME[] = "rerun.components.Transform3DIndicator"; +} + namespace rerun { - namespace archetypes { - const char Transform3D::INDICATOR_COMPONENT_NAME[] = - "rerun.components.Transform3DIndicator"; - } Result> AsComponents::serialize( const archetypes::Transform3D& archetype diff --git a/rerun_cpp/src/rerun/archetypes/transform3d.hpp b/rerun_cpp/src/rerun/archetypes/transform3d.hpp index a3c9b43a2d59..11dc4da4766f 100644 --- a/rerun_cpp/src/rerun/archetypes/transform3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/transform3d.hpp @@ -13,246 +13,242 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: A 3D transform. - /// - /// ## Example - /// - /// ### Variety of 3D transforms - /// ![image](https://static.rerun.io/transform3d_simple/141368b07360ce3fcb1553079258ae3f42bdb9ac/full.png) - /// - /// ```cpp - /// #include - /// - /// constexpr float TAU = 6.28318530717958647692528676655900577f; - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_transform3d"); - /// rec.spawn().exit_on_failure(); - /// - /// auto arrow = - /// rerun::Arrows3D::from_vectors({{0.0f, 1.0f, 0.0f}}).with_origins({{0.0f, 0.0f, 0.0f}}); - /// - /// rec.log("base", arrow); - /// - /// rec.log("base/translated", rerun::Transform3D({1.0f, 0.0f, 0.0f})); - /// rec.log("base/translated", arrow); - /// - /// rec.log( - /// "base/rotated_scaled", - /// rerun::Transform3D( - /// rerun::RotationAxisAngle({0.0f, 0.0f, 1.0f}, rerun::Angle::radians(TAU / 8.0f)), - /// 2.0f - /// ) - /// ); - /// rec.log("base/rotated_scaled", arrow); - /// } - /// ``` - struct Transform3D { - /// The transform - rerun::components::Transform3D transform; +namespace rerun::archetypes { + /// **Archetype**: A 3D transform. + /// + /// ## Example + /// + /// ### Variety of 3D transforms + /// ![image](https://static.rerun.io/transform3d_simple/141368b07360ce3fcb1553079258ae3f42bdb9ac/full.png) + /// + /// ```cpp + /// #include + /// + /// constexpr float TAU = 6.28318530717958647692528676655900577f; + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_transform3d"); + /// rec.spawn().exit_on_failure(); + /// + /// auto arrow = + /// rerun::Arrows3D::from_vectors({{0.0f, 1.0f, 0.0f}}).with_origins({{0.0f, 0.0f, 0.0f}}); + /// + /// rec.log("base", arrow); + /// + /// rec.log("base/translated", rerun::Transform3D({1.0f, 0.0f, 0.0f})); + /// rec.log("base/translated", arrow); + /// + /// rec.log( + /// "base/rotated_scaled", + /// rerun::Transform3D( + /// rerun::RotationAxisAngle({0.0f, 0.0f, 1.0f}, rerun::Angle::radians(TAU / 8.0f)), + /// 2.0f + /// ) + /// ); + /// rec.log("base/rotated_scaled", arrow); + /// } + /// ``` + struct Transform3D { + /// The transform + rerun::components::Transform3D transform; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - // Extensions to generated type defined in 'transform3d_ext.cpp' + public: + // Extensions to generated type defined in 'transform3d_ext.cpp' - /// Identity transformation. - /// - /// Applying this transform does not alter an entity's transformation. - static const Transform3D IDENTITY; + /// Identity transformation. + /// + /// Applying this transform does not alter an entity's transformation. + static const Transform3D IDENTITY; - /// New 3D transform from translation/matrix datatype. - /// - /// \param translation_and_mat3x3 Combined translation/matrix. - Transform3D(const datatypes::TranslationAndMat3x3& translation_and_mat3x3) - : Transform3D(datatypes::Transform3D::translation_and_mat3x3(translation_and_mat3x3) - ) {} + /// New 3D transform from translation/matrix datatype. + /// + /// \param translation_and_mat3x3 Combined translation/matrix. + Transform3D(const datatypes::TranslationAndMat3x3& translation_and_mat3x3) + : Transform3D(datatypes::Transform3D::translation_and_mat3x3(translation_and_mat3x3)) {} - /// Creates a new 3D transform from translation and matrix provided as 3 columns. - /// - /// \param translation \çopydoc datatypes::TranslationAndMat3x3::translation - /// \param columns Column vectors of 3x3 matrix. - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - /// - /// _Implementation note:_ This overload is necessary, otherwise the array may be - /// interpreted as bool and call the wrong overload. - Transform3D( - const datatypes::Vec3D& translation, const datatypes::Vec3D (&columns)[3], - bool from_parent = false - ) - : Transform3D(datatypes::TranslationAndMat3x3(translation, columns, from_parent)) {} + /// Creates a new 3D transform from translation and matrix provided as 3 columns. + /// + /// \param translation \çopydoc datatypes::TranslationAndMat3x3::translation + /// \param columns Column vectors of 3x3 matrix. + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + /// + /// _Implementation note:_ This overload is necessary, otherwise the array may be + /// interpreted as bool and call the wrong overload. + Transform3D( + const datatypes::Vec3D& translation, const datatypes::Vec3D (&columns)[3], + bool from_parent = false + ) + : Transform3D(datatypes::TranslationAndMat3x3(translation, columns, from_parent)) {} - /// Creates a new 3D transform from translation/matrix. - /// - /// \param translation \çopydoc datatypes::TranslationAndMat3x3::translation - /// \param matrix \copydoc datatypes::TranslationAndMat3x3::mat3x3 - /// \param from_parent \copydoc datatypes::TranslationAndMat3x3::from_parent - Transform3D( - const datatypes::Vec3D& translation, const datatypes::Mat3x3& matrix, - bool from_parent = false - ) - : Transform3D(datatypes::TranslationAndMat3x3(translation, matrix, from_parent)) {} + /// Creates a new 3D transform from translation/matrix. + /// + /// \param translation \çopydoc datatypes::TranslationAndMat3x3::translation + /// \param matrix \copydoc datatypes::TranslationAndMat3x3::mat3x3 + /// \param from_parent \copydoc datatypes::TranslationAndMat3x3::from_parent + Transform3D( + const datatypes::Vec3D& translation, const datatypes::Mat3x3& matrix, + bool from_parent = false + ) + : Transform3D(datatypes::TranslationAndMat3x3(translation, matrix, from_parent)) {} - /// From translation only. - /// - /// \param translation \çopydoc datatypes::TranslationRotationScale3D::translation - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - Transform3D(const datatypes::Vec3D& translation, bool from_parent = false) - : Transform3D(datatypes::TranslationRotationScale3D(translation, from_parent)) {} + /// From translation only. + /// + /// \param translation \çopydoc datatypes::TranslationRotationScale3D::translation + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + Transform3D(const datatypes::Vec3D& translation, bool from_parent = false) + : Transform3D(datatypes::TranslationRotationScale3D(translation, from_parent)) {} - /// From 3x3 matrix only. - /// - /// \param matrix \copydoc datatypes::TranslationAndMat3x3::mat3x3 - /// \param from_parent \copydoc datatypes::TranslationAndMat3x3::from_parent - Transform3D(const datatypes::Mat3x3& matrix, bool from_parent = false) - : Transform3D(datatypes::TranslationAndMat3x3(matrix, from_parent)) {} + /// From 3x3 matrix only. + /// + /// \param matrix \copydoc datatypes::TranslationAndMat3x3::mat3x3 + /// \param from_parent \copydoc datatypes::TranslationAndMat3x3::from_parent + Transform3D(const datatypes::Mat3x3& matrix, bool from_parent = false) + : Transform3D(datatypes::TranslationAndMat3x3(matrix, from_parent)) {} - /// From 3x3 matrix provided as 3 columns only. - /// - /// \param columns Column vectors of 3x3 matrix. - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - Transform3D(const datatypes::Vec3D (&columns)[3], bool from_parent = false) - : Transform3D(datatypes::TranslationAndMat3x3(columns, from_parent)) {} + /// From 3x3 matrix provided as 3 columns only. + /// + /// \param columns Column vectors of 3x3 matrix. + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + Transform3D(const datatypes::Vec3D (&columns)[3], bool from_parent = false) + : Transform3D(datatypes::TranslationAndMat3x3(columns, from_parent)) {} - /// New 3D transform from translation/rotation/scale datatype. - /// \param translation_rotation_scale3d Combined translation/rotation/scale. - Transform3D(const datatypes::TranslationRotationScale3D& translation_rotation_scale3d) - : Transform3D(datatypes::Transform3D::translation_rotation_scale( - translation_rotation_scale3d - )) {} + /// New 3D transform from translation/rotation/scale datatype. + /// \param translation_rotation_scale3d Combined translation/rotation/scale. + Transform3D(const datatypes::TranslationRotationScale3D& translation_rotation_scale3d) + : Transform3D( + datatypes::Transform3D::translation_rotation_scale(translation_rotation_scale3d) + ) {} - /// Creates a new 3D transform from translation/rotation/scale. - /// - /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation - /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation - /// \param scale \copydoc datatypes::TranslationRotationScale3D::scale - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - Transform3D( - const datatypes::Vec3D& translation, const datatypes::Rotation3D& rotation, - const datatypes::Scale3D& scale, bool from_parent = false - ) - : Transform3D(datatypes::TranslationRotationScale3D( - translation, rotation, scale, from_parent - )) {} + /// Creates a new 3D transform from translation/rotation/scale. + /// + /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation + /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation + /// \param scale \copydoc datatypes::TranslationRotationScale3D::scale + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + Transform3D( + const datatypes::Vec3D& translation, const datatypes::Rotation3D& rotation, + const datatypes::Scale3D& scale, bool from_parent = false + ) + : Transform3D( + datatypes::TranslationRotationScale3D(translation, rotation, scale, from_parent) + ) {} - /// Creates a new 3D transform from translation/rotation/uniform-scale. - /// - /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation - /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation - /// \param uniform_scale Uniform scale factor that is applied to all axis equally. - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - /// - /// _Implementation note:_ This explicit overload prevents interpretation of the float as - /// bool, leading to a call to the wrong overload. - Transform3D( - const datatypes::Vec3D& translation, const datatypes::Rotation3D& rotation, - float uniform_scale, bool from_parent = false - ) - : Transform3D(datatypes::TranslationRotationScale3D( - translation, rotation, uniform_scale, from_parent - )) {} + /// Creates a new 3D transform from translation/rotation/uniform-scale. + /// + /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation + /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation + /// \param uniform_scale Uniform scale factor that is applied to all axis equally. + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + /// + /// _Implementation note:_ This explicit overload prevents interpretation of the float as + /// bool, leading to a call to the wrong overload. + Transform3D( + const datatypes::Vec3D& translation, const datatypes::Rotation3D& rotation, + float uniform_scale, bool from_parent = false + ) + : Transform3D(datatypes::TranslationRotationScale3D( + translation, rotation, uniform_scale, from_parent + )) {} - /// Creates a new rigid transform (translation & rotation only). - /// - /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation - /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - Transform3D( - const datatypes::Vec3D& translation, const datatypes::Rotation3D& rotation, - bool from_parent = false - ) - : Transform3D( - datatypes::TranslationRotationScale3D(translation, rotation, from_parent) - ) {} + /// Creates a new rigid transform (translation & rotation only). + /// + /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation + /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + Transform3D( + const datatypes::Vec3D& translation, const datatypes::Rotation3D& rotation, + bool from_parent = false + ) + : Transform3D(datatypes::TranslationRotationScale3D(translation, rotation, from_parent) + ) {} - /// From translation & scale only. - /// - /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation - /// \param scale datatypes::TranslationRotationScale3D::scale - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - Transform3D( - const datatypes::Vec3D& translation, const datatypes::Scale3D& scale, - bool from_parent = false - ) - : Transform3D(datatypes::TranslationRotationScale3D(translation, scale, from_parent) - ) {} + /// From translation & scale only. + /// + /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation + /// \param scale datatypes::TranslationRotationScale3D::scale + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + Transform3D( + const datatypes::Vec3D& translation, const datatypes::Scale3D& scale, + bool from_parent = false + ) + : Transform3D(datatypes::TranslationRotationScale3D(translation, scale, from_parent)) {} - /// From translation & uniform scale only. - /// - /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation - /// \param uniform_scale Uniform scale factor that is applied to all axis equally. - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - /// - /// _Implementation note:_ This explicit overload prevents interpretation of the float as - /// bool, leading to a call to the wrong overload. - Transform3D( - const datatypes::Vec3D& translation, float uniform_scale, bool from_parent = false - ) - : Transform3D( - datatypes::TranslationRotationScale3D(translation, uniform_scale, from_parent) - ) {} + /// From translation & uniform scale only. + /// + /// \param translation \copydoc datatypes::TranslationRotationScale3D::translation + /// \param uniform_scale Uniform scale factor that is applied to all axis equally. + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + /// + /// _Implementation note:_ This explicit overload prevents interpretation of the float as + /// bool, leading to a call to the wrong overload. + Transform3D( + const datatypes::Vec3D& translation, float uniform_scale, bool from_parent = false + ) + : Transform3D( + datatypes::TranslationRotationScale3D(translation, uniform_scale, from_parent) + ) {} - /// From rotation & scale. - /// - /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation - /// \param scale datatypes::TranslationRotationScale3D::scale - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - Transform3D( - const datatypes::Rotation3D& rotation, const datatypes::Scale3D& scale, - bool from_parent = false - ) - : Transform3D(datatypes::TranslationRotationScale3D(rotation, scale, from_parent)) { - } + /// From rotation & scale. + /// + /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation + /// \param scale datatypes::TranslationRotationScale3D::scale + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + Transform3D( + const datatypes::Rotation3D& rotation, const datatypes::Scale3D& scale, + bool from_parent = false + ) + : Transform3D(datatypes::TranslationRotationScale3D(rotation, scale, from_parent)) {} - /// From rotation & uniform scale. - /// - /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation - /// \param uniform_scale Uniform scale factor that is applied to all axis equally. - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - /// - /// _Implementation note:_ This explicit overload prevents interpretation of the float as - /// bool, leading to a call to the wrong overload. - Transform3D( - const datatypes::Rotation3D& rotation, float uniform_scale, bool from_parent = false - ) - : Transform3D( - datatypes::TranslationRotationScale3D(rotation, uniform_scale, from_parent) - ) {} + /// From rotation & uniform scale. + /// + /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation + /// \param uniform_scale Uniform scale factor that is applied to all axis equally. + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + /// + /// _Implementation note:_ This explicit overload prevents interpretation of the float as + /// bool, leading to a call to the wrong overload. + Transform3D( + const datatypes::Rotation3D& rotation, float uniform_scale, bool from_parent = false + ) + : Transform3D( + datatypes::TranslationRotationScale3D(rotation, uniform_scale, from_parent) + ) {} - /// From rotation only. - /// - /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent - Transform3D(const datatypes::Rotation3D& rotation, bool from_parent = false) - : Transform3D(datatypes::TranslationRotationScale3D(rotation, from_parent)) {} + /// From rotation only. + /// + /// \param rotation \copydoc datatypes::TranslationRotationScale3D::rotation + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::from_parent + Transform3D(const datatypes::Rotation3D& rotation, bool from_parent = false) + : Transform3D(datatypes::TranslationRotationScale3D(rotation, from_parent)) {} - /// From scale only. - /// - /// \param scale \copydoc datatypes::TranslationRotationScale3D::from_parent - /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::scale - Transform3D(const datatypes::Scale3D& scale, bool from_parent = false) - : Transform3D(datatypes::TranslationRotationScale3D(scale, from_parent)) {} + /// From scale only. + /// + /// \param scale \copydoc datatypes::TranslationRotationScale3D::from_parent + /// \param from_parent \copydoc datatypes::TranslationRotationScale3D::scale + Transform3D(const datatypes::Scale3D& scale, bool from_parent = false) + : Transform3D(datatypes::TranslationRotationScale3D(scale, from_parent)) {} - public: - Transform3D() = default; - Transform3D(Transform3D&& other) = default; + public: + Transform3D() = default; + Transform3D(Transform3D&& other) = default; - explicit Transform3D(rerun::components::Transform3D _transform) - : transform(std::move(_transform)) {} + explicit Transform3D(rerun::components::Transform3D _transform) + : transform(std::move(_transform)) {} - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/archetypes/view_coordinates.cpp b/rerun_cpp/src/rerun/archetypes/view_coordinates.cpp index 9dff9e58db13..719036bb6325 100644 --- a/rerun_cpp/src/rerun/archetypes/view_coordinates.cpp +++ b/rerun_cpp/src/rerun/archetypes/view_coordinates.cpp @@ -5,11 +5,12 @@ #include "../component_batch_adapter_builtins.hpp" +namespace rerun::archetypes { + const char ViewCoordinates::INDICATOR_COMPONENT_NAME[] = + "rerun.components.ViewCoordinatesIndicator"; +} + namespace rerun { - namespace archetypes { - const char ViewCoordinates::INDICATOR_COMPONENT_NAME[] = - "rerun.components.ViewCoordinatesIndicator"; - } Result> AsComponents< archetypes::ViewCoordinates>::serialize(const archetypes::ViewCoordinates& archetype) { diff --git a/rerun_cpp/src/rerun/archetypes/view_coordinates.hpp b/rerun_cpp/src/rerun/archetypes/view_coordinates.hpp index 1d084e714a3c..3bf56de9ab40 100644 --- a/rerun_cpp/src/rerun/archetypes/view_coordinates.hpp +++ b/rerun_cpp/src/rerun/archetypes/view_coordinates.hpp @@ -13,131 +13,130 @@ #include #include -namespace rerun { - namespace archetypes { - /// **Archetype**: How we interpret the coordinate system of an entity/space. - /// - /// For instance: What is "up"? What does the Z axis mean? Is this right-handed or left-handed? - /// - /// The three coordinates are always ordered as [x, y, z]. - /// - /// For example [Right, Down, Forward] means that the X axis points to the right, the Y axis points - /// down, and the Z axis points forward. - /// - /// ## Example - /// - /// ### View coordinates for adjusting the eye camera - /// ![image](https://static.rerun.io/viewcoordinates/0833f0dc8616a676b7b2c566f2a6f613363680c5/full.png) - /// - /// ```cpp - /// #include - /// - /// int main() { - /// const auto rec = rerun::RecordingStream("rerun_example_view_coordinates"); - /// rec.spawn().exit_on_failure(); - /// - /// rec.log_timeless("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis - /// rec.log( - /// "world/xyz", - /// rerun::Arrows3D::from_vectors({{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}} - /// ).with_colors({{255, 0, 0}, {0, 255, 0}, {0, 0, 255}}) - /// ); - /// } - /// ``` - struct ViewCoordinates { - rerun::components::ViewCoordinates xyz; +namespace rerun::archetypes { + /// **Archetype**: How we interpret the coordinate system of an entity/space. + /// + /// For instance: What is "up"? What does the Z axis mean? Is this right-handed or left-handed? + /// + /// The three coordinates are always ordered as [x, y, z]. + /// + /// For example [Right, Down, Forward] means that the X axis points to the right, the Y axis points + /// down, and the Z axis points forward. + /// + /// ## Example + /// + /// ### View coordinates for adjusting the eye camera + /// ![image](https://static.rerun.io/viewcoordinates/0833f0dc8616a676b7b2c566f2a6f613363680c5/full.png) + /// + /// ```cpp + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_view_coordinates"); + /// rec.spawn().exit_on_failure(); + /// + /// rec.log_timeless("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis + /// rec.log( + /// "world/xyz", + /// rerun::Arrows3D::from_vectors({{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}} + /// ).with_colors({{255, 0, 0}, {0, 255, 0}, {0, 0, 255}}) + /// ); + /// } + /// ``` + struct ViewCoordinates { + rerun::components::ViewCoordinates xyz; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - // Extensions to generated type defined in 'view_coordinates_ext.cpp' + public: + // Extensions to generated type defined in 'view_coordinates_ext.cpp' - /// Construct Vec3D from x/y/z values. - constexpr ViewCoordinates(uint8_t axis0, uint8_t axis1, uint8_t axis2) - : xyz(rerun::components::ViewCoordinates(axis0, axis1, axis2)) {} + /// Construct Vec3D from x/y/z values. + constexpr ViewCoordinates(uint8_t axis0, uint8_t axis1, uint8_t axis2) + : xyz(rerun::components::ViewCoordinates(axis0, axis1, axis2)) {} - // - // This section is generated by running `scripts/generate_view_coordinate_defs.py --cpp` - static const rerun::archetypes::ViewCoordinates ULF; - static const rerun::archetypes::ViewCoordinates UFL; - static const rerun::archetypes::ViewCoordinates LUF; - static const rerun::archetypes::ViewCoordinates LFU; - static const rerun::archetypes::ViewCoordinates FUL; - static const rerun::archetypes::ViewCoordinates FLU; - static const rerun::archetypes::ViewCoordinates ULB; - static const rerun::archetypes::ViewCoordinates UBL; - static const rerun::archetypes::ViewCoordinates LUB; - static const rerun::archetypes::ViewCoordinates LBU; - static const rerun::archetypes::ViewCoordinates BUL; - static const rerun::archetypes::ViewCoordinates BLU; - static const rerun::archetypes::ViewCoordinates URF; - static const rerun::archetypes::ViewCoordinates UFR; - static const rerun::archetypes::ViewCoordinates RUF; - static const rerun::archetypes::ViewCoordinates RFU; - static const rerun::archetypes::ViewCoordinates FUR; - static const rerun::archetypes::ViewCoordinates FRU; - static const rerun::archetypes::ViewCoordinates URB; - static const rerun::archetypes::ViewCoordinates UBR; - static const rerun::archetypes::ViewCoordinates RUB; - static const rerun::archetypes::ViewCoordinates RBU; - static const rerun::archetypes::ViewCoordinates BUR; - static const rerun::archetypes::ViewCoordinates BRU; - static const rerun::archetypes::ViewCoordinates DLF; - static const rerun::archetypes::ViewCoordinates DFL; - static const rerun::archetypes::ViewCoordinates LDF; - static const rerun::archetypes::ViewCoordinates LFD; - static const rerun::archetypes::ViewCoordinates FDL; - static const rerun::archetypes::ViewCoordinates FLD; - static const rerun::archetypes::ViewCoordinates DLB; - static const rerun::archetypes::ViewCoordinates DBL; - static const rerun::archetypes::ViewCoordinates LDB; - static const rerun::archetypes::ViewCoordinates LBD; - static const rerun::archetypes::ViewCoordinates BDL; - static const rerun::archetypes::ViewCoordinates BLD; - static const rerun::archetypes::ViewCoordinates DRF; - static const rerun::archetypes::ViewCoordinates DFR; - static const rerun::archetypes::ViewCoordinates RDF; - static const rerun::archetypes::ViewCoordinates RFD; - static const rerun::archetypes::ViewCoordinates FDR; - static const rerun::archetypes::ViewCoordinates FRD; - static const rerun::archetypes::ViewCoordinates DRB; - static const rerun::archetypes::ViewCoordinates DBR; - static const rerun::archetypes::ViewCoordinates RDB; - static const rerun::archetypes::ViewCoordinates RBD; - static const rerun::archetypes::ViewCoordinates BDR; - static const rerun::archetypes::ViewCoordinates BRD; - static const rerun::archetypes::ViewCoordinates RIGHT_HAND_X_UP; - static const rerun::archetypes::ViewCoordinates RIGHT_HAND_X_DOWN; - static const rerun::archetypes::ViewCoordinates RIGHT_HAND_Y_UP; - static const rerun::archetypes::ViewCoordinates RIGHT_HAND_Y_DOWN; - static const rerun::archetypes::ViewCoordinates RIGHT_HAND_Z_UP; - static const rerun::archetypes::ViewCoordinates RIGHT_HAND_Z_DOWN; - static const rerun::archetypes::ViewCoordinates LEFT_HAND_X_UP; - static const rerun::archetypes::ViewCoordinates LEFT_HAND_X_DOWN; - static const rerun::archetypes::ViewCoordinates LEFT_HAND_Y_UP; - static const rerun::archetypes::ViewCoordinates LEFT_HAND_Y_DOWN; - static const rerun::archetypes::ViewCoordinates LEFT_HAND_Z_UP; - static const rerun::archetypes::ViewCoordinates LEFT_HAND_Z_DOWN; - // + // + // This section is generated by running `scripts/generate_view_coordinate_defs.py --cpp` + static const rerun::archetypes::ViewCoordinates ULF; + static const rerun::archetypes::ViewCoordinates UFL; + static const rerun::archetypes::ViewCoordinates LUF; + static const rerun::archetypes::ViewCoordinates LFU; + static const rerun::archetypes::ViewCoordinates FUL; + static const rerun::archetypes::ViewCoordinates FLU; + static const rerun::archetypes::ViewCoordinates ULB; + static const rerun::archetypes::ViewCoordinates UBL; + static const rerun::archetypes::ViewCoordinates LUB; + static const rerun::archetypes::ViewCoordinates LBU; + static const rerun::archetypes::ViewCoordinates BUL; + static const rerun::archetypes::ViewCoordinates BLU; + static const rerun::archetypes::ViewCoordinates URF; + static const rerun::archetypes::ViewCoordinates UFR; + static const rerun::archetypes::ViewCoordinates RUF; + static const rerun::archetypes::ViewCoordinates RFU; + static const rerun::archetypes::ViewCoordinates FUR; + static const rerun::archetypes::ViewCoordinates FRU; + static const rerun::archetypes::ViewCoordinates URB; + static const rerun::archetypes::ViewCoordinates UBR; + static const rerun::archetypes::ViewCoordinates RUB; + static const rerun::archetypes::ViewCoordinates RBU; + static const rerun::archetypes::ViewCoordinates BUR; + static const rerun::archetypes::ViewCoordinates BRU; + static const rerun::archetypes::ViewCoordinates DLF; + static const rerun::archetypes::ViewCoordinates DFL; + static const rerun::archetypes::ViewCoordinates LDF; + static const rerun::archetypes::ViewCoordinates LFD; + static const rerun::archetypes::ViewCoordinates FDL; + static const rerun::archetypes::ViewCoordinates FLD; + static const rerun::archetypes::ViewCoordinates DLB; + static const rerun::archetypes::ViewCoordinates DBL; + static const rerun::archetypes::ViewCoordinates LDB; + static const rerun::archetypes::ViewCoordinates LBD; + static const rerun::archetypes::ViewCoordinates BDL; + static const rerun::archetypes::ViewCoordinates BLD; + static const rerun::archetypes::ViewCoordinates DRF; + static const rerun::archetypes::ViewCoordinates DFR; + static const rerun::archetypes::ViewCoordinates RDF; + static const rerun::archetypes::ViewCoordinates RFD; + static const rerun::archetypes::ViewCoordinates FDR; + static const rerun::archetypes::ViewCoordinates FRD; + static const rerun::archetypes::ViewCoordinates DRB; + static const rerun::archetypes::ViewCoordinates DBR; + static const rerun::archetypes::ViewCoordinates RDB; + static const rerun::archetypes::ViewCoordinates RBD; + static const rerun::archetypes::ViewCoordinates BDR; + static const rerun::archetypes::ViewCoordinates BRD; + static const rerun::archetypes::ViewCoordinates RIGHT_HAND_X_UP; + static const rerun::archetypes::ViewCoordinates RIGHT_HAND_X_DOWN; + static const rerun::archetypes::ViewCoordinates RIGHT_HAND_Y_UP; + static const rerun::archetypes::ViewCoordinates RIGHT_HAND_Y_DOWN; + static const rerun::archetypes::ViewCoordinates RIGHT_HAND_Z_UP; + static const rerun::archetypes::ViewCoordinates RIGHT_HAND_Z_DOWN; + static const rerun::archetypes::ViewCoordinates LEFT_HAND_X_UP; + static const rerun::archetypes::ViewCoordinates LEFT_HAND_X_DOWN; + static const rerun::archetypes::ViewCoordinates LEFT_HAND_Y_UP; + static const rerun::archetypes::ViewCoordinates LEFT_HAND_Y_DOWN; + static const rerun::archetypes::ViewCoordinates LEFT_HAND_Z_UP; + static const rerun::archetypes::ViewCoordinates LEFT_HAND_Z_DOWN; + // - public: - ViewCoordinates() = default; - ViewCoordinates(ViewCoordinates&& other) = default; + public: + ViewCoordinates() = default; + ViewCoordinates(ViewCoordinates&& other) = default; - explicit ViewCoordinates(rerun::components::ViewCoordinates _xyz) - : xyz(std::move(_xyz)) {} + explicit ViewCoordinates(rerun::components::ViewCoordinates _xyz) : xyz(std::move(_xyz)) {} - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/src/rerun/blueprint/auto_space_views.cpp b/rerun_cpp/src/rerun/blueprint/auto_space_views.cpp index 25cad807f3b2..773097eea403 100644 --- a/rerun_cpp/src/rerun/blueprint/auto_space_views.cpp +++ b/rerun_cpp/src/rerun/blueprint/auto_space_views.cpp @@ -6,46 +6,41 @@ #include #include -namespace rerun { - namespace blueprint { - const std::shared_ptr& AutoSpaceViews::arrow_datatype() { - static const auto datatype = arrow::boolean(); - return datatype; +namespace rerun::blueprint { + const std::shared_ptr& AutoSpaceViews::arrow_datatype() { + static const auto datatype = arrow::boolean(); + return datatype; + } + + Result> AutoSpaceViews::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AutoSpaceViews::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error AutoSpaceViews::fill_arrow_array_builder( + arrow::BooleanBuilder* builder, const AutoSpaceViews* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error AutoSpaceViews::fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const AutoSpaceViews* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(*elements) == sizeof(elements->enabled)); - ARROW_RETURN_NOT_OK(builder->AppendValues( - reinterpret_cast(&elements->enabled), - static_cast(num_elements) - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace blueprint -} // namespace rerun + + static_assert(sizeof(*elements) == sizeof(elements->enabled)); + ARROW_RETURN_NOT_OK(builder->AppendValues( + reinterpret_cast(&elements->enabled), + static_cast(num_elements) + )); + + return Error::ok(); + } +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/auto_space_views.hpp b/rerun_cpp/src/rerun/blueprint/auto_space_views.hpp index a6f1eaa04bf6..99416e48639c 100644 --- a/rerun_cpp/src/rerun/blueprint/auto_space_views.hpp +++ b/rerun_cpp/src/rerun/blueprint/auto_space_views.hpp @@ -14,36 +14,34 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace blueprint { - /// **Blueprint**: A flag indicating space views should be automatically populated. - /// - /// Unstable. Used for the ongoing blueprint experimentations. - struct AutoSpaceViews { - bool enabled; - - public: - AutoSpaceViews() = default; - - AutoSpaceViews(bool enabled_) : enabled(enabled_) {} - - AutoSpaceViews& operator=(bool enabled_) { - enabled = enabled_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const AutoSpaceViews* elements, size_t num_elements - ); - }; - } // namespace blueprint -} // namespace rerun +namespace rerun::blueprint { + /// **Blueprint**: A flag indicating space views should be automatically populated. + /// + /// Unstable. Used for the ongoing blueprint experimentations. + struct AutoSpaceViews { + bool enabled; + + public: + AutoSpaceViews() = default; + + AutoSpaceViews(bool enabled_) : enabled(enabled_) {} + + AutoSpaceViews& operator=(bool enabled_) { + enabled = enabled_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::BooleanBuilder* builder, const AutoSpaceViews* elements, size_t num_elements + ); + }; +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/panel_view.cpp b/rerun_cpp/src/rerun/blueprint/panel_view.cpp index 227f36ad29b8..1d595f1cefac 100644 --- a/rerun_cpp/src/rerun/blueprint/panel_view.cpp +++ b/rerun_cpp/src/rerun/blueprint/panel_view.cpp @@ -6,57 +6,52 @@ #include #include -namespace rerun { - namespace blueprint { - const std::shared_ptr& PanelView::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("is_expanded", arrow::boolean(), false), - }); - return datatype; +namespace rerun::blueprint { + const std::shared_ptr& PanelView::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("is_expanded", arrow::boolean(), false), + }); + return datatype; + } + + Result> PanelView::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> PanelView::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared(memory_pool), - }) - )); + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared(memory_pool), + }) + )); + } + + rerun::Error PanelView::fill_arrow_array_builder( + arrow::StructBuilder* builder, const PanelView* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error PanelView::fill_arrow_array_builder( - arrow::StructBuilder* builder, const PanelView* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].is_expanded)); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].is_expanded)); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace blueprint -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/panel_view.hpp b/rerun_cpp/src/rerun/blueprint/panel_view.hpp index 552b3bfb6468..902dd7aad825 100644 --- a/rerun_cpp/src/rerun/blueprint/panel_view.hpp +++ b/rerun_cpp/src/rerun/blueprint/panel_view.hpp @@ -14,36 +14,34 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace blueprint { - /// **Blueprint**: The state of the panels. - /// - /// Unstable. Used for the ongoing blueprint experimentations. - struct PanelView { - bool is_expanded; - - public: - PanelView() = default; - - PanelView(bool is_expanded_) : is_expanded(is_expanded_) {} - - PanelView& operator=(bool is_expanded_) { - is_expanded = is_expanded_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const PanelView* elements, size_t num_elements - ); - }; - } // namespace blueprint -} // namespace rerun +namespace rerun::blueprint { + /// **Blueprint**: The state of the panels. + /// + /// Unstable. Used for the ongoing blueprint experimentations. + struct PanelView { + bool is_expanded; + + public: + PanelView() = default; + + PanelView(bool is_expanded_) : is_expanded(is_expanded_) {} + + PanelView& operator=(bool is_expanded_) { + is_expanded = is_expanded_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const PanelView* elements, size_t num_elements + ); + }; +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/space_view_component.cpp b/rerun_cpp/src/rerun/blueprint/space_view_component.cpp index 59f5a4a23847..91368099c2ef 100644 --- a/rerun_cpp/src/rerun/blueprint/space_view_component.cpp +++ b/rerun_cpp/src/rerun/blueprint/space_view_component.cpp @@ -6,74 +6,68 @@ #include #include -namespace rerun { - namespace blueprint { - const std::shared_ptr& SpaceViewComponent::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field( - "space_view", - arrow::list(arrow::field("item", arrow::uint8(), false)), - false - ), - }); - return datatype; +namespace rerun::blueprint { + const std::shared_ptr& SpaceViewComponent::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field( + "space_view", + arrow::list(arrow::field("item", arrow::uint8(), false)), + false + ), + }); + return datatype; + } + + Result> SpaceViewComponent::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> SpaceViewComponent::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared( + memory_pool, + std::make_shared(memory_pool) + ), + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - }) - )); + rerun::Error SpaceViewComponent::fill_arrow_array_builder( + arrow::StructBuilder* builder, const SpaceViewComponent* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error SpaceViewComponent::fill_arrow_array_builder( - arrow::StructBuilder* builder, const SpaceViewComponent* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + { + auto field_builder = static_cast(builder->field_builder(0)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(field_builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - element.space_view.data(), - static_cast(element.space_view.size()), - nullptr - )); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(field_builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + element.space_view.data(), + static_cast(element.space_view.size()), + nullptr + )); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace blueprint -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/space_view_component.hpp b/rerun_cpp/src/rerun/blueprint/space_view_component.hpp index e33d19ba651a..35261ca169e2 100644 --- a/rerun_cpp/src/rerun/blueprint/space_view_component.hpp +++ b/rerun_cpp/src/rerun/blueprint/space_view_component.hpp @@ -16,38 +16,34 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace blueprint { - /// **Blueprint**: A view of a space. - /// - /// Unstable. Used for the ongoing blueprint experimentations. - struct SpaceViewComponent { - std::vector space_view; - - public: - SpaceViewComponent() = default; - - SpaceViewComponent(std::vector space_view_) - : space_view(std::move(space_view_)) {} - - SpaceViewComponent& operator=(std::vector space_view_) { - space_view = std::move(space_view_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const SpaceViewComponent* elements, - size_t num_elements - ); - }; - } // namespace blueprint -} // namespace rerun +namespace rerun::blueprint { + /// **Blueprint**: A view of a space. + /// + /// Unstable. Used for the ongoing blueprint experimentations. + struct SpaceViewComponent { + std::vector space_view; + + public: + SpaceViewComponent() = default; + + SpaceViewComponent(std::vector space_view_) : space_view(std::move(space_view_)) {} + + SpaceViewComponent& operator=(std::vector space_view_) { + space_view = std::move(space_view_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const SpaceViewComponent* elements, size_t num_elements + ); + }; +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/space_view_maximized.cpp b/rerun_cpp/src/rerun/blueprint/space_view_maximized.cpp index c3121242d793..a4ee03122cee 100644 --- a/rerun_cpp/src/rerun/blueprint/space_view_maximized.cpp +++ b/rerun_cpp/src/rerun/blueprint/space_view_maximized.cpp @@ -6,61 +6,56 @@ #include #include -namespace rerun { - namespace blueprint { - const std::shared_ptr& SpaceViewMaximized::arrow_datatype() { - static const auto datatype = arrow::list(arrow::field("item", arrow::uint8(), false)); - return datatype; +namespace rerun::blueprint { + const std::shared_ptr& SpaceViewMaximized::arrow_datatype() { + static const auto datatype = arrow::list(arrow::field("item", arrow::uint8(), false)); + return datatype; + } + + Result> SpaceViewMaximized::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> SpaceViewMaximized::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool) - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool) + )); + } + + rerun::Error SpaceViewMaximized::fill_arrow_array_builder( + arrow::ListBuilder* builder, const SpaceViewMaximized* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error SpaceViewMaximized::fill_arrow_array_builder( - arrow::ListBuilder* builder, const SpaceViewMaximized* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.id.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - element.id.value().data(), - static_cast(element.id.value().size()), - nullptr - )); - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); - } + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); + + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.id.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + element.id.value().data(), + static_cast(element.id.value().size()), + nullptr + )); + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - } // namespace blueprint -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp b/rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp index b8a7c028e6fe..693b72aafe14 100644 --- a/rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp +++ b/rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp @@ -17,36 +17,34 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace blueprint { - /// **Blueprint**: Whether a space view is maximized. - /// - /// Unstable. Used for the ongoing blueprint experimentations. - struct SpaceViewMaximized { - std::optional> id; - - public: - SpaceViewMaximized() = default; - - SpaceViewMaximized(std::optional> id_) : id(std::move(id_)) {} - - SpaceViewMaximized& operator=(std::optional> id_) { - id = std::move(id_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::ListBuilder* builder, const SpaceViewMaximized* elements, size_t num_elements - ); - }; - } // namespace blueprint -} // namespace rerun +namespace rerun::blueprint { + /// **Blueprint**: Whether a space view is maximized. + /// + /// Unstable. Used for the ongoing blueprint experimentations. + struct SpaceViewMaximized { + std::optional> id; + + public: + SpaceViewMaximized() = default; + + SpaceViewMaximized(std::optional> id_) : id(std::move(id_)) {} + + SpaceViewMaximized& operator=(std::optional> id_) { + id = std::move(id_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::ListBuilder* builder, const SpaceViewMaximized* elements, size_t num_elements + ); + }; +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/viewport_layout.cpp b/rerun_cpp/src/rerun/blueprint/viewport_layout.cpp index 5ab1dcae508b..5211a74da744 100644 --- a/rerun_cpp/src/rerun/blueprint/viewport_layout.cpp +++ b/rerun_cpp/src/rerun/blueprint/viewport_layout.cpp @@ -6,109 +6,98 @@ #include #include -namespace rerun { - namespace blueprint { - const std::shared_ptr& ViewportLayout::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field( - "space_view_keys", - arrow::list(arrow::field("item", arrow::uint8(), false)), - false - ), - arrow::field( - "tree", - arrow::list(arrow::field("item", arrow::uint8(), false)), - false - ), - arrow::field("auto_layout", arrow::boolean(), false), - }); - return datatype; +namespace rerun::blueprint { + const std::shared_ptr& ViewportLayout::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field( + "space_view_keys", + arrow::list(arrow::field("item", arrow::uint8(), false)), + false + ), + arrow::field("tree", arrow::list(arrow::field("item", arrow::uint8(), false)), false), + arrow::field("auto_layout", arrow::boolean(), false), + }); + return datatype; + } + + Result> ViewportLayout::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> ViewportLayout::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared( + memory_pool, + std::make_shared(memory_pool) + ), + std::make_shared( + memory_pool, + std::make_shared(memory_pool) + ), + std::make_shared(memory_pool), + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared(memory_pool), - }) - )); + rerun::Error ViewportLayout::fill_arrow_array_builder( + arrow::StructBuilder* builder, const ViewportLayout* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error ViewportLayout::fill_arrow_array_builder( - arrow::StructBuilder* builder, const ViewportLayout* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + { + auto field_builder = static_cast(builder->field_builder(0)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(field_builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - element.space_view_keys.data(), - static_cast(element.space_view_keys.size()), - nullptr - )); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(field_builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + element.space_view_keys.data(), + static_cast(element.space_view_keys.size()), + nullptr + )); } - { - auto field_builder = static_cast(builder->field_builder(1)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + } + { + auto field_builder = static_cast(builder->field_builder(1)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(field_builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - element.tree.data(), - static_cast(element.tree.size()), - nullptr - )); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(field_builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + element.tree.data(), + static_cast(element.tree.size()), + nullptr + )); } - { - auto field_builder = static_cast(builder->field_builder(2)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].auto_layout)); - } + } + { + auto field_builder = static_cast(builder->field_builder(2)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].auto_layout)); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace blueprint -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/blueprint/viewport_layout.hpp b/rerun_cpp/src/rerun/blueprint/viewport_layout.hpp index 882ddad9eac6..1e36ca31d356 100644 --- a/rerun_cpp/src/rerun/blueprint/viewport_layout.hpp +++ b/rerun_cpp/src/rerun/blueprint/viewport_layout.hpp @@ -15,36 +15,34 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace blueprint { - /// **Blueprint**: A view of a space. - /// - /// Unstable. Used for the ongoing blueprint experimentations. - struct ViewportLayout { - /// space_view_keys - std::vector space_view_keys; - - /// tree - std::vector tree; - - /// auto_layout - bool auto_layout; - - public: - ViewportLayout() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const ViewportLayout* elements, size_t num_elements - ); - }; - } // namespace blueprint -} // namespace rerun +namespace rerun::blueprint { + /// **Blueprint**: A view of a space. + /// + /// Unstable. Used for the ongoing blueprint experimentations. + struct ViewportLayout { + /// space_view_keys + std::vector space_view_keys; + + /// tree + std::vector tree; + + /// auto_layout + bool auto_layout; + + public: + ViewportLayout() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const ViewportLayout* elements, size_t num_elements + ); + }; +} // namespace rerun::blueprint diff --git a/rerun_cpp/src/rerun/components/annotation_context.cpp b/rerun_cpp/src/rerun/components/annotation_context.cpp index 47fe8caacc0b..d1787cff4153 100644 --- a/rerun_cpp/src/rerun/components/annotation_context.cpp +++ b/rerun_cpp/src/rerun/components/annotation_context.cpp @@ -8,94 +8,84 @@ #include #include -namespace rerun { - namespace components { - const char AnnotationContext::NAME[] = "rerun.components.AnnotationContext"; +namespace rerun::components { + const char AnnotationContext::NAME[] = "rerun.components.AnnotationContext"; - const std::shared_ptr& AnnotationContext::arrow_datatype() { - static const auto datatype = arrow::list(arrow::field( - "item", - rerun::datatypes::ClassDescriptionMapElem::arrow_datatype(), - false - )); - return datatype; + const std::shared_ptr& AnnotationContext::arrow_datatype() { + static const auto datatype = arrow::list( + arrow::field("item", rerun::datatypes::ClassDescriptionMapElem::arrow_datatype(), false) + ); + return datatype; + } + + Result> AnnotationContext::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AnnotationContext::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + rerun::datatypes::ClassDescriptionMapElem::new_arrow_array_builder(memory_pool).value + )); + } - return Result(std::make_shared( - memory_pool, - rerun::datatypes::ClassDescriptionMapElem::new_arrow_array_builder(memory_pool) - .value - )); + rerun::Error AnnotationContext::fill_arrow_array_builder( + arrow::ListBuilder* builder, const AnnotationContext* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AnnotationContext::fill_arrow_array_builder( - arrow::ListBuilder* builder, const AnnotationContext* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append()); - if (element.class_map.data()) { - RR_RETURN_NOT_OK( - rerun::datatypes::ClassDescriptionMapElem::fill_arrow_array_builder( - value_builder, - element.class_map.data(), - element.class_map.size() - ) - ); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append()); + if (element.class_map.data()) { + RR_RETURN_NOT_OK( + rerun::datatypes::ClassDescriptionMapElem::fill_arrow_array_builder( + value_builder, + element.class_map.data(), + element.class_map.size() + ) + ); } - - return Error::ok(); } - Result AnnotationContext::to_data_cell( - const AnnotationContext* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = AnnotationContext::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(AnnotationContext::fill_arrow_array_builder( - builder.get(), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result AnnotationContext::to_data_cell( + const AnnotationContext* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - AnnotationContext::NAME, - AnnotationContext::arrow_datatype(), - std::move(array) + auto builder_result = AnnotationContext::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AnnotationContext::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AnnotationContext::NAME, + AnnotationContext::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/annotation_context.hpp b/rerun_cpp/src/rerun/components/annotation_context.hpp index d370528c2653..cfdab680cb03 100644 --- a/rerun_cpp/src/rerun/components/annotation_context.hpp +++ b/rerun_cpp/src/rerun/components/annotation_context.hpp @@ -18,64 +18,62 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: The `AnnotationContext` provides additional information on how to display entities. - /// - /// Entities can use `ClassId`s and `KeypointId`s to provide annotations, and - /// the labels and colors will be looked up in the appropriate - /// `AnnotationContext`. We use the *first* annotation context we find in the - /// path-hierarchy when searching up through the ancestors of a given entity - /// path. - struct AnnotationContext { - /// List of class descriptions, mapping class indices to class names, colors etc. - std::vector class_map; +namespace rerun::components { + /// **Component**: The `AnnotationContext` provides additional information on how to display entities. + /// + /// Entities can use `ClassId`s and `KeypointId`s to provide annotations, and + /// the labels and colors will be looked up in the appropriate + /// `AnnotationContext`. We use the *first* annotation context we find in the + /// path-hierarchy when searching up through the ancestors of a given entity + /// path. + struct AnnotationContext { + /// List of class descriptions, mapping class indices to class names, colors etc. + std::vector class_map; - /// Name of the component, used for serialization. - static const char NAME[]; + /// Name of the component, used for serialization. + static const char NAME[]; - public: - // Extensions to generated type defined in 'annotation_context_ext.cpp' + public: + // Extensions to generated type defined in 'annotation_context_ext.cpp' - AnnotationContext( - std::initializer_list class_descriptions - ) { - class_map.reserve(class_descriptions.size()); - for (const auto& class_description : class_descriptions) { - class_map.emplace_back(std::move(class_description)); - } + AnnotationContext( + std::initializer_list class_descriptions + ) { + class_map.reserve(class_descriptions.size()); + for (const auto& class_description : class_descriptions) { + class_map.emplace_back(std::move(class_description)); } + } - public: - AnnotationContext() = default; + public: + AnnotationContext() = default; - AnnotationContext(std::vector class_map_) - : class_map(std::move(class_map_)) {} + AnnotationContext(std::vector class_map_) + : class_map(std::move(class_map_)) {} - AnnotationContext& operator=( - std::vector class_map_ - ) { - class_map = std::move(class_map_); - return *this; - } + AnnotationContext& operator=( + std::vector class_map_ + ) { + class_map = std::move(class_map_); + return *this; + } - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::ListBuilder* builder, const AnnotationContext* elements, size_t num_elements - ); + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::ListBuilder* builder, const AnnotationContext* elements, size_t num_elements + ); - /// Creates a Rerun DataCell from an array of AnnotationContext components. - static Result to_data_cell( - const AnnotationContext* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun + /// Creates a Rerun DataCell from an array of AnnotationContext components. + static Result to_data_cell( + const AnnotationContext* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/blob.cpp b/rerun_cpp/src/rerun/components/blob.cpp index b280e3f1e46c..d8e731dcf1ba 100644 --- a/rerun_cpp/src/rerun/components/blob.cpp +++ b/rerun_cpp/src/rerun/components/blob.cpp @@ -6,77 +6,71 @@ #include #include -namespace rerun { - namespace components { - const char Blob::NAME[] = "rerun.components.Blob"; +namespace rerun::components { + const char Blob::NAME[] = "rerun.components.Blob"; - const std::shared_ptr& Blob::arrow_datatype() { - static const auto datatype = arrow::list(arrow::field("item", arrow::uint8(), false)); - return datatype; - } - - Result> Blob::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Blob::arrow_datatype() { + static const auto datatype = arrow::list(arrow::field("item", arrow::uint8(), false)); + return datatype; + } - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool) - )); + Result> Blob::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Blob::fill_arrow_array_builder( - arrow::ListBuilder* builder, const Blob* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool) + )); + } - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + rerun::Error Blob::fill_arrow_array_builder( + arrow::ListBuilder* builder, const Blob* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - element.data.data(), - static_cast(element.data.size()), - nullptr - )); - } + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - return Error::ok(); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + element.data.data(), + static_cast(element.data.size()), + nullptr + )); } - Result Blob::to_data_cell(const Blob* instances, size_t num_instances) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = Blob::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Blob::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Blob::to_data_cell(const Blob* instances, size_t num_instances) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create(Blob::NAME, Blob::arrow_datatype(), std::move(array)); + auto builder_result = Blob::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK(Blob::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create(Blob::NAME, Blob::arrow_datatype(), std::move(array)); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/blob.hpp b/rerun_cpp/src/rerun/components/blob.hpp index d09e8d8619a1..d942ea2694c1 100644 --- a/rerun_cpp/src/rerun/components/blob.hpp +++ b/rerun_cpp/src/rerun/components/blob.hpp @@ -17,42 +17,38 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A binary blob of data. - struct Blob { - std::vector data; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - Blob() = default; - - Blob(std::vector data_) : data(std::move(data_)) {} - - Blob& operator=(std::vector data_) { - data = std::move(data_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::ListBuilder* builder, const Blob* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Blob components. - static Result to_data_cell( - const Blob* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A binary blob of data. + struct Blob { + std::vector data; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + Blob() = default; + + Blob(std::vector data_) : data(std::move(data_)) {} + + Blob& operator=(std::vector data_) { + data = std::move(data_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::ListBuilder* builder, const Blob* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Blob components. + static Result to_data_cell(const Blob* instances, size_t num_instances); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/class_id.cpp b/rerun_cpp/src/rerun/components/class_id.cpp index 34c9f636114d..c6857c662762 100644 --- a/rerun_cpp/src/rerun/components/class_id.cpp +++ b/rerun_cpp/src/rerun/components/class_id.cpp @@ -8,73 +8,62 @@ #include #include -namespace rerun { - namespace components { - const char ClassId::NAME[] = "rerun.components.ClassId"; +namespace rerun::components { + const char ClassId::NAME[] = "rerun.components.ClassId"; - const std::shared_ptr& ClassId::arrow_datatype() { - static const auto datatype = rerun::datatypes::ClassId::arrow_datatype(); - return datatype; - } - - Result> ClassId::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& ClassId::arrow_datatype() { + static const auto datatype = rerun::datatypes::ClassId::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::ClassId::new_arrow_array_builder(memory_pool).value); + Result> ClassId::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error ClassId::fill_arrow_array_builder( - arrow::UInt16Builder* builder, const ClassId* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::ClassId::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::ClassId) == sizeof(ClassId)); - RR_RETURN_NOT_OK(rerun::datatypes::ClassId::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error ClassId::fill_arrow_array_builder( + arrow::UInt16Builder* builder, const ClassId* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::ClassId) == sizeof(ClassId)); + RR_RETURN_NOT_OK(rerun::datatypes::ClassId::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - 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(); + return Error::ok(); + } - auto builder_result = ClassId::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - ClassId::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - ClassId::NAME, - ClassId::arrow_datatype(), - std::move(array) + auto builder_result = ClassId::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + ClassId::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create(ClassId::NAME, ClassId::arrow_datatype(), std::move(array)); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/class_id.hpp b/rerun_cpp/src/rerun/components/class_id.hpp index 29e4cc97fcec..78b58c90cde6 100644 --- a/rerun_cpp/src/rerun/components/class_id.hpp +++ b/rerun_cpp/src/rerun/components/class_id.hpp @@ -21,54 +21,50 @@ namespace arrow { using UInt16Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A 16-bit ID representing a type of semantic class. - struct ClassId { - rerun::datatypes::ClassId id; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - ClassId() = default; - - ClassId(rerun::datatypes::ClassId id_) : id(id_) {} - - ClassId& operator=(rerun::datatypes::ClassId id_) { - id = id_; - return *this; - } - - ClassId(uint16_t id_) : id(id_) {} - - ClassId& operator=(uint16_t id_) { - id = id_; - return *this; - } - - /// Cast to the underlying ClassId datatype - operator rerun::datatypes::ClassId() const { - return id; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const ClassId* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A 16-bit ID representing a type of semantic class. + struct ClassId { + rerun::datatypes::ClassId id; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + ClassId() = default; + + ClassId(rerun::datatypes::ClassId id_) : id(id_) {} + + ClassId& operator=(rerun::datatypes::ClassId id_) { + id = id_; + return *this; + } + + ClassId(uint16_t id_) : id(id_) {} + + ClassId& operator=(uint16_t id_) { + id = id_; + return *this; + } + + /// Cast to the underlying ClassId datatype + operator rerun::datatypes::ClassId() const { + return id; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell(const ClassId* instances, size_t num_instances); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/clear_is_recursive.cpp b/rerun_cpp/src/rerun/components/clear_is_recursive.cpp index d6c2199f35b7..2471e1541ad8 100644 --- a/rerun_cpp/src/rerun/components/clear_is_recursive.cpp +++ b/rerun_cpp/src/rerun/components/clear_is_recursive.cpp @@ -6,74 +6,67 @@ #include #include -namespace rerun { - namespace components { - const char ClearIsRecursive::NAME[] = "rerun.components.ClearIsRecursive"; +namespace rerun::components { + const char ClearIsRecursive::NAME[] = "rerun.components.ClearIsRecursive"; - const std::shared_ptr& ClearIsRecursive::arrow_datatype() { - static const auto datatype = arrow::boolean(); - return datatype; - } - - Result> ClearIsRecursive::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& ClearIsRecursive::arrow_datatype() { + static const auto datatype = arrow::boolean(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> ClearIsRecursive::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error ClearIsRecursive::fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const ClearIsRecursive* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - static_assert(sizeof(*elements) == sizeof(elements->recursive)); - ARROW_RETURN_NOT_OK(builder->AppendValues( - reinterpret_cast(&elements->recursive), - static_cast(num_elements) - )); - - return Error::ok(); + rerun::Error ClearIsRecursive::fill_arrow_array_builder( + arrow::BooleanBuilder* builder, const ClearIsRecursive* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(*elements) == sizeof(elements->recursive)); + ARROW_RETURN_NOT_OK(builder->AppendValues( + reinterpret_cast(&elements->recursive), + static_cast(num_elements) + )); - Result ClearIsRecursive::to_data_cell( - const ClearIsRecursive* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = ClearIsRecursive::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(ClearIsRecursive::fill_arrow_array_builder( - builder.get(), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result ClearIsRecursive::to_data_cell( + const ClearIsRecursive* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - ClearIsRecursive::NAME, - ClearIsRecursive::arrow_datatype(), - std::move(array) + auto builder_result = ClearIsRecursive::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + ClearIsRecursive::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + ClearIsRecursive::NAME, + ClearIsRecursive::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/clear_is_recursive.hpp b/rerun_cpp/src/rerun/components/clear_is_recursive.hpp index da93fb97e1f0..6dfd68a2a7aa 100644 --- a/rerun_cpp/src/rerun/components/clear_is_recursive.hpp +++ b/rerun_cpp/src/rerun/components/clear_is_recursive.hpp @@ -15,44 +15,41 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Configures how a clear operation should behave - recursive or not. - struct ClearIsRecursive { - /// If true, also clears all recursive children entities. - bool recursive; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - ClearIsRecursive() = default; - - ClearIsRecursive(bool recursive_) : recursive(recursive_) {} - - ClearIsRecursive& operator=(bool recursive_) { - recursive = recursive_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const ClearIsRecursive* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of ClearIsRecursive components. - static Result to_data_cell( - const ClearIsRecursive* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: Configures how a clear operation should behave - recursive or not. + struct ClearIsRecursive { + /// If true, also clears all recursive children entities. + bool recursive; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + ClearIsRecursive() = default; + + ClearIsRecursive(bool recursive_) : recursive(recursive_) {} + + ClearIsRecursive& operator=(bool recursive_) { + recursive = recursive_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::BooleanBuilder* builder, const ClearIsRecursive* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of ClearIsRecursive components. + static Result to_data_cell( + const ClearIsRecursive* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/color.cpp b/rerun_cpp/src/rerun/components/color.cpp index fb50ca7f30d4..6f6a0db10e22 100644 --- a/rerun_cpp/src/rerun/components/color.cpp +++ b/rerun_cpp/src/rerun/components/color.cpp @@ -8,67 +8,62 @@ #include #include -namespace rerun { - namespace components { - const char Color::NAME[] = "rerun.components.Color"; +namespace rerun::components { + const char Color::NAME[] = "rerun.components.Color"; - const std::shared_ptr& Color::arrow_datatype() { - static const auto datatype = rerun::datatypes::Rgba32::arrow_datatype(); - return datatype; - } - - Result> Color::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Color::arrow_datatype() { + static const auto datatype = rerun::datatypes::Rgba32::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Rgba32::new_arrow_array_builder(memory_pool).value); + Result> Color::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Color::fill_arrow_array_builder( - arrow::UInt32Builder* builder, const Color* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::Rgba32) == sizeof(Color)); - RR_RETURN_NOT_OK(rerun::datatypes::Rgba32::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + return Result(rerun::datatypes::Rgba32::new_arrow_array_builder(memory_pool).value); + } - return Error::ok(); + rerun::Error Color::fill_arrow_array_builder( + arrow::UInt32Builder* builder, const Color* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Rgba32) == sizeof(Color)); + RR_RETURN_NOT_OK(rerun::datatypes::Rgba32::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - 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(); + return Error::ok(); + } - auto builder_result = Color::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Color::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create(Color::NAME, Color::arrow_datatype(), std::move(array)); + auto builder_result = Color::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Color::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create(Color::NAME, Color::arrow_datatype(), std::move(array)); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/color.hpp b/rerun_cpp/src/rerun/components/color.hpp index 57a4ed8d407d..49e47a18bde9 100644 --- a/rerun_cpp/src/rerun/components/color.hpp +++ b/rerun_cpp/src/rerun/components/color.hpp @@ -21,79 +21,75 @@ namespace arrow { using UInt32Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: An RGBA color with unmultiplied/separate alpha, in sRGB gamma space with linear alpha. - /// - /// The color is stored as a 32-bit integer, where the most significant - /// byte is `R` and the least significant byte is `A`. - struct Color { - rerun::datatypes::Rgba32 rgba; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'color_ext.cpp' - - /// Construct Color from unmultiplied RGBA values. - Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) : rgba(r, g, b, a) {} - - uint8_t r() const { - return rgba.r(); - } - - uint8_t g() const { - return rgba.g(); - } - - uint8_t b() const { - return rgba.b(); - } - - uint8_t a() const { - return rgba.a(); - } - - public: - Color() = default; - - Color(rerun::datatypes::Rgba32 rgba_) : rgba(rgba_) {} - - Color& operator=(rerun::datatypes::Rgba32 rgba_) { - rgba = rgba_; - return *this; - } - - Color(uint32_t rgba_) : rgba(rgba_) {} - - Color& operator=(uint32_t rgba_) { - rgba = rgba_; - return *this; - } - - /// Cast to the underlying Rgba32 datatype - operator rerun::datatypes::Rgba32() const { - return rgba; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const Color* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: An RGBA color with unmultiplied/separate alpha, in sRGB gamma space with linear alpha. + /// + /// The color is stored as a 32-bit integer, where the most significant + /// byte is `R` and the least significant byte is `A`. + struct Color { + rerun::datatypes::Rgba32 rgba; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'color_ext.cpp' + + /// Construct Color from unmultiplied RGBA values. + Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) : rgba(r, g, b, a) {} + + uint8_t r() const { + return rgba.r(); + } + + uint8_t g() const { + return rgba.g(); + } + + uint8_t b() const { + return rgba.b(); + } + + uint8_t a() const { + return rgba.a(); + } + + public: + Color() = default; + + Color(rerun::datatypes::Rgba32 rgba_) : rgba(rgba_) {} + + Color& operator=(rerun::datatypes::Rgba32 rgba_) { + rgba = rgba_; + return *this; + } + + Color(uint32_t rgba_) : rgba(rgba_) {} + + Color& operator=(uint32_t rgba_) { + rgba = rgba_; + return *this; + } + + /// Cast to the underlying Rgba32 datatype + operator rerun::datatypes::Rgba32() const { + return rgba; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell(const Color* instances, size_t num_instances); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/depth_meter.cpp b/rerun_cpp/src/rerun/components/depth_meter.cpp index c3c2cfaa610f..85fed9af168f 100644 --- a/rerun_cpp/src/rerun/components/depth_meter.cpp +++ b/rerun_cpp/src/rerun/components/depth_meter.cpp @@ -6,71 +6,66 @@ #include #include -namespace rerun { - namespace components { - const char DepthMeter::NAME[] = "rerun.components.DepthMeter"; +namespace rerun::components { + const char DepthMeter::NAME[] = "rerun.components.DepthMeter"; - const std::shared_ptr& DepthMeter::arrow_datatype() { - static const auto datatype = arrow::float32(); - return datatype; - } - - Result> DepthMeter::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& DepthMeter::arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> DepthMeter::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error DepthMeter::fill_arrow_array_builder( - arrow::FloatBuilder* builder, const DepthMeter* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - static_assert(sizeof(*elements) == sizeof(elements->value)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->value, static_cast(num_elements)) + rerun::Error DepthMeter::fill_arrow_array_builder( + arrow::FloatBuilder* builder, const DepthMeter* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - Result DepthMeter::to_data_cell( - const DepthMeter* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + static_assert(sizeof(*elements) == sizeof(elements->value)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->value, static_cast(num_elements)) + ); + + return Error::ok(); + } - auto builder_result = DepthMeter::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - DepthMeter::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result DepthMeter::to_data_cell( + const DepthMeter* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - DepthMeter::NAME, - DepthMeter::arrow_datatype(), - std::move(array) + auto builder_result = DepthMeter::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + DepthMeter::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + DepthMeter::NAME, + DepthMeter::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/depth_meter.hpp b/rerun_cpp/src/rerun/components/depth_meter.hpp index 5182c20d6f9b..e7d07e85eb6a 100644 --- a/rerun_cpp/src/rerun/components/depth_meter.hpp +++ b/rerun_cpp/src/rerun/components/depth_meter.hpp @@ -20,42 +20,40 @@ namespace arrow { using FloatBuilder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A component indicating how long a meter is, expressed in native units. - struct DepthMeter { - float value; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - DepthMeter() = default; - - DepthMeter(float value_) : value(value_) {} - - DepthMeter& operator=(float value_) { - value = value_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FloatBuilder* builder, const DepthMeter* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of DepthMeter components. - static Result to_data_cell( - const DepthMeter* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A component indicating how long a meter is, expressed in native units. + struct DepthMeter { + float value; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + DepthMeter() = default; + + DepthMeter(float value_) : value(value_) {} + + DepthMeter& operator=(float value_) { + value = value_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FloatBuilder* builder, const DepthMeter* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of DepthMeter components. + static Result to_data_cell( + const DepthMeter* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/disconnected_space.cpp b/rerun_cpp/src/rerun/components/disconnected_space.cpp index f96ffd12f1ca..c91fda02b0f4 100644 --- a/rerun_cpp/src/rerun/components/disconnected_space.cpp +++ b/rerun_cpp/src/rerun/components/disconnected_space.cpp @@ -6,74 +6,67 @@ #include #include -namespace rerun { - namespace components { - const char DisconnectedSpace::NAME[] = "rerun.components.DisconnectedSpace"; +namespace rerun::components { + const char DisconnectedSpace::NAME[] = "rerun.components.DisconnectedSpace"; - const std::shared_ptr& DisconnectedSpace::arrow_datatype() { - static const auto datatype = arrow::boolean(); - return datatype; - } - - Result> DisconnectedSpace::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& DisconnectedSpace::arrow_datatype() { + static const auto datatype = arrow::boolean(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> DisconnectedSpace::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error DisconnectedSpace::fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const DisconnectedSpace* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - static_assert(sizeof(*elements) == sizeof(elements->is_disconnected)); - ARROW_RETURN_NOT_OK(builder->AppendValues( - reinterpret_cast(&elements->is_disconnected), - static_cast(num_elements) - )); - - return Error::ok(); + rerun::Error DisconnectedSpace::fill_arrow_array_builder( + arrow::BooleanBuilder* builder, const DisconnectedSpace* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(*elements) == sizeof(elements->is_disconnected)); + ARROW_RETURN_NOT_OK(builder->AppendValues( + reinterpret_cast(&elements->is_disconnected), + static_cast(num_elements) + )); - 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(); + return Error::ok(); + } - auto builder_result = DisconnectedSpace::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(DisconnectedSpace::fill_arrow_array_builder( - builder.get(), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - DisconnectedSpace::NAME, - DisconnectedSpace::arrow_datatype(), - std::move(array) + auto builder_result = DisconnectedSpace::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + DisconnectedSpace::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + DisconnectedSpace::NAME, + DisconnectedSpace::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/disconnected_space.hpp b/rerun_cpp/src/rerun/components/disconnected_space.hpp index 439c762aacad..628bc7b3c2bb 100644 --- a/rerun_cpp/src/rerun/components/disconnected_space.hpp +++ b/rerun_cpp/src/rerun/components/disconnected_space.hpp @@ -15,48 +15,45 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Specifies that the entity path at which this is logged is disconnected from its parent. - /// - /// This is useful for specifying that a subgraph is independent of the rest of the scene. - /// - /// If a transform or pinhole is logged on the same path, this component will be ignored. - struct DisconnectedSpace { - /// Whether the entity path at which this is logged is disconnected from its parent. - bool is_disconnected; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - DisconnectedSpace() = default; - - DisconnectedSpace(bool is_disconnected_) : is_disconnected(is_disconnected_) {} - - DisconnectedSpace& operator=(bool is_disconnected_) { - is_disconnected = is_disconnected_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const DisconnectedSpace* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of DisconnectedSpace components. - static Result to_data_cell( - const DisconnectedSpace* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: Specifies that the entity path at which this is logged is disconnected from its parent. + /// + /// This is useful for specifying that a subgraph is independent of the rest of the scene. + /// + /// If a transform or pinhole is logged on the same path, this component will be ignored. + struct DisconnectedSpace { + /// Whether the entity path at which this is logged is disconnected from its parent. + bool is_disconnected; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + DisconnectedSpace() = default; + + DisconnectedSpace(bool is_disconnected_) : is_disconnected(is_disconnected_) {} + + DisconnectedSpace& operator=(bool is_disconnected_) { + is_disconnected = is_disconnected_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::BooleanBuilder* builder, const DisconnectedSpace* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of DisconnectedSpace components. + static Result to_data_cell( + const DisconnectedSpace* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/draw_order.cpp b/rerun_cpp/src/rerun/components/draw_order.cpp index 3e9f948d35f5..e2b92d52f443 100644 --- a/rerun_cpp/src/rerun/components/draw_order.cpp +++ b/rerun_cpp/src/rerun/components/draw_order.cpp @@ -6,71 +6,66 @@ #include #include -namespace rerun { - namespace components { - const char DrawOrder::NAME[] = "rerun.components.DrawOrder"; +namespace rerun::components { + const char DrawOrder::NAME[] = "rerun.components.DrawOrder"; - const std::shared_ptr& DrawOrder::arrow_datatype() { - static const auto datatype = arrow::float32(); - return datatype; - } - - Result> DrawOrder::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& DrawOrder::arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> DrawOrder::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error DrawOrder::fill_arrow_array_builder( - arrow::FloatBuilder* builder, const DrawOrder* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - static_assert(sizeof(*elements) == sizeof(elements->value)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->value, static_cast(num_elements)) + rerun::Error DrawOrder::fill_arrow_array_builder( + arrow::FloatBuilder* builder, const DrawOrder* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - 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(); + static_assert(sizeof(*elements) == sizeof(elements->value)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->value, static_cast(num_elements)) + ); + + return Error::ok(); + } - auto builder_result = DrawOrder::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - DrawOrder::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - DrawOrder::NAME, - DrawOrder::arrow_datatype(), - std::move(array) + auto builder_result = DrawOrder::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + DrawOrder::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + DrawOrder::NAME, + DrawOrder::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/draw_order.hpp b/rerun_cpp/src/rerun/components/draw_order.hpp index f2f7210dae9a..93dae6754061 100644 --- a/rerun_cpp/src/rerun/components/draw_order.hpp +++ b/rerun_cpp/src/rerun/components/draw_order.hpp @@ -20,48 +20,46 @@ namespace arrow { using FloatBuilder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Draw order used for the display order of 2D elements. - /// - /// Higher values are drawn on top of lower values. - /// An entity can have only a single draw order component. - /// Within an entity draw order is governed by the order of the components. - /// - /// Draw order for entities with the same draw order is generally undefined. - struct DrawOrder { - float value; +namespace rerun::components { + /// **Component**: Draw order used for the display order of 2D elements. + /// + /// Higher values are drawn on top of lower values. + /// An entity can have only a single draw order component. + /// Within an entity draw order is governed by the order of the components. + /// + /// Draw order for entities with the same draw order is generally undefined. + struct DrawOrder { + float value; - /// Name of the component, used for serialization. - static const char NAME[]; + /// Name of the component, used for serialization. + static const char NAME[]; - public: - DrawOrder() = default; + public: + DrawOrder() = default; - DrawOrder(float value_) : value(value_) {} + DrawOrder(float value_) : value(value_) {} - DrawOrder& operator=(float value_) { - value = value_; - return *this; - } + DrawOrder& operator=(float value_) { + value = value_; + return *this; + } - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FloatBuilder* builder, const DrawOrder* elements, size_t num_elements - ); + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( - const DrawOrder* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun + /// Creates a Rerun DataCell from an array of DrawOrder components. + static Result to_data_cell( + const DrawOrder* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/half_sizes2d.cpp b/rerun_cpp/src/rerun/components/half_sizes2d.cpp index c3012b9743f7..a3a4526e750d 100644 --- a/rerun_cpp/src/rerun/components/half_sizes2d.cpp +++ b/rerun_cpp/src/rerun/components/half_sizes2d.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char HalfSizes2D::NAME[] = "rerun.components.HalfSizes2D"; +namespace rerun::components { + const char HalfSizes2D::NAME[] = "rerun.components.HalfSizes2D"; - const std::shared_ptr& HalfSizes2D::arrow_datatype() { - static const auto datatype = rerun::datatypes::Vec2D::arrow_datatype(); - return datatype; - } - - Result> HalfSizes2D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& HalfSizes2D::arrow_datatype() { + static const auto datatype = rerun::datatypes::Vec2D::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Vec2D::new_arrow_array_builder(memory_pool).value); + Result> HalfSizes2D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error HalfSizes2D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const HalfSizes2D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Vec2D::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Vec2D) == sizeof(HalfSizes2D)); - RR_RETURN_NOT_OK(rerun::datatypes::Vec2D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error HalfSizes2D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const HalfSizes2D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Vec2D) == sizeof(HalfSizes2D)); + RR_RETURN_NOT_OK(rerun::datatypes::Vec2D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result HalfSizes2D::to_data_cell( - const HalfSizes2D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = HalfSizes2D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - HalfSizes2D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result HalfSizes2D::to_data_cell( + const HalfSizes2D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - HalfSizes2D::NAME, - HalfSizes2D::arrow_datatype(), - std::move(array) + auto builder_result = HalfSizes2D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + HalfSizes2D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + HalfSizes2D::NAME, + HalfSizes2D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/half_sizes2d.hpp b/rerun_cpp/src/rerun/components/half_sizes2d.hpp index f260008e5c27..0f00f0f4376f 100644 --- a/rerun_cpp/src/rerun/components/half_sizes2d.hpp +++ b/rerun_cpp/src/rerun/components/half_sizes2d.hpp @@ -17,72 +17,69 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Half-sizes (extents) of a 2D box along its local axis, starting at its local origin/center. - /// - /// The box extends both in negative and positive direction along each axis. - /// Negative sizes indicate that the box is flipped along the respective axis, but this has no effect on how it is displayed. - struct HalfSizes2D { - rerun::datatypes::Vec2D xy; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'half_sizes2d_ext.cpp' - - /// Construct HalfSizes2D from x/y values. - HalfSizes2D(float x, float y) : xy{x, y} {} - - float x() const { - return xy.x(); - } - - float y() const { - return xy.y(); - } - - public: - HalfSizes2D() = default; - - HalfSizes2D(rerun::datatypes::Vec2D xy_) : xy(xy_) {} - - HalfSizes2D& operator=(rerun::datatypes::Vec2D xy_) { - xy = xy_; - return *this; - } - - HalfSizes2D(std::array xy_) : xy(xy_) {} - - HalfSizes2D& operator=(std::array xy_) { - xy = xy_; - return *this; - } - - /// Cast to the underlying Vec2D datatype - operator rerun::datatypes::Vec2D() const { - return xy; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const HalfSizes2D* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of HalfSizes2D components. - static Result to_data_cell( - const HalfSizes2D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: Half-sizes (extents) of a 2D box along its local axis, starting at its local origin/center. + /// + /// The box extends both in negative and positive direction along each axis. + /// Negative sizes indicate that the box is flipped along the respective axis, but this has no effect on how it is displayed. + struct HalfSizes2D { + rerun::datatypes::Vec2D xy; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'half_sizes2d_ext.cpp' + + /// Construct HalfSizes2D from x/y values. + HalfSizes2D(float x, float y) : xy{x, y} {} + + float x() const { + return xy.x(); + } + + float y() const { + return xy.y(); + } + + public: + HalfSizes2D() = default; + + HalfSizes2D(rerun::datatypes::Vec2D xy_) : xy(xy_) {} + + HalfSizes2D& operator=(rerun::datatypes::Vec2D xy_) { + xy = xy_; + return *this; + } + + HalfSizes2D(std::array xy_) : xy(xy_) {} + + HalfSizes2D& operator=(std::array xy_) { + xy = xy_; + return *this; + } + + /// Cast to the underlying Vec2D datatype + operator rerun::datatypes::Vec2D() const { + return xy; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const HalfSizes2D* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of HalfSizes2D components. + static Result to_data_cell( + const HalfSizes2D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/half_sizes3d.cpp b/rerun_cpp/src/rerun/components/half_sizes3d.cpp index 83635727e988..7673d6d87056 100644 --- a/rerun_cpp/src/rerun/components/half_sizes3d.cpp +++ b/rerun_cpp/src/rerun/components/half_sizes3d.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char HalfSizes3D::NAME[] = "rerun.components.HalfSizes3D"; +namespace rerun::components { + const char HalfSizes3D::NAME[] = "rerun.components.HalfSizes3D"; - const std::shared_ptr& HalfSizes3D::arrow_datatype() { - static const auto datatype = rerun::datatypes::Vec3D::arrow_datatype(); - return datatype; - } - - Result> HalfSizes3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& HalfSizes3D::arrow_datatype() { + static const auto datatype = rerun::datatypes::Vec3D::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value); + Result> HalfSizes3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error HalfSizes3D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const HalfSizes3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Vec3D) == sizeof(HalfSizes3D)); - RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error HalfSizes3D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const HalfSizes3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Vec3D) == sizeof(HalfSizes3D)); + RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result HalfSizes3D::to_data_cell( - const HalfSizes3D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = HalfSizes3D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - HalfSizes3D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result HalfSizes3D::to_data_cell( + const HalfSizes3D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - HalfSizes3D::NAME, - HalfSizes3D::arrow_datatype(), - std::move(array) + auto builder_result = HalfSizes3D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + HalfSizes3D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + HalfSizes3D::NAME, + HalfSizes3D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/half_sizes3d.hpp b/rerun_cpp/src/rerun/components/half_sizes3d.hpp index 4ddddd3ae354..7b322797c767 100644 --- a/rerun_cpp/src/rerun/components/half_sizes3d.hpp +++ b/rerun_cpp/src/rerun/components/half_sizes3d.hpp @@ -17,76 +17,73 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Half-sizes (extents) of a 3D box along its local axis, starting at its local origin/center. - /// - /// The box extends both in negative and positive direction along each axis. - /// Negative sizes indicate that the box is flipped along the respective axis, but this has no effect on how it is displayed. - struct HalfSizes3D { - rerun::datatypes::Vec3D xyz; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'half_sizes3d_ext.cpp' - - /// Construct HalfSizes3D from x/y/z values. - HalfSizes3D(float x, float y, float z) : xyz{x, y, z} {} - - float x() const { - return xyz.x(); - } - - float y() const { - return xyz.y(); - } - - float z() const { - return xyz.z(); - } - - public: - HalfSizes3D() = default; - - HalfSizes3D(rerun::datatypes::Vec3D xyz_) : xyz(xyz_) {} - - HalfSizes3D& operator=(rerun::datatypes::Vec3D xyz_) { - xyz = xyz_; - return *this; - } - - HalfSizes3D(std::array xyz_) : xyz(xyz_) {} - - HalfSizes3D& operator=(std::array xyz_) { - xyz = xyz_; - return *this; - } - - /// Cast to the underlying Vec3D datatype - operator rerun::datatypes::Vec3D() const { - return xyz; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const HalfSizes3D* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of HalfSizes3D components. - static Result to_data_cell( - const HalfSizes3D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: Half-sizes (extents) of a 3D box along its local axis, starting at its local origin/center. + /// + /// The box extends both in negative and positive direction along each axis. + /// Negative sizes indicate that the box is flipped along the respective axis, but this has no effect on how it is displayed. + struct HalfSizes3D { + rerun::datatypes::Vec3D xyz; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'half_sizes3d_ext.cpp' + + /// Construct HalfSizes3D from x/y/z values. + HalfSizes3D(float x, float y, float z) : xyz{x, y, z} {} + + float x() const { + return xyz.x(); + } + + float y() const { + return xyz.y(); + } + + float z() const { + return xyz.z(); + } + + public: + HalfSizes3D() = default; + + HalfSizes3D(rerun::datatypes::Vec3D xyz_) : xyz(xyz_) {} + + HalfSizes3D& operator=(rerun::datatypes::Vec3D xyz_) { + xyz = xyz_; + return *this; + } + + HalfSizes3D(std::array xyz_) : xyz(xyz_) {} + + HalfSizes3D& operator=(std::array xyz_) { + xyz = xyz_; + return *this; + } + + /// Cast to the underlying Vec3D datatype + operator rerun::datatypes::Vec3D() const { + return xyz; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const HalfSizes3D* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of HalfSizes3D components. + static Result to_data_cell( + const HalfSizes3D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/instance_key.cpp b/rerun_cpp/src/rerun/components/instance_key.cpp index 252d913d6458..6d5bfa8f1339 100644 --- a/rerun_cpp/src/rerun/components/instance_key.cpp +++ b/rerun_cpp/src/rerun/components/instance_key.cpp @@ -6,71 +6,66 @@ #include #include -namespace rerun { - namespace components { - const char InstanceKey::NAME[] = "rerun.components.InstanceKey"; +namespace rerun::components { + const char InstanceKey::NAME[] = "rerun.components.InstanceKey"; - const std::shared_ptr& InstanceKey::arrow_datatype() { - static const auto datatype = arrow::uint64(); - return datatype; - } - - Result> InstanceKey::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& InstanceKey::arrow_datatype() { + static const auto datatype = arrow::uint64(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> InstanceKey::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error InstanceKey::fill_arrow_array_builder( - arrow::UInt64Builder* builder, const InstanceKey* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - static_assert(sizeof(*elements) == sizeof(elements->value)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->value, static_cast(num_elements)) + rerun::Error InstanceKey::fill_arrow_array_builder( + arrow::UInt64Builder* builder, const InstanceKey* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - 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(); + static_assert(sizeof(*elements) == sizeof(elements->value)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->value, static_cast(num_elements)) + ); + + return Error::ok(); + } - auto builder_result = InstanceKey::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - InstanceKey::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - InstanceKey::NAME, - InstanceKey::arrow_datatype(), - std::move(array) + auto builder_result = InstanceKey::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + InstanceKey::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + InstanceKey::NAME, + InstanceKey::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/instance_key.hpp b/rerun_cpp/src/rerun/components/instance_key.hpp index 823d74365c96..20ed0858da2f 100644 --- a/rerun_cpp/src/rerun/components/instance_key.hpp +++ b/rerun_cpp/src/rerun/components/instance_key.hpp @@ -20,42 +20,40 @@ namespace arrow { using UInt64Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A unique numeric identifier for each individual instance within a batch. - struct InstanceKey { - uint64_t value; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - InstanceKey() = default; - - InstanceKey(uint64_t value_) : value(value_) {} - - InstanceKey& operator=(uint64_t value_) { - value = value_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const InstanceKey* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A unique numeric identifier for each individual instance within a batch. + struct InstanceKey { + uint64_t value; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + InstanceKey() = default; + + InstanceKey(uint64_t value_) : value(value_) {} + + InstanceKey& operator=(uint64_t value_) { + value = value_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const InstanceKey* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/keypoint_id.cpp b/rerun_cpp/src/rerun/components/keypoint_id.cpp index 105cf9cd7d4c..a214678de280 100644 --- a/rerun_cpp/src/rerun/components/keypoint_id.cpp +++ b/rerun_cpp/src/rerun/components/keypoint_id.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char KeypointId::NAME[] = "rerun.components.KeypointId"; +namespace rerun::components { + const char KeypointId::NAME[] = "rerun.components.KeypointId"; - const std::shared_ptr& KeypointId::arrow_datatype() { - static const auto datatype = rerun::datatypes::KeypointId::arrow_datatype(); - return datatype; - } - - Result> KeypointId::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& KeypointId::arrow_datatype() { + static const auto datatype = rerun::datatypes::KeypointId::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::KeypointId::new_arrow_array_builder(memory_pool).value); + Result> KeypointId::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error KeypointId::fill_arrow_array_builder( - arrow::UInt16Builder* builder, const KeypointId* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::KeypointId::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::KeypointId) == sizeof(KeypointId)); - RR_RETURN_NOT_OK(rerun::datatypes::KeypointId::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error KeypointId::fill_arrow_array_builder( + arrow::UInt16Builder* builder, const KeypointId* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::KeypointId) == sizeof(KeypointId)); + RR_RETURN_NOT_OK(rerun::datatypes::KeypointId::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - 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(); + return Error::ok(); + } - auto builder_result = KeypointId::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - KeypointId::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - KeypointId::NAME, - KeypointId::arrow_datatype(), - std::move(array) + auto builder_result = KeypointId::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + KeypointId::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + KeypointId::NAME, + KeypointId::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/keypoint_id.hpp b/rerun_cpp/src/rerun/components/keypoint_id.hpp index 4c258dda4663..a82ca6249f3e 100644 --- a/rerun_cpp/src/rerun/components/keypoint_id.hpp +++ b/rerun_cpp/src/rerun/components/keypoint_id.hpp @@ -21,54 +21,52 @@ namespace arrow { using UInt16Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A 16-bit ID representing a type of semantic keypoint within a class. - struct KeypointId { - rerun::datatypes::KeypointId id; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - KeypointId() = default; - - KeypointId(rerun::datatypes::KeypointId id_) : id(id_) {} - - KeypointId& operator=(rerun::datatypes::KeypointId id_) { - id = id_; - return *this; - } - - KeypointId(uint16_t id_) : id(id_) {} - - KeypointId& operator=(uint16_t id_) { - id = id_; - return *this; - } - - /// Cast to the underlying KeypointId datatype - operator rerun::datatypes::KeypointId() const { - return id; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const KeypointId* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A 16-bit ID representing a type of semantic keypoint within a class. + struct KeypointId { + rerun::datatypes::KeypointId id; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + KeypointId() = default; + + KeypointId(rerun::datatypes::KeypointId id_) : id(id_) {} + + KeypointId& operator=(rerun::datatypes::KeypointId id_) { + id = id_; + return *this; + } + + KeypointId(uint16_t id_) : id(id_) {} + + KeypointId& operator=(uint16_t id_) { + id = id_; + return *this; + } + + /// Cast to the underlying KeypointId datatype + operator rerun::datatypes::KeypointId() const { + return id; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const KeypointId* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/line_strip2d.cpp b/rerun_cpp/src/rerun/components/line_strip2d.cpp index 1c80e88578a4..6b0c24e4e73d 100644 --- a/rerun_cpp/src/rerun/components/line_strip2d.cpp +++ b/rerun_cpp/src/rerun/components/line_strip2d.cpp @@ -8,87 +8,81 @@ #include #include -namespace rerun { - namespace components { - const char LineStrip2D::NAME[] = "rerun.components.LineStrip2D"; +namespace rerun::components { + const char LineStrip2D::NAME[] = "rerun.components.LineStrip2D"; - const std::shared_ptr& LineStrip2D::arrow_datatype() { - static const auto datatype = - arrow::list(arrow::field("item", rerun::datatypes::Vec2D::arrow_datatype(), false)); - return datatype; + const std::shared_ptr& LineStrip2D::arrow_datatype() { + static const auto datatype = + arrow::list(arrow::field("item", rerun::datatypes::Vec2D::arrow_datatype(), false)); + return datatype; + } + + Result> LineStrip2D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> LineStrip2D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + rerun::datatypes::Vec2D::new_arrow_array_builder(memory_pool).value + )); + } - return Result(std::make_shared( - memory_pool, - rerun::datatypes::Vec2D::new_arrow_array_builder(memory_pool).value - )); + rerun::Error LineStrip2D::fill_arrow_array_builder( + arrow::ListBuilder* builder, const LineStrip2D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error LineStrip2D::fill_arrow_array_builder( - arrow::ListBuilder* builder, const LineStrip2D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = - static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append()); - if (element.points.data()) { - RR_RETURN_NOT_OK(rerun::datatypes::Vec2D::fill_arrow_array_builder( - value_builder, - element.points.data(), - element.points.size() - )); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append()); + if (element.points.data()) { + RR_RETURN_NOT_OK(rerun::datatypes::Vec2D::fill_arrow_array_builder( + value_builder, + element.points.data(), + element.points.size() + )); } - - return Error::ok(); } - Result LineStrip2D::to_data_cell( - const LineStrip2D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = LineStrip2D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - LineStrip2D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result LineStrip2D::to_data_cell( + const LineStrip2D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - LineStrip2D::NAME, - LineStrip2D::arrow_datatype(), - std::move(array) + auto builder_result = LineStrip2D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + LineStrip2D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + LineStrip2D::NAME, + LineStrip2D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/line_strip2d.hpp b/rerun_cpp/src/rerun/components/line_strip2d.hpp index 62e1cb0bca20..5b5f9677b390 100644 --- a/rerun_cpp/src/rerun/components/line_strip2d.hpp +++ b/rerun_cpp/src/rerun/components/line_strip2d.hpp @@ -19,64 +19,61 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A line strip in 2D space. - /// - /// A line strip is a list of points connected by line segments. It can be used to draw - /// approximations of smooth curves. - /// - /// The points will be connected in order, like so: - /// ```text - /// 2------3 5 - /// / \ / - /// 0----1 \ / - /// 4 - /// ``` - struct LineStrip2D { - std::vector points; +namespace rerun::components { + /// **Component**: A line strip in 2D space. + /// + /// A line strip is a list of points connected by line segments. It can be used to draw + /// approximations of smooth curves. + /// + /// The points will be connected in order, like so: + /// ```text + /// 2------3 5 + /// / \ / + /// 0----1 \ / + /// 4 + /// ``` + struct LineStrip2D { + std::vector points; - /// Name of the component, used for serialization. - static const char NAME[]; + /// Name of the component, used for serialization. + static const char NAME[]; - public: - // Extensions to generated type defined in 'line_strip2d_ext.cpp' + public: + // Extensions to generated type defined in 'line_strip2d_ext.cpp' - template - LineStrip2D(const std::vector& points_) : points(points_.size()) { - std::transform(points_.begin(), points_.end(), points.begin(), [](const T& pt) { - return rerun::datatypes::Vec2D(pt); - }); - } + template + LineStrip2D(const std::vector& points_) : points(points_.size()) { + std::transform(points_.begin(), points_.end(), points.begin(), [](const T& pt) { + return rerun::datatypes::Vec2D(pt); + }); + } - public: - LineStrip2D() = default; + public: + LineStrip2D() = default; - LineStrip2D(std::vector points_) - : points(std::move(points_)) {} + LineStrip2D(std::vector points_) : points(std::move(points_)) {} - LineStrip2D& operator=(std::vector points_) { - points = std::move(points_); - return *this; - } + LineStrip2D& operator=(std::vector points_) { + points = std::move(points_); + return *this; + } - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::ListBuilder* builder, const LineStrip2D* elements, size_t num_elements - ); + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::ListBuilder* builder, const LineStrip2D* elements, size_t num_elements + ); - /// Creates a Rerun DataCell from an array of LineStrip2D components. - static Result to_data_cell( - const LineStrip2D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun + /// Creates a Rerun DataCell from an array of LineStrip2D components. + static Result to_data_cell( + const LineStrip2D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/line_strip3d.cpp b/rerun_cpp/src/rerun/components/line_strip3d.cpp index cab2492b6ee0..760dfa615d83 100644 --- a/rerun_cpp/src/rerun/components/line_strip3d.cpp +++ b/rerun_cpp/src/rerun/components/line_strip3d.cpp @@ -8,87 +8,81 @@ #include #include -namespace rerun { - namespace components { - const char LineStrip3D::NAME[] = "rerun.components.LineStrip3D"; +namespace rerun::components { + const char LineStrip3D::NAME[] = "rerun.components.LineStrip3D"; - const std::shared_ptr& LineStrip3D::arrow_datatype() { - static const auto datatype = - arrow::list(arrow::field("item", rerun::datatypes::Vec3D::arrow_datatype(), false)); - return datatype; + const std::shared_ptr& LineStrip3D::arrow_datatype() { + static const auto datatype = + arrow::list(arrow::field("item", rerun::datatypes::Vec3D::arrow_datatype(), false)); + return datatype; + } + + Result> LineStrip3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> LineStrip3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value + )); + } - return Result(std::make_shared( - memory_pool, - rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value - )); + rerun::Error LineStrip3D::fill_arrow_array_builder( + arrow::ListBuilder* builder, const LineStrip3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error LineStrip3D::fill_arrow_array_builder( - arrow::ListBuilder* builder, const LineStrip3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = - static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append()); - if (element.points.data()) { - RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( - value_builder, - element.points.data(), - element.points.size() - )); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append()); + if (element.points.data()) { + RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( + value_builder, + element.points.data(), + element.points.size() + )); } - - return Error::ok(); } - Result LineStrip3D::to_data_cell( - const LineStrip3D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = LineStrip3D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - LineStrip3D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result LineStrip3D::to_data_cell( + const LineStrip3D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - LineStrip3D::NAME, - LineStrip3D::arrow_datatype(), - std::move(array) + auto builder_result = LineStrip3D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + LineStrip3D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + LineStrip3D::NAME, + LineStrip3D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/line_strip3d.hpp b/rerun_cpp/src/rerun/components/line_strip3d.hpp index 8b802e6b3e07..1f897cc2e19a 100644 --- a/rerun_cpp/src/rerun/components/line_strip3d.hpp +++ b/rerun_cpp/src/rerun/components/line_strip3d.hpp @@ -19,64 +19,61 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A line strip in 3D space. - /// - /// A line strip is a list of points connected by line segments. It can be used to draw - /// approximations of smooth curves. - /// - /// The points will be connected in order, like so: - /// ```text - /// 2------3 5 - /// / \ / - /// 0----1 \ / - /// 4 - /// ``` - struct LineStrip3D { - std::vector points; +namespace rerun::components { + /// **Component**: A line strip in 3D space. + /// + /// A line strip is a list of points connected by line segments. It can be used to draw + /// approximations of smooth curves. + /// + /// The points will be connected in order, like so: + /// ```text + /// 2------3 5 + /// / \ / + /// 0----1 \ / + /// 4 + /// ``` + struct LineStrip3D { + std::vector points; - /// Name of the component, used for serialization. - static const char NAME[]; + /// Name of the component, used for serialization. + static const char NAME[]; - public: - // Extensions to generated type defined in 'line_strip3d_ext.cpp' + public: + // Extensions to generated type defined in 'line_strip3d_ext.cpp' - template - LineStrip3D(const std::vector& points_) : points(points_.size()) { - std::transform(points_.begin(), points_.end(), points.begin(), [](const T& pt) { - return rerun::datatypes::Vec3D(pt); - }); - } + template + LineStrip3D(const std::vector& points_) : points(points_.size()) { + std::transform(points_.begin(), points_.end(), points.begin(), [](const T& pt) { + return rerun::datatypes::Vec3D(pt); + }); + } - public: - LineStrip3D() = default; + public: + LineStrip3D() = default; - LineStrip3D(std::vector points_) - : points(std::move(points_)) {} + LineStrip3D(std::vector points_) : points(std::move(points_)) {} - LineStrip3D& operator=(std::vector points_) { - points = std::move(points_); - return *this; - } + LineStrip3D& operator=(std::vector points_) { + points = std::move(points_); + return *this; + } - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::ListBuilder* builder, const LineStrip3D* elements, size_t num_elements - ); + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::ListBuilder* builder, const LineStrip3D* elements, size_t num_elements + ); - /// Creates a Rerun DataCell from an array of LineStrip3D components. - static Result to_data_cell( - const LineStrip3D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun + /// Creates a Rerun DataCell from an array of LineStrip3D components. + static Result to_data_cell( + const LineStrip3D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/material.cpp b/rerun_cpp/src/rerun/components/material.cpp index afd52d1a24a0..7a55716e292c 100644 --- a/rerun_cpp/src/rerun/components/material.cpp +++ b/rerun_cpp/src/rerun/components/material.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char Material::NAME[] = "rerun.components.Material"; +namespace rerun::components { + const char Material::NAME[] = "rerun.components.Material"; - const std::shared_ptr& Material::arrow_datatype() { - static const auto datatype = rerun::datatypes::Material::arrow_datatype(); - return datatype; - } - - Result> Material::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Material::arrow_datatype() { + static const auto datatype = rerun::datatypes::Material::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Material::new_arrow_array_builder(memory_pool).value); + Result> Material::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Material::fill_arrow_array_builder( - arrow::StructBuilder* builder, const Material* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Material::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Material) == sizeof(Material)); - RR_RETURN_NOT_OK(rerun::datatypes::Material::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error Material::fill_arrow_array_builder( + arrow::StructBuilder* builder, const Material* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Material) == sizeof(Material)); + RR_RETURN_NOT_OK(rerun::datatypes::Material::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result Material::to_data_cell( - const Material* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = Material::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Material::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Material::to_data_cell( + const Material* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - Material::NAME, - Material::arrow_datatype(), - std::move(array) + auto builder_result = Material::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Material::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + Material::NAME, + Material::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/material.hpp b/rerun_cpp/src/rerun/components/material.hpp index 3bfe70cc2ee9..972cb3f01d01 100644 --- a/rerun_cpp/src/rerun/components/material.hpp +++ b/rerun_cpp/src/rerun/components/material.hpp @@ -18,62 +18,60 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Material properties of a mesh. - struct Material { - rerun::datatypes::Material material; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'material_ext.cpp' - - static Material from_albedo_factor(rerun::datatypes::Rgba32 color) { - return Material(color); - } - - public: - Material() = default; - - Material(rerun::datatypes::Material material_) : material(material_) {} - - Material& operator=(rerun::datatypes::Material material_) { - material = material_; - return *this; - } - - Material(std::optional albedo_factor_) - : material(albedo_factor_) {} - - Material& operator=(std::optional albedo_factor_) { - material = albedo_factor_; - return *this; - } - - /// Cast to the underlying Material datatype - operator rerun::datatypes::Material() const { - return material; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const Material* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Material components. - static Result to_data_cell( - const Material* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: Material properties of a mesh. + struct Material { + rerun::datatypes::Material material; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'material_ext.cpp' + + static Material from_albedo_factor(rerun::datatypes::Rgba32 color) { + return Material(color); + } + + public: + Material() = default; + + Material(rerun::datatypes::Material material_) : material(material_) {} + + Material& operator=(rerun::datatypes::Material material_) { + material = material_; + return *this; + } + + Material(std::optional albedo_factor_) + : material(albedo_factor_) {} + + Material& operator=(std::optional albedo_factor_) { + material = albedo_factor_; + return *this; + } + + /// Cast to the underlying Material datatype + operator rerun::datatypes::Material() const { + return material; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const Material* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Material components. + static Result to_data_cell( + const Material* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/media_type.cpp b/rerun_cpp/src/rerun/components/media_type.cpp index 4f2a2bf385f3..836c332df5be 100644 --- a/rerun_cpp/src/rerun/components/media_type.cpp +++ b/rerun_cpp/src/rerun/components/media_type.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char MediaType::NAME[] = "rerun.components.MediaType"; +namespace rerun::components { + const char MediaType::NAME[] = "rerun.components.MediaType"; - const std::shared_ptr& MediaType::arrow_datatype() { - static const auto datatype = rerun::datatypes::Utf8::arrow_datatype(); - return datatype; - } - - Result> MediaType::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& MediaType::arrow_datatype() { + static const auto datatype = rerun::datatypes::Utf8::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Utf8::new_arrow_array_builder(memory_pool).value); + Result> MediaType::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error MediaType::fill_arrow_array_builder( - arrow::StringBuilder* builder, const MediaType* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Utf8::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Utf8) == sizeof(MediaType)); - RR_RETURN_NOT_OK(rerun::datatypes::Utf8::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error MediaType::fill_arrow_array_builder( + arrow::StringBuilder* builder, const MediaType* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Utf8) == sizeof(MediaType)); + RR_RETURN_NOT_OK(rerun::datatypes::Utf8::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result MediaType::to_data_cell( - const MediaType* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = MediaType::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - MediaType::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result MediaType::to_data_cell( + const MediaType* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - MediaType::NAME, - MediaType::arrow_datatype(), - std::move(array) + auto builder_result = MediaType::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + MediaType::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + MediaType::NAME, + MediaType::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/media_type.hpp b/rerun_cpp/src/rerun/components/media_type.hpp index d51fe28c6c52..43b6c0d82b3a 100644 --- a/rerun_cpp/src/rerun/components/media_type.hpp +++ b/rerun_cpp/src/rerun/components/media_type.hpp @@ -18,99 +18,97 @@ namespace arrow { class StringBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A standardized media type (RFC2046, formerly known as MIME types), encoded as a utf8 string. +namespace rerun::components { + /// **Component**: A standardized media type (RFC2046, formerly known as MIME types), encoded as a utf8 string. + /// + /// The complete reference of officially registered media types is maintained by the IANA and can be + /// consulted at . + struct MediaType { + rerun::datatypes::Utf8 value; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'media_type_ext.cpp' + + /// Construct media type from a null-terminated UTF8 string. + MediaType(const char* media_type) : value(media_type) {} + + // TODO(#2388): come up with some DSL in our flatbuffers definitions so that we can + // declare these constants directly in there. + + /// `text/plain` + static MediaType plain_text() { + return "text/plain"; + } + + /// `text/markdown` + /// + /// + static MediaType markdown() { + return "text/markdown"; + } + + /// `glTF`(https://en.wikipedia.org/wiki/GlTF): `model/gltf+json`. + /// + /// + static MediaType gltf() { + return "model/gltf+json"; + } + + /// Binary `glTF`(https://en.wikipedia.org/wiki/GlTF): `model/gltf-binary`. + /// + /// + static MediaType glb() { + return "model/gltf-binary"; + } + + /// [Wavefront .obj](https://en.wikipedia.org/wiki/Wavefront_.obj_file): `model/obj`. /// - /// The complete reference of officially registered media types is maintained by the IANA and can be - /// consulted at . - struct MediaType { - rerun::datatypes::Utf8 value; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'media_type_ext.cpp' - - /// Construct media type from a null-terminated UTF8 string. - MediaType(const char* media_type) : value(media_type) {} - - // TODO(#2388): come up with some DSL in our flatbuffers definitions so that we can - // declare these constants directly in there. - - /// `text/plain` - static MediaType plain_text() { - return "text/plain"; - } - - /// `text/markdown` - /// - /// - static MediaType markdown() { - return "text/markdown"; - } - - /// `glTF`(https://en.wikipedia.org/wiki/GlTF): `model/gltf+json`. - /// - /// - static MediaType gltf() { - return "model/gltf+json"; - } - - /// Binary `glTF`(https://en.wikipedia.org/wiki/GlTF): `model/gltf-binary`. - /// - /// - static MediaType glb() { - return "model/gltf-binary"; - } - - /// [Wavefront .obj](https://en.wikipedia.org/wiki/Wavefront_.obj_file): `model/obj`. - /// - /// - static MediaType obj() { - return "model/obj"; - } - - public: - MediaType() = default; - - MediaType(rerun::datatypes::Utf8 value_) : value(std::move(value_)) {} - - MediaType& operator=(rerun::datatypes::Utf8 value_) { - value = std::move(value_); - return *this; - } - - MediaType(std::string value_) : value(std::move(value_)) {} - - MediaType& operator=(std::string value_) { - value = std::move(value_); - return *this; - } - - /// Cast to the underlying Utf8 datatype - operator rerun::datatypes::Utf8() const { - return value; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StringBuilder* builder, const MediaType* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of MediaType components. - static Result to_data_cell( - const MediaType* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun + /// + static MediaType obj() { + return "model/obj"; + } + + public: + MediaType() = default; + + MediaType(rerun::datatypes::Utf8 value_) : value(std::move(value_)) {} + + MediaType& operator=(rerun::datatypes::Utf8 value_) { + value = std::move(value_); + return *this; + } + + MediaType(std::string value_) : value(std::move(value_)) {} + + MediaType& operator=(std::string value_) { + value = std::move(value_); + return *this; + } + + /// Cast to the underlying Utf8 datatype + operator rerun::datatypes::Utf8() const { + return value; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StringBuilder* builder, const MediaType* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of MediaType components. + static Result to_data_cell( + const MediaType* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/mesh_properties.cpp b/rerun_cpp/src/rerun/components/mesh_properties.cpp index 8b33d597e4b1..51ea809a108c 100644 --- a/rerun_cpp/src/rerun/components/mesh_properties.cpp +++ b/rerun_cpp/src/rerun/components/mesh_properties.cpp @@ -8,77 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char MeshProperties::NAME[] = "rerun.components.MeshProperties"; +namespace rerun::components { + const char MeshProperties::NAME[] = "rerun.components.MeshProperties"; - const std::shared_ptr& MeshProperties::arrow_datatype() { - static const auto datatype = rerun::datatypes::MeshProperties::arrow_datatype(); - return datatype; + const std::shared_ptr& MeshProperties::arrow_datatype() { + static const auto datatype = rerun::datatypes::MeshProperties::arrow_datatype(); + return datatype; + } + + Result> MeshProperties::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> MeshProperties::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::MeshProperties::new_arrow_array_builder(memory_pool).value); + } - return Result( - rerun::datatypes::MeshProperties::new_arrow_array_builder(memory_pool).value + rerun::Error MeshProperties::fill_arrow_array_builder( + arrow::StructBuilder* builder, const MeshProperties* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error MeshProperties::fill_arrow_array_builder( - arrow::StructBuilder* builder, const MeshProperties* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::MeshProperties) == sizeof(MeshProperties)); - RR_RETURN_NOT_OK(rerun::datatypes::MeshProperties::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::MeshProperties) == sizeof(MeshProperties)); + RR_RETURN_NOT_OK(rerun::datatypes::MeshProperties::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - Result MeshProperties::to_data_cell( - const MeshProperties* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = MeshProperties::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(MeshProperties::fill_arrow_array_builder( - builder.get(), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result MeshProperties::to_data_cell( + const MeshProperties* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - MeshProperties::NAME, - MeshProperties::arrow_datatype(), - std::move(array) + auto builder_result = MeshProperties::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + MeshProperties::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + MeshProperties::NAME, + MeshProperties::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/mesh_properties.hpp b/rerun_cpp/src/rerun/components/mesh_properties.hpp index b87db050491c..d3ced1e69203 100644 --- a/rerun_cpp/src/rerun/components/mesh_properties.hpp +++ b/rerun_cpp/src/rerun/components/mesh_properties.hpp @@ -19,62 +19,60 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Optional triangle indices for a mesh. - struct MeshProperties { - rerun::datatypes::MeshProperties props; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'mesh_properties_ext.cpp' - - static MeshProperties from_triangle_indices(std::vector indices) { - return MeshProperties(indices); - } - - public: - MeshProperties() = default; - - MeshProperties(rerun::datatypes::MeshProperties props_) : props(std::move(props_)) {} - - MeshProperties& operator=(rerun::datatypes::MeshProperties props_) { - props = std::move(props_); - return *this; - } - - MeshProperties(std::optional> indices_) - : props(std::move(indices_)) {} - - MeshProperties& operator=(std::optional> indices_) { - props = std::move(indices_); - return *this; - } - - /// Cast to the underlying MeshProperties datatype - operator rerun::datatypes::MeshProperties() const { - return props; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const MeshProperties* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of MeshProperties components. - static Result to_data_cell( - const MeshProperties* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: Optional triangle indices for a mesh. + struct MeshProperties { + rerun::datatypes::MeshProperties props; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'mesh_properties_ext.cpp' + + static MeshProperties from_triangle_indices(std::vector indices) { + return MeshProperties(indices); + } + + public: + MeshProperties() = default; + + MeshProperties(rerun::datatypes::MeshProperties props_) : props(std::move(props_)) {} + + MeshProperties& operator=(rerun::datatypes::MeshProperties props_) { + props = std::move(props_); + return *this; + } + + MeshProperties(std::optional> indices_) + : props(std::move(indices_)) {} + + MeshProperties& operator=(std::optional> indices_) { + props = std::move(indices_); + return *this; + } + + /// Cast to the underlying MeshProperties datatype + operator rerun::datatypes::MeshProperties() const { + return props; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const MeshProperties* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of MeshProperties components. + static Result to_data_cell( + const MeshProperties* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/out_of_tree_transform3d.cpp b/rerun_cpp/src/rerun/components/out_of_tree_transform3d.cpp index a3d9a88fe007..63b2da42d752 100644 --- a/rerun_cpp/src/rerun/components/out_of_tree_transform3d.cpp +++ b/rerun_cpp/src/rerun/components/out_of_tree_transform3d.cpp @@ -8,76 +8,70 @@ #include #include -namespace rerun { - namespace components { - const char OutOfTreeTransform3D::NAME[] = "rerun.components.OutOfTreeTransform3D"; +namespace rerun::components { + const char OutOfTreeTransform3D::NAME[] = "rerun.components.OutOfTreeTransform3D"; - const std::shared_ptr& OutOfTreeTransform3D::arrow_datatype() { - static const auto datatype = rerun::datatypes::Transform3D::arrow_datatype(); - return datatype; + const std::shared_ptr& OutOfTreeTransform3D::arrow_datatype() { + static const auto datatype = rerun::datatypes::Transform3D::arrow_datatype(); + return datatype; + } + + Result> OutOfTreeTransform3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> - OutOfTreeTransform3D::new_arrow_array_builder(arrow::MemoryPool* memory_pool) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::Transform3D::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::Transform3D::new_arrow_array_builder(memory_pool).value + rerun::Error OutOfTreeTransform3D::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const OutOfTreeTransform3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error OutOfTreeTransform3D::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const OutOfTreeTransform3D* elements, - size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + static_assert(sizeof(rerun::datatypes::Transform3D) == sizeof(OutOfTreeTransform3D)); + RR_RETURN_NOT_OK(rerun::datatypes::Transform3D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - static_assert(sizeof(rerun::datatypes::Transform3D) == sizeof(OutOfTreeTransform3D)); - RR_RETURN_NOT_OK(rerun::datatypes::Transform3D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); - } + return Error::ok(); + } - Result OutOfTreeTransform3D::to_data_cell( - const OutOfTreeTransform3D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + Result OutOfTreeTransform3D::to_data_cell( + const OutOfTreeTransform3D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - auto builder_result = OutOfTreeTransform3D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(OutOfTreeTransform3D::fill_arrow_array_builder( - builder.get(), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); - - return rerun::DataCell::create( - OutOfTreeTransform3D::NAME, - OutOfTreeTransform3D::arrow_datatype(), - std::move(array) - ); + auto builder_result = OutOfTreeTransform3D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK(OutOfTreeTransform3D::fill_arrow_array_builder( + builder.get(), + instances, + num_instances + )); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + OutOfTreeTransform3D::NAME, + OutOfTreeTransform3D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/out_of_tree_transform3d.hpp b/rerun_cpp/src/rerun/components/out_of_tree_transform3d.hpp index e1da8c036001..7ac637047bfc 100644 --- a/rerun_cpp/src/rerun/components/out_of_tree_transform3d.hpp +++ b/rerun_cpp/src/rerun/components/out_of_tree_transform3d.hpp @@ -16,51 +16,49 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: An out-of-tree affine transform between two 3D spaces, represented in a given direction. - /// - /// "Out-of-tree" means that the transform only affects its own entity: children don't inherit from it. - struct OutOfTreeTransform3D { - /// Representation of the transform. - rerun::datatypes::Transform3D repr; +namespace rerun::components { + /// **Component**: An out-of-tree affine transform between two 3D spaces, represented in a given direction. + /// + /// "Out-of-tree" means that the transform only affects its own entity: children don't inherit from it. + struct OutOfTreeTransform3D { + /// Representation of the transform. + rerun::datatypes::Transform3D repr; - /// Name of the component, used for serialization. - static const char NAME[]; + /// Name of the component, used for serialization. + static const char NAME[]; - public: - OutOfTreeTransform3D() = default; + public: + OutOfTreeTransform3D() = default; - OutOfTreeTransform3D(rerun::datatypes::Transform3D repr_) : repr(repr_) {} + OutOfTreeTransform3D(rerun::datatypes::Transform3D repr_) : repr(repr_) {} - OutOfTreeTransform3D& operator=(rerun::datatypes::Transform3D repr_) { - repr = repr_; - return *this; - } + OutOfTreeTransform3D& operator=(rerun::datatypes::Transform3D repr_) { + repr = repr_; + return *this; + } - /// Cast to the underlying Transform3D datatype - operator rerun::datatypes::Transform3D() const { - return repr; - } + /// Cast to the underlying Transform3D datatype + operator rerun::datatypes::Transform3D() const { + return repr; + } - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const OutOfTreeTransform3D* elements, - size_t num_elements - ); + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const OutOfTreeTransform3D* elements, + size_t num_elements + ); - /// Creates a Rerun DataCell from an array of OutOfTreeTransform3D components. - static Result to_data_cell( - const OutOfTreeTransform3D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun + /// Creates a Rerun DataCell from an array of OutOfTreeTransform3D components. + static Result to_data_cell( + const OutOfTreeTransform3D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/pinhole_projection.cpp b/rerun_cpp/src/rerun/components/pinhole_projection.cpp index f8688e71bf15..ecd10aa39069 100644 --- a/rerun_cpp/src/rerun/components/pinhole_projection.cpp +++ b/rerun_cpp/src/rerun/components/pinhole_projection.cpp @@ -8,75 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char PinholeProjection::NAME[] = "rerun.components.PinholeProjection"; +namespace rerun::components { + const char PinholeProjection::NAME[] = "rerun.components.PinholeProjection"; - const std::shared_ptr& PinholeProjection::arrow_datatype() { - static const auto datatype = rerun::datatypes::Mat3x3::arrow_datatype(); - return datatype; - } - - Result> - PinholeProjection::new_arrow_array_builder(arrow::MemoryPool* memory_pool) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& PinholeProjection::arrow_datatype() { + static const auto datatype = rerun::datatypes::Mat3x3::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Mat3x3::new_arrow_array_builder(memory_pool).value); + Result> PinholeProjection::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error PinholeProjection::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const PinholeProjection* elements, - size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Mat3x3::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Mat3x3) == sizeof(PinholeProjection)); - RR_RETURN_NOT_OK(rerun::datatypes::Mat3x3::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error PinholeProjection::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const PinholeProjection* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Mat3x3) == sizeof(PinholeProjection)); + RR_RETURN_NOT_OK(rerun::datatypes::Mat3x3::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result PinholeProjection::to_data_cell( - const PinholeProjection* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = PinholeProjection::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(PinholeProjection::fill_arrow_array_builder( - builder.get(), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result PinholeProjection::to_data_cell( + const PinholeProjection* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - PinholeProjection::NAME, - PinholeProjection::arrow_datatype(), - std::move(array) + auto builder_result = PinholeProjection::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + PinholeProjection::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + PinholeProjection::NAME, + PinholeProjection::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/pinhole_projection.hpp b/rerun_cpp/src/rerun/components/pinhole_projection.hpp index 1fae08a27eec..ec82c102f5fb 100644 --- a/rerun_cpp/src/rerun/components/pinhole_projection.hpp +++ b/rerun_cpp/src/rerun/components/pinhole_projection.hpp @@ -17,75 +17,72 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Camera projection, from image coordinates to view coordinates. - /// - /// Child from parent. - /// Image coordinates from camera view coordinates. - /// - /// Example: - /// ```text - /// 1496.1 0.0 980.5 - /// 0.0 1496.1 744.5 - /// 0.0 0.0 1.0 - /// ``` - struct PinholeProjection { - rerun::datatypes::Mat3x3 image_from_camera; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'pinhole_projection_ext.cpp' - - /// Construct a new 3x3 pinhole matrix from a pointer to 9 floats (in row major order). - static PinholeProjection from_mat3x3(const float* elements) { - return PinholeProjection(rerun::datatypes::Mat3x3(elements)); - } - - public: - PinholeProjection() = default; - - PinholeProjection(rerun::datatypes::Mat3x3 image_from_camera_) - : image_from_camera(image_from_camera_) {} - - PinholeProjection& operator=(rerun::datatypes::Mat3x3 image_from_camera_) { - image_from_camera = image_from_camera_; - return *this; - } - - PinholeProjection(std::array flat_columns_) - : image_from_camera(flat_columns_) {} - - PinholeProjection& operator=(std::array flat_columns_) { - image_from_camera = flat_columns_; - return *this; - } - - /// Cast to the underlying Mat3x3 datatype - operator rerun::datatypes::Mat3x3() const { - return image_from_camera; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const PinholeProjection* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of PinholeProjection components. - static Result to_data_cell( - const PinholeProjection* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: Camera projection, from image coordinates to view coordinates. + /// + /// Child from parent. + /// Image coordinates from camera view coordinates. + /// + /// Example: + /// ```text + /// 1496.1 0.0 980.5 + /// 0.0 1496.1 744.5 + /// 0.0 0.0 1.0 + /// ``` + struct PinholeProjection { + rerun::datatypes::Mat3x3 image_from_camera; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'pinhole_projection_ext.cpp' + + /// Construct a new 3x3 pinhole matrix from a pointer to 9 floats (in row major order). + static PinholeProjection from_mat3x3(const float* elements) { + return PinholeProjection(rerun::datatypes::Mat3x3(elements)); + } + + public: + PinholeProjection() = default; + + PinholeProjection(rerun::datatypes::Mat3x3 image_from_camera_) + : image_from_camera(image_from_camera_) {} + + PinholeProjection& operator=(rerun::datatypes::Mat3x3 image_from_camera_) { + image_from_camera = image_from_camera_; + return *this; + } + + PinholeProjection(std::array flat_columns_) : image_from_camera(flat_columns_) {} + + PinholeProjection& operator=(std::array flat_columns_) { + image_from_camera = flat_columns_; + return *this; + } + + /// Cast to the underlying Mat3x3 datatype + operator rerun::datatypes::Mat3x3() const { + return image_from_camera; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const PinholeProjection* elements, + size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of PinholeProjection components. + static Result to_data_cell( + const PinholeProjection* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/position2d.cpp b/rerun_cpp/src/rerun/components/position2d.cpp index 8f165a340761..fef5d42df7e4 100644 --- a/rerun_cpp/src/rerun/components/position2d.cpp +++ b/rerun_cpp/src/rerun/components/position2d.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char Position2D::NAME[] = "rerun.components.Position2D"; +namespace rerun::components { + const char Position2D::NAME[] = "rerun.components.Position2D"; - const std::shared_ptr& Position2D::arrow_datatype() { - static const auto datatype = rerun::datatypes::Vec2D::arrow_datatype(); - return datatype; - } - - Result> Position2D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Position2D::arrow_datatype() { + static const auto datatype = rerun::datatypes::Vec2D::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Vec2D::new_arrow_array_builder(memory_pool).value); + Result> Position2D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Position2D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Position2D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Vec2D::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Vec2D) == sizeof(Position2D)); - RR_RETURN_NOT_OK(rerun::datatypes::Vec2D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error Position2D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Position2D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Vec2D) == sizeof(Position2D)); + RR_RETURN_NOT_OK(rerun::datatypes::Vec2D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result Position2D::to_data_cell( - const Position2D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = Position2D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Position2D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Position2D::to_data_cell( + const Position2D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - Position2D::NAME, - Position2D::arrow_datatype(), - std::move(array) + auto builder_result = Position2D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Position2D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + Position2D::NAME, + Position2D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/position2d.hpp b/rerun_cpp/src/rerun/components/position2d.hpp index 95cd832e3642..99e8de364035 100644 --- a/rerun_cpp/src/rerun/components/position2d.hpp +++ b/rerun_cpp/src/rerun/components/position2d.hpp @@ -17,69 +17,66 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A position in 2D space. - struct Position2D { - rerun::datatypes::Vec2D xy; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'position2d_ext.cpp' - - /// Construct Position2D from x/y values. - Position2D(float x, float y) : xy{x, y} {} - - float x() const { - return xy.x(); - } - - float y() const { - return xy.y(); - } - - public: - Position2D() = default; - - Position2D(rerun::datatypes::Vec2D xy_) : xy(xy_) {} - - Position2D& operator=(rerun::datatypes::Vec2D xy_) { - xy = xy_; - return *this; - } - - Position2D(std::array xy_) : xy(xy_) {} - - Position2D& operator=(std::array xy_) { - xy = xy_; - return *this; - } - - /// Cast to the underlying Vec2D datatype - operator rerun::datatypes::Vec2D() const { - return xy; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Position2D* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Position2D components. - static Result to_data_cell( - const Position2D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A position in 2D space. + struct Position2D { + rerun::datatypes::Vec2D xy; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'position2d_ext.cpp' + + /// Construct Position2D from x/y values. + Position2D(float x, float y) : xy{x, y} {} + + float x() const { + return xy.x(); + } + + float y() const { + return xy.y(); + } + + public: + Position2D() = default; + + Position2D(rerun::datatypes::Vec2D xy_) : xy(xy_) {} + + Position2D& operator=(rerun::datatypes::Vec2D xy_) { + xy = xy_; + return *this; + } + + Position2D(std::array xy_) : xy(xy_) {} + + Position2D& operator=(std::array xy_) { + xy = xy_; + return *this; + } + + /// Cast to the underlying Vec2D datatype + operator rerun::datatypes::Vec2D() const { + return xy; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Position2D* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Position2D components. + static Result to_data_cell( + const Position2D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/position3d.cpp b/rerun_cpp/src/rerun/components/position3d.cpp index 5806cc4fbed1..cec0dc511d8a 100644 --- a/rerun_cpp/src/rerun/components/position3d.cpp +++ b/rerun_cpp/src/rerun/components/position3d.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char Position3D::NAME[] = "rerun.components.Position3D"; +namespace rerun::components { + const char Position3D::NAME[] = "rerun.components.Position3D"; - const std::shared_ptr& Position3D::arrow_datatype() { - static const auto datatype = rerun::datatypes::Vec3D::arrow_datatype(); - return datatype; - } - - Result> Position3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Position3D::arrow_datatype() { + static const auto datatype = rerun::datatypes::Vec3D::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value); + Result> Position3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Position3D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Position3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Vec3D) == sizeof(Position3D)); - RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error Position3D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Position3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Vec3D) == sizeof(Position3D)); + RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result Position3D::to_data_cell( - const Position3D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = Position3D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Position3D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Position3D::to_data_cell( + const Position3D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - Position3D::NAME, - Position3D::arrow_datatype(), - std::move(array) + auto builder_result = Position3D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Position3D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + Position3D::NAME, + Position3D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/position3d.hpp b/rerun_cpp/src/rerun/components/position3d.hpp index 614292b02aaf..0dd8aa8d65a4 100644 --- a/rerun_cpp/src/rerun/components/position3d.hpp +++ b/rerun_cpp/src/rerun/components/position3d.hpp @@ -17,73 +17,70 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A position in 3D space. - struct Position3D { - rerun::datatypes::Vec3D xyz; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'position3d_ext.cpp' - - /// Construct Position3D from x/y/z values. - Position3D(float x, float y, float z) : xyz{x, y, z} {} - - float x() const { - return xyz.x(); - } - - float y() const { - return xyz.y(); - } - - float z() const { - return xyz.z(); - } - - public: - Position3D() = default; - - Position3D(rerun::datatypes::Vec3D xyz_) : xyz(xyz_) {} - - Position3D& operator=(rerun::datatypes::Vec3D xyz_) { - xyz = xyz_; - return *this; - } - - Position3D(std::array xyz_) : xyz(xyz_) {} - - Position3D& operator=(std::array xyz_) { - xyz = xyz_; - return *this; - } - - /// Cast to the underlying Vec3D datatype - operator rerun::datatypes::Vec3D() const { - return xyz; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Position3D* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Position3D components. - static Result to_data_cell( - const Position3D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A position in 3D space. + struct Position3D { + rerun::datatypes::Vec3D xyz; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'position3d_ext.cpp' + + /// Construct Position3D from x/y/z values. + Position3D(float x, float y, float z) : xyz{x, y, z} {} + + float x() const { + return xyz.x(); + } + + float y() const { + return xyz.y(); + } + + float z() const { + return xyz.z(); + } + + public: + Position3D() = default; + + Position3D(rerun::datatypes::Vec3D xyz_) : xyz(xyz_) {} + + Position3D& operator=(rerun::datatypes::Vec3D xyz_) { + xyz = xyz_; + return *this; + } + + Position3D(std::array xyz_) : xyz(xyz_) {} + + Position3D& operator=(std::array xyz_) { + xyz = xyz_; + return *this; + } + + /// Cast to the underlying Vec3D datatype + operator rerun::datatypes::Vec3D() const { + return xyz; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Position3D* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Position3D components. + static Result to_data_cell( + const Position3D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/radius.cpp b/rerun_cpp/src/rerun/components/radius.cpp index 8ed086a4f16a..dc116c93df66 100644 --- a/rerun_cpp/src/rerun/components/radius.cpp +++ b/rerun_cpp/src/rerun/components/radius.cpp @@ -6,71 +6,60 @@ #include #include -namespace rerun { - namespace components { - const char Radius::NAME[] = "rerun.components.Radius"; +namespace rerun::components { + const char Radius::NAME[] = "rerun.components.Radius"; - const std::shared_ptr& Radius::arrow_datatype() { - static const auto datatype = arrow::float32(); - return datatype; - } - - Result> Radius::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Radius::arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> Radius::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Radius::fill_arrow_array_builder( - arrow::FloatBuilder* builder, const Radius* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - static_assert(sizeof(*elements) == sizeof(elements->value)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->value, static_cast(num_elements)) + rerun::Error Radius::fill_arrow_array_builder( + arrow::FloatBuilder* builder, const Radius* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - 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(); + static_assert(sizeof(*elements) == sizeof(elements->value)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->value, static_cast(num_elements)) + ); + + return Error::ok(); + } - auto builder_result = Radius::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Radius::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - Radius::NAME, - Radius::arrow_datatype(), - std::move(array) + auto builder_result = Radius::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Radius::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create(Radius::NAME, Radius::arrow_datatype(), std::move(array)); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/radius.hpp b/rerun_cpp/src/rerun/components/radius.hpp index 7f73a74cc6c9..d6dd752a2610 100644 --- a/rerun_cpp/src/rerun/components/radius.hpp +++ b/rerun_cpp/src/rerun/components/radius.hpp @@ -20,42 +20,38 @@ namespace arrow { using FloatBuilder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A Radius component. - struct Radius { - float value; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - Radius() = default; - - Radius(float value_) : value(value_) {} - - Radius& operator=(float value_) { - value = value_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const Radius* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A Radius component. + struct Radius { + float value; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + Radius() = default; + + Radius(float value_) : value(value_) {} + + Radius& operator=(float value_) { + value = value_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell(const Radius* instances, size_t num_instances); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/resolution.cpp b/rerun_cpp/src/rerun/components/resolution.cpp index 9be825b20978..f00fe442eec1 100644 --- a/rerun_cpp/src/rerun/components/resolution.cpp +++ b/rerun_cpp/src/rerun/components/resolution.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char Resolution::NAME[] = "rerun.components.Resolution"; +namespace rerun::components { + const char Resolution::NAME[] = "rerun.components.Resolution"; - const std::shared_ptr& Resolution::arrow_datatype() { - static const auto datatype = rerun::datatypes::Vec2D::arrow_datatype(); - return datatype; - } - - Result> Resolution::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Resolution::arrow_datatype() { + static const auto datatype = rerun::datatypes::Vec2D::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Vec2D::new_arrow_array_builder(memory_pool).value); + Result> Resolution::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Resolution::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Resolution* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Vec2D::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Vec2D) == sizeof(Resolution)); - RR_RETURN_NOT_OK(rerun::datatypes::Vec2D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error Resolution::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Resolution* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Vec2D) == sizeof(Resolution)); + RR_RETURN_NOT_OK(rerun::datatypes::Vec2D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result Resolution::to_data_cell( - const Resolution* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = Resolution::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Resolution::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Resolution::to_data_cell( + const Resolution* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - Resolution::NAME, - Resolution::arrow_datatype(), - std::move(array) + auto builder_result = Resolution::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Resolution::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + Resolution::NAME, + Resolution::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/resolution.hpp b/rerun_cpp/src/rerun/components/resolution.hpp index 95fac6b05fd7..2c7109181103 100644 --- a/rerun_cpp/src/rerun/components/resolution.hpp +++ b/rerun_cpp/src/rerun/components/resolution.hpp @@ -17,69 +17,66 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: Pixel resolution width & height, e.g. of a camera sensor. - /// - /// Typically in integer units, but for some use cases floating point may be used. - struct Resolution { - rerun::datatypes::Vec2D resolution; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'resolution_ext.cpp' - - static const Resolution IDENTITY; - - /// Construct resolution from width and height floats. - Resolution(float width, float height) : resolution{width, height} {} - - /// Construct resolution from width and height integers. - Resolution(int width, int height) - : resolution{static_cast(width), static_cast(height)} {} - - public: - Resolution() = default; - - Resolution(rerun::datatypes::Vec2D resolution_) : resolution(resolution_) {} - - Resolution& operator=(rerun::datatypes::Vec2D resolution_) { - resolution = resolution_; - return *this; - } - - Resolution(std::array xy_) : resolution(xy_) {} - - Resolution& operator=(std::array xy_) { - resolution = xy_; - return *this; - } - - /// Cast to the underlying Vec2D datatype - operator rerun::datatypes::Vec2D() const { - return resolution; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Resolution* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Resolution components. - static Result to_data_cell( - const Resolution* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: Pixel resolution width & height, e.g. of a camera sensor. + /// + /// Typically in integer units, but for some use cases floating point may be used. + struct Resolution { + rerun::datatypes::Vec2D resolution; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'resolution_ext.cpp' + + static const Resolution IDENTITY; + + /// Construct resolution from width and height floats. + Resolution(float width, float height) : resolution{width, height} {} + + /// Construct resolution from width and height integers. + Resolution(int width, int height) + : resolution{static_cast(width), static_cast(height)} {} + + public: + Resolution() = default; + + Resolution(rerun::datatypes::Vec2D resolution_) : resolution(resolution_) {} + + Resolution& operator=(rerun::datatypes::Vec2D resolution_) { + resolution = resolution_; + return *this; + } + + Resolution(std::array xy_) : resolution(xy_) {} + + Resolution& operator=(std::array xy_) { + resolution = xy_; + return *this; + } + + /// Cast to the underlying Vec2D datatype + operator rerun::datatypes::Vec2D() const { + return resolution; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Resolution* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Resolution components. + static Result to_data_cell( + const Resolution* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/rotation3d.cpp b/rerun_cpp/src/rerun/components/rotation3d.cpp index a6f46413d61c..6379c65fe8bd 100644 --- a/rerun_cpp/src/rerun/components/rotation3d.cpp +++ b/rerun_cpp/src/rerun/components/rotation3d.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char Rotation3D::NAME[] = "rerun.components.Rotation3D"; +namespace rerun::components { + const char Rotation3D::NAME[] = "rerun.components.Rotation3D"; - const std::shared_ptr& Rotation3D::arrow_datatype() { - static const auto datatype = rerun::datatypes::Rotation3D::arrow_datatype(); - return datatype; - } - - Result> Rotation3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Rotation3D::arrow_datatype() { + static const auto datatype = rerun::datatypes::Rotation3D::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Rotation3D::new_arrow_array_builder(memory_pool).value); + Result> Rotation3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Rotation3D::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Rotation3D::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Rotation3D) == sizeof(Rotation3D)); - RR_RETURN_NOT_OK(rerun::datatypes::Rotation3D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error Rotation3D::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Rotation3D) == sizeof(Rotation3D)); + RR_RETURN_NOT_OK(rerun::datatypes::Rotation3D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result Rotation3D::to_data_cell( - const Rotation3D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = Rotation3D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Rotation3D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Rotation3D::to_data_cell( + const Rotation3D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - Rotation3D::NAME, - Rotation3D::arrow_datatype(), - std::move(array) + auto builder_result = Rotation3D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Rotation3D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + Rotation3D::NAME, + Rotation3D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/rotation3d.hpp b/rerun_cpp/src/rerun/components/rotation3d.hpp index b26e1c67c529..7801839489f0 100644 --- a/rerun_cpp/src/rerun/components/rotation3d.hpp +++ b/rerun_cpp/src/rerun/components/rotation3d.hpp @@ -16,59 +16,57 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A 3D rotation, represented either by a quaternion or a rotation around axis. - struct Rotation3D { - /// Representation of the rotation. - rerun::datatypes::Rotation3D repr; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'rotation3d_ext.cpp' - - static const Rotation3D IDENTITY; - - /// Construct Rotation3d from Quaternion. - Rotation3D(datatypes::Quaternion quaternion) : repr{quaternion} {} - - /// Construct Rotation3d from axis-angle - Rotation3D(datatypes::RotationAxisAngle axis_angle) : repr{axis_angle} {} - - public: - Rotation3D() = default; - - Rotation3D(rerun::datatypes::Rotation3D repr_) : repr(repr_) {} - - Rotation3D& operator=(rerun::datatypes::Rotation3D repr_) { - repr = repr_; - return *this; - } - - /// Cast to the underlying Rotation3D datatype - operator rerun::datatypes::Rotation3D() const { - return repr; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Rotation3D components. - static Result to_data_cell( - const Rotation3D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A 3D rotation, represented either by a quaternion or a rotation around axis. + struct Rotation3D { + /// Representation of the rotation. + rerun::datatypes::Rotation3D repr; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'rotation3d_ext.cpp' + + static const Rotation3D IDENTITY; + + /// Construct Rotation3d from Quaternion. + Rotation3D(datatypes::Quaternion quaternion) : repr{quaternion} {} + + /// Construct Rotation3d from axis-angle + Rotation3D(datatypes::RotationAxisAngle axis_angle) : repr{axis_angle} {} + + public: + Rotation3D() = default; + + Rotation3D(rerun::datatypes::Rotation3D repr_) : repr(repr_) {} + + Rotation3D& operator=(rerun::datatypes::Rotation3D repr_) { + repr = repr_; + return *this; + } + + /// Cast to the underlying Rotation3D datatype + operator rerun::datatypes::Rotation3D() const { + return repr; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Rotation3D components. + static Result to_data_cell( + const Rotation3D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/scalar.cpp b/rerun_cpp/src/rerun/components/scalar.cpp index 4ea3f35de1e1..e3520e3a6b51 100644 --- a/rerun_cpp/src/rerun/components/scalar.cpp +++ b/rerun_cpp/src/rerun/components/scalar.cpp @@ -6,71 +6,60 @@ #include #include -namespace rerun { - namespace components { - const char Scalar::NAME[] = "rerun.components.Scalar"; +namespace rerun::components { + const char Scalar::NAME[] = "rerun.components.Scalar"; - const std::shared_ptr& Scalar::arrow_datatype() { - static const auto datatype = arrow::float64(); - return datatype; - } - - Result> Scalar::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Scalar::arrow_datatype() { + static const auto datatype = arrow::float64(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> Scalar::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Scalar::fill_arrow_array_builder( - arrow::DoubleBuilder* builder, const Scalar* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - static_assert(sizeof(*elements) == sizeof(elements->value)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->value, static_cast(num_elements)) + rerun::Error Scalar::fill_arrow_array_builder( + arrow::DoubleBuilder* builder, const Scalar* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - Result Scalar::to_data_cell( - const Scalar* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + static_assert(sizeof(*elements) == sizeof(elements->value)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->value, static_cast(num_elements)) + ); + + return Error::ok(); + } - auto builder_result = Scalar::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Scalar::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Scalar::to_data_cell(const Scalar* instances, size_t num_instances) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - Scalar::NAME, - Scalar::arrow_datatype(), - std::move(array) + auto builder_result = Scalar::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Scalar::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create(Scalar::NAME, Scalar::arrow_datatype(), std::move(array)); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/scalar.hpp b/rerun_cpp/src/rerun/components/scalar.hpp index 4207b3bb450c..26d9ca22983e 100644 --- a/rerun_cpp/src/rerun/components/scalar.hpp +++ b/rerun_cpp/src/rerun/components/scalar.hpp @@ -20,44 +20,40 @@ namespace arrow { using DoubleBuilder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A double-precision scalar. - /// - /// Used for time series plots. - struct Scalar { - double value; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - Scalar() = default; - - Scalar(double value_) : value(value_) {} - - Scalar& operator=(double value_) { - value = value_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DoubleBuilder* builder, const Scalar* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Scalar components. - static Result to_data_cell( - const Scalar* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A double-precision scalar. + /// + /// Used for time series plots. + struct Scalar { + double value; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + Scalar() = default; + + Scalar(double value_) : value(value_) {} + + Scalar& operator=(double value_) { + value = value_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DoubleBuilder* builder, const Scalar* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Scalar components. + static Result to_data_cell(const Scalar* instances, size_t num_instances); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/scalar_scattering.cpp b/rerun_cpp/src/rerun/components/scalar_scattering.cpp index 2770bb08c46f..0b0621daae7e 100644 --- a/rerun_cpp/src/rerun/components/scalar_scattering.cpp +++ b/rerun_cpp/src/rerun/components/scalar_scattering.cpp @@ -6,74 +6,67 @@ #include #include -namespace rerun { - namespace components { - const char ScalarScattering::NAME[] = "rerun.components.ScalarScattering"; +namespace rerun::components { + const char ScalarScattering::NAME[] = "rerun.components.ScalarScattering"; - const std::shared_ptr& ScalarScattering::arrow_datatype() { - static const auto datatype = arrow::boolean(); - return datatype; - } - - Result> ScalarScattering::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& ScalarScattering::arrow_datatype() { + static const auto datatype = arrow::boolean(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> ScalarScattering::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error ScalarScattering::fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const ScalarScattering* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - static_assert(sizeof(*elements) == sizeof(elements->scattered)); - ARROW_RETURN_NOT_OK(builder->AppendValues( - reinterpret_cast(&elements->scattered), - static_cast(num_elements) - )); - - return Error::ok(); + rerun::Error ScalarScattering::fill_arrow_array_builder( + arrow::BooleanBuilder* builder, const ScalarScattering* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(*elements) == sizeof(elements->scattered)); + ARROW_RETURN_NOT_OK(builder->AppendValues( + reinterpret_cast(&elements->scattered), + static_cast(num_elements) + )); - Result ScalarScattering::to_data_cell( - const ScalarScattering* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = ScalarScattering::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(ScalarScattering::fill_arrow_array_builder( - builder.get(), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result ScalarScattering::to_data_cell( + const ScalarScattering* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - ScalarScattering::NAME, - ScalarScattering::arrow_datatype(), - std::move(array) + auto builder_result = ScalarScattering::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + ScalarScattering::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + ScalarScattering::NAME, + ScalarScattering::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/scalar_scattering.hpp b/rerun_cpp/src/rerun/components/scalar_scattering.hpp index f460c124ee49..38563b971eed 100644 --- a/rerun_cpp/src/rerun/components/scalar_scattering.hpp +++ b/rerun_cpp/src/rerun/components/scalar_scattering.hpp @@ -15,43 +15,40 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: If true, a scalar will be shown as individual point in a scatter plot. - struct ScalarScattering { - bool scattered; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - ScalarScattering() = default; - - ScalarScattering(bool scattered_) : scattered(scattered_) {} - - ScalarScattering& operator=(bool scattered_) { - scattered = scattered_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::BooleanBuilder* builder, const ScalarScattering* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of ScalarScattering components. - static Result to_data_cell( - const ScalarScattering* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: If true, a scalar will be shown as individual point in a scatter plot. + struct ScalarScattering { + bool scattered; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + ScalarScattering() = default; + + ScalarScattering(bool scattered_) : scattered(scattered_) {} + + ScalarScattering& operator=(bool scattered_) { + scattered = scattered_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::BooleanBuilder* builder, const ScalarScattering* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of ScalarScattering components. + static Result to_data_cell( + const ScalarScattering* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/tensor_data.cpp b/rerun_cpp/src/rerun/components/tensor_data.cpp index b02a9ea552dc..43e238267175 100644 --- a/rerun_cpp/src/rerun/components/tensor_data.cpp +++ b/rerun_cpp/src/rerun/components/tensor_data.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char TensorData::NAME[] = "rerun.components.TensorData"; +namespace rerun::components { + const char TensorData::NAME[] = "rerun.components.TensorData"; - const std::shared_ptr& TensorData::arrow_datatype() { - static const auto datatype = rerun::datatypes::TensorData::arrow_datatype(); - return datatype; - } - - Result> TensorData::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& TensorData::arrow_datatype() { + static const auto datatype = rerun::datatypes::TensorData::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::TensorData::new_arrow_array_builder(memory_pool).value); + Result> TensorData::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error TensorData::fill_arrow_array_builder( - arrow::StructBuilder* builder, const TensorData* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::TensorData::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::TensorData) == sizeof(TensorData)); - RR_RETURN_NOT_OK(rerun::datatypes::TensorData::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error TensorData::fill_arrow_array_builder( + arrow::StructBuilder* builder, const TensorData* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::TensorData) == sizeof(TensorData)); + RR_RETURN_NOT_OK(rerun::datatypes::TensorData::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result TensorData::to_data_cell( - const TensorData* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = TensorData::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - TensorData::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result TensorData::to_data_cell( + const TensorData* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - TensorData::NAME, - TensorData::arrow_datatype(), - std::move(array) + auto builder_result = TensorData::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + TensorData::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + TensorData::NAME, + TensorData::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/tensor_data.hpp b/rerun_cpp/src/rerun/components/tensor_data.hpp index 8613ad1a8e26..9b7138b96ba8 100644 --- a/rerun_cpp/src/rerun/components/tensor_data.hpp +++ b/rerun_cpp/src/rerun/components/tensor_data.hpp @@ -17,57 +17,55 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A multi-dimensional `Tensor` with optionally named arguments. - struct TensorData { - rerun::datatypes::TensorData data; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'tensor_data_ext.cpp' - - /// New Tensor from dimensions and tensor buffer. - TensorData( - std::vector shape, - rerun::datatypes::TensorBuffer buffer - ) - : data(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} - - public: - TensorData() = default; - - TensorData(rerun::datatypes::TensorData data_) : data(std::move(data_)) {} - - TensorData& operator=(rerun::datatypes::TensorData data_) { - data = std::move(data_); - return *this; - } - - /// Cast to the underlying TensorData datatype - operator rerun::datatypes::TensorData() const { - return data; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const TensorData* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of TensorData components. - static Result to_data_cell( - const TensorData* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A multi-dimensional `Tensor` with optionally named arguments. + struct TensorData { + rerun::datatypes::TensorData data; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'tensor_data_ext.cpp' + + /// New Tensor from dimensions and tensor buffer. + TensorData( + std::vector shape, + rerun::datatypes::TensorBuffer buffer + ) + : data(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} + + public: + TensorData() = default; + + TensorData(rerun::datatypes::TensorData data_) : data(std::move(data_)) {} + + TensorData& operator=(rerun::datatypes::TensorData data_) { + data = std::move(data_); + return *this; + } + + /// Cast to the underlying TensorData datatype + operator rerun::datatypes::TensorData() const { + return data; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const TensorData* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of TensorData components. + static Result to_data_cell( + const TensorData* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/text.cpp b/rerun_cpp/src/rerun/components/text.cpp index 0410144f8e16..d6e39912b754 100644 --- a/rerun_cpp/src/rerun/components/text.cpp +++ b/rerun_cpp/src/rerun/components/text.cpp @@ -8,67 +8,61 @@ #include #include -namespace rerun { - namespace components { - const char Text::NAME[] = "rerun.components.Text"; +namespace rerun::components { + const char Text::NAME[] = "rerun.components.Text"; - const std::shared_ptr& Text::arrow_datatype() { - static const auto datatype = rerun::datatypes::Utf8::arrow_datatype(); - return datatype; - } - - Result> Text::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Text::arrow_datatype() { + static const auto datatype = rerun::datatypes::Utf8::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Utf8::new_arrow_array_builder(memory_pool).value); + Result> Text::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Text::fill_arrow_array_builder( - arrow::StringBuilder* builder, const Text* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::Utf8) == sizeof(Text)); - RR_RETURN_NOT_OK(rerun::datatypes::Utf8::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + return Result(rerun::datatypes::Utf8::new_arrow_array_builder(memory_pool).value); + } - return Error::ok(); + rerun::Error Text::fill_arrow_array_builder( + arrow::StringBuilder* builder, const Text* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Utf8) == sizeof(Text)); + RR_RETURN_NOT_OK(rerun::datatypes::Utf8::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result Text::to_data_cell(const Text* instances, size_t num_instances) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = Text::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Text::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Text::to_data_cell(const Text* instances, size_t num_instances) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create(Text::NAME, Text::arrow_datatype(), std::move(array)); + auto builder_result = Text::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK(Text::fill_arrow_array_builder(builder.get(), instances, num_instances) + ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create(Text::NAME, Text::arrow_datatype(), std::move(array)); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/text.hpp b/rerun_cpp/src/rerun/components/text.hpp index d6f996dc63cd..6e160c4b8235 100644 --- a/rerun_cpp/src/rerun/components/text.hpp +++ b/rerun_cpp/src/rerun/components/text.hpp @@ -18,64 +18,60 @@ namespace arrow { class StringBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A string of text, e.g. for labels and text documents. - struct Text { - rerun::datatypes::Utf8 value; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'text_ext.cpp' - - /// Construct `Text` from a null-terminated UTF8 string. - Text(const char* str) : value(str) {} - - const char* c_str() const { - return value.c_str(); - } - - public: - Text() = default; - - Text(rerun::datatypes::Utf8 value_) : value(std::move(value_)) {} - - Text& operator=(rerun::datatypes::Utf8 value_) { - value = std::move(value_); - return *this; - } - - Text(std::string value_) : value(std::move(value_)) {} - - Text& operator=(std::string value_) { - value = std::move(value_); - return *this; - } - - /// Cast to the underlying Utf8 datatype - operator rerun::datatypes::Utf8() const { - return value; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StringBuilder* builder, const Text* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Text components. - static Result to_data_cell( - const Text* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A string of text, e.g. for labels and text documents. + struct Text { + rerun::datatypes::Utf8 value; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'text_ext.cpp' + + /// Construct `Text` from a null-terminated UTF8 string. + Text(const char* str) : value(str) {} + + const char* c_str() const { + return value.c_str(); + } + + public: + Text() = default; + + Text(rerun::datatypes::Utf8 value_) : value(std::move(value_)) {} + + Text& operator=(rerun::datatypes::Utf8 value_) { + value = std::move(value_); + return *this; + } + + Text(std::string value_) : value(std::move(value_)) {} + + Text& operator=(std::string value_) { + value = std::move(value_); + return *this; + } + + /// Cast to the underlying Utf8 datatype + operator rerun::datatypes::Utf8() const { + return value; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StringBuilder* builder, const Text* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Text components. + static Result to_data_cell(const Text* instances, size_t num_instances); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/text_log_level.cpp b/rerun_cpp/src/rerun/components/text_log_level.cpp index f90d91772559..5b675743bf57 100644 --- a/rerun_cpp/src/rerun/components/text_log_level.cpp +++ b/rerun_cpp/src/rerun/components/text_log_level.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char TextLogLevel::NAME[] = "rerun.components.TextLogLevel"; +namespace rerun::components { + const char TextLogLevel::NAME[] = "rerun.components.TextLogLevel"; - const std::shared_ptr& TextLogLevel::arrow_datatype() { - static const auto datatype = rerun::datatypes::Utf8::arrow_datatype(); - return datatype; - } - - Result> TextLogLevel::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& TextLogLevel::arrow_datatype() { + static const auto datatype = rerun::datatypes::Utf8::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Utf8::new_arrow_array_builder(memory_pool).value); + Result> TextLogLevel::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error TextLogLevel::fill_arrow_array_builder( - arrow::StringBuilder* builder, const TextLogLevel* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Utf8::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Utf8) == sizeof(TextLogLevel)); - RR_RETURN_NOT_OK(rerun::datatypes::Utf8::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error TextLogLevel::fill_arrow_array_builder( + arrow::StringBuilder* builder, const TextLogLevel* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Utf8) == sizeof(TextLogLevel)); + RR_RETURN_NOT_OK(rerun::datatypes::Utf8::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result TextLogLevel::to_data_cell( - const TextLogLevel* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = TextLogLevel::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - TextLogLevel::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result TextLogLevel::to_data_cell( + const TextLogLevel* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - TextLogLevel::NAME, - TextLogLevel::arrow_datatype(), - std::move(array) + auto builder_result = TextLogLevel::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + TextLogLevel::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + TextLogLevel::NAME, + TextLogLevel::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/text_log_level.hpp b/rerun_cpp/src/rerun/components/text_log_level.hpp index e5ec74c9818d..a636b4a2fe4a 100644 --- a/rerun_cpp/src/rerun/components/text_log_level.hpp +++ b/rerun_cpp/src/rerun/components/text_log_level.hpp @@ -18,90 +18,88 @@ namespace arrow { class StringBuilder; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: The severity level of a text log message. - /// - /// Recommended to be one of: - /// * `"CRITICAL"` - /// * `"ERROR"` - /// * `"WARN"` - /// * `"INFO"` - /// * `"DEBUG"` - /// * `"TRACE"` - struct TextLogLevel { - rerun::datatypes::Utf8 value; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'text_log_level_ext.cpp' - - /// Designates catastrophic failures. - static const TextLogLevel Critical; - - /// Designates very serious errors. - static const TextLogLevel Error; - - /// Designates hazardous situations. - static const TextLogLevel Warning; - - /// Designates useful information. - static const TextLogLevel Info; - - /// Designates lower priority information. - static const TextLogLevel Debug; - - /// Designates very low priority, often extremely verbose, information. - static const TextLogLevel Trace; - - /// Construct `TextLogLevel` from a null-terminated UTF8 string. - TextLogLevel(const char* str) : value(str) {} - - const char* c_str() const { - return value.c_str(); - } - - public: - TextLogLevel() = default; - - TextLogLevel(rerun::datatypes::Utf8 value_) : value(std::move(value_)) {} - - TextLogLevel& operator=(rerun::datatypes::Utf8 value_) { - value = std::move(value_); - return *this; - } - - TextLogLevel(std::string value_) : value(std::move(value_)) {} - - TextLogLevel& operator=(std::string value_) { - value = std::move(value_); - return *this; - } - - /// Cast to the underlying Utf8 datatype - operator rerun::datatypes::Utf8() const { - return value; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StringBuilder* builder, const TextLogLevel* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of TextLogLevel components. - static Result to_data_cell( - const TextLogLevel* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: The severity level of a text log message. + /// + /// Recommended to be one of: + /// * `"CRITICAL"` + /// * `"ERROR"` + /// * `"WARN"` + /// * `"INFO"` + /// * `"DEBUG"` + /// * `"TRACE"` + struct TextLogLevel { + rerun::datatypes::Utf8 value; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'text_log_level_ext.cpp' + + /// Designates catastrophic failures. + static const TextLogLevel Critical; + + /// Designates very serious errors. + static const TextLogLevel Error; + + /// Designates hazardous situations. + static const TextLogLevel Warning; + + /// Designates useful information. + static const TextLogLevel Info; + + /// Designates lower priority information. + static const TextLogLevel Debug; + + /// Designates very low priority, often extremely verbose, information. + static const TextLogLevel Trace; + + /// Construct `TextLogLevel` from a null-terminated UTF8 string. + TextLogLevel(const char* str) : value(str) {} + + const char* c_str() const { + return value.c_str(); + } + + public: + TextLogLevel() = default; + + TextLogLevel(rerun::datatypes::Utf8 value_) : value(std::move(value_)) {} + + TextLogLevel& operator=(rerun::datatypes::Utf8 value_) { + value = std::move(value_); + return *this; + } + + TextLogLevel(std::string value_) : value(std::move(value_)) {} + + TextLogLevel& operator=(std::string value_) { + value = std::move(value_); + return *this; + } + + /// Cast to the underlying Utf8 datatype + operator rerun::datatypes::Utf8() const { + return value; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StringBuilder* builder, const TextLogLevel* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of TextLogLevel components. + static Result to_data_cell( + const TextLogLevel* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/transform3d.cpp b/rerun_cpp/src/rerun/components/transform3d.cpp index 28d251b47fd6..be3da54190af 100644 --- a/rerun_cpp/src/rerun/components/transform3d.cpp +++ b/rerun_cpp/src/rerun/components/transform3d.cpp @@ -8,74 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char Transform3D::NAME[] = "rerun.components.Transform3D"; +namespace rerun::components { + const char Transform3D::NAME[] = "rerun.components.Transform3D"; - const std::shared_ptr& Transform3D::arrow_datatype() { - static const auto datatype = rerun::datatypes::Transform3D::arrow_datatype(); - return datatype; + const std::shared_ptr& Transform3D::arrow_datatype() { + static const auto datatype = rerun::datatypes::Transform3D::arrow_datatype(); + return datatype; + } + + Result> Transform3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Transform3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::Transform3D::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::Transform3D::new_arrow_array_builder(memory_pool).value + rerun::Error Transform3D::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Transform3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error Transform3D::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Transform3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::Transform3D) == sizeof(Transform3D)); - RR_RETURN_NOT_OK(rerun::datatypes::Transform3D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::Transform3D) == sizeof(Transform3D)); + RR_RETURN_NOT_OK(rerun::datatypes::Transform3D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - 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(); + return Error::ok(); + } - auto builder_result = Transform3D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Transform3D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - Transform3D::NAME, - Transform3D::arrow_datatype(), - std::move(array) + auto builder_result = Transform3D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Transform3D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + Transform3D::NAME, + Transform3D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/transform3d.hpp b/rerun_cpp/src/rerun/components/transform3d.hpp index 7a9141354398..c9dd167cbe2c 100644 --- a/rerun_cpp/src/rerun/components/transform3d.hpp +++ b/rerun_cpp/src/rerun/components/transform3d.hpp @@ -16,48 +16,46 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: An affine transform between two 3D spaces, represented in a given direction. - struct Transform3D { - /// Representation of the transform. - rerun::datatypes::Transform3D repr; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - Transform3D() = default; - - Transform3D(rerun::datatypes::Transform3D repr_) : repr(repr_) {} - - Transform3D& operator=(rerun::datatypes::Transform3D repr_) { - repr = repr_; - return *this; - } - - /// Cast to the underlying Transform3D datatype - operator rerun::datatypes::Transform3D() const { - return repr; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const Transform3D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: An affine transform between two 3D spaces, represented in a given direction. + struct Transform3D { + /// Representation of the transform. + rerun::datatypes::Transform3D repr; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + Transform3D() = default; + + Transform3D(rerun::datatypes::Transform3D repr_) : repr(repr_) {} + + Transform3D& operator=(rerun::datatypes::Transform3D repr_) { + repr = repr_; + return *this; + } + + /// Cast to the underlying Transform3D datatype + operator rerun::datatypes::Transform3D() const { + return repr; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const Transform3D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/vector3d.cpp b/rerun_cpp/src/rerun/components/vector3d.cpp index 8e2284d60ea7..08beb7039f05 100644 --- a/rerun_cpp/src/rerun/components/vector3d.cpp +++ b/rerun_cpp/src/rerun/components/vector3d.cpp @@ -8,73 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char Vector3D::NAME[] = "rerun.components.Vector3D"; +namespace rerun::components { + const char Vector3D::NAME[] = "rerun.components.Vector3D"; - const std::shared_ptr& Vector3D::arrow_datatype() { - static const auto datatype = rerun::datatypes::Vec3D::arrow_datatype(); - return datatype; - } - - Result> Vector3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& Vector3D::arrow_datatype() { + static const auto datatype = rerun::datatypes::Vec3D::arrow_datatype(); + return datatype; + } - return Result(rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value); + Result> Vector3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error Vector3D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Vector3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value); + } - static_assert(sizeof(rerun::datatypes::Vec3D) == sizeof(Vector3D)); - RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); - - return Error::ok(); + rerun::Error Vector3D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Vector3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } + + static_assert(sizeof(rerun::datatypes::Vec3D) == sizeof(Vector3D)); + RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - Result Vector3D::to_data_cell( - const Vector3D* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = Vector3D::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - Vector3D::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result Vector3D::to_data_cell( + const Vector3D* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - Vector3D::NAME, - Vector3D::arrow_datatype(), - std::move(array) + auto builder_result = Vector3D::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + Vector3D::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + Vector3D::NAME, + Vector3D::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/vector3d.hpp b/rerun_cpp/src/rerun/components/vector3d.hpp index e5e8d7514e64..72750b1082f7 100644 --- a/rerun_cpp/src/rerun/components/vector3d.hpp +++ b/rerun_cpp/src/rerun/components/vector3d.hpp @@ -17,75 +17,73 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: A vector in 3D space. - struct Vector3D { - rerun::datatypes::Vec3D vector; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'vector3d_ext.cpp' - - /// Construct Vector3D from x/y/z values. - Vector3D(float x, float y, float z) : vector{x, y, z} {} - - /// Construct Vec3D from x/y/z float pointer. - explicit Vector3D(const float* xyz) : vector{xyz[0], xyz[1], xyz[2]} {} - - float x() const { - return vector.x(); - } - - float y() const { - return vector.y(); - } - - float z() const { - return vector.z(); - } - - public: - Vector3D() = default; - - Vector3D(rerun::datatypes::Vec3D vector_) : vector(vector_) {} - - Vector3D& operator=(rerun::datatypes::Vec3D vector_) { - vector = vector_; - return *this; - } - - Vector3D(std::array xyz_) : vector(xyz_) {} - - Vector3D& operator=(std::array xyz_) { - vector = xyz_; - return *this; - } - - /// Cast to the underlying Vec3D datatype - operator rerun::datatypes::Vec3D() const { - return vector; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Vector3D* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of Vector3D components. - static Result to_data_cell( - const Vector3D* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + /// **Component**: A vector in 3D space. + struct Vector3D { + rerun::datatypes::Vec3D vector; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'vector3d_ext.cpp' + + /// Construct Vector3D from x/y/z values. + Vector3D(float x, float y, float z) : vector{x, y, z} {} + + /// Construct Vec3D from x/y/z float pointer. + explicit Vector3D(const float* xyz) : vector{xyz[0], xyz[1], xyz[2]} {} + + float x() const { + return vector.x(); + } + + float y() const { + return vector.y(); + } + + float z() const { + return vector.z(); + } + + public: + Vector3D() = default; + + Vector3D(rerun::datatypes::Vec3D vector_) : vector(vector_) {} + + Vector3D& operator=(rerun::datatypes::Vec3D vector_) { + vector = vector_; + return *this; + } + + Vector3D(std::array xyz_) : vector(xyz_) {} + + Vector3D& operator=(std::array xyz_) { + vector = xyz_; + return *this; + } + + /// Cast to the underlying Vec3D datatype + operator rerun::datatypes::Vec3D() const { + return vector; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Vector3D* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of Vector3D components. + static Result to_data_cell( + const Vector3D* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/view_coordinates.cpp b/rerun_cpp/src/rerun/components/view_coordinates.cpp index 17511c25509b..68c8af3e76ef 100644 --- a/rerun_cpp/src/rerun/components/view_coordinates.cpp +++ b/rerun_cpp/src/rerun/components/view_coordinates.cpp @@ -6,83 +6,76 @@ #include #include -namespace rerun { - namespace components { - const char ViewCoordinates::NAME[] = "rerun.components.ViewCoordinates"; +namespace rerun::components { + const char ViewCoordinates::NAME[] = "rerun.components.ViewCoordinates"; - const std::shared_ptr& ViewCoordinates::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::uint8(), false), 3); - return datatype; - } - - Result> - ViewCoordinates::new_arrow_array_builder(arrow::MemoryPool* memory_pool) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& ViewCoordinates::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::uint8(), false), 3); + return datatype; + } - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 3 - )); + Result> ViewCoordinates::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error ViewCoordinates::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const ViewCoordinates* elements, - size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 3 + )); + } - auto value_builder = static_cast(builder->value_builder()); + rerun::Error ViewCoordinates::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const ViewCoordinates* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].coordinates) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].coordinates.data(), - static_cast(num_elements * 3), - nullptr - )); + auto value_builder = static_cast(builder->value_builder()); - return Error::ok(); - } + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].coordinates) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].coordinates.data(), + static_cast(num_elements * 3), + nullptr + )); - Result ViewCoordinates::to_data_cell( - const ViewCoordinates* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = ViewCoordinates::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(ViewCoordinates::fill_arrow_array_builder( - builder.get(), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result ViewCoordinates::to_data_cell( + const ViewCoordinates* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - ViewCoordinates::NAME, - ViewCoordinates::arrow_datatype(), - std::move(array) + auto builder_result = ViewCoordinates::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + ViewCoordinates::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + ViewCoordinates::NAME, + ViewCoordinates::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/view_coordinates.hpp b/rerun_cpp/src/rerun/components/view_coordinates.hpp index 2df093e5641f..da1112a2feb5 100644 --- a/rerun_cpp/src/rerun/components/view_coordinates.hpp +++ b/rerun_cpp/src/rerun/components/view_coordinates.hpp @@ -16,143 +16,141 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - /// **Component**: How we interpret the coordinate system of an entity/space. - /// - /// For instance: What is "up"? What does the Z axis mean? Is this right-handed or left-handed? - /// - /// The three coordinates are always ordered as [x, y, z]. - /// - /// For example [Right, Down, Forward] means that the X axis points to the right, the Y axis points - /// down, and the Z axis points forward. - /// - /// The following constants are used to represent the different directions: - /// * Up = 1 - /// * Down = 2 - /// * Right = 3 - /// * Left = 4 - /// * Forward = 5 - /// * Back = 6 - struct ViewCoordinates { - /// The directions of the [x, y, z] axes. - std::array coordinates; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - // Extensions to generated type defined in 'view_coordinates_ext.cpp' - - enum ViewDir : uint8_t { - Up = 1, - Down = 2, - Right = 3, - Left = 4, - Forward = 5, - Back = 6, - }; - - /// Construct Vec3D from x/y/z values. - constexpr ViewCoordinates(uint8_t axis0, uint8_t axis1, uint8_t axis2) - : coordinates{axis0, axis1, axis2} {} - - /// Construct Vec3D from x/y/z values. - constexpr ViewCoordinates(ViewDir axis0, ViewDir axis1, ViewDir axis2) - : coordinates{axis0, axis1, axis2} {} - - // - // This section is generated by running `scripts/generate_view_coordinate_defs.py --cpp` - static const rerun::components::ViewCoordinates ULF; - static const rerun::components::ViewCoordinates UFL; - static const rerun::components::ViewCoordinates LUF; - static const rerun::components::ViewCoordinates LFU; - static const rerun::components::ViewCoordinates FUL; - static const rerun::components::ViewCoordinates FLU; - static const rerun::components::ViewCoordinates ULB; - static const rerun::components::ViewCoordinates UBL; - static const rerun::components::ViewCoordinates LUB; - static const rerun::components::ViewCoordinates LBU; - static const rerun::components::ViewCoordinates BUL; - static const rerun::components::ViewCoordinates BLU; - static const rerun::components::ViewCoordinates URF; - static const rerun::components::ViewCoordinates UFR; - static const rerun::components::ViewCoordinates RUF; - static const rerun::components::ViewCoordinates RFU; - static const rerun::components::ViewCoordinates FUR; - static const rerun::components::ViewCoordinates FRU; - static const rerun::components::ViewCoordinates URB; - static const rerun::components::ViewCoordinates UBR; - static const rerun::components::ViewCoordinates RUB; - static const rerun::components::ViewCoordinates RBU; - static const rerun::components::ViewCoordinates BUR; - static const rerun::components::ViewCoordinates BRU; - static const rerun::components::ViewCoordinates DLF; - static const rerun::components::ViewCoordinates DFL; - static const rerun::components::ViewCoordinates LDF; - static const rerun::components::ViewCoordinates LFD; - static const rerun::components::ViewCoordinates FDL; - static const rerun::components::ViewCoordinates FLD; - static const rerun::components::ViewCoordinates DLB; - static const rerun::components::ViewCoordinates DBL; - static const rerun::components::ViewCoordinates LDB; - static const rerun::components::ViewCoordinates LBD; - static const rerun::components::ViewCoordinates BDL; - static const rerun::components::ViewCoordinates BLD; - static const rerun::components::ViewCoordinates DRF; - static const rerun::components::ViewCoordinates DFR; - static const rerun::components::ViewCoordinates RDF; - static const rerun::components::ViewCoordinates RFD; - static const rerun::components::ViewCoordinates FDR; - static const rerun::components::ViewCoordinates FRD; - static const rerun::components::ViewCoordinates DRB; - static const rerun::components::ViewCoordinates DBR; - static const rerun::components::ViewCoordinates RDB; - static const rerun::components::ViewCoordinates RBD; - static const rerun::components::ViewCoordinates BDR; - static const rerun::components::ViewCoordinates BRD; - static const rerun::components::ViewCoordinates RIGHT_HAND_X_UP; - static const rerun::components::ViewCoordinates RIGHT_HAND_X_DOWN; - static const rerun::components::ViewCoordinates RIGHT_HAND_Y_UP; - static const rerun::components::ViewCoordinates RIGHT_HAND_Y_DOWN; - static const rerun::components::ViewCoordinates RIGHT_HAND_Z_UP; - static const rerun::components::ViewCoordinates RIGHT_HAND_Z_DOWN; - static const rerun::components::ViewCoordinates LEFT_HAND_X_UP; - static const rerun::components::ViewCoordinates LEFT_HAND_X_DOWN; - static const rerun::components::ViewCoordinates LEFT_HAND_Y_UP; - static const rerun::components::ViewCoordinates LEFT_HAND_Y_DOWN; - static const rerun::components::ViewCoordinates LEFT_HAND_Z_UP; - static const rerun::components::ViewCoordinates LEFT_HAND_Z_DOWN; - // - - public: - ViewCoordinates() = default; - - ViewCoordinates(std::array coordinates_) : coordinates(coordinates_) {} - - ViewCoordinates& operator=(std::array coordinates_) { - coordinates = coordinates_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const ViewCoordinates* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of ViewCoordinates components. - static Result to_data_cell( - const ViewCoordinates* instances, size_t num_instances - ); +namespace rerun::components { + /// **Component**: How we interpret the coordinate system of an entity/space. + /// + /// For instance: What is "up"? What does the Z axis mean? Is this right-handed or left-handed? + /// + /// The three coordinates are always ordered as [x, y, z]. + /// + /// For example [Right, Down, Forward] means that the X axis points to the right, the Y axis points + /// down, and the Z axis points forward. + /// + /// The following constants are used to represent the different directions: + /// * Up = 1 + /// * Down = 2 + /// * Right = 3 + /// * Left = 4 + /// * Forward = 5 + /// * Back = 6 + struct ViewCoordinates { + /// The directions of the [x, y, z] axes. + std::array coordinates; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + // Extensions to generated type defined in 'view_coordinates_ext.cpp' + + enum ViewDir : uint8_t { + Up = 1, + Down = 2, + Right = 3, + Left = 4, + Forward = 5, + Back = 6, }; - } // namespace components -} // namespace rerun + + /// Construct Vec3D from x/y/z values. + constexpr ViewCoordinates(uint8_t axis0, uint8_t axis1, uint8_t axis2) + : coordinates{axis0, axis1, axis2} {} + + /// Construct Vec3D from x/y/z values. + constexpr ViewCoordinates(ViewDir axis0, ViewDir axis1, ViewDir axis2) + : coordinates{axis0, axis1, axis2} {} + + // + // This section is generated by running `scripts/generate_view_coordinate_defs.py --cpp` + static const rerun::components::ViewCoordinates ULF; + static const rerun::components::ViewCoordinates UFL; + static const rerun::components::ViewCoordinates LUF; + static const rerun::components::ViewCoordinates LFU; + static const rerun::components::ViewCoordinates FUL; + static const rerun::components::ViewCoordinates FLU; + static const rerun::components::ViewCoordinates ULB; + static const rerun::components::ViewCoordinates UBL; + static const rerun::components::ViewCoordinates LUB; + static const rerun::components::ViewCoordinates LBU; + static const rerun::components::ViewCoordinates BUL; + static const rerun::components::ViewCoordinates BLU; + static const rerun::components::ViewCoordinates URF; + static const rerun::components::ViewCoordinates UFR; + static const rerun::components::ViewCoordinates RUF; + static const rerun::components::ViewCoordinates RFU; + static const rerun::components::ViewCoordinates FUR; + static const rerun::components::ViewCoordinates FRU; + static const rerun::components::ViewCoordinates URB; + static const rerun::components::ViewCoordinates UBR; + static const rerun::components::ViewCoordinates RUB; + static const rerun::components::ViewCoordinates RBU; + static const rerun::components::ViewCoordinates BUR; + static const rerun::components::ViewCoordinates BRU; + static const rerun::components::ViewCoordinates DLF; + static const rerun::components::ViewCoordinates DFL; + static const rerun::components::ViewCoordinates LDF; + static const rerun::components::ViewCoordinates LFD; + static const rerun::components::ViewCoordinates FDL; + static const rerun::components::ViewCoordinates FLD; + static const rerun::components::ViewCoordinates DLB; + static const rerun::components::ViewCoordinates DBL; + static const rerun::components::ViewCoordinates LDB; + static const rerun::components::ViewCoordinates LBD; + static const rerun::components::ViewCoordinates BDL; + static const rerun::components::ViewCoordinates BLD; + static const rerun::components::ViewCoordinates DRF; + static const rerun::components::ViewCoordinates DFR; + static const rerun::components::ViewCoordinates RDF; + static const rerun::components::ViewCoordinates RFD; + static const rerun::components::ViewCoordinates FDR; + static const rerun::components::ViewCoordinates FRD; + static const rerun::components::ViewCoordinates DRB; + static const rerun::components::ViewCoordinates DBR; + static const rerun::components::ViewCoordinates RDB; + static const rerun::components::ViewCoordinates RBD; + static const rerun::components::ViewCoordinates BDR; + static const rerun::components::ViewCoordinates BRD; + static const rerun::components::ViewCoordinates RIGHT_HAND_X_UP; + static const rerun::components::ViewCoordinates RIGHT_HAND_X_DOWN; + static const rerun::components::ViewCoordinates RIGHT_HAND_Y_UP; + static const rerun::components::ViewCoordinates RIGHT_HAND_Y_DOWN; + static const rerun::components::ViewCoordinates RIGHT_HAND_Z_UP; + static const rerun::components::ViewCoordinates RIGHT_HAND_Z_DOWN; + static const rerun::components::ViewCoordinates LEFT_HAND_X_UP; + static const rerun::components::ViewCoordinates LEFT_HAND_X_DOWN; + static const rerun::components::ViewCoordinates LEFT_HAND_Y_UP; + static const rerun::components::ViewCoordinates LEFT_HAND_Y_DOWN; + static const rerun::components::ViewCoordinates LEFT_HAND_Z_UP; + static const rerun::components::ViewCoordinates LEFT_HAND_Z_DOWN; + // + + public: + ViewCoordinates() = default; + + ViewCoordinates(std::array coordinates_) : coordinates(coordinates_) {} + + ViewCoordinates& operator=(std::array coordinates_) { + coordinates = coordinates_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const ViewCoordinates* elements, + size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of ViewCoordinates components. + static Result to_data_cell( + const ViewCoordinates* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/datatypes/angle.cpp b/rerun_cpp/src/rerun/datatypes/angle.cpp index b3cdb881fff4..378d97402588 100644 --- a/rerun_cpp/src/rerun/datatypes/angle.cpp +++ b/rerun_cpp/src/rerun/datatypes/angle.cpp @@ -6,78 +6,73 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Angle::arrow_datatype() { - static const auto datatype = arrow::dense_union({ - arrow::field("_null_markers", arrow::null(), true, nullptr), - arrow::field("Radians", arrow::float32(), false), - arrow::field("Degrees", arrow::float32(), false), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Angle::arrow_datatype() { + static const auto datatype = arrow::dense_union({ + arrow::field("_null_markers", arrow::null(), true, nullptr), + arrow::field("Radians", arrow::float32(), false), + arrow::field("Degrees", arrow::float32(), false), + }); + return datatype; + } + + Result> Angle::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Angle::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + // Children: + std::vector>({ + std::make_shared(memory_pool), + std::make_shared(memory_pool), + std::make_shared(memory_pool), + }), + arrow_datatype() + )); + } - return Result(std::make_shared( - memory_pool, - // Children: - std::vector>({ - std::make_shared(memory_pool), - std::make_shared(memory_pool), - std::make_shared(memory_pool), - }), - arrow_datatype() - )); + rerun::Error Angle::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Angle* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error Angle::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Angle* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& union_instance = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& union_instance = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); - auto variant_index = static_cast(union_instance._tag); - auto variant_builder_untyped = builder->child_builder(variant_index).get(); + auto variant_index = static_cast(union_instance._tag); + auto variant_builder_untyped = builder->child_builder(variant_index).get(); - switch (union_instance._tag) { - case detail::AngleTag::None: { - ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); - } break; - case detail::AngleTag::Radians: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append(union_instance._data.radians)); - } break; - case detail::AngleTag::Degrees: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append(union_instance._data.degrees)); - } break; - } + switch (union_instance._tag) { + case detail::AngleTag::None: { + ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); + } break; + case detail::AngleTag::Radians: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append(union_instance._data.radians)); + } break; + case detail::AngleTag::Degrees: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append(union_instance._data.degrees)); + } break; } - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/angle.hpp b/rerun_cpp/src/rerun/datatypes/angle.hpp index aaeafc218773..c2b14cabf062 100644 --- a/rerun_cpp/src/rerun/datatypes/angle.hpp +++ b/rerun_cpp/src/rerun/datatypes/angle.hpp @@ -17,120 +17,118 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - namespace detail { - /// \private - enum class AngleTag : uint8_t { - /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. - None = 0, - Radians, - Degrees, - }; - - /// \private - union AngleData { - float radians; - - float degrees; - - AngleData() { - std::memset(reinterpret_cast(this), 0, sizeof(AngleData)); - } - - ~AngleData() {} - - void swap(AngleData& other) noexcept { - // This bitwise swap would fail for self-referential types, but we don't have any of those. - char temp[sizeof(AngleData)]; - void* otherbytes = reinterpret_cast(&other); - void* thisbytes = reinterpret_cast(this); - std::memcpy(temp, thisbytes, sizeof(AngleData)); - std::memcpy(thisbytes, otherbytes, sizeof(AngleData)); - std::memcpy(otherbytes, temp, sizeof(AngleData)); - } - }; - } // namespace detail - - /// **Datatype**: Angle in either radians or degrees. - struct Angle { - Angle() : _tag(detail::AngleTag::None) {} - - /// Copy constructor - Angle(const Angle& other) : _tag(other._tag) { - const void* otherbytes = reinterpret_cast(&other._data); - void* thisbytes = reinterpret_cast(&this->_data); - std::memcpy(thisbytes, otherbytes, sizeof(detail::AngleData)); - } - - Angle& operator=(const Angle& other) noexcept { - Angle tmp(other); - this->swap(tmp); - return *this; - } +namespace rerun::datatypes { + namespace detail { + /// \private + enum class AngleTag : uint8_t { + /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. + None = 0, + Radians, + Degrees, + }; - Angle(Angle&& other) noexcept : Angle() { - this->swap(other); - } + /// \private + union AngleData { + float radians; - Angle& operator=(Angle&& other) noexcept { - this->swap(other); - return *this; - } + float degrees; - void swap(Angle& other) noexcept { - std::swap(this->_tag, other._tag); - this->_data.swap(other._data); + AngleData() { + std::memset(reinterpret_cast(this), 0, sizeof(AngleData)); } - static Angle radians(float radians) { - Angle self; - self._tag = detail::AngleTag::Radians; - new (&self._data.radians) float(std::move(radians)); - return self; - } + ~AngleData() {} - static Angle degrees(float degrees) { - Angle self; - self._tag = detail::AngleTag::Degrees; - new (&self._data.degrees) float(std::move(degrees)); - return self; + void swap(AngleData& other) noexcept { + // This bitwise swap would fail for self-referential types, but we don't have any of those. + char temp[sizeof(AngleData)]; + void* otherbytes = reinterpret_cast(&other); + void* thisbytes = reinterpret_cast(this); + std::memcpy(temp, thisbytes, sizeof(AngleData)); + std::memcpy(thisbytes, otherbytes, sizeof(AngleData)); + std::memcpy(otherbytes, temp, sizeof(AngleData)); } - - /// Return a pointer to radians if the union is in that state, otherwise `nullptr`. - const float* get_radians() const { - if (_tag == detail::AngleTag::Radians) { - return &_data.radians; - } else { - return nullptr; - } + }; + } // namespace detail + + /// **Datatype**: Angle in either radians or degrees. + struct Angle { + Angle() : _tag(detail::AngleTag::None) {} + + /// Copy constructor + Angle(const Angle& other) : _tag(other._tag) { + const void* otherbytes = reinterpret_cast(&other._data); + void* thisbytes = reinterpret_cast(&this->_data); + std::memcpy(thisbytes, otherbytes, sizeof(detail::AngleData)); + } + + Angle& operator=(const Angle& other) noexcept { + Angle tmp(other); + this->swap(tmp); + return *this; + } + + Angle(Angle&& other) noexcept : Angle() { + this->swap(other); + } + + Angle& operator=(Angle&& other) noexcept { + this->swap(other); + return *this; + } + + void swap(Angle& other) noexcept { + std::swap(this->_tag, other._tag); + this->_data.swap(other._data); + } + + static Angle radians(float radians) { + Angle self; + self._tag = detail::AngleTag::Radians; + new (&self._data.radians) float(std::move(radians)); + return self; + } + + static Angle degrees(float degrees) { + Angle self; + self._tag = detail::AngleTag::Degrees; + new (&self._data.degrees) float(std::move(degrees)); + return self; + } + + /// Return a pointer to radians if the union is in that state, otherwise `nullptr`. + const float* get_radians() const { + if (_tag == detail::AngleTag::Radians) { + return &_data.radians; + } else { + return nullptr; } - - /// Return a pointer to degrees if the union is in that state, otherwise `nullptr`. - const float* get_degrees() const { - if (_tag == detail::AngleTag::Degrees) { - return &_data.degrees; - } else { - return nullptr; - } + } + + /// Return a pointer to degrees if the union is in that state, otherwise `nullptr`. + const float* get_degrees() const { + if (_tag == detail::AngleTag::Degrees) { + return &_data.degrees; + } else { + return nullptr; } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Angle* elements, size_t num_elements - ); - - private: - detail::AngleTag _tag; - detail::AngleData _data; - }; - } // namespace datatypes -} // namespace rerun + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Angle* elements, size_t num_elements + ); + + private: + detail::AngleTag _tag; + detail::AngleData _data; + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/annotation_info.cpp b/rerun_cpp/src/rerun/datatypes/annotation_info.cpp index 7d99c2f36506..fcafd0e69fb6 100644 --- a/rerun_cpp/src/rerun/datatypes/annotation_info.cpp +++ b/rerun_cpp/src/rerun/datatypes/annotation_info.cpp @@ -9,93 +9,88 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& AnnotationInfo::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("id", arrow::uint16(), false), - arrow::field("label", rerun::datatypes::Utf8::arrow_datatype(), true), - arrow::field("color", rerun::datatypes::Rgba32::arrow_datatype(), true), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& AnnotationInfo::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("id", arrow::uint16(), false), + arrow::field("label", rerun::datatypes::Utf8::arrow_datatype(), true), + arrow::field("color", rerun::datatypes::Rgba32::arrow_datatype(), true), + }); + return datatype; + } + + Result> AnnotationInfo::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AnnotationInfo::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared(memory_pool), + rerun::datatypes::Utf8::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::Rgba32::new_arrow_array_builder(memory_pool).value, + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared(memory_pool), - rerun::datatypes::Utf8::new_arrow_array_builder(memory_pool).value, - rerun::datatypes::Rgba32::new_arrow_array_builder(memory_pool).value, - }) - )); + rerun::Error AnnotationInfo::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AnnotationInfo* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AnnotationInfo::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AnnotationInfo* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].id)); } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].id)); - } - } - { - auto field_builder = static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.label.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::Utf8::fill_arrow_array_builder( - field_builder, - &element.label.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + } + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.label.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::Utf8::fill_arrow_array_builder( + field_builder, + &element.label.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - { - auto field_builder = static_cast(builder->field_builder(2)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.color.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::Rgba32::fill_arrow_array_builder( - field_builder, - &element.color.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + } + { + auto field_builder = static_cast(builder->field_builder(2)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.color.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::Rgba32::fill_arrow_array_builder( + field_builder, + &element.color.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/annotation_info.hpp b/rerun_cpp/src/rerun/datatypes/annotation_info.hpp index a14c1a8996a2..a2364bbbdc2e 100644 --- a/rerun_cpp/src/rerun/datatypes/annotation_info.hpp +++ b/rerun_cpp/src/rerun/datatypes/annotation_info.hpp @@ -17,49 +17,47 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: Annotation info annotating a class id or key-point id. - /// - /// Color and label will be used to annotate entities/keypoints which reference the id. - /// The id refers either to a class or key-point id - struct AnnotationInfo { - /// `ClassId` or `KeypointId` to which this annotation info belongs. - uint16_t id; - - /// The label that will be shown in the UI. - std::optional label; - - /// The color that will be applied to the annotated entity. - std::optional color; - - public: - // Extensions to generated type defined in 'annotation_info_ext.cpp' - - AnnotationInfo( - uint16_t _id, std::optional _label = std::nullopt, - std::optional _color = std::nullopt - ) - : id(_id), label(std::move(_label)), color(_color) {} - - AnnotationInfo(uint16_t _id, datatypes::Rgba32 _color) - : id(_id), label(std::nullopt), color(_color) {} - - public: - AnnotationInfo() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const AnnotationInfo* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: Annotation info annotating a class id or key-point id. + /// + /// Color and label will be used to annotate entities/keypoints which reference the id. + /// The id refers either to a class or key-point id + struct AnnotationInfo { + /// `ClassId` or `KeypointId` to which this annotation info belongs. + uint16_t id; + + /// The label that will be shown in the UI. + std::optional label; + + /// The color that will be applied to the annotated entity. + std::optional color; + + public: + // Extensions to generated type defined in 'annotation_info_ext.cpp' + + AnnotationInfo( + uint16_t _id, std::optional _label = std::nullopt, + std::optional _color = std::nullopt + ) + : id(_id), label(std::move(_label)), color(_color) {} + + AnnotationInfo(uint16_t _id, datatypes::Rgba32 _color) + : id(_id), label(std::nullopt), color(_color) {} + + public: + AnnotationInfo() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const AnnotationInfo* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/class_description.cpp b/rerun_cpp/src/rerun/datatypes/class_description.cpp index 6aa07bede6d1..1d433ca2a2ce 100644 --- a/rerun_cpp/src/rerun/datatypes/class_description.cpp +++ b/rerun_cpp/src/rerun/datatypes/class_description.cpp @@ -9,125 +9,114 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& ClassDescription::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("info", rerun::datatypes::AnnotationInfo::arrow_datatype(), false), - arrow::field( - "keypoint_annotations", - arrow::list(arrow::field( - "item", - rerun::datatypes::AnnotationInfo::arrow_datatype(), - false - )), - false +namespace rerun::datatypes { + const std::shared_ptr& ClassDescription::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("info", rerun::datatypes::AnnotationInfo::arrow_datatype(), false), + arrow::field( + "keypoint_annotations", + arrow::list( + arrow::field("item", rerun::datatypes::AnnotationInfo::arrow_datatype(), false) ), - arrow::field( - "keypoint_connections", - arrow::list(arrow::field( - "item", - rerun::datatypes::KeypointPair::arrow_datatype(), - false - )), - false + false + ), + arrow::field( + "keypoint_connections", + arrow::list( + arrow::field("item", rerun::datatypes::KeypointPair::arrow_datatype(), false) ), - }); - return datatype; + false + ), + }); + return datatype; + } + + Result> ClassDescription::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> ClassDescription::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::AnnotationInfo::new_arrow_array_builder(memory_pool).value, + std::make_shared( + memory_pool, + rerun::datatypes::AnnotationInfo::new_arrow_array_builder(memory_pool).value + ), + std::make_shared( + memory_pool, + rerun::datatypes::KeypointPair::new_arrow_array_builder(memory_pool).value + ), + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::AnnotationInfo::new_arrow_array_builder(memory_pool).value, - std::make_shared( - memory_pool, - rerun::datatypes::AnnotationInfo::new_arrow_array_builder(memory_pool).value - ), - std::make_shared( - memory_pool, - rerun::datatypes::KeypointPair::new_arrow_array_builder(memory_pool).value - ), - }) - )); + rerun::Error ClassDescription::fill_arrow_array_builder( + arrow::StructBuilder* builder, const ClassDescription* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error ClassDescription::fill_arrow_array_builder( - arrow::StructBuilder* builder, const ClassDescription* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::AnnotationInfo::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].info, + 1 + )); } + } + { + auto field_builder = static_cast(builder->field_builder(1)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(field_builder->Append()); + if (element.keypoint_annotations.data()) { RR_RETURN_NOT_OK(rerun::datatypes::AnnotationInfo::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].info, - 1 + value_builder, + element.keypoint_annotations.data(), + element.keypoint_annotations.size() )); } } - { - auto field_builder = static_cast(builder->field_builder(1)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(field_builder->Append()); - if (element.keypoint_annotations.data()) { - RR_RETURN_NOT_OK(rerun::datatypes::AnnotationInfo::fill_arrow_array_builder( - value_builder, - element.keypoint_annotations.data(), - element.keypoint_annotations.size() - )); - } - } - } - { - auto field_builder = static_cast(builder->field_builder(2)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + } + { + auto field_builder = static_cast(builder->field_builder(2)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(field_builder->Append()); - if (element.keypoint_connections.data()) { - RR_RETURN_NOT_OK(rerun::datatypes::KeypointPair::fill_arrow_array_builder( - value_builder, - element.keypoint_connections.data(), - element.keypoint_connections.size() - )); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(field_builder->Append()); + if (element.keypoint_connections.data()) { + RR_RETURN_NOT_OK(rerun::datatypes::KeypointPair::fill_arrow_array_builder( + value_builder, + element.keypoint_connections.data(), + element.keypoint_connections.size() + )); } } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/class_description.hpp b/rerun_cpp/src/rerun/datatypes/class_description.hpp index 3436161f7152..84fc643b12fc 100644 --- a/rerun_cpp/src/rerun/datatypes/class_description.hpp +++ b/rerun_cpp/src/rerun/datatypes/class_description.hpp @@ -17,58 +17,56 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: The description of a semantic Class. - /// - /// If an entity is annotated with a corresponding `ClassId`, rerun will use - /// the attached `AnnotationInfo` to derive labels and colors. - /// - /// Keypoints within an annotation class can similarly be annotated with a - /// `KeypointId` in which case we should defer to the label and color for the - /// `AnnotationInfo` specifically associated with the Keypoint. - /// - /// Keypoints within the class can also be decorated with skeletal edges. - /// Keypoint-connections are pairs of `KeypointId`s. If an edge is - /// defined, and both keypoints exist within the instance of the class, then the - /// keypoints should be connected with an edge. The edge should be labeled and - /// colored as described by the class's `AnnotationInfo`. - struct ClassDescription { - /// The `AnnotationInfo` for the class. - rerun::datatypes::AnnotationInfo info; +namespace rerun::datatypes { + /// **Datatype**: The description of a semantic Class. + /// + /// If an entity is annotated with a corresponding `ClassId`, rerun will use + /// the attached `AnnotationInfo` to derive labels and colors. + /// + /// Keypoints within an annotation class can similarly be annotated with a + /// `KeypointId` in which case we should defer to the label and color for the + /// `AnnotationInfo` specifically associated with the Keypoint. + /// + /// Keypoints within the class can also be decorated with skeletal edges. + /// Keypoint-connections are pairs of `KeypointId`s. If an edge is + /// defined, and both keypoints exist within the instance of the class, then the + /// keypoints should be connected with an edge. The edge should be labeled and + /// colored as described by the class's `AnnotationInfo`. + struct ClassDescription { + /// The `AnnotationInfo` for the class. + rerun::datatypes::AnnotationInfo info; - /// The `AnnotationInfo` for all of the keypoints. - std::vector keypoint_annotations; + /// The `AnnotationInfo` for all of the keypoints. + std::vector keypoint_annotations; - /// The connections between keypoints. - std::vector keypoint_connections; + /// The connections between keypoints. + std::vector keypoint_connections; - public: - // Extensions to generated type defined in 'class_description_ext.cpp' + public: + // Extensions to generated type defined in 'class_description_ext.cpp' - ClassDescription( - AnnotationInfo _info, std::vector _keypoint_annotations = {}, - std::vector _keypoint_connections = {} - ) - : info(std::move(_info)), - keypoint_annotations(std::move(_keypoint_annotations)), - keypoint_connections(std::move(_keypoint_connections)) {} + ClassDescription( + AnnotationInfo _info, std::vector _keypoint_annotations = {}, + std::vector _keypoint_connections = {} + ) + : info(std::move(_info)), + keypoint_annotations(std::move(_keypoint_annotations)), + keypoint_connections(std::move(_keypoint_connections)) {} - public: - ClassDescription() = default; + public: + ClassDescription() = default; - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const ClassDescription* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const ClassDescription* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/class_description_map_elem.cpp b/rerun_cpp/src/rerun/datatypes/class_description_map_elem.cpp index 34aa4425ba20..32a10b6bbf01 100644 --- a/rerun_cpp/src/rerun/datatypes/class_description_map_elem.cpp +++ b/rerun_cpp/src/rerun/datatypes/class_description_map_elem.cpp @@ -9,78 +9,73 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& ClassDescriptionMapElem::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("class_id", rerun::datatypes::ClassId::arrow_datatype(), false), - arrow::field( - "class_description", - rerun::datatypes::ClassDescription::arrow_datatype(), - false - ), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& ClassDescriptionMapElem::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("class_id", rerun::datatypes::ClassId::arrow_datatype(), false), + arrow::field( + "class_description", + rerun::datatypes::ClassDescription::arrow_datatype(), + false + ), + }); + return datatype; + } + + Result> ClassDescriptionMapElem::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> - ClassDescriptionMapElem::new_arrow_array_builder(arrow::MemoryPool* memory_pool) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::ClassId::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::ClassDescription::new_arrow_array_builder(memory_pool).value, + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::ClassId::new_arrow_array_builder(memory_pool).value, - rerun::datatypes::ClassDescription::new_arrow_array_builder(memory_pool).value, - }) - )); + rerun::Error ClassDescriptionMapElem::fill_arrow_array_builder( + arrow::StructBuilder* builder, const ClassDescriptionMapElem* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error ClassDescriptionMapElem::fill_arrow_array_builder( - arrow::StructBuilder* builder, const ClassDescriptionMapElem* elements, - size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::ClassId::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].class_id, - 1 - )); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::ClassId::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].class_id, + 1 + )); } - { - auto field_builder = static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::ClassDescription::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].class_description, - 1 - )); - } + } + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::ClassDescription::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].class_description, + 1 + )); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/class_description_map_elem.hpp b/rerun_cpp/src/rerun/datatypes/class_description_map_elem.hpp index 130bdae6d6cf..bc742875cc2f 100644 --- a/rerun_cpp/src/rerun/datatypes/class_description_map_elem.hpp +++ b/rerun_cpp/src/rerun/datatypes/class_description_map_elem.hpp @@ -16,41 +16,39 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A helper type for mapping class IDs to class descriptions. - /// - /// This is internal to the `AnnotationContext` structure. - struct ClassDescriptionMapElem { - /// The key: the class ID. - rerun::datatypes::ClassId class_id; - - /// The value: class name, color, etc. - rerun::datatypes::ClassDescription class_description; - - public: - // Extensions to generated type defined in 'class_description_map_elem_ext.cpp' - - ClassDescriptionMapElem(ClassDescription _class_description) - : class_id(_class_description.info.id), - class_description(std::move(_class_description)) {} - - public: - ClassDescriptionMapElem() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const ClassDescriptionMapElem* elements, - size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A helper type for mapping class IDs to class descriptions. + /// + /// This is internal to the `AnnotationContext` structure. + struct ClassDescriptionMapElem { + /// The key: the class ID. + rerun::datatypes::ClassId class_id; + + /// The value: class name, color, etc. + rerun::datatypes::ClassDescription class_description; + + public: + // Extensions to generated type defined in 'class_description_map_elem_ext.cpp' + + ClassDescriptionMapElem(ClassDescription _class_description) + : class_id(_class_description.info.id), + class_description(std::move(_class_description)) {} + + public: + ClassDescriptionMapElem() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const ClassDescriptionMapElem* elements, + size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/class_id.cpp b/rerun_cpp/src/rerun/datatypes/class_id.cpp index 54198a5e01a6..93e831586ca0 100644 --- a/rerun_cpp/src/rerun/datatypes/class_id.cpp +++ b/rerun_cpp/src/rerun/datatypes/class_id.cpp @@ -6,45 +6,39 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& ClassId::arrow_datatype() { - static const auto datatype = arrow::uint16(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& ClassId::arrow_datatype() { + static const auto datatype = arrow::uint16(); + return datatype; + } + + Result> ClassId::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> ClassId::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error ClassId::fill_arrow_array_builder( + arrow::UInt16Builder* builder, const ClassId* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error ClassId::fill_arrow_array_builder( - arrow::UInt16Builder* builder, const ClassId* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(*elements) == sizeof(elements->id)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->id, static_cast(num_elements)) + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + static_assert(sizeof(*elements) == sizeof(elements->id)); + ARROW_RETURN_NOT_OK(builder->AppendValues(&elements->id, static_cast(num_elements)) + ); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/class_id.hpp b/rerun_cpp/src/rerun/datatypes/class_id.hpp index d6ed48840071..edc02437a1f8 100644 --- a/rerun_cpp/src/rerun/datatypes/class_id.hpp +++ b/rerun_cpp/src/rerun/datatypes/class_id.hpp @@ -19,34 +19,32 @@ namespace arrow { using UInt16Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A 16-bit ID representing a type of semantic class. - struct ClassId { - uint16_t id; - - public: - ClassId() = default; - - ClassId(uint16_t id_) : id(id_) {} - - ClassId& operator=(uint16_t id_) { - id = id_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::UInt16Builder* builder, const ClassId* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A 16-bit ID representing a type of semantic class. + struct ClassId { + uint16_t id; + + public: + ClassId() = default; + + ClassId(uint16_t id_) : id(id_) {} + + ClassId& operator=(uint16_t id_) { + id = id_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::UInt16Builder* builder, const ClassId* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/float32.cpp b/rerun_cpp/src/rerun/datatypes/float32.cpp index d8c169685311..8e1d605fd729 100644 --- a/rerun_cpp/src/rerun/datatypes/float32.cpp +++ b/rerun_cpp/src/rerun/datatypes/float32.cpp @@ -6,45 +6,40 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Float32::arrow_datatype() { - static const auto datatype = arrow::float32(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Float32::arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; + } + + Result> Float32::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Float32::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error Float32::fill_arrow_array_builder( + arrow::FloatBuilder* builder, const Float32* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error Float32::fill_arrow_array_builder( - arrow::FloatBuilder* builder, const Float32* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(*elements) == sizeof(elements->value)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->value, static_cast(num_elements)) + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + static_assert(sizeof(*elements) == sizeof(elements->value)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->value, static_cast(num_elements)) + ); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/float32.hpp b/rerun_cpp/src/rerun/datatypes/float32.hpp index 9ad9fd2aae8e..6b8f67d9dbe5 100644 --- a/rerun_cpp/src/rerun/datatypes/float32.hpp +++ b/rerun_cpp/src/rerun/datatypes/float32.hpp @@ -19,34 +19,32 @@ namespace arrow { using FloatBuilder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A single-precision 32-bit IEEE 754 floating point number. - struct Float32 { - float value; - - public: - Float32() = default; - - Float32(float value_) : value(value_) {} - - Float32& operator=(float value_) { - value = value_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FloatBuilder* builder, const Float32* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A single-precision 32-bit IEEE 754 floating point number. + struct Float32 { + float value; + + public: + Float32() = default; + + Float32(float value_) : value(value_) {} + + Float32& operator=(float value_) { + value = value_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FloatBuilder* builder, const Float32* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/keypoint_id.cpp b/rerun_cpp/src/rerun/datatypes/keypoint_id.cpp index 5025d20d02be..789f7819535e 100644 --- a/rerun_cpp/src/rerun/datatypes/keypoint_id.cpp +++ b/rerun_cpp/src/rerun/datatypes/keypoint_id.cpp @@ -6,45 +6,39 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& KeypointId::arrow_datatype() { - static const auto datatype = arrow::uint16(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& KeypointId::arrow_datatype() { + static const auto datatype = arrow::uint16(); + return datatype; + } + + Result> KeypointId::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> KeypointId::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error KeypointId::fill_arrow_array_builder( + arrow::UInt16Builder* builder, const KeypointId* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error KeypointId::fill_arrow_array_builder( - arrow::UInt16Builder* builder, const KeypointId* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(*elements) == sizeof(elements->id)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->id, static_cast(num_elements)) + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + static_assert(sizeof(*elements) == sizeof(elements->id)); + ARROW_RETURN_NOT_OK(builder->AppendValues(&elements->id, static_cast(num_elements)) + ); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/keypoint_id.hpp b/rerun_cpp/src/rerun/datatypes/keypoint_id.hpp index b3a8b28ebce7..a013cfbcdfc7 100644 --- a/rerun_cpp/src/rerun/datatypes/keypoint_id.hpp +++ b/rerun_cpp/src/rerun/datatypes/keypoint_id.hpp @@ -19,34 +19,32 @@ namespace arrow { using UInt16Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A 16-bit ID representing a type of semantic keypoint within a class. - struct KeypointId { - uint16_t id; - - public: - KeypointId() = default; - - KeypointId(uint16_t id_) : id(id_) {} - - KeypointId& operator=(uint16_t id_) { - id = id_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::UInt16Builder* builder, const KeypointId* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A 16-bit ID representing a type of semantic keypoint within a class. + struct KeypointId { + uint16_t id; + + public: + KeypointId() = default; + + KeypointId(uint16_t id_) : id(id_) {} + + KeypointId& operator=(uint16_t id_) { + id = id_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::UInt16Builder* builder, const KeypointId* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/keypoint_pair.cpp b/rerun_cpp/src/rerun/datatypes/keypoint_pair.cpp index 8a280810f095..bd79a9a6445c 100644 --- a/rerun_cpp/src/rerun/datatypes/keypoint_pair.cpp +++ b/rerun_cpp/src/rerun/datatypes/keypoint_pair.cpp @@ -8,74 +8,69 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& KeypointPair::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("keypoint0", rerun::datatypes::KeypointId::arrow_datatype(), false), - arrow::field("keypoint1", rerun::datatypes::KeypointId::arrow_datatype(), false), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& KeypointPair::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("keypoint0", rerun::datatypes::KeypointId::arrow_datatype(), false), + arrow::field("keypoint1", rerun::datatypes::KeypointId::arrow_datatype(), false), + }); + return datatype; + } + + Result> KeypointPair::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> KeypointPair::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::KeypointId::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::KeypointId::new_arrow_array_builder(memory_pool).value, + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::KeypointId::new_arrow_array_builder(memory_pool).value, - rerun::datatypes::KeypointId::new_arrow_array_builder(memory_pool).value, - }) - )); + rerun::Error KeypointPair::fill_arrow_array_builder( + arrow::StructBuilder* builder, const KeypointPair* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error KeypointPair::fill_arrow_array_builder( - arrow::StructBuilder* builder, const KeypointPair* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::KeypointId::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].keypoint0, - 1 - )); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::KeypointId::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].keypoint0, + 1 + )); } - { - auto field_builder = static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::KeypointId::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].keypoint1, - 1 - )); - } + } + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::KeypointId::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].keypoint1, + 1 + )); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/keypoint_pair.hpp b/rerun_cpp/src/rerun/datatypes/keypoint_pair.hpp index 48ccf758ef5b..e9572cb17049 100644 --- a/rerun_cpp/src/rerun/datatypes/keypoint_pair.hpp +++ b/rerun_cpp/src/rerun/datatypes/keypoint_pair.hpp @@ -15,40 +15,38 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A connection between two `Keypoints`. - struct KeypointPair { - /// The first point of the pair. - rerun::datatypes::KeypointId keypoint0; - - /// The second point of the pair. - rerun::datatypes::KeypointId keypoint1; - - public: - // Extensions to generated type defined in 'keypoint_pair_ext.cpp' - - KeypointPair(uint16_t _keypoint0, uint16_t _keypoint1) - : keypoint0(_keypoint0), keypoint1(_keypoint1) {} - - KeypointPair(std::pair pair) - : keypoint0(pair.first), keypoint1(pair.second) {} - - public: - KeypointPair() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const KeypointPair* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A connection between two `Keypoints`. + struct KeypointPair { + /// The first point of the pair. + rerun::datatypes::KeypointId keypoint0; + + /// The second point of the pair. + rerun::datatypes::KeypointId keypoint1; + + public: + // Extensions to generated type defined in 'keypoint_pair_ext.cpp' + + KeypointPair(uint16_t _keypoint0, uint16_t _keypoint1) + : keypoint0(_keypoint0), keypoint1(_keypoint1) {} + + KeypointPair(std::pair pair) + : keypoint0(pair.first), keypoint1(pair.second) {} + + public: + KeypointPair() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const KeypointPair* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/mat3x3.cpp b/rerun_cpp/src/rerun/datatypes/mat3x3.cpp index 9394c2b90e41..e6162a208e08 100644 --- a/rerun_cpp/src/rerun/datatypes/mat3x3.cpp +++ b/rerun_cpp/src/rerun/datatypes/mat3x3.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Mat3x3::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 9); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Mat3x3::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 9); + return datatype; + } + + Result> Mat3x3::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Mat3x3::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 9 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 9 + )); + } + + rerun::Error Mat3x3::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Mat3x3* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error Mat3x3::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Mat3x3* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].flat_columns) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].flat_columns.data(), - static_cast(num_elements * 9), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].flat_columns) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].flat_columns.data(), + static_cast(num_elements * 9), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/mat3x3.hpp b/rerun_cpp/src/rerun/datatypes/mat3x3.hpp index 8868a01f2f1f..7053656ef7b6 100644 --- a/rerun_cpp/src/rerun/datatypes/mat3x3.hpp +++ b/rerun_cpp/src/rerun/datatypes/mat3x3.hpp @@ -16,77 +16,75 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A 3x3 Matrix. - /// - /// Matrices in Rerun are stored as flat list of coefficients in column-major order: - /// ```text - /// column 0 column 1 column 2 - /// ------------------------------------------------- - /// row 0 | flat_columns[0] flat_columns[3] flat_columns[6] - /// row 1 | flat_columns[1] flat_columns[4] flat_columns[7] - /// row 2 | flat_columns[2] flat_columns[5] flat_columns[8] - /// ``` - struct Mat3x3 { - /// Flat list of matrix coefficients in column-major order. - std::array flat_columns; +namespace rerun::datatypes { + /// **Datatype**: A 3x3 Matrix. + /// + /// Matrices in Rerun are stored as flat list of coefficients in column-major order: + /// ```text + /// column 0 column 1 column 2 + /// ------------------------------------------------- + /// row 0 | flat_columns[0] flat_columns[3] flat_columns[6] + /// row 1 | flat_columns[1] flat_columns[4] flat_columns[7] + /// row 2 | flat_columns[2] flat_columns[5] flat_columns[8] + /// ``` + struct Mat3x3 { + /// Flat list of matrix coefficients in column-major order. + std::array flat_columns; - public: - // Extensions to generated type defined in 'mat3x3_ext.cpp' + public: + // Extensions to generated type defined in 'mat3x3_ext.cpp' - static const Mat3x3 IDENTITY; + static const Mat3x3 IDENTITY; - /// Creates a new 3x3 matrix from 3 *columns* of 3 elements each. - Mat3x3(const Vec3D (&columns)[3]) - : flat_columns{ - columns[0].x(), - columns[0].y(), - columns[0].z(), - columns[1].x(), - columns[1].y(), - columns[1].z(), - columns[2].x(), - columns[2].y(), - columns[2].z(), - } {} + /// Creates a new 3x3 matrix from 3 *columns* of 3 elements each. + Mat3x3(const Vec3D (&columns)[3]) + : flat_columns{ + columns[0].x(), + columns[0].y(), + columns[0].z(), + columns[1].x(), + columns[1].y(), + columns[1].z(), + columns[2].x(), + columns[2].y(), + columns[2].z(), + } {} - /// Construct a new 3x3 matrix from a pointer to 9 floats (in row major order). - explicit Mat3x3(const float* elements) - : flat_columns{ - elements[0], - elements[1], - elements[2], - elements[3], - elements[4], - elements[5], - elements[6], - elements[7], - elements[8], - } {} + /// Construct a new 3x3 matrix from a pointer to 9 floats (in row major order). + explicit Mat3x3(const float* elements) + : flat_columns{ + elements[0], + elements[1], + elements[2], + elements[3], + elements[4], + elements[5], + elements[6], + elements[7], + elements[8], + } {} - public: - Mat3x3() = default; + public: + Mat3x3() = default; - Mat3x3(std::array flat_columns_) : flat_columns(flat_columns_) {} + Mat3x3(std::array flat_columns_) : flat_columns(flat_columns_) {} - Mat3x3& operator=(std::array flat_columns_) { - flat_columns = flat_columns_; - return *this; - } + Mat3x3& operator=(std::array flat_columns_) { + flat_columns = flat_columns_; + return *this; + } - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Mat3x3* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Mat3x3* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/mat4x4.cpp b/rerun_cpp/src/rerun/datatypes/mat4x4.cpp index b69b5ece5098..3ecbf1273379 100644 --- a/rerun_cpp/src/rerun/datatypes/mat4x4.cpp +++ b/rerun_cpp/src/rerun/datatypes/mat4x4.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Mat4x4::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 16); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Mat4x4::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 16); + return datatype; + } + + Result> Mat4x4::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Mat4x4::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 16 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 16 + )); + } + + rerun::Error Mat4x4::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Mat4x4* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error Mat4x4::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Mat4x4* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].flat_columns) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].flat_columns.data(), - static_cast(num_elements * 16), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].flat_columns) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].flat_columns.data(), + static_cast(num_elements * 16), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/mat4x4.hpp b/rerun_cpp/src/rerun/datatypes/mat4x4.hpp index 9eb2ed37c475..e969e3616543 100644 --- a/rerun_cpp/src/rerun/datatypes/mat4x4.hpp +++ b/rerun_cpp/src/rerun/datatypes/mat4x4.hpp @@ -16,92 +16,90 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A 4x4 Matrix. - /// - /// Matrices in Rerun are stored as flat list of coefficients in column-major order: - /// ```text - /// column 0 column 1 column 2 column 3 - /// -------------------------------------------------------------------- - /// row 0 | flat_columns[0] flat_columns[4] flat_columns[8] flat_columns[12] - /// row 1 | flat_columns[1] flat_columns[5] flat_columns[9] flat_columns[13] - /// row 2 | flat_columns[2] flat_columns[6] flat_columns[10] flat_columns[14] - /// row 3 | flat_columns[3] flat_columns[7] flat_columns[11] flat_columns[15] - /// ``` - struct Mat4x4 { - /// Flat list of matrix coefficients in column-major order. - std::array flat_columns; +namespace rerun::datatypes { + /// **Datatype**: A 4x4 Matrix. + /// + /// Matrices in Rerun are stored as flat list of coefficients in column-major order: + /// ```text + /// column 0 column 1 column 2 column 3 + /// -------------------------------------------------------------------- + /// row 0 | flat_columns[0] flat_columns[4] flat_columns[8] flat_columns[12] + /// row 1 | flat_columns[1] flat_columns[5] flat_columns[9] flat_columns[13] + /// row 2 | flat_columns[2] flat_columns[6] flat_columns[10] flat_columns[14] + /// row 3 | flat_columns[3] flat_columns[7] flat_columns[11] flat_columns[15] + /// ``` + struct Mat4x4 { + /// Flat list of matrix coefficients in column-major order. + std::array flat_columns; - public: - // Extensions to generated type defined in 'mat4x4_ext.cpp' + public: + // Extensions to generated type defined in 'mat4x4_ext.cpp' - static const Mat4x4 IDENTITY; + static const Mat4x4 IDENTITY; - /// Creates a new 4x4 matrix from 3 *columns* of 4 elements each. - Mat4x4(const Vec4D (&columns)[4]) - : flat_columns{ - columns[0].x(), - columns[0].y(), - columns[0].z(), - columns[0].w(), - columns[1].x(), - columns[1].y(), - columns[1].z(), - columns[1].w(), - columns[2].x(), - columns[2].y(), - columns[2].z(), - columns[2].w(), - columns[3].x(), - columns[3].y(), - columns[3].z(), - columns[3].w(), - } {} + /// Creates a new 4x4 matrix from 3 *columns* of 4 elements each. + Mat4x4(const Vec4D (&columns)[4]) + : flat_columns{ + columns[0].x(), + columns[0].y(), + columns[0].z(), + columns[0].w(), + columns[1].x(), + columns[1].y(), + columns[1].z(), + columns[1].w(), + columns[2].x(), + columns[2].y(), + columns[2].z(), + columns[2].w(), + columns[3].x(), + columns[3].y(), + columns[3].z(), + columns[3].w(), + } {} - /// Construct a new 4x4 matrix from a pointer to 16 floats (in row major order). - explicit Mat4x4(const float* elements) - : flat_columns{ - elements[0], - elements[1], - elements[2], - elements[3], - elements[4], - elements[5], - elements[6], - elements[7], - elements[8], - elements[9], - elements[10], - elements[11], - elements[12], - elements[13], - elements[14], - elements[15], - } {} + /// Construct a new 4x4 matrix from a pointer to 16 floats (in row major order). + explicit Mat4x4(const float* elements) + : flat_columns{ + elements[0], + elements[1], + elements[2], + elements[3], + elements[4], + elements[5], + elements[6], + elements[7], + elements[8], + elements[9], + elements[10], + elements[11], + elements[12], + elements[13], + elements[14], + elements[15], + } {} - public: - Mat4x4() = default; + public: + Mat4x4() = default; - Mat4x4(std::array flat_columns_) : flat_columns(flat_columns_) {} + Mat4x4(std::array flat_columns_) : flat_columns(flat_columns_) {} - Mat4x4& operator=(std::array flat_columns_) { - flat_columns = flat_columns_; - return *this; - } + Mat4x4& operator=(std::array flat_columns_) { + flat_columns = flat_columns_; + return *this; + } - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Mat4x4* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Mat4x4* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/material.cpp b/rerun_cpp/src/rerun/datatypes/material.cpp index 525fd6a365d1..9336cd5fedce 100644 --- a/rerun_cpp/src/rerun/datatypes/material.cpp +++ b/rerun_cpp/src/rerun/datatypes/material.cpp @@ -8,66 +8,61 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Material::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("albedo_factor", rerun::datatypes::Rgba32::arrow_datatype(), true), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Material::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("albedo_factor", rerun::datatypes::Rgba32::arrow_datatype(), true), + }); + return datatype; + } + + Result> Material::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Material::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::Rgba32::new_arrow_array_builder(memory_pool).value, + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::Rgba32::new_arrow_array_builder(memory_pool).value, - }) - )); + rerun::Error Material::fill_arrow_array_builder( + arrow::StructBuilder* builder, const Material* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error Material::fill_arrow_array_builder( - arrow::StructBuilder* builder, const Material* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.albedo_factor.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::Rgba32::fill_arrow_array_builder( - field_builder, - &element.albedo_factor.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.albedo_factor.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::Rgba32::fill_arrow_array_builder( + field_builder, + &element.albedo_factor.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/material.hpp b/rerun_cpp/src/rerun/datatypes/material.hpp index 030696fe9352..d38700aa87a3 100644 --- a/rerun_cpp/src/rerun/datatypes/material.hpp +++ b/rerun_cpp/src/rerun/datatypes/material.hpp @@ -16,43 +16,41 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: Material properties of a mesh. - struct Material { - /// Optional color multiplier. - std::optional albedo_factor; - - public: - Material() = default; - - Material(std::optional albedo_factor_) - : albedo_factor(albedo_factor_) {} - - Material& operator=(std::optional albedo_factor_) { - albedo_factor = albedo_factor_; - return *this; - } - - Material(uint32_t rgba_) : albedo_factor(rgba_) {} - - Material& operator=(uint32_t rgba_) { - albedo_factor = rgba_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const Material* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: Material properties of a mesh. + struct Material { + /// Optional color multiplier. + std::optional albedo_factor; + + public: + Material() = default; + + Material(std::optional albedo_factor_) + : albedo_factor(albedo_factor_) {} + + Material& operator=(std::optional albedo_factor_) { + albedo_factor = albedo_factor_; + return *this; + } + + Material(uint32_t rgba_) : albedo_factor(rgba_) {} + + Material& operator=(uint32_t rgba_) { + albedo_factor = rgba_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const Material* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/mesh_properties.cpp b/rerun_cpp/src/rerun/datatypes/mesh_properties.cpp index 424167c44141..292db67de902 100644 --- a/rerun_cpp/src/rerun/datatypes/mesh_properties.cpp +++ b/rerun_cpp/src/rerun/datatypes/mesh_properties.cpp @@ -6,78 +6,72 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& MeshProperties::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field( - "indices", - arrow::list(arrow::field("item", arrow::uint32(), false)), - true - ), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& MeshProperties::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field( + "indices", + arrow::list(arrow::field("item", arrow::uint32(), false)), + true + ), + }); + return datatype; + } + + Result> MeshProperties::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> MeshProperties::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared( + memory_pool, + std::make_shared(memory_pool) + ), + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - }) - )); + rerun::Error MeshProperties::fill_arrow_array_builder( + arrow::StructBuilder* builder, const MeshProperties* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error MeshProperties::fill_arrow_array_builder( - arrow::StructBuilder* builder, const MeshProperties* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); + { + auto field_builder = static_cast(builder->field_builder(0)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.indices.has_value()) { - ARROW_RETURN_NOT_OK(field_builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - element.indices.value().data(), - static_cast(element.indices.value().size()), - nullptr - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.indices.has_value()) { + ARROW_RETURN_NOT_OK(field_builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + element.indices.value().data(), + static_cast(element.indices.value().size()), + nullptr + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/mesh_properties.hpp b/rerun_cpp/src/rerun/datatypes/mesh_properties.hpp index ee97f17c77a1..b37a84bf2d90 100644 --- a/rerun_cpp/src/rerun/datatypes/mesh_properties.hpp +++ b/rerun_cpp/src/rerun/datatypes/mesh_properties.hpp @@ -17,38 +17,36 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: Optional triangle indices for a mesh. - struct MeshProperties { - /// A flattened array of vertex indices that describe the mesh's triangles. - /// - /// Its length must be divisible by 3. - std::optional> indices; - - public: - MeshProperties() = default; - - MeshProperties(std::optional> indices_) - : indices(std::move(indices_)) {} - - MeshProperties& operator=(std::optional> indices_) { - indices = std::move(indices_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const MeshProperties* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: Optional triangle indices for a mesh. + struct MeshProperties { + /// A flattened array of vertex indices that describe the mesh's triangles. + /// + /// Its length must be divisible by 3. + std::optional> indices; + + public: + MeshProperties() = default; + + MeshProperties(std::optional> indices_) + : indices(std::move(indices_)) {} + + MeshProperties& operator=(std::optional> indices_) { + indices = std::move(indices_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const MeshProperties* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/quaternion.cpp b/rerun_cpp/src/rerun/datatypes/quaternion.cpp index d75a97eda950..51f334de667a 100644 --- a/rerun_cpp/src/rerun/datatypes/quaternion.cpp +++ b/rerun_cpp/src/rerun/datatypes/quaternion.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Quaternion::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 4); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Quaternion::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 4); + return datatype; + } + + Result> Quaternion::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Quaternion::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 4 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 4 + )); + } + + rerun::Error Quaternion::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Quaternion* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error Quaternion::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Quaternion* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].xyzw) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].xyzw.data(), - static_cast(num_elements * 4), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].xyzw) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].xyzw.data(), + static_cast(num_elements * 4), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/quaternion.hpp b/rerun_cpp/src/rerun/datatypes/quaternion.hpp index 71206b6ac2f5..88bf802b1dc0 100644 --- a/rerun_cpp/src/rerun/datatypes/quaternion.hpp +++ b/rerun_cpp/src/rerun/datatypes/quaternion.hpp @@ -15,84 +15,81 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A Quaternion represented by 4 real numbers. - /// - /// Note: although the x,y,z,w components of the quaternion will be passed through to the - /// datastore as provided, when used in the viewer Quaternions will always be normalized. - struct Quaternion { - std::array xyzw; - - public: - // Extensions to generated type defined in 'quaternion_ext.cpp' - - static const Quaternion IDENTITY; - - /// Construct Quaternion from x/y/z/w values. - static Quaternion from_xyzw(float x, float y, float z, float w) { - return Quaternion::from_xyzw({x, y, z, w}); - } - - /// Construct Quaternion from w/x/y/z values. - static Quaternion from_wxyz(float w, float x, float y, float z) { - return Quaternion::from_xyzw(x, y, z, w); - } - - /// Construct Quaternion from x/y/z/w array. - static Quaternion from_xyzw(std::array xyzw_) { - Quaternion q; - q.xyzw = xyzw_; - return q; - } - - /// Construct Quaternion from w/x/y/z array. - static Quaternion from_wxyz(std::array wxyz_) { - return Quaternion::from_xyzw(wxyz_[1], wxyz_[2], wxyz_[3], wxyz_[0]); - } - - /// Construct Quaternion from x/y/z/w float pointer. - static Quaternion from_xyzw(const float* xyzw_) { - return Quaternion::from_xyzw(xyzw_[0], xyzw_[1], xyzw_[2], xyzw_[3]); - } - - /// Construct Quaternion from w/x/y/z float pointer. - static Quaternion from_wxyz(const float* wxyz_) { - return Quaternion::from_xyzw(wxyz_[1], wxyz_[2], wxyz_[3], wxyz_[0]); - } - - float x() const { - return xyzw[0]; - } - - float y() const { - return xyzw[1]; - } - - float z() const { - return xyzw[2]; - } - - float w() const { - return xyzw[3]; - } - - public: - Quaternion() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Quaternion* elements, - size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A Quaternion represented by 4 real numbers. + /// + /// Note: although the x,y,z,w components of the quaternion will be passed through to the + /// datastore as provided, when used in the viewer Quaternions will always be normalized. + struct Quaternion { + std::array xyzw; + + public: + // Extensions to generated type defined in 'quaternion_ext.cpp' + + static const Quaternion IDENTITY; + + /// Construct Quaternion from x/y/z/w values. + static Quaternion from_xyzw(float x, float y, float z, float w) { + return Quaternion::from_xyzw({x, y, z, w}); + } + + /// Construct Quaternion from w/x/y/z values. + static Quaternion from_wxyz(float w, float x, float y, float z) { + return Quaternion::from_xyzw(x, y, z, w); + } + + /// Construct Quaternion from x/y/z/w array. + static Quaternion from_xyzw(std::array xyzw_) { + Quaternion q; + q.xyzw = xyzw_; + return q; + } + + /// Construct Quaternion from w/x/y/z array. + static Quaternion from_wxyz(std::array wxyz_) { + return Quaternion::from_xyzw(wxyz_[1], wxyz_[2], wxyz_[3], wxyz_[0]); + } + + /// Construct Quaternion from x/y/z/w float pointer. + static Quaternion from_xyzw(const float* xyzw_) { + return Quaternion::from_xyzw(xyzw_[0], xyzw_[1], xyzw_[2], xyzw_[3]); + } + + /// Construct Quaternion from w/x/y/z float pointer. + static Quaternion from_wxyz(const float* wxyz_) { + return Quaternion::from_xyzw(wxyz_[1], wxyz_[2], wxyz_[3], wxyz_[0]); + } + + float x() const { + return xyzw[0]; + } + + float y() const { + return xyzw[1]; + } + + float z() const { + return xyzw[2]; + } + + float w() const { + return xyzw[3]; + } + + public: + Quaternion() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Quaternion* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/rgba32.cpp b/rerun_cpp/src/rerun/datatypes/rgba32.cpp index a4f5cb3d71bf..935e560fa5f2 100644 --- a/rerun_cpp/src/rerun/datatypes/rgba32.cpp +++ b/rerun_cpp/src/rerun/datatypes/rgba32.cpp @@ -6,45 +6,40 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Rgba32::arrow_datatype() { - static const auto datatype = arrow::uint32(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Rgba32::arrow_datatype() { + static const auto datatype = arrow::uint32(); + return datatype; + } + + Result> Rgba32::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Rgba32::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error Rgba32::fill_arrow_array_builder( + arrow::UInt32Builder* builder, const Rgba32* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error Rgba32::fill_arrow_array_builder( - arrow::UInt32Builder* builder, const Rgba32* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(*elements) == sizeof(elements->rgba)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->rgba, static_cast(num_elements)) + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + static_assert(sizeof(*elements) == sizeof(elements->rgba)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->rgba, static_cast(num_elements)) + ); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/rgba32.hpp b/rerun_cpp/src/rerun/datatypes/rgba32.hpp index b9ea4bc7aea8..ff3e9e3aa861 100644 --- a/rerun_cpp/src/rerun/datatypes/rgba32.hpp +++ b/rerun_cpp/src/rerun/datatypes/rgba32.hpp @@ -19,66 +19,64 @@ namespace arrow { using UInt32Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: An RGBA color with unmultiplied/separate alpha, in sRGB gamma space with linear alpha. - /// - /// The color is stored as a 32-bit integer, where the most significant - /// byte is `R` and the least significant byte is `A`. - struct Rgba32 { - uint32_t rgba; - - public: - // Extensions to generated type defined in 'rgba32_ext.cpp' - - /// Construct Rgba32 from unmultiplied RGBA values. - Rgba32(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) - : Rgba32(static_cast((r << 24) | (g << 16) | (b << 8) | a)) {} - - /// Construct Rgba32 from unmultiplied RGBA values. - Rgba32(const uint8_t (&_rgba)[4]) : Rgba32(_rgba[0], _rgba[1], _rgba[2], _rgba[3]) {} - - /// Construct Rgba32 from RGB values, setting alpha to 255. - Rgba32(const uint8_t (&_rgb)[3]) : Rgba32(_rgb[0], _rgb[1], _rgb[2]) {} - - uint8_t r() const { - return static_cast((rgba >> 24) & 0xFF); - } - - uint8_t g() const { - return static_cast((rgba >> 16) & 0xFF); - } - - uint8_t b() const { - return static_cast((rgba >> 8) & 0xFF); - } - - uint8_t a() const { - return static_cast(rgba & 0xFF); - } - - public: - Rgba32() = default; - - Rgba32(uint32_t rgba_) : rgba(rgba_) {} - - Rgba32& operator=(uint32_t rgba_) { - rgba = rgba_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::UInt32Builder* builder, const Rgba32* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: An RGBA color with unmultiplied/separate alpha, in sRGB gamma space with linear alpha. + /// + /// The color is stored as a 32-bit integer, where the most significant + /// byte is `R` and the least significant byte is `A`. + struct Rgba32 { + uint32_t rgba; + + public: + // Extensions to generated type defined in 'rgba32_ext.cpp' + + /// Construct Rgba32 from unmultiplied RGBA values. + Rgba32(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) + : Rgba32(static_cast((r << 24) | (g << 16) | (b << 8) | a)) {} + + /// Construct Rgba32 from unmultiplied RGBA values. + Rgba32(const uint8_t (&_rgba)[4]) : Rgba32(_rgba[0], _rgba[1], _rgba[2], _rgba[3]) {} + + /// Construct Rgba32 from RGB values, setting alpha to 255. + Rgba32(const uint8_t (&_rgb)[3]) : Rgba32(_rgb[0], _rgb[1], _rgb[2]) {} + + uint8_t r() const { + return static_cast((rgba >> 24) & 0xFF); + } + + uint8_t g() const { + return static_cast((rgba >> 16) & 0xFF); + } + + uint8_t b() const { + return static_cast((rgba >> 8) & 0xFF); + } + + uint8_t a() const { + return static_cast(rgba & 0xFF); + } + + public: + Rgba32() = default; + + Rgba32(uint32_t rgba_) : rgba(rgba_) {} + + Rgba32& operator=(uint32_t rgba_) { + rgba = rgba_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::UInt32Builder* builder, const Rgba32* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/rotation3d.cpp b/rerun_cpp/src/rerun/datatypes/rotation3d.cpp index 1a31803e5a3e..7c9135819650 100644 --- a/rerun_cpp/src/rerun/datatypes/rotation3d.cpp +++ b/rerun_cpp/src/rerun/datatypes/rotation3d.cpp @@ -9,92 +9,81 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Rotation3D::arrow_datatype() { - static const auto datatype = arrow::dense_union({ - arrow::field("_null_markers", arrow::null(), true, nullptr), - arrow::field("Quaternion", rerun::datatypes::Quaternion::arrow_datatype(), false), - arrow::field( - "AxisAngle", - rerun::datatypes::RotationAxisAngle::arrow_datatype(), - false - ), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Rotation3D::arrow_datatype() { + static const auto datatype = arrow::dense_union({ + arrow::field("_null_markers", arrow::null(), true, nullptr), + arrow::field("Quaternion", rerun::datatypes::Quaternion::arrow_datatype(), false), + arrow::field("AxisAngle", rerun::datatypes::RotationAxisAngle::arrow_datatype(), false), + }); + return datatype; + } + + Result> Rotation3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Rotation3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + // Children: + std::vector>({ + std::make_shared(memory_pool), + rerun::datatypes::Quaternion::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::RotationAxisAngle::new_arrow_array_builder(memory_pool).value, + }), + arrow_datatype() + )); + } - return Result(std::make_shared( - memory_pool, - // Children: - std::vector>({ - std::make_shared(memory_pool), - rerun::datatypes::Quaternion::new_arrow_array_builder(memory_pool).value, - rerun::datatypes::RotationAxisAngle::new_arrow_array_builder(memory_pool).value, - }), - arrow_datatype() - )); + rerun::Error Rotation3D::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error Rotation3D::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& union_instance = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& union_instance = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); - auto variant_index = static_cast(union_instance._tag); - auto variant_builder_untyped = builder->child_builder(variant_index).get(); + auto variant_index = static_cast(union_instance._tag); + auto variant_builder_untyped = builder->child_builder(variant_index).get(); - switch (union_instance._tag) { - case detail::Rotation3DTag::None: { - ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); - } break; - case detail::Rotation3DTag::Quaternion: { - auto variant_builder = - static_cast(variant_builder_untyped); - RR_RETURN_NOT_OK(rerun::datatypes::Quaternion::fill_arrow_array_builder( - variant_builder, - &union_instance._data.quaternion, - 1 - )); - } break; - case detail::Rotation3DTag::AxisAngle: { - auto variant_builder = - static_cast(variant_builder_untyped); - RR_RETURN_NOT_OK( - rerun::datatypes::RotationAxisAngle::fill_arrow_array_builder( - variant_builder, - &union_instance._data.axis_angle, - 1 - ) - ); - } break; - } + switch (union_instance._tag) { + case detail::Rotation3DTag::None: { + ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); + } break; + case detail::Rotation3DTag::Quaternion: { + auto variant_builder = + static_cast(variant_builder_untyped); + RR_RETURN_NOT_OK(rerun::datatypes::Quaternion::fill_arrow_array_builder( + variant_builder, + &union_instance._data.quaternion, + 1 + )); + } break; + case detail::Rotation3DTag::AxisAngle: { + auto variant_builder = + static_cast(variant_builder_untyped); + RR_RETURN_NOT_OK(rerun::datatypes::RotationAxisAngle::fill_arrow_array_builder( + variant_builder, + &union_instance._data.axis_angle, + 1 + )); + } break; } - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/rotation3d.hpp b/rerun_cpp/src/rerun/datatypes/rotation3d.hpp index b04de2e5283e..8a1864cc1348 100644 --- a/rerun_cpp/src/rerun/datatypes/rotation3d.hpp +++ b/rerun_cpp/src/rerun/datatypes/rotation3d.hpp @@ -19,140 +19,137 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - namespace detail { - /// \private - enum class Rotation3DTag : uint8_t { - /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. - None = 0, - Quaternion, - AxisAngle, - }; - - /// \private - union Rotation3DData { - /// Rotation defined by a quaternion. - rerun::datatypes::Quaternion quaternion; - - /// Rotation defined with an axis and an angle. - rerun::datatypes::RotationAxisAngle axis_angle; - - Rotation3DData() { - std::memset(reinterpret_cast(this), 0, sizeof(Rotation3DData)); - } - - ~Rotation3DData() {} - - void swap(Rotation3DData& other) noexcept { - // This bitwise swap would fail for self-referential types, but we don't have any of those. - char temp[sizeof(Rotation3DData)]; - void* otherbytes = reinterpret_cast(&other); - void* thisbytes = reinterpret_cast(this); - std::memcpy(temp, thisbytes, sizeof(Rotation3DData)); - std::memcpy(thisbytes, otherbytes, sizeof(Rotation3DData)); - std::memcpy(otherbytes, temp, sizeof(Rotation3DData)); - } - }; - } // namespace detail - - /// **Datatype**: A 3D rotation. - struct Rotation3D { - Rotation3D() : _tag(detail::Rotation3DTag::None) {} - - /// Copy constructor - Rotation3D(const Rotation3D& other) : _tag(other._tag) { - const void* otherbytes = reinterpret_cast(&other._data); - void* thisbytes = reinterpret_cast(&this->_data); - std::memcpy(thisbytes, otherbytes, sizeof(detail::Rotation3DData)); - } - - Rotation3D& operator=(const Rotation3D& other) noexcept { - Rotation3D tmp(other); - this->swap(tmp); - return *this; - } - - Rotation3D(Rotation3D&& other) noexcept : Rotation3D() { - this->swap(other); - } - - Rotation3D& operator=(Rotation3D&& other) noexcept { - this->swap(other); - return *this; - } - - public: - // Extensions to generated type defined in 'rotation3d_ext.cpp' - - static const Rotation3D IDENTITY; - - void swap(Rotation3D& other) noexcept { - std::swap(this->_tag, other._tag); - this->_data.swap(other._data); - } +namespace rerun::datatypes { + namespace detail { + /// \private + enum class Rotation3DTag : uint8_t { + /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. + None = 0, + Quaternion, + AxisAngle, + }; + /// \private + union Rotation3DData { /// Rotation defined by a quaternion. - Rotation3D(rerun::datatypes::Quaternion quaternion) : Rotation3D() { - *this = Rotation3D::quaternion(std::move(quaternion)); - } + rerun::datatypes::Quaternion quaternion; /// Rotation defined with an axis and an angle. - Rotation3D(rerun::datatypes::RotationAxisAngle axis_angle) : Rotation3D() { - *this = Rotation3D::axis_angle(std::move(axis_angle)); - } - - /// Rotation defined by a quaternion. - static Rotation3D quaternion(rerun::datatypes::Quaternion quaternion) { - Rotation3D self; - self._tag = detail::Rotation3DTag::Quaternion; - new (&self._data.quaternion) rerun::datatypes::Quaternion(std::move(quaternion)); - return self; - } + rerun::datatypes::RotationAxisAngle axis_angle; - /// Rotation defined with an axis and an angle. - static Rotation3D axis_angle(rerun::datatypes::RotationAxisAngle axis_angle) { - Rotation3D self; - self._tag = detail::Rotation3DTag::AxisAngle; - new (&self._data.axis_angle) - rerun::datatypes::RotationAxisAngle(std::move(axis_angle)); - return self; + Rotation3DData() { + std::memset(reinterpret_cast(this), 0, sizeof(Rotation3DData)); } - /// Return a pointer to quaternion if the union is in that state, otherwise `nullptr`. - const rerun::datatypes::Quaternion* get_quaternion() const { - if (_tag == detail::Rotation3DTag::Quaternion) { - return &_data.quaternion; - } else { - return nullptr; - } - } + ~Rotation3DData() {} - /// Return a pointer to axis_angle if the union is in that state, otherwise `nullptr`. - const rerun::datatypes::RotationAxisAngle* get_axis_angle() const { - if (_tag == detail::Rotation3DTag::AxisAngle) { - return &_data.axis_angle; - } else { - return nullptr; - } + void swap(Rotation3DData& other) noexcept { + // This bitwise swap would fail for self-referential types, but we don't have any of those. + char temp[sizeof(Rotation3DData)]; + void* otherbytes = reinterpret_cast(&other); + void* thisbytes = reinterpret_cast(this); + std::memcpy(temp, thisbytes, sizeof(Rotation3DData)); + std::memcpy(thisbytes, otherbytes, sizeof(Rotation3DData)); + std::memcpy(otherbytes, temp, sizeof(Rotation3DData)); } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements - ); - - private: - detail::Rotation3DTag _tag; - detail::Rotation3DData _data; }; - } // namespace datatypes -} // namespace rerun + } // namespace detail + + /// **Datatype**: A 3D rotation. + struct Rotation3D { + Rotation3D() : _tag(detail::Rotation3DTag::None) {} + + /// Copy constructor + Rotation3D(const Rotation3D& other) : _tag(other._tag) { + const void* otherbytes = reinterpret_cast(&other._data); + void* thisbytes = reinterpret_cast(&this->_data); + std::memcpy(thisbytes, otherbytes, sizeof(detail::Rotation3DData)); + } + + Rotation3D& operator=(const Rotation3D& other) noexcept { + Rotation3D tmp(other); + this->swap(tmp); + return *this; + } + + Rotation3D(Rotation3D&& other) noexcept : Rotation3D() { + this->swap(other); + } + + Rotation3D& operator=(Rotation3D&& other) noexcept { + this->swap(other); + return *this; + } + + public: + // Extensions to generated type defined in 'rotation3d_ext.cpp' + + static const Rotation3D IDENTITY; + + void swap(Rotation3D& other) noexcept { + std::swap(this->_tag, other._tag); + this->_data.swap(other._data); + } + + /// Rotation defined by a quaternion. + Rotation3D(rerun::datatypes::Quaternion quaternion) : Rotation3D() { + *this = Rotation3D::quaternion(std::move(quaternion)); + } + + /// Rotation defined with an axis and an angle. + Rotation3D(rerun::datatypes::RotationAxisAngle axis_angle) : Rotation3D() { + *this = Rotation3D::axis_angle(std::move(axis_angle)); + } + + /// Rotation defined by a quaternion. + static Rotation3D quaternion(rerun::datatypes::Quaternion quaternion) { + Rotation3D self; + self._tag = detail::Rotation3DTag::Quaternion; + new (&self._data.quaternion) rerun::datatypes::Quaternion(std::move(quaternion)); + return self; + } + + /// Rotation defined with an axis and an angle. + static Rotation3D axis_angle(rerun::datatypes::RotationAxisAngle axis_angle) { + Rotation3D self; + self._tag = detail::Rotation3DTag::AxisAngle; + new (&self._data.axis_angle) rerun::datatypes::RotationAxisAngle(std::move(axis_angle)); + return self; + } + + /// Return a pointer to quaternion if the union is in that state, otherwise `nullptr`. + const rerun::datatypes::Quaternion* get_quaternion() const { + if (_tag == detail::Rotation3DTag::Quaternion) { + return &_data.quaternion; + } else { + return nullptr; + } + } + + /// Return a pointer to axis_angle if the union is in that state, otherwise `nullptr`. + const rerun::datatypes::RotationAxisAngle* get_axis_angle() const { + if (_tag == detail::Rotation3DTag::AxisAngle) { + return &_data.axis_angle; + } else { + return nullptr; + } + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Rotation3D* elements, size_t num_elements + ); + + private: + detail::Rotation3DTag _tag; + detail::Rotation3DData _data; + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/rotation_axis_angle.cpp b/rerun_cpp/src/rerun/datatypes/rotation_axis_angle.cpp index f45ac81526b5..930cc82b4783 100644 --- a/rerun_cpp/src/rerun/datatypes/rotation_axis_angle.cpp +++ b/rerun_cpp/src/rerun/datatypes/rotation_axis_angle.cpp @@ -9,76 +9,70 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& RotationAxisAngle::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("axis", rerun::datatypes::Vec3D::arrow_datatype(), false), - arrow::field("angle", rerun::datatypes::Angle::arrow_datatype(), false), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& RotationAxisAngle::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("axis", rerun::datatypes::Vec3D::arrow_datatype(), false), + arrow::field("angle", rerun::datatypes::Angle::arrow_datatype(), false), + }); + return datatype; + } + + Result> RotationAxisAngle::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> RotationAxisAngle::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::Angle::new_arrow_array_builder(memory_pool).value, + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value, - rerun::datatypes::Angle::new_arrow_array_builder(memory_pool).value, - }) - )); + rerun::Error RotationAxisAngle::fill_arrow_array_builder( + arrow::StructBuilder* builder, const RotationAxisAngle* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error RotationAxisAngle::fill_arrow_array_builder( - arrow::StructBuilder* builder, const RotationAxisAngle* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = - static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].axis, - 1 - )); - } + { + auto field_builder = + static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].axis, + 1 + )); } - { - auto field_builder = - static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::Angle::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].angle, - 1 - )); - } + } + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::Angle::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].angle, + 1 + )); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/rotation_axis_angle.hpp b/rerun_cpp/src/rerun/datatypes/rotation_axis_angle.hpp index 667702354e0c..e9942a9633c6 100644 --- a/rerun_cpp/src/rerun/datatypes/rotation_axis_angle.hpp +++ b/rerun_cpp/src/rerun/datatypes/rotation_axis_angle.hpp @@ -16,42 +16,38 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: 3D rotation represented by a rotation around a given axis. - struct RotationAxisAngle { - /// Axis to rotate around. - /// - /// This is not required to be normalized. - /// If normalization fails (typically because the vector is length zero), the rotation is silently - /// ignored. - rerun::datatypes::Vec3D axis; - - /// How much to rotate around the axis. - rerun::datatypes::Angle angle; - - public: - // Extensions to generated type defined in 'rotation_axis_angle_ext.cpp' - - RotationAxisAngle(const Vec3D& _axis, const Angle& _angle) - : axis(_axis), angle(_angle) {} - - public: - RotationAxisAngle() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const RotationAxisAngle* elements, - size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: 3D rotation represented by a rotation around a given axis. + struct RotationAxisAngle { + /// Axis to rotate around. + /// + /// This is not required to be normalized. + /// If normalization fails (typically because the vector is length zero), the rotation is silently + /// ignored. + rerun::datatypes::Vec3D axis; + + /// How much to rotate around the axis. + rerun::datatypes::Angle angle; + + public: + // Extensions to generated type defined in 'rotation_axis_angle_ext.cpp' + + RotationAxisAngle(const Vec3D& _axis, const Angle& _angle) : axis(_axis), angle(_angle) {} + + public: + RotationAxisAngle() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const RotationAxisAngle* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/scale3d.cpp b/rerun_cpp/src/rerun/datatypes/scale3d.cpp index 8188771f037c..671d0c8617d7 100644 --- a/rerun_cpp/src/rerun/datatypes/scale3d.cpp +++ b/rerun_cpp/src/rerun/datatypes/scale3d.cpp @@ -8,82 +8,77 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Scale3D::arrow_datatype() { - static const auto datatype = arrow::dense_union({ - arrow::field("_null_markers", arrow::null(), true, nullptr), - arrow::field("ThreeD", rerun::datatypes::Vec3D::arrow_datatype(), false), - arrow::field("Uniform", arrow::float32(), false), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Scale3D::arrow_datatype() { + static const auto datatype = arrow::dense_union({ + arrow::field("_null_markers", arrow::null(), true, nullptr), + arrow::field("ThreeD", rerun::datatypes::Vec3D::arrow_datatype(), false), + arrow::field("Uniform", arrow::float32(), false), + }); + return datatype; + } + + Result> Scale3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Scale3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + // Children: + std::vector>({ + std::make_shared(memory_pool), + rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value, + std::make_shared(memory_pool), + }), + arrow_datatype() + )); + } - return Result(std::make_shared( - memory_pool, - // Children: - std::vector>({ - std::make_shared(memory_pool), - rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value, - std::make_shared(memory_pool), - }), - arrow_datatype() - )); + rerun::Error Scale3D::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Scale3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error Scale3D::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Scale3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& union_instance = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& union_instance = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); - auto variant_index = static_cast(union_instance._tag); - auto variant_builder_untyped = builder->child_builder(variant_index).get(); + auto variant_index = static_cast(union_instance._tag); + auto variant_builder_untyped = builder->child_builder(variant_index).get(); - switch (union_instance._tag) { - case detail::Scale3DTag::None: { - ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); - } break; - case detail::Scale3DTag::ThreeD: { - auto variant_builder = - static_cast(variant_builder_untyped); - RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( - variant_builder, - &union_instance._data.three_d, - 1 - )); - } break; - case detail::Scale3DTag::Uniform: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append(union_instance._data.uniform)); - } break; - } + switch (union_instance._tag) { + case detail::Scale3DTag::None: { + ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); + } break; + case detail::Scale3DTag::ThreeD: { + auto variant_builder = + static_cast(variant_builder_untyped); + RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( + variant_builder, + &union_instance._data.three_d, + 1 + )); + } break; + case detail::Scale3DTag::Uniform: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append(union_instance._data.uniform)); + } break; } - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/scale3d.hpp b/rerun_cpp/src/rerun/datatypes/scale3d.hpp index b9cc79dac8ef..9732fa154636 100644 --- a/rerun_cpp/src/rerun/datatypes/scale3d.hpp +++ b/rerun_cpp/src/rerun/datatypes/scale3d.hpp @@ -18,134 +18,132 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - namespace detail { - /// \private - enum class Scale3DTag : uint8_t { - /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. - None = 0, - ThreeD, - Uniform, - }; - - /// \private - union Scale3DData { - /// Individual scaling factors for each axis, distorting the original object. - rerun::datatypes::Vec3D three_d; - - /// Uniform scaling factor along all axis. - float uniform; - - Scale3DData() { - std::memset(reinterpret_cast(this), 0, sizeof(Scale3DData)); - } - - ~Scale3DData() {} - - void swap(Scale3DData& other) noexcept { - // This bitwise swap would fail for self-referential types, but we don't have any of those. - char temp[sizeof(Scale3DData)]; - void* otherbytes = reinterpret_cast(&other); - void* thisbytes = reinterpret_cast(this); - std::memcpy(temp, thisbytes, sizeof(Scale3DData)); - std::memcpy(thisbytes, otherbytes, sizeof(Scale3DData)); - std::memcpy(otherbytes, temp, sizeof(Scale3DData)); - } - }; - } // namespace detail - - /// **Datatype**: 3D scaling factor, part of a transform representation. - struct Scale3D { - Scale3D() : _tag(detail::Scale3DTag::None) {} - - /// Copy constructor - Scale3D(const Scale3D& other) : _tag(other._tag) { - const void* otherbytes = reinterpret_cast(&other._data); - void* thisbytes = reinterpret_cast(&this->_data); - std::memcpy(thisbytes, otherbytes, sizeof(detail::Scale3DData)); - } - - Scale3D& operator=(const Scale3D& other) noexcept { - Scale3D tmp(other); - this->swap(tmp); - return *this; - } - - Scale3D(Scale3D&& other) noexcept : Scale3D() { - this->swap(other); - } - - Scale3D& operator=(Scale3D&& other) noexcept { - this->swap(other); - return *this; - } - - void swap(Scale3D& other) noexcept { - std::swap(this->_tag, other._tag); - this->_data.swap(other._data); - } +namespace rerun::datatypes { + namespace detail { + /// \private + enum class Scale3DTag : uint8_t { + /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. + None = 0, + ThreeD, + Uniform, + }; + /// \private + union Scale3DData { /// Individual scaling factors for each axis, distorting the original object. - Scale3D(rerun::datatypes::Vec3D three_d) : Scale3D() { - *this = Scale3D::three_d(std::move(three_d)); - } + rerun::datatypes::Vec3D three_d; /// Uniform scaling factor along all axis. - Scale3D(float uniform) : Scale3D() { - *this = Scale3D::uniform(std::move(uniform)); - } + float uniform; - /// Individual scaling factors for each axis, distorting the original object. - static Scale3D three_d(rerun::datatypes::Vec3D three_d) { - Scale3D self; - self._tag = detail::Scale3DTag::ThreeD; - new (&self._data.three_d) rerun::datatypes::Vec3D(std::move(three_d)); - return self; - } - - /// Uniform scaling factor along all axis. - static Scale3D uniform(float uniform) { - Scale3D self; - self._tag = detail::Scale3DTag::Uniform; - new (&self._data.uniform) float(std::move(uniform)); - return self; + Scale3DData() { + std::memset(reinterpret_cast(this), 0, sizeof(Scale3DData)); } - /// Return a pointer to three_d if the union is in that state, otherwise `nullptr`. - const rerun::datatypes::Vec3D* get_three_d() const { - if (_tag == detail::Scale3DTag::ThreeD) { - return &_data.three_d; - } else { - return nullptr; - } - } + ~Scale3DData() {} - /// Return a pointer to uniform if the union is in that state, otherwise `nullptr`. - const float* get_uniform() const { - if (_tag == detail::Scale3DTag::Uniform) { - return &_data.uniform; - } else { - return nullptr; - } + void swap(Scale3DData& other) noexcept { + // This bitwise swap would fail for self-referential types, but we don't have any of those. + char temp[sizeof(Scale3DData)]; + void* otherbytes = reinterpret_cast(&other); + void* thisbytes = reinterpret_cast(this); + std::memcpy(temp, thisbytes, sizeof(Scale3DData)); + std::memcpy(thisbytes, otherbytes, sizeof(Scale3DData)); + std::memcpy(otherbytes, temp, sizeof(Scale3DData)); } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Scale3D* elements, size_t num_elements - ); - - private: - detail::Scale3DTag _tag; - detail::Scale3DData _data; }; - } // namespace datatypes -} // namespace rerun + } // namespace detail + + /// **Datatype**: 3D scaling factor, part of a transform representation. + struct Scale3D { + Scale3D() : _tag(detail::Scale3DTag::None) {} + + /// Copy constructor + Scale3D(const Scale3D& other) : _tag(other._tag) { + const void* otherbytes = reinterpret_cast(&other._data); + void* thisbytes = reinterpret_cast(&this->_data); + std::memcpy(thisbytes, otherbytes, sizeof(detail::Scale3DData)); + } + + Scale3D& operator=(const Scale3D& other) noexcept { + Scale3D tmp(other); + this->swap(tmp); + return *this; + } + + Scale3D(Scale3D&& other) noexcept : Scale3D() { + this->swap(other); + } + + Scale3D& operator=(Scale3D&& other) noexcept { + this->swap(other); + return *this; + } + + void swap(Scale3D& other) noexcept { + std::swap(this->_tag, other._tag); + this->_data.swap(other._data); + } + + /// Individual scaling factors for each axis, distorting the original object. + Scale3D(rerun::datatypes::Vec3D three_d) : Scale3D() { + *this = Scale3D::three_d(std::move(three_d)); + } + + /// Uniform scaling factor along all axis. + Scale3D(float uniform) : Scale3D() { + *this = Scale3D::uniform(std::move(uniform)); + } + + /// Individual scaling factors for each axis, distorting the original object. + static Scale3D three_d(rerun::datatypes::Vec3D three_d) { + Scale3D self; + self._tag = detail::Scale3DTag::ThreeD; + new (&self._data.three_d) rerun::datatypes::Vec3D(std::move(three_d)); + return self; + } + + /// Uniform scaling factor along all axis. + static Scale3D uniform(float uniform) { + Scale3D self; + self._tag = detail::Scale3DTag::Uniform; + new (&self._data.uniform) float(std::move(uniform)); + return self; + } + + /// Return a pointer to three_d if the union is in that state, otherwise `nullptr`. + const rerun::datatypes::Vec3D* get_three_d() const { + if (_tag == detail::Scale3DTag::ThreeD) { + return &_data.three_d; + } else { + return nullptr; + } + } + + /// Return a pointer to uniform if the union is in that state, otherwise `nullptr`. + const float* get_uniform() const { + if (_tag == detail::Scale3DTag::Uniform) { + return &_data.uniform; + } else { + return nullptr; + } + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Scale3D* elements, size_t num_elements + ); + + private: + detail::Scale3DTag _tag; + detail::Scale3DData _data; + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/tensor_buffer.cpp b/rerun_cpp/src/rerun/datatypes/tensor_buffer.cpp index 4d816d67efb1..fe0b1c455f48 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_buffer.cpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_buffer.cpp @@ -6,317 +6,268 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& TensorBuffer::arrow_datatype() { - static const auto datatype = arrow::dense_union({ - arrow::field("_null_markers", arrow::null(), true, nullptr), - arrow::field("U8", arrow::list(arrow::field("item", arrow::uint8(), false)), false), - arrow::field( - "U16", - arrow::list(arrow::field("item", arrow::uint16(), false)), - false +namespace rerun::datatypes { + const std::shared_ptr& TensorBuffer::arrow_datatype() { + static const auto datatype = arrow::dense_union({ + arrow::field("_null_markers", arrow::null(), true, nullptr), + arrow::field("U8", arrow::list(arrow::field("item", arrow::uint8(), false)), false), + arrow::field("U16", arrow::list(arrow::field("item", arrow::uint16(), false)), false), + arrow::field("U32", arrow::list(arrow::field("item", arrow::uint32(), false)), false), + arrow::field("U64", arrow::list(arrow::field("item", arrow::uint64(), false)), false), + arrow::field("I8", arrow::list(arrow::field("item", arrow::int8(), false)), false), + arrow::field("I16", arrow::list(arrow::field("item", arrow::int16(), false)), false), + arrow::field("I32", arrow::list(arrow::field("item", arrow::int32(), false)), false), + arrow::field("I64", arrow::list(arrow::field("item", arrow::int64(), false)), false), + arrow::field("F16", arrow::list(arrow::field("item", arrow::float16(), false)), false), + arrow::field("F32", arrow::list(arrow::field("item", arrow::float32(), false)), false), + arrow::field("F64", arrow::list(arrow::field("item", arrow::float64(), false)), false), + arrow::field("JPEG", arrow::list(arrow::field("item", arrow::uint8(), false)), false), + arrow::field("NV12", arrow::list(arrow::field("item", arrow::uint8(), false)), false), + }); + return datatype; + } + + Result> TensorBuffer::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); + } + + return Result(std::make_shared( + memory_pool, + // Children: + std::vector>({ + std::make_shared(memory_pool), + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "U32", - arrow::list(arrow::field("item", arrow::uint32(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "U64", - arrow::list(arrow::field("item", arrow::uint64(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field("I8", arrow::list(arrow::field("item", arrow::int8(), false)), false), - arrow::field( - "I16", - arrow::list(arrow::field("item", arrow::int16(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "I32", - arrow::list(arrow::field("item", arrow::int32(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "I64", - arrow::list(arrow::field("item", arrow::int64(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "F16", - arrow::list(arrow::field("item", arrow::float16(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "F32", - arrow::list(arrow::field("item", arrow::float32(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "F64", - arrow::list(arrow::field("item", arrow::float64(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "JPEG", - arrow::list(arrow::field("item", arrow::uint8(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "NV12", - arrow::list(arrow::field("item", arrow::uint8(), false)), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - }); - return datatype; - } - - Result> TensorBuffer::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + std::make_shared( + memory_pool, + std::make_shared(memory_pool) + ), + std::make_shared( + memory_pool, + std::make_shared(memory_pool) + ), + }), + arrow_datatype() + )); + } - return Result(std::make_shared( - memory_pool, - // Children: - std::vector>({ - std::make_shared(memory_pool), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - }), - arrow_datatype() - )); + rerun::Error TensorBuffer::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const TensorBuffer* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error TensorBuffer::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const TensorBuffer* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& union_instance = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& union_instance = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); - auto variant_index = static_cast(union_instance._tag); - auto variant_builder_untyped = builder->child_builder(variant_index).get(); + auto variant_index = static_cast(union_instance._tag); + auto variant_builder_untyped = builder->child_builder(variant_index).get(); - switch (union_instance._tag) { - case detail::TensorBufferTag::None: { - ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); - } break; - case detail::TensorBufferTag::U8: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.u8.data(), - static_cast(union_instance._data.u8.size()) - )); - } break; - case detail::TensorBufferTag::U16: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.u16.data(), - static_cast(union_instance._data.u16.size()) - )); - } break; - case detail::TensorBufferTag::U32: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.u32.data(), - static_cast(union_instance._data.u32.size()) - )); - } break; - case detail::TensorBufferTag::U64: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.u64.data(), - static_cast(union_instance._data.u64.size()) - )); - } break; - case detail::TensorBufferTag::I8: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.i8.data(), - static_cast(union_instance._data.i8.size()) - )); - } break; - case detail::TensorBufferTag::I16: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.i16.data(), - static_cast(union_instance._data.i16.size()) - )); - } break; - case detail::TensorBufferTag::I32: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.i32.data(), - static_cast(union_instance._data.i32.size()) - )); - } break; - case detail::TensorBufferTag::I64: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.i64.data(), - static_cast(union_instance._data.i64.size()) - )); - } break; - case detail::TensorBufferTag::F16: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - const rerun::half* values = union_instance._data.f16.data(); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - reinterpret_cast(values), - static_cast(union_instance._data.f16.size()) - )); - } break; - case detail::TensorBufferTag::F32: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.f32.data(), - static_cast(union_instance._data.f32.size()) - )); - } break; - case detail::TensorBufferTag::F64: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.f64.data(), - static_cast(union_instance._data.f64.size()) - )); - } break; - case detail::TensorBufferTag::JPEG: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.jpeg.data(), - static_cast(union_instance._data.jpeg.size()) - )); - } break; - case detail::TensorBufferTag::NV12: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append()); - auto value_builder = - static_cast(variant_builder->value_builder()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - union_instance._data.nv12.data(), - static_cast(union_instance._data.nv12.size()) - )); - } break; - } + switch (union_instance._tag) { + case detail::TensorBufferTag::None: { + ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); + } break; + case detail::TensorBufferTag::U8: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.u8.data(), + static_cast(union_instance._data.u8.size()) + )); + } break; + case detail::TensorBufferTag::U16: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.u16.data(), + static_cast(union_instance._data.u16.size()) + )); + } break; + case detail::TensorBufferTag::U32: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.u32.data(), + static_cast(union_instance._data.u32.size()) + )); + } break; + case detail::TensorBufferTag::U64: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.u64.data(), + static_cast(union_instance._data.u64.size()) + )); + } break; + case detail::TensorBufferTag::I8: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.i8.data(), + static_cast(union_instance._data.i8.size()) + )); + } break; + case detail::TensorBufferTag::I16: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.i16.data(), + static_cast(union_instance._data.i16.size()) + )); + } break; + case detail::TensorBufferTag::I32: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.i32.data(), + static_cast(union_instance._data.i32.size()) + )); + } break; + case detail::TensorBufferTag::I64: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.i64.data(), + static_cast(union_instance._data.i64.size()) + )); + } break; + case detail::TensorBufferTag::F16: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + const rerun::half* values = union_instance._data.f16.data(); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + reinterpret_cast(values), + static_cast(union_instance._data.f16.size()) + )); + } break; + case detail::TensorBufferTag::F32: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.f32.data(), + static_cast(union_instance._data.f32.size()) + )); + } break; + case detail::TensorBufferTag::F64: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.f64.data(), + static_cast(union_instance._data.f64.size()) + )); + } break; + case detail::TensorBufferTag::JPEG: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.jpeg.data(), + static_cast(union_instance._data.jpeg.size()) + )); + } break; + case detail::TensorBufferTag::NV12: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append()); + auto value_builder = + static_cast(variant_builder->value_builder()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + union_instance._data.nv12.data(), + static_cast(union_instance._data.nv12.size()) + )); + } break; } - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/tensor_buffer.hpp b/rerun_cpp/src/rerun/datatypes/tensor_buffer.hpp index c59b3cd94a99..1211db72c494 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_buffer.hpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_buffer.hpp @@ -19,496 +19,486 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - namespace detail { - /// \private - enum class TensorBufferTag : uint8_t { - /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. - None = 0, - U8, - U16, - U32, - U64, - I8, - I16, - I32, - I64, - F16, - F32, - F64, - JPEG, - NV12, - }; - - /// \private - union TensorBufferData { - std::vector u8; - - std::vector u16; - - std::vector u32; - - std::vector u64; - - std::vector i8; - - std::vector i16; - - std::vector i32; - - std::vector i64; - - std::vector f16; - - std::vector f32; - - std::vector f64; - - std::vector jpeg; - - std::vector nv12; - - TensorBufferData() { - std::memset(reinterpret_cast(this), 0, sizeof(TensorBufferData)); - } - - ~TensorBufferData() {} - - void swap(TensorBufferData& other) noexcept { - // This bitwise swap would fail for self-referential types, but we don't have any of those. - char temp[sizeof(TensorBufferData)]; - void* otherbytes = reinterpret_cast(&other); - void* thisbytes = reinterpret_cast(this); - std::memcpy(temp, thisbytes, sizeof(TensorBufferData)); - std::memcpy(thisbytes, otherbytes, sizeof(TensorBufferData)); - std::memcpy(otherbytes, temp, sizeof(TensorBufferData)); - } - }; - } // namespace detail - - /// **Datatype**: The underlying storage for a `Tensor`. - /// - /// Tensor elements are stored in a contiguous buffer of a single type. - struct TensorBuffer { - TensorBuffer() : _tag(detail::TensorBufferTag::None) {} - - /// Copy constructor - TensorBuffer(const TensorBuffer& other) : _tag(other._tag) { - switch (other._tag) { - case detail::TensorBufferTag::U8: { - using TypeAlias = std::vector; - new (&_data.u8) TypeAlias(other._data.u8); - } break; - case detail::TensorBufferTag::U16: { - using TypeAlias = std::vector; - new (&_data.u16) TypeAlias(other._data.u16); - } break; - case detail::TensorBufferTag::U32: { - using TypeAlias = std::vector; - new (&_data.u32) TypeAlias(other._data.u32); - } break; - case detail::TensorBufferTag::U64: { - using TypeAlias = std::vector; - new (&_data.u64) TypeAlias(other._data.u64); - } break; - case detail::TensorBufferTag::I8: { - using TypeAlias = std::vector; - new (&_data.i8) TypeAlias(other._data.i8); - } break; - case detail::TensorBufferTag::I16: { - using TypeAlias = std::vector; - new (&_data.i16) TypeAlias(other._data.i16); - } break; - case detail::TensorBufferTag::I32: { - using TypeAlias = std::vector; - new (&_data.i32) TypeAlias(other._data.i32); - } break; - case detail::TensorBufferTag::I64: { - using TypeAlias = std::vector; - new (&_data.i64) TypeAlias(other._data.i64); - } break; - case detail::TensorBufferTag::F16: { - using TypeAlias = std::vector; - new (&_data.f16) TypeAlias(other._data.f16); - } break; - case detail::TensorBufferTag::F32: { - using TypeAlias = std::vector; - new (&_data.f32) TypeAlias(other._data.f32); - } break; - case detail::TensorBufferTag::F64: { - using TypeAlias = std::vector; - new (&_data.f64) TypeAlias(other._data.f64); - } break; - case detail::TensorBufferTag::JPEG: { - using TypeAlias = std::vector; - new (&_data.jpeg) TypeAlias(other._data.jpeg); - } break; - case detail::TensorBufferTag::NV12: { - using TypeAlias = std::vector; - new (&_data.nv12) TypeAlias(other._data.nv12); - } break; - case detail::TensorBufferTag::None: { - } break; - } - } - - TensorBuffer& operator=(const TensorBuffer& other) noexcept { - TensorBuffer tmp(other); - this->swap(tmp); - return *this; - } - - TensorBuffer(TensorBuffer&& other) noexcept : TensorBuffer() { - this->swap(other); - } - - TensorBuffer& operator=(TensorBuffer&& other) noexcept { - this->swap(other); - return *this; - } - - ~TensorBuffer() { - switch (this->_tag) { - case detail::TensorBufferTag::None: { - // Nothing to destroy - } break; - case detail::TensorBufferTag::U8: { - using TypeAlias = std::vector; - _data.u8.~TypeAlias(); - } break; - case detail::TensorBufferTag::U16: { - using TypeAlias = std::vector; - _data.u16.~TypeAlias(); - } break; - case detail::TensorBufferTag::U32: { - using TypeAlias = std::vector; - _data.u32.~TypeAlias(); - } break; - case detail::TensorBufferTag::U64: { - using TypeAlias = std::vector; - _data.u64.~TypeAlias(); - } break; - case detail::TensorBufferTag::I8: { - using TypeAlias = std::vector; - _data.i8.~TypeAlias(); - } break; - case detail::TensorBufferTag::I16: { - using TypeAlias = std::vector; - _data.i16.~TypeAlias(); - } break; - case detail::TensorBufferTag::I32: { - using TypeAlias = std::vector; - _data.i32.~TypeAlias(); - } break; - case detail::TensorBufferTag::I64: { - using TypeAlias = std::vector; - _data.i64.~TypeAlias(); - } break; - case detail::TensorBufferTag::F16: { - using TypeAlias = std::vector; - _data.f16.~TypeAlias(); - } break; - case detail::TensorBufferTag::F32: { - using TypeAlias = std::vector; - _data.f32.~TypeAlias(); - } break; - case detail::TensorBufferTag::F64: { - using TypeAlias = std::vector; - _data.f64.~TypeAlias(); - } break; - case detail::TensorBufferTag::JPEG: { - using TypeAlias = std::vector; - _data.jpeg.~TypeAlias(); - } break; - case detail::TensorBufferTag::NV12: { - using TypeAlias = std::vector; - _data.nv12.~TypeAlias(); - } break; - } - } - - public: - // Extensions to generated type defined in 'tensor_buffer_ext.cpp' - - // TODO(#3794): don't use std::vector here - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u8) : TensorBuffer(TensorBuffer::u8(std::move(u8))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u16) - : TensorBuffer(TensorBuffer::u16(std::move(u16))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u32) - : TensorBuffer(TensorBuffer::u32(std::move(u32))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u64) - : TensorBuffer(TensorBuffer::u64(std::move(u64))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i8) : TensorBuffer(TensorBuffer::i8(std::move(i8))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i16) - : TensorBuffer(TensorBuffer::i16(std::move(i16))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i32) - : TensorBuffer(TensorBuffer::i32(std::move(i32))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i64) - : TensorBuffer(TensorBuffer::i64(std::move(i64))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f16) - : TensorBuffer(TensorBuffer::f16(std::move(f16))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f32) - : TensorBuffer(TensorBuffer::f32(std::move(f32))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f64) - : TensorBuffer(TensorBuffer::f64(std::move(f64))) {} - - /// Number of elements in the buffer. - /// - /// You may NOT call this for JPEG buffers. - size_t num_elems() const; - - void swap(TensorBuffer& other) noexcept { - std::swap(this->_tag, other._tag); - this->_data.swap(other._data); - } - - static TensorBuffer u8(std::vector u8) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::U8; - new (&self._data.u8) std::vector(std::move(u8)); - return self; - } - - static TensorBuffer u16(std::vector u16) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::U16; - new (&self._data.u16) std::vector(std::move(u16)); - return self; - } - - static TensorBuffer u32(std::vector u32) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::U32; - new (&self._data.u32) std::vector(std::move(u32)); - return self; - } - - static TensorBuffer u64(std::vector u64) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::U64; - new (&self._data.u64) std::vector(std::move(u64)); - return self; - } - - static TensorBuffer i8(std::vector i8) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::I8; - new (&self._data.i8) std::vector(std::move(i8)); - return self; - } - - static TensorBuffer i16(std::vector i16) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::I16; - new (&self._data.i16) std::vector(std::move(i16)); - return self; - } - - static TensorBuffer i32(std::vector i32) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::I32; - new (&self._data.i32) std::vector(std::move(i32)); - return self; - } - - static TensorBuffer i64(std::vector i64) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::I64; - new (&self._data.i64) std::vector(std::move(i64)); - return self; - } - - static TensorBuffer f16(std::vector f16) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::F16; - new (&self._data.f16) std::vector(std::move(f16)); - return self; - } - - static TensorBuffer f32(std::vector f32) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::F32; - new (&self._data.f32) std::vector(std::move(f32)); - return self; - } +namespace rerun::datatypes { + namespace detail { + /// \private + enum class TensorBufferTag : uint8_t { + /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. + None = 0, + U8, + U16, + U32, + U64, + I8, + I16, + I32, + I64, + F16, + F32, + F64, + JPEG, + NV12, + }; - static TensorBuffer f64(std::vector f64) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::F64; - new (&self._data.f64) std::vector(std::move(f64)); - return self; - } + /// \private + union TensorBufferData { + std::vector u8; - static TensorBuffer jpeg(std::vector jpeg) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::JPEG; - new (&self._data.jpeg) std::vector(std::move(jpeg)); - return self; - } + std::vector u16; - static TensorBuffer nv12(std::vector nv12) { - TensorBuffer self; - self._tag = detail::TensorBufferTag::NV12; - new (&self._data.nv12) std::vector(std::move(nv12)); - return self; - } + std::vector u32; - /// Return a pointer to u8 if the union is in that state, otherwise `nullptr`. - const std::vector* get_u8() const { - if (_tag == detail::TensorBufferTag::U8) { - return &_data.u8; - } else { - return nullptr; - } - } + std::vector u64; - /// Return a pointer to u16 if the union is in that state, otherwise `nullptr`. - const std::vector* get_u16() const { - if (_tag == detail::TensorBufferTag::U16) { - return &_data.u16; - } else { - return nullptr; - } - } + std::vector i8; - /// Return a pointer to u32 if the union is in that state, otherwise `nullptr`. - const std::vector* get_u32() const { - if (_tag == detail::TensorBufferTag::U32) { - return &_data.u32; - } else { - return nullptr; - } - } + std::vector i16; - /// Return a pointer to u64 if the union is in that state, otherwise `nullptr`. - const std::vector* get_u64() const { - if (_tag == detail::TensorBufferTag::U64) { - return &_data.u64; - } else { - return nullptr; - } - } + std::vector i32; - /// Return a pointer to i8 if the union is in that state, otherwise `nullptr`. - const std::vector* get_i8() const { - if (_tag == detail::TensorBufferTag::I8) { - return &_data.i8; - } else { - return nullptr; - } - } + std::vector i64; - /// Return a pointer to i16 if the union is in that state, otherwise `nullptr`. - const std::vector* get_i16() const { - if (_tag == detail::TensorBufferTag::I16) { - return &_data.i16; - } else { - return nullptr; - } - } + std::vector f16; - /// Return a pointer to i32 if the union is in that state, otherwise `nullptr`. - const std::vector* get_i32() const { - if (_tag == detail::TensorBufferTag::I32) { - return &_data.i32; - } else { - return nullptr; - } - } + std::vector f32; - /// Return a pointer to i64 if the union is in that state, otherwise `nullptr`. - const std::vector* get_i64() const { - if (_tag == detail::TensorBufferTag::I64) { - return &_data.i64; - } else { - return nullptr; - } - } + std::vector f64; - /// Return a pointer to f16 if the union is in that state, otherwise `nullptr`. - const std::vector* get_f16() const { - if (_tag == detail::TensorBufferTag::F16) { - return &_data.f16; - } else { - return nullptr; - } - } + std::vector jpeg; - /// Return a pointer to f32 if the union is in that state, otherwise `nullptr`. - const std::vector* get_f32() const { - if (_tag == detail::TensorBufferTag::F32) { - return &_data.f32; - } else { - return nullptr; - } - } + std::vector nv12; - /// Return a pointer to f64 if the union is in that state, otherwise `nullptr`. - const std::vector* get_f64() const { - if (_tag == detail::TensorBufferTag::F64) { - return &_data.f64; - } else { - return nullptr; - } + TensorBufferData() { + std::memset(reinterpret_cast(this), 0, sizeof(TensorBufferData)); } - /// Return a pointer to jpeg if the union is in that state, otherwise `nullptr`. - const std::vector* get_jpeg() const { - if (_tag == detail::TensorBufferTag::JPEG) { - return &_data.jpeg; - } else { - return nullptr; - } - } + ~TensorBufferData() {} - /// Return a pointer to nv12 if the union is in that state, otherwise `nullptr`. - const std::vector* get_nv12() const { - if (_tag == detail::TensorBufferTag::NV12) { - return &_data.nv12; - } else { - return nullptr; - } + void swap(TensorBufferData& other) noexcept { + // This bitwise swap would fail for self-referential types, but we don't have any of those. + char temp[sizeof(TensorBufferData)]; + void* otherbytes = reinterpret_cast(&other); + void* thisbytes = reinterpret_cast(this); + std::memcpy(temp, thisbytes, sizeof(TensorBufferData)); + std::memcpy(thisbytes, otherbytes, sizeof(TensorBufferData)); + std::memcpy(otherbytes, temp, sizeof(TensorBufferData)); } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const TensorBuffer* elements, size_t num_elements - ); - - private: - detail::TensorBufferTag _tag; - detail::TensorBufferData _data; }; - } // namespace datatypes -} // namespace rerun + } // namespace detail + + /// **Datatype**: The underlying storage for a `Tensor`. + /// + /// Tensor elements are stored in a contiguous buffer of a single type. + struct TensorBuffer { + TensorBuffer() : _tag(detail::TensorBufferTag::None) {} + + /// Copy constructor + TensorBuffer(const TensorBuffer& other) : _tag(other._tag) { + switch (other._tag) { + case detail::TensorBufferTag::U8: { + using TypeAlias = std::vector; + new (&_data.u8) TypeAlias(other._data.u8); + } break; + case detail::TensorBufferTag::U16: { + using TypeAlias = std::vector; + new (&_data.u16) TypeAlias(other._data.u16); + } break; + case detail::TensorBufferTag::U32: { + using TypeAlias = std::vector; + new (&_data.u32) TypeAlias(other._data.u32); + } break; + case detail::TensorBufferTag::U64: { + using TypeAlias = std::vector; + new (&_data.u64) TypeAlias(other._data.u64); + } break; + case detail::TensorBufferTag::I8: { + using TypeAlias = std::vector; + new (&_data.i8) TypeAlias(other._data.i8); + } break; + case detail::TensorBufferTag::I16: { + using TypeAlias = std::vector; + new (&_data.i16) TypeAlias(other._data.i16); + } break; + case detail::TensorBufferTag::I32: { + using TypeAlias = std::vector; + new (&_data.i32) TypeAlias(other._data.i32); + } break; + case detail::TensorBufferTag::I64: { + using TypeAlias = std::vector; + new (&_data.i64) TypeAlias(other._data.i64); + } break; + case detail::TensorBufferTag::F16: { + using TypeAlias = std::vector; + new (&_data.f16) TypeAlias(other._data.f16); + } break; + case detail::TensorBufferTag::F32: { + using TypeAlias = std::vector; + new (&_data.f32) TypeAlias(other._data.f32); + } break; + case detail::TensorBufferTag::F64: { + using TypeAlias = std::vector; + new (&_data.f64) TypeAlias(other._data.f64); + } break; + case detail::TensorBufferTag::JPEG: { + using TypeAlias = std::vector; + new (&_data.jpeg) TypeAlias(other._data.jpeg); + } break; + case detail::TensorBufferTag::NV12: { + using TypeAlias = std::vector; + new (&_data.nv12) TypeAlias(other._data.nv12); + } break; + case detail::TensorBufferTag::None: { + } break; + } + } + + TensorBuffer& operator=(const TensorBuffer& other) noexcept { + TensorBuffer tmp(other); + this->swap(tmp); + return *this; + } + + TensorBuffer(TensorBuffer&& other) noexcept : TensorBuffer() { + this->swap(other); + } + + TensorBuffer& operator=(TensorBuffer&& other) noexcept { + this->swap(other); + return *this; + } + + ~TensorBuffer() { + switch (this->_tag) { + case detail::TensorBufferTag::None: { + // Nothing to destroy + } break; + case detail::TensorBufferTag::U8: { + using TypeAlias = std::vector; + _data.u8.~TypeAlias(); + } break; + case detail::TensorBufferTag::U16: { + using TypeAlias = std::vector; + _data.u16.~TypeAlias(); + } break; + case detail::TensorBufferTag::U32: { + using TypeAlias = std::vector; + _data.u32.~TypeAlias(); + } break; + case detail::TensorBufferTag::U64: { + using TypeAlias = std::vector; + _data.u64.~TypeAlias(); + } break; + case detail::TensorBufferTag::I8: { + using TypeAlias = std::vector; + _data.i8.~TypeAlias(); + } break; + case detail::TensorBufferTag::I16: { + using TypeAlias = std::vector; + _data.i16.~TypeAlias(); + } break; + case detail::TensorBufferTag::I32: { + using TypeAlias = std::vector; + _data.i32.~TypeAlias(); + } break; + case detail::TensorBufferTag::I64: { + using TypeAlias = std::vector; + _data.i64.~TypeAlias(); + } break; + case detail::TensorBufferTag::F16: { + using TypeAlias = std::vector; + _data.f16.~TypeAlias(); + } break; + case detail::TensorBufferTag::F32: { + using TypeAlias = std::vector; + _data.f32.~TypeAlias(); + } break; + case detail::TensorBufferTag::F64: { + using TypeAlias = std::vector; + _data.f64.~TypeAlias(); + } break; + case detail::TensorBufferTag::JPEG: { + using TypeAlias = std::vector; + _data.jpeg.~TypeAlias(); + } break; + case detail::TensorBufferTag::NV12: { + using TypeAlias = std::vector; + _data.nv12.~TypeAlias(); + } break; + } + } + + public: + // Extensions to generated type defined in 'tensor_buffer_ext.cpp' + + // TODO(#3794): don't use std::vector here + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector u8) : TensorBuffer(TensorBuffer::u8(std::move(u8))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector u16) : TensorBuffer(TensorBuffer::u16(std::move(u16))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector u32) : TensorBuffer(TensorBuffer::u32(std::move(u32))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector u64) : TensorBuffer(TensorBuffer::u64(std::move(u64))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector i8) : TensorBuffer(TensorBuffer::i8(std::move(i8))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector i16) : TensorBuffer(TensorBuffer::i16(std::move(i16))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector i32) : TensorBuffer(TensorBuffer::i32(std::move(i32))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector i64) : TensorBuffer(TensorBuffer::i64(std::move(i64))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector f16) + : TensorBuffer(TensorBuffer::f16(std::move(f16))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector f32) : TensorBuffer(TensorBuffer::f32(std::move(f32))) {} + + /// Construct a `TensorBuffer` from a `std::vector`. + TensorBuffer(std::vector f64) : TensorBuffer(TensorBuffer::f64(std::move(f64))) {} + + /// Number of elements in the buffer. + /// + /// You may NOT call this for JPEG buffers. + size_t num_elems() const; + + void swap(TensorBuffer& other) noexcept { + std::swap(this->_tag, other._tag); + this->_data.swap(other._data); + } + + static TensorBuffer u8(std::vector u8) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::U8; + new (&self._data.u8) std::vector(std::move(u8)); + return self; + } + + static TensorBuffer u16(std::vector u16) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::U16; + new (&self._data.u16) std::vector(std::move(u16)); + return self; + } + + static TensorBuffer u32(std::vector u32) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::U32; + new (&self._data.u32) std::vector(std::move(u32)); + return self; + } + + static TensorBuffer u64(std::vector u64) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::U64; + new (&self._data.u64) std::vector(std::move(u64)); + return self; + } + + static TensorBuffer i8(std::vector i8) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::I8; + new (&self._data.i8) std::vector(std::move(i8)); + return self; + } + + static TensorBuffer i16(std::vector i16) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::I16; + new (&self._data.i16) std::vector(std::move(i16)); + return self; + } + + static TensorBuffer i32(std::vector i32) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::I32; + new (&self._data.i32) std::vector(std::move(i32)); + return self; + } + + static TensorBuffer i64(std::vector i64) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::I64; + new (&self._data.i64) std::vector(std::move(i64)); + return self; + } + + static TensorBuffer f16(std::vector f16) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::F16; + new (&self._data.f16) std::vector(std::move(f16)); + return self; + } + + static TensorBuffer f32(std::vector f32) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::F32; + new (&self._data.f32) std::vector(std::move(f32)); + return self; + } + + static TensorBuffer f64(std::vector f64) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::F64; + new (&self._data.f64) std::vector(std::move(f64)); + return self; + } + + static TensorBuffer jpeg(std::vector jpeg) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::JPEG; + new (&self._data.jpeg) std::vector(std::move(jpeg)); + return self; + } + + static TensorBuffer nv12(std::vector nv12) { + TensorBuffer self; + self._tag = detail::TensorBufferTag::NV12; + new (&self._data.nv12) std::vector(std::move(nv12)); + return self; + } + + /// Return a pointer to u8 if the union is in that state, otherwise `nullptr`. + const std::vector* get_u8() const { + if (_tag == detail::TensorBufferTag::U8) { + return &_data.u8; + } else { + return nullptr; + } + } + + /// Return a pointer to u16 if the union is in that state, otherwise `nullptr`. + const std::vector* get_u16() const { + if (_tag == detail::TensorBufferTag::U16) { + return &_data.u16; + } else { + return nullptr; + } + } + + /// Return a pointer to u32 if the union is in that state, otherwise `nullptr`. + const std::vector* get_u32() const { + if (_tag == detail::TensorBufferTag::U32) { + return &_data.u32; + } else { + return nullptr; + } + } + + /// Return a pointer to u64 if the union is in that state, otherwise `nullptr`. + const std::vector* get_u64() const { + if (_tag == detail::TensorBufferTag::U64) { + return &_data.u64; + } else { + return nullptr; + } + } + + /// Return a pointer to i8 if the union is in that state, otherwise `nullptr`. + const std::vector* get_i8() const { + if (_tag == detail::TensorBufferTag::I8) { + return &_data.i8; + } else { + return nullptr; + } + } + + /// Return a pointer to i16 if the union is in that state, otherwise `nullptr`. + const std::vector* get_i16() const { + if (_tag == detail::TensorBufferTag::I16) { + return &_data.i16; + } else { + return nullptr; + } + } + + /// Return a pointer to i32 if the union is in that state, otherwise `nullptr`. + const std::vector* get_i32() const { + if (_tag == detail::TensorBufferTag::I32) { + return &_data.i32; + } else { + return nullptr; + } + } + + /// Return a pointer to i64 if the union is in that state, otherwise `nullptr`. + const std::vector* get_i64() const { + if (_tag == detail::TensorBufferTag::I64) { + return &_data.i64; + } else { + return nullptr; + } + } + + /// Return a pointer to f16 if the union is in that state, otherwise `nullptr`. + const std::vector* get_f16() const { + if (_tag == detail::TensorBufferTag::F16) { + return &_data.f16; + } else { + return nullptr; + } + } + + /// Return a pointer to f32 if the union is in that state, otherwise `nullptr`. + const std::vector* get_f32() const { + if (_tag == detail::TensorBufferTag::F32) { + return &_data.f32; + } else { + return nullptr; + } + } + + /// Return a pointer to f64 if the union is in that state, otherwise `nullptr`. + const std::vector* get_f64() const { + if (_tag == detail::TensorBufferTag::F64) { + return &_data.f64; + } else { + return nullptr; + } + } + + /// Return a pointer to jpeg if the union is in that state, otherwise `nullptr`. + const std::vector* get_jpeg() const { + if (_tag == detail::TensorBufferTag::JPEG) { + return &_data.jpeg; + } else { + return nullptr; + } + } + + /// Return a pointer to nv12 if the union is in that state, otherwise `nullptr`. + const std::vector* get_nv12() const { + if (_tag == detail::TensorBufferTag::NV12) { + return &_data.nv12; + } else { + return nullptr; + } + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const TensorBuffer* elements, size_t num_elements + ); + + private: + detail::TensorBufferTag _tag; + detail::TensorBufferData _data; + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/tensor_data.cpp b/rerun_cpp/src/rerun/datatypes/tensor_data.cpp index 22c4cd1c9e19..b1afb1676a43 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_data.cpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_data.cpp @@ -9,97 +9,85 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& TensorData::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field( - "shape", - arrow::list(arrow::field( - "item", - rerun::datatypes::TensorDimension::arrow_datatype(), - false - )), - false +namespace rerun::datatypes { + const std::shared_ptr& TensorData::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field( + "shape", + arrow::list( + arrow::field("item", rerun::datatypes::TensorDimension::arrow_datatype(), false) ), - arrow::field("buffer", rerun::datatypes::TensorBuffer::arrow_datatype(), false), - }); - return datatype; + false + ), + arrow::field("buffer", rerun::datatypes::TensorBuffer::arrow_datatype(), false), + }); + return datatype; + } + + Result> TensorData::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> TensorData::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared( + memory_pool, + rerun::datatypes::TensorDimension::new_arrow_array_builder(memory_pool).value + ), + rerun::datatypes::TensorBuffer::new_arrow_array_builder(memory_pool).value, + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared( - memory_pool, - rerun::datatypes::TensorDimension::new_arrow_array_builder(memory_pool) - .value - ), - rerun::datatypes::TensorBuffer::new_arrow_array_builder(memory_pool).value, - }) - )); + rerun::Error TensorData::fill_arrow_array_builder( + arrow::StructBuilder* builder, const TensorData* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error TensorData::fill_arrow_array_builder( - arrow::StructBuilder* builder, const TensorData* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + { + auto field_builder = static_cast(builder->field_builder(0)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(field_builder->Append()); - if (element.shape.data()) { - RR_RETURN_NOT_OK( - rerun::datatypes::TensorDimension::fill_arrow_array_builder( - value_builder, - element.shape.data(), - element.shape.size() - ) - ); - } - } - } - { - auto field_builder = - static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::TensorBuffer::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].buffer, - 1 + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(field_builder->Append()); + if (element.shape.data()) { + RR_RETURN_NOT_OK(rerun::datatypes::TensorDimension::fill_arrow_array_builder( + value_builder, + element.shape.data(), + element.shape.size() )); } } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::TensorBuffer::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].buffer, + 1 + )); + } + } + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/tensor_data.hpp b/rerun_cpp/src/rerun/datatypes/tensor_data.hpp index 99837b580e2f..89ea0b8cbf44 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_data.hpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_data.hpp @@ -17,46 +17,44 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A multi-dimensional `Tensor` of data. - /// - /// The number of dimensions and their respective lengths is specified by the `shape` field. - /// The dimensions are ordered from outermost to innermost. For example, in the common case of - /// a 2D RGB Image, the shape would be `[height, width, channel]`. - /// - /// These dimensions are combined with an index to look up values from the `buffer` field, - /// which stores a contiguous array of typed values. - struct TensorData { - std::vector shape; - - rerun::datatypes::TensorBuffer buffer; - - public: - // Extensions to generated type defined in 'tensor_data_ext.cpp' - - // TODO(#3794): There should be the option to not have TensorData take ownership of the buffer. - TensorData( - std::vector shape_, - rerun::datatypes::TensorBuffer buffer_ - ) - : shape(std::move(shape_)), buffer(std::move(buffer_)) {} - - public: - TensorData() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const TensorData* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A multi-dimensional `Tensor` of data. + /// + /// The number of dimensions and their respective lengths is specified by the `shape` field. + /// The dimensions are ordered from outermost to innermost. For example, in the common case of + /// a 2D RGB Image, the shape would be `[height, width, channel]`. + /// + /// These dimensions are combined with an index to look up values from the `buffer` field, + /// which stores a contiguous array of typed values. + struct TensorData { + std::vector shape; + + rerun::datatypes::TensorBuffer buffer; + + public: + // Extensions to generated type defined in 'tensor_data_ext.cpp' + + // TODO(#3794): There should be the option to not have TensorData take ownership of the buffer. + TensorData( + std::vector shape_, + rerun::datatypes::TensorBuffer buffer_ + ) + : shape(std::move(shape_)), buffer(std::move(buffer_)) {} + + public: + TensorData() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const TensorData* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/tensor_dimension.cpp b/rerun_cpp/src/rerun/datatypes/tensor_dimension.cpp index dba86595c94f..1398d2464772 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_dimension.cpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_dimension.cpp @@ -6,71 +6,66 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& TensorDimension::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("size", arrow::uint64(), false), - arrow::field("name", arrow::utf8(), true), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& TensorDimension::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("size", arrow::uint64(), false), + arrow::field("name", arrow::utf8(), true), + }); + return datatype; + } + + Result> TensorDimension::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> TensorDimension::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared(memory_pool), + std::make_shared(memory_pool), + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared(memory_pool), - std::make_shared(memory_pool), - }) - )); + rerun::Error TensorDimension::fill_arrow_array_builder( + arrow::StructBuilder* builder, const TensorDimension* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error TensorDimension::fill_arrow_array_builder( - arrow::StructBuilder* builder, const TensorDimension* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].size)); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].size)); } - { - auto field_builder = static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.name.has_value()) { - ARROW_RETURN_NOT_OK(field_builder->Append(element.name.value())); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + } + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.name.has_value()) { + ARROW_RETURN_NOT_OK(field_builder->Append(element.name.value())); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/tensor_dimension.hpp b/rerun_cpp/src/rerun/datatypes/tensor_dimension.hpp index 571f4b1dbbb0..17c90a97ec26 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_dimension.hpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_dimension.hpp @@ -16,41 +16,38 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A single dimension within a multi-dimensional tensor. - struct TensorDimension { - /// The length of this dimension. - uint64_t size; - - /// The name of this dimension, e.g. "width", "height", "channel", "batch', …. - std::optional name; - - public: - // Extensions to generated type defined in 'tensor_dimension_ext.cpp' - - /// Nameless dimension. - TensorDimension(size_t size_) : size(size_) {} - - /// Dimension with name. - TensorDimension(size_t size_, std::string name_) - : size(size_), name(std::move(name_)) {} - - public: - TensorDimension() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const TensorDimension* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A single dimension within a multi-dimensional tensor. + struct TensorDimension { + /// The length of this dimension. + uint64_t size; + + /// The name of this dimension, e.g. "width", "height", "channel", "batch', …. + std::optional name; + + public: + // Extensions to generated type defined in 'tensor_dimension_ext.cpp' + + /// Nameless dimension. + TensorDimension(size_t size_) : size(size_) {} + + /// Dimension with name. + TensorDimension(size_t size_, std::string name_) : size(size_), name(std::move(name_)) {} + + public: + TensorDimension() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const TensorDimension* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/transform3d.cpp b/rerun_cpp/src/rerun/datatypes/transform3d.cpp index 7c45f0bf9f01..2b8131c6156d 100644 --- a/rerun_cpp/src/rerun/datatypes/transform3d.cpp +++ b/rerun_cpp/src/rerun/datatypes/transform3d.cpp @@ -9,102 +9,94 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Transform3D::arrow_datatype() { - static const auto datatype = arrow::dense_union({ - arrow::field("_null_markers", arrow::null(), true, nullptr), - arrow::field( - "TranslationAndMat3x3", - rerun::datatypes::TranslationAndMat3x3::arrow_datatype(), - false - ), - arrow::field( - "TranslationRotationScale", - rerun::datatypes::TranslationRotationScale3D::arrow_datatype(), - false - ), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Transform3D::arrow_datatype() { + static const auto datatype = arrow::dense_union({ + arrow::field("_null_markers", arrow::null(), true, nullptr), + arrow::field( + "TranslationAndMat3x3", + rerun::datatypes::TranslationAndMat3x3::arrow_datatype(), + false + ), + arrow::field( + "TranslationRotationScale", + rerun::datatypes::TranslationRotationScale3D::arrow_datatype(), + false + ), + }); + return datatype; + } + + Result> Transform3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Transform3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + // Children: + std::vector>({ + std::make_shared(memory_pool), + rerun::datatypes::TranslationAndMat3x3::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::TranslationRotationScale3D::new_arrow_array_builder(memory_pool) + .value, + }), + arrow_datatype() + )); + } - return Result(std::make_shared( - memory_pool, - // Children: - std::vector>({ - std::make_shared(memory_pool), - rerun::datatypes::TranslationAndMat3x3::new_arrow_array_builder(memory_pool) - .value, - rerun::datatypes::TranslationRotationScale3D::new_arrow_array_builder( - memory_pool - ) - .value, - }), - arrow_datatype() - )); + rerun::Error Transform3D::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Transform3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error Transform3D::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Transform3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& union_instance = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& union_instance = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); - auto variant_index = static_cast(union_instance._tag); - auto variant_builder_untyped = builder->child_builder(variant_index).get(); + auto variant_index = static_cast(union_instance._tag); + auto variant_builder_untyped = builder->child_builder(variant_index).get(); - switch (union_instance._tag) { - case detail::Transform3DTag::None: { - ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); - } break; - case detail::Transform3DTag::TranslationAndMat3x3: { - auto variant_builder = - static_cast(variant_builder_untyped); - RR_RETURN_NOT_OK( - rerun::datatypes::TranslationAndMat3x3::fill_arrow_array_builder( - variant_builder, - &union_instance._data.translation_and_mat3x3, - 1 - ) - ); - } break; - case detail::Transform3DTag::TranslationRotationScale: { - auto variant_builder = - static_cast(variant_builder_untyped); - RR_RETURN_NOT_OK( - rerun::datatypes::TranslationRotationScale3D::fill_arrow_array_builder( - variant_builder, - &union_instance._data.translation_rotation_scale, - 1 - ) - ); - } break; - } + switch (union_instance._tag) { + case detail::Transform3DTag::None: { + ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); + } break; + case detail::Transform3DTag::TranslationAndMat3x3: { + auto variant_builder = + static_cast(variant_builder_untyped); + RR_RETURN_NOT_OK( + rerun::datatypes::TranslationAndMat3x3::fill_arrow_array_builder( + variant_builder, + &union_instance._data.translation_and_mat3x3, + 1 + ) + ); + } break; + case detail::Transform3DTag::TranslationRotationScale: { + auto variant_builder = + static_cast(variant_builder_untyped); + RR_RETURN_NOT_OK( + rerun::datatypes::TranslationRotationScale3D::fill_arrow_array_builder( + variant_builder, + &union_instance._data.translation_rotation_scale, + 1 + ) + ); + } break; } - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/transform3d.hpp b/rerun_cpp/src/rerun/datatypes/transform3d.hpp index af4bd48d0b1d..1408dc3cb16a 100644 --- a/rerun_cpp/src/rerun/datatypes/transform3d.hpp +++ b/rerun_cpp/src/rerun/datatypes/transform3d.hpp @@ -19,139 +19,133 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - namespace detail { - /// \private - enum class Transform3DTag : uint8_t { - /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. - None = 0, - TranslationAndMat3x3, - TranslationRotationScale, - }; - - /// \private - union Transform3DData { - rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3; - - rerun::datatypes::TranslationRotationScale3D translation_rotation_scale; - - Transform3DData() { - std::memset(reinterpret_cast(this), 0, sizeof(Transform3DData)); - } - - ~Transform3DData() {} - - void swap(Transform3DData& other) noexcept { - // This bitwise swap would fail for self-referential types, but we don't have any of those. - char temp[sizeof(Transform3DData)]; - void* otherbytes = reinterpret_cast(&other); - void* thisbytes = reinterpret_cast(this); - std::memcpy(temp, thisbytes, sizeof(Transform3DData)); - std::memcpy(thisbytes, otherbytes, sizeof(Transform3DData)); - std::memcpy(otherbytes, temp, sizeof(Transform3DData)); - } - }; - } // namespace detail - - /// **Datatype**: Representation of a 3D affine transform. - struct Transform3D { - Transform3D() : _tag(detail::Transform3DTag::None) {} - - /// Copy constructor - Transform3D(const Transform3D& other) : _tag(other._tag) { - const void* otherbytes = reinterpret_cast(&other._data); - void* thisbytes = reinterpret_cast(&this->_data); - std::memcpy(thisbytes, otherbytes, sizeof(detail::Transform3DData)); - } - - Transform3D& operator=(const Transform3D& other) noexcept { - Transform3D tmp(other); - this->swap(tmp); - return *this; - } - - Transform3D(Transform3D&& other) noexcept : Transform3D() { - this->swap(other); - } +namespace rerun::datatypes { + namespace detail { + /// \private + enum class Transform3DTag : uint8_t { + /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. + None = 0, + TranslationAndMat3x3, + TranslationRotationScale, + }; - Transform3D& operator=(Transform3D&& other) noexcept { - this->swap(other); - return *this; - } + /// \private + union Transform3DData { + rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3; - void swap(Transform3D& other) noexcept { - std::swap(this->_tag, other._tag); - this->_data.swap(other._data); - } + rerun::datatypes::TranslationRotationScale3D translation_rotation_scale; - Transform3D(rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3) - : Transform3D() { - *this = Transform3D::translation_and_mat3x3(std::move(translation_and_mat3x3)); + Transform3DData() { + std::memset(reinterpret_cast(this), 0, sizeof(Transform3DData)); } - Transform3D(rerun::datatypes::TranslationRotationScale3D translation_rotation_scale) - : Transform3D() { - *this = - Transform3D::translation_rotation_scale(std::move(translation_rotation_scale)); - } + ~Transform3DData() {} - static Transform3D translation_and_mat3x3( - rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3 - ) { - Transform3D self; - self._tag = detail::Transform3DTag::TranslationAndMat3x3; - new (&self._data.translation_and_mat3x3) - rerun::datatypes::TranslationAndMat3x3(std::move(translation_and_mat3x3)); - return self; + void swap(Transform3DData& other) noexcept { + // This bitwise swap would fail for self-referential types, but we don't have any of those. + char temp[sizeof(Transform3DData)]; + void* otherbytes = reinterpret_cast(&other); + void* thisbytes = reinterpret_cast(this); + std::memcpy(temp, thisbytes, sizeof(Transform3DData)); + std::memcpy(thisbytes, otherbytes, sizeof(Transform3DData)); + std::memcpy(otherbytes, temp, sizeof(Transform3DData)); } - - static Transform3D translation_rotation_scale( - rerun::datatypes::TranslationRotationScale3D translation_rotation_scale - ) { - Transform3D self; - self._tag = detail::Transform3DTag::TranslationRotationScale; - new (&self._data.translation_rotation_scale - ) rerun::datatypes::TranslationRotationScale3D(std::move(translation_rotation_scale) - ); - return self; + }; + } // namespace detail + + /// **Datatype**: Representation of a 3D affine transform. + struct Transform3D { + Transform3D() : _tag(detail::Transform3DTag::None) {} + + /// Copy constructor + Transform3D(const Transform3D& other) : _tag(other._tag) { + const void* otherbytes = reinterpret_cast(&other._data); + void* thisbytes = reinterpret_cast(&this->_data); + std::memcpy(thisbytes, otherbytes, sizeof(detail::Transform3DData)); + } + + Transform3D& operator=(const Transform3D& other) noexcept { + Transform3D tmp(other); + this->swap(tmp); + return *this; + } + + Transform3D(Transform3D&& other) noexcept : Transform3D() { + this->swap(other); + } + + Transform3D& operator=(Transform3D&& other) noexcept { + this->swap(other); + return *this; + } + + void swap(Transform3D& other) noexcept { + std::swap(this->_tag, other._tag); + this->_data.swap(other._data); + } + + Transform3D(rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3) : Transform3D() { + *this = Transform3D::translation_and_mat3x3(std::move(translation_and_mat3x3)); + } + + Transform3D(rerun::datatypes::TranslationRotationScale3D translation_rotation_scale) + : Transform3D() { + *this = Transform3D::translation_rotation_scale(std::move(translation_rotation_scale)); + } + + static Transform3D translation_and_mat3x3( + rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3 + ) { + Transform3D self; + self._tag = detail::Transform3DTag::TranslationAndMat3x3; + new (&self._data.translation_and_mat3x3) + rerun::datatypes::TranslationAndMat3x3(std::move(translation_and_mat3x3)); + return self; + } + + static Transform3D translation_rotation_scale( + rerun::datatypes::TranslationRotationScale3D translation_rotation_scale + ) { + Transform3D self; + self._tag = detail::Transform3DTag::TranslationRotationScale; + new (&self._data.translation_rotation_scale) + rerun::datatypes::TranslationRotationScale3D(std::move(translation_rotation_scale)); + return self; + } + + /// Return a pointer to translation_and_mat3x3 if the union is in that state, otherwise `nullptr`. + const rerun::datatypes::TranslationAndMat3x3* get_translation_and_mat3x3() const { + if (_tag == detail::Transform3DTag::TranslationAndMat3x3) { + return &_data.translation_and_mat3x3; + } else { + return nullptr; } - - /// Return a pointer to translation_and_mat3x3 if the union is in that state, otherwise `nullptr`. - const rerun::datatypes::TranslationAndMat3x3* get_translation_and_mat3x3() const { - if (_tag == detail::Transform3DTag::TranslationAndMat3x3) { - return &_data.translation_and_mat3x3; - } else { - return nullptr; - } + } + + /// Return a pointer to translation_rotation_scale if the union is in that state, otherwise `nullptr`. + const rerun::datatypes::TranslationRotationScale3D* get_translation_rotation_scale() const { + if (_tag == detail::Transform3DTag::TranslationRotationScale) { + return &_data.translation_rotation_scale; + } else { + return nullptr; } - - /// Return a pointer to translation_rotation_scale if the union is in that state, otherwise `nullptr`. - const rerun::datatypes::TranslationRotationScale3D* get_translation_rotation_scale( - ) const { - if (_tag == detail::Transform3DTag::TranslationRotationScale) { - return &_data.translation_rotation_scale; - } else { - return nullptr; - } - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const Transform3D* elements, size_t num_elements - ); - - private: - detail::Transform3DTag _tag; - detail::Transform3DData _data; - }; - } // namespace datatypes -} // namespace rerun + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const Transform3D* elements, size_t num_elements + ); + + private: + detail::Transform3DTag _tag; + detail::Transform3DData _data; + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.cpp b/rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.cpp index fa770110bd6a..8c1cd8d006a0 100644 --- a/rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.cpp +++ b/rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.cpp @@ -9,95 +9,90 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& TranslationAndMat3x3::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("translation", rerun::datatypes::Vec3D::arrow_datatype(), true), - arrow::field("mat3x3", rerun::datatypes::Mat3x3::arrow_datatype(), true), - arrow::field("from_parent", arrow::boolean(), false), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& TranslationAndMat3x3::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("translation", rerun::datatypes::Vec3D::arrow_datatype(), true), + arrow::field("mat3x3", rerun::datatypes::Mat3x3::arrow_datatype(), true), + arrow::field("from_parent", arrow::boolean(), false), + }); + return datatype; + } + + Result> TranslationAndMat3x3::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> TranslationAndMat3x3::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::Mat3x3::new_arrow_array_builder(memory_pool).value, + std::make_shared(memory_pool), + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value, - rerun::datatypes::Mat3x3::new_arrow_array_builder(memory_pool).value, - std::make_shared(memory_pool), - }) - )); + rerun::Error TranslationAndMat3x3::fill_arrow_array_builder( + arrow::StructBuilder* builder, const TranslationAndMat3x3* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error TranslationAndMat3x3::fill_arrow_array_builder( - arrow::StructBuilder* builder, const TranslationAndMat3x3* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = - static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.translation.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( - field_builder, - &element.translation.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + { + auto field_builder = + static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.translation.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( + field_builder, + &element.translation.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - { - auto field_builder = - static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.mat3x3.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::Mat3x3::fill_arrow_array_builder( - field_builder, - &element.mat3x3.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + } + { + auto field_builder = + static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.mat3x3.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::Mat3x3::fill_arrow_array_builder( + field_builder, + &element.mat3x3.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - { - auto field_builder = static_cast(builder->field_builder(2)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].from_parent)); - } + } + { + auto field_builder = static_cast(builder->field_builder(2)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].from_parent)); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.hpp b/rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.hpp index 24b7efd9c727..c2e5d108d21b 100644 --- a/rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.hpp +++ b/rerun_cpp/src/rerun/datatypes/translation_and_mat3x3.hpp @@ -17,74 +17,71 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: Representation of an affine transform via a 3x3 affine matrix paired with a translation. +namespace rerun::datatypes { + /// **Datatype**: Representation of an affine transform via a 3x3 affine matrix paired with a translation. + /// + /// First applies the matrix, then the translation. + struct TranslationAndMat3x3 { + /// 3D translation, applied after the matrix. + std::optional translation; + + /// 3x3 matrix for scale, rotation & shear. + std::optional mat3x3; + + /// If true, this transform is from the parent space to the space where the transform was logged. /// - /// First applies the matrix, then the translation. - struct TranslationAndMat3x3 { - /// 3D translation, applied after the matrix. - std::optional translation; - - /// 3x3 matrix for scale, rotation & shear. - std::optional mat3x3; - - /// If true, this transform is from the parent space to the space where the transform was logged. - /// - /// If false (default), the transform maps from this space to its parent, - /// i.e. the translation is the position in the parent space. - bool from_parent; - - public: - // Extensions to generated type defined in 'translation_and_mat3x3_ext.cpp' - - /// Identity transformation. - /// - /// Applying this transform does not alter an entity's transformation. - /// It has all optional fields set to `std::nullopt`. - static const TranslationAndMat3x3 IDENTITY; - - /// Creates a new 3D transform from translation/matrix. - /// - /// \param translation_ \copydoc TranslationAndMat3x3::translation - /// \param mat3x3_ \copydoc TranslationAndMat3x3::mat3x3 - /// \param from_parent_ \copydoc TranslationAndMat3x3::from_parent - TranslationAndMat3x3( - const std::optional& translation_, const std::optional& mat3x3_, - bool from_parent_ - ) - : translation(translation_), mat3x3(mat3x3_), from_parent(from_parent_) {} - - /// From rotation only. - /// - /// \param mat3x3_ \copydoc TranslationAndMat3x3::mat3x3 - /// \param from_parent_ \copydoc TranslationAndMat3x3::from_parent - TranslationAndMat3x3(const Mat3x3& mat3x3_, bool from_parent_ = false) - : translation(std::nullopt), mat3x3(mat3x3_), from_parent(from_parent_) {} - - /// From translation only. - /// - /// \param translation_ \copydoc TranslationAndMat3x3::translation - /// \param from_parent_ \copydoc TranslationAndMat3x3::from_parent - TranslationAndMat3x3(const Vec3D& translation_, bool from_parent_ = false) - : translation(translation_), mat3x3(std::nullopt), from_parent(from_parent_) {} - - public: - TranslationAndMat3x3() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const TranslationAndMat3x3* elements, - size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun + /// If false (default), the transform maps from this space to its parent, + /// i.e. the translation is the position in the parent space. + bool from_parent; + + public: + // Extensions to generated type defined in 'translation_and_mat3x3_ext.cpp' + + /// Identity transformation. + /// + /// Applying this transform does not alter an entity's transformation. + /// It has all optional fields set to `std::nullopt`. + static const TranslationAndMat3x3 IDENTITY; + + /// Creates a new 3D transform from translation/matrix. + /// + /// \param translation_ \copydoc TranslationAndMat3x3::translation + /// \param mat3x3_ \copydoc TranslationAndMat3x3::mat3x3 + /// \param from_parent_ \copydoc TranslationAndMat3x3::from_parent + TranslationAndMat3x3( + const std::optional& translation_, const std::optional& mat3x3_, + bool from_parent_ + ) + : translation(translation_), mat3x3(mat3x3_), from_parent(from_parent_) {} + + /// From rotation only. + /// + /// \param mat3x3_ \copydoc TranslationAndMat3x3::mat3x3 + /// \param from_parent_ \copydoc TranslationAndMat3x3::from_parent + TranslationAndMat3x3(const Mat3x3& mat3x3_, bool from_parent_ = false) + : translation(std::nullopt), mat3x3(mat3x3_), from_parent(from_parent_) {} + + /// From translation only. + /// + /// \param translation_ \copydoc TranslationAndMat3x3::translation + /// \param from_parent_ \copydoc TranslationAndMat3x3::from_parent + TranslationAndMat3x3(const Vec3D& translation_, bool from_parent_ = false) + : translation(translation_), mat3x3(std::nullopt), from_parent(from_parent_) {} + + public: + TranslationAndMat3x3() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const TranslationAndMat3x3* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.cpp b/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.cpp index f7f927847e3a..3c7b440d1ff9 100644 --- a/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.cpp +++ b/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.cpp @@ -10,114 +10,107 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& TranslationRotationScale3D::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("translation", rerun::datatypes::Vec3D::arrow_datatype(), true), - arrow::field("rotation", rerun::datatypes::Rotation3D::arrow_datatype(), true), - arrow::field("scale", rerun::datatypes::Scale3D::arrow_datatype(), true), - arrow::field("from_parent", arrow::boolean(), false), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& TranslationRotationScale3D::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("translation", rerun::datatypes::Vec3D::arrow_datatype(), true), + arrow::field("rotation", rerun::datatypes::Rotation3D::arrow_datatype(), true), + arrow::field("scale", rerun::datatypes::Scale3D::arrow_datatype(), true), + arrow::field("from_parent", arrow::boolean(), false), + }); + return datatype; + } + + Result> + TranslationRotationScale3D::new_arrow_array_builder(arrow::MemoryPool* memory_pool) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> - TranslationRotationScale3D::new_arrow_array_builder(arrow::MemoryPool* memory_pool) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::Rotation3D::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::Scale3D::new_arrow_array_builder(memory_pool).value, + std::make_shared(memory_pool), + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::Vec3D::new_arrow_array_builder(memory_pool).value, - rerun::datatypes::Rotation3D::new_arrow_array_builder(memory_pool).value, - rerun::datatypes::Scale3D::new_arrow_array_builder(memory_pool).value, - std::make_shared(memory_pool), - }) - )); + rerun::Error TranslationRotationScale3D::fill_arrow_array_builder( + arrow::StructBuilder* builder, const TranslationRotationScale3D* elements, + size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error TranslationRotationScale3D::fill_arrow_array_builder( - arrow::StructBuilder* builder, const TranslationRotationScale3D* elements, - size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = - static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.translation.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( - field_builder, - &element.translation.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + { + auto field_builder = + static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.translation.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::Vec3D::fill_arrow_array_builder( + field_builder, + &element.translation.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - { - auto field_builder = - static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.rotation.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::Rotation3D::fill_arrow_array_builder( - field_builder, - &element.rotation.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + } + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.rotation.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::Rotation3D::fill_arrow_array_builder( + field_builder, + &element.rotation.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - { - auto field_builder = - static_cast(builder->field_builder(2)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.scale.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::Scale3D::fill_arrow_array_builder( - field_builder, - &element.scale.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + } + { + auto field_builder = static_cast(builder->field_builder(2)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.scale.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::Scale3D::fill_arrow_array_builder( + field_builder, + &element.scale.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - { - auto field_builder = static_cast(builder->field_builder(3)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].from_parent)); - } + } + { + auto field_builder = static_cast(builder->field_builder(3)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].from_parent)); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.hpp b/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.hpp index 2a79493f0d9c..56716203dd4f 100644 --- a/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.hpp +++ b/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.hpp @@ -19,198 +19,195 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: Representation of an affine transform via separate translation, rotation & scale. - struct TranslationRotationScale3D { - /// 3D translation vector, applied last. - std::optional translation; - - /// 3D rotation, applied second. - std::optional rotation; - - /// 3D scale, applied first. - std::optional scale; - - /// If true, this transform is from the parent space to the space where the transform was logged. - /// - /// If false (default), the transform maps from this space to its parent, - /// i.e. the translation is the position in the parent space. - bool from_parent; - - public: - // Extensions to generated type defined in 'translation_rotation_scale3d_ext.cpp' - - /// Identity transformation. - /// - /// Applying this transform does not alter an entity's transformation. - /// It has all optional fields set to `std::nullopt`. - static const TranslationRotationScale3D IDENTITY; - - // Need to disable the maybe-uninitialized here because the compiler gets confused by the combination - // of union-types datatypes inside of an optional component. - // - // See: https://github.com/rerun-io/rerun/issues/4027 - DISABLE_MAYBE_UNINITIALIZED_PUSH - TranslationRotationScale3D(const TranslationRotationScale3D& other) - : translation(other.translation), - rotation(other.rotation), - scale(other.scale), - from_parent(other.from_parent) {} - - DISABLE_MAYBE_UNINITIALIZED_POP - - /// Creates a new 3D transform from translation/rotation/scale. - /// - /// \param translation_ \copydoc TranslationRotationScale3D::translation - /// \param rotation_ \copydoc TranslationRotationScale3D::rotation - /// \param scale_ \copydoc TranslationRotationScale3D::scale - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - TranslationRotationScale3D( - const std::optional& translation_, - const std::optional& rotation_, const std::optional& scale_, - bool from_parent_ = false - ) - : translation(translation_), - rotation(rotation_), - scale(scale_), - from_parent(from_parent_) {} - - /// Creates a new 3D transform from translation/rotation/uniform-scale. - /// - /// \param translation_ \copydoc TranslationRotationScale3D::translation - /// \param rotation_ \copydoc TranslationRotationScale3D::rotation - /// \param uniform_scale Uniform scale factor that is applied to all axis equally. - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - /// - /// _Implementation note:_ This explicit overload prevents interpretation of the float as - /// bool, leading to a call to the wrong overload. - TranslationRotationScale3D( - const Vec3D& translation_, const Rotation3D& rotation_, float uniform_scale, - bool from_parent_ = false - ) - : translation(translation_), - rotation(rotation_), - scale(uniform_scale), - from_parent(from_parent_) {} - - /// Creates a new rigid transform (translation & rotation only). - /// - /// \param translation_ \copydoc TranslationRotationScale3D::translation - /// \param rotation_ \copydoc TranslationRotationScale3D::rotation - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - TranslationRotationScale3D( - const Vec3D& translation_, const Rotation3D& rotation_, bool from_parent_ = false - ) - : translation(translation_), - rotation(rotation_), - scale(std::nullopt), - from_parent(from_parent_) {} - - /// From translation & scale only. - /// - /// \param translation_ \copydoc TranslationRotationScale3D::translation - /// \param scale_ \copydoc TranslationRotationScale3D::scale - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - TranslationRotationScale3D( - const Vec3D& translation_, const Scale3D& scale_, bool from_parent_ = false - ) - : translation(translation_), - rotation(std::nullopt), - scale(scale_), - from_parent(from_parent_) {} - - /// From translation & uniform scale. - /// - /// \param translation_ \copydoc TranslationRotationScale3D::translation - /// \param uniform_scale Uniform scale factor that is applied to all axis equally. - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - /// - /// _Implementation note:_ This explicit overload prevents interpretation of the float as - /// bool, leading to a call to the wrong overload. - TranslationRotationScale3D( - const Vec3D& translation_, float uniform_scale, bool from_parent_ = false - ) - : translation(translation_), - rotation(std::nullopt), - scale(uniform_scale), - from_parent(from_parent_) {} - - /// From rotation & scale only. - /// - /// \param rotation_ \copydoc TranslationRotationScale3D::rotation - /// \param scale_ \copydoc TranslationRotationScale3D::scale - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - TranslationRotationScale3D( - const Rotation3D& rotation_, const Scale3D& scale_, bool from_parent_ = false - ) - : translation(std::nullopt), - rotation(rotation_), - scale(scale_), - from_parent(from_parent_) {} - - /// From rotation & uniform scale. - /// - /// \param rotation_ \copydoc TranslationRotationScale3D::rotation - /// \param uniform_scale Uniform scale factor that is applied to all axis equally. - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - /// - /// _Implementation note:_ This explicit overload prevents interpretation of the float as - /// bool, leading to a call to the wrong overload. - TranslationRotationScale3D( - const Rotation3D& rotation_, float uniform_scale, bool from_parent_ = false - ) - : translation(std::nullopt), - rotation(rotation_), - scale(uniform_scale), - from_parent(from_parent_) {} - - /// From translation only. - /// - /// \param translation_ 3D translation. - /// \param from_parent_ - TranslationRotationScale3D(const Vec3D& translation_, bool from_parent_ = false) - : translation(translation_), - rotation(std::nullopt), - scale(std::nullopt), - from_parent(from_parent_) {} - - /// From rotation only. - /// - /// \param rotation_ \copydoc TranslationRotationScale3D::rotation - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - TranslationRotationScale3D(const Rotation3D& rotation_, bool from_parent_ = false) - : translation(std::nullopt), - rotation(rotation_), - scale(std::nullopt), - from_parent(from_parent_) {} - - /// From scale only. - /// - /// \param scale_ \copydoc TranslationRotationScale3D::scale - /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent - TranslationRotationScale3D(const Scale3D& scale_, bool from_parent_ = false) - : translation(std::nullopt), - rotation(std::nullopt), - scale(scale_), - from_parent(from_parent_) {} - - public: - TranslationRotationScale3D() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const TranslationRotationScale3D* elements, - size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: Representation of an affine transform via separate translation, rotation & scale. + struct TranslationRotationScale3D { + /// 3D translation vector, applied last. + std::optional translation; + + /// 3D rotation, applied second. + std::optional rotation; + + /// 3D scale, applied first. + std::optional scale; + + /// If true, this transform is from the parent space to the space where the transform was logged. + /// + /// If false (default), the transform maps from this space to its parent, + /// i.e. the translation is the position in the parent space. + bool from_parent; + + public: + // Extensions to generated type defined in 'translation_rotation_scale3d_ext.cpp' + + /// Identity transformation. + /// + /// Applying this transform does not alter an entity's transformation. + /// It has all optional fields set to `std::nullopt`. + static const TranslationRotationScale3D IDENTITY; + + // Need to disable the maybe-uninitialized here because the compiler gets confused by the combination + // of union-types datatypes inside of an optional component. + // + // See: https://github.com/rerun-io/rerun/issues/4027 + DISABLE_MAYBE_UNINITIALIZED_PUSH + TranslationRotationScale3D(const TranslationRotationScale3D& other) + : translation(other.translation), + rotation(other.rotation), + scale(other.scale), + from_parent(other.from_parent) {} + + DISABLE_MAYBE_UNINITIALIZED_POP + + /// Creates a new 3D transform from translation/rotation/scale. + /// + /// \param translation_ \copydoc TranslationRotationScale3D::translation + /// \param rotation_ \copydoc TranslationRotationScale3D::rotation + /// \param scale_ \copydoc TranslationRotationScale3D::scale + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + TranslationRotationScale3D( + const std::optional& translation_, const std::optional& rotation_, + const std::optional& scale_, bool from_parent_ = false + ) + : translation(translation_), + rotation(rotation_), + scale(scale_), + from_parent(from_parent_) {} + + /// Creates a new 3D transform from translation/rotation/uniform-scale. + /// + /// \param translation_ \copydoc TranslationRotationScale3D::translation + /// \param rotation_ \copydoc TranslationRotationScale3D::rotation + /// \param uniform_scale Uniform scale factor that is applied to all axis equally. + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + /// + /// _Implementation note:_ This explicit overload prevents interpretation of the float as + /// bool, leading to a call to the wrong overload. + TranslationRotationScale3D( + const Vec3D& translation_, const Rotation3D& rotation_, float uniform_scale, + bool from_parent_ = false + ) + : translation(translation_), + rotation(rotation_), + scale(uniform_scale), + from_parent(from_parent_) {} + + /// Creates a new rigid transform (translation & rotation only). + /// + /// \param translation_ \copydoc TranslationRotationScale3D::translation + /// \param rotation_ \copydoc TranslationRotationScale3D::rotation + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + TranslationRotationScale3D( + const Vec3D& translation_, const Rotation3D& rotation_, bool from_parent_ = false + ) + : translation(translation_), + rotation(rotation_), + scale(std::nullopt), + from_parent(from_parent_) {} + + /// From translation & scale only. + /// + /// \param translation_ \copydoc TranslationRotationScale3D::translation + /// \param scale_ \copydoc TranslationRotationScale3D::scale + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + TranslationRotationScale3D( + const Vec3D& translation_, const Scale3D& scale_, bool from_parent_ = false + ) + : translation(translation_), + rotation(std::nullopt), + scale(scale_), + from_parent(from_parent_) {} + + /// From translation & uniform scale. + /// + /// \param translation_ \copydoc TranslationRotationScale3D::translation + /// \param uniform_scale Uniform scale factor that is applied to all axis equally. + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + /// + /// _Implementation note:_ This explicit overload prevents interpretation of the float as + /// bool, leading to a call to the wrong overload. + TranslationRotationScale3D( + const Vec3D& translation_, float uniform_scale, bool from_parent_ = false + ) + : translation(translation_), + rotation(std::nullopt), + scale(uniform_scale), + from_parent(from_parent_) {} + + /// From rotation & scale only. + /// + /// \param rotation_ \copydoc TranslationRotationScale3D::rotation + /// \param scale_ \copydoc TranslationRotationScale3D::scale + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + TranslationRotationScale3D( + const Rotation3D& rotation_, const Scale3D& scale_, bool from_parent_ = false + ) + : translation(std::nullopt), + rotation(rotation_), + scale(scale_), + from_parent(from_parent_) {} + + /// From rotation & uniform scale. + /// + /// \param rotation_ \copydoc TranslationRotationScale3D::rotation + /// \param uniform_scale Uniform scale factor that is applied to all axis equally. + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + /// + /// _Implementation note:_ This explicit overload prevents interpretation of the float as + /// bool, leading to a call to the wrong overload. + TranslationRotationScale3D( + const Rotation3D& rotation_, float uniform_scale, bool from_parent_ = false + ) + : translation(std::nullopt), + rotation(rotation_), + scale(uniform_scale), + from_parent(from_parent_) {} + + /// From translation only. + /// + /// \param translation_ 3D translation. + /// \param from_parent_ + TranslationRotationScale3D(const Vec3D& translation_, bool from_parent_ = false) + : translation(translation_), + rotation(std::nullopt), + scale(std::nullopt), + from_parent(from_parent_) {} + + /// From rotation only. + /// + /// \param rotation_ \copydoc TranslationRotationScale3D::rotation + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + TranslationRotationScale3D(const Rotation3D& rotation_, bool from_parent_ = false) + : translation(std::nullopt), + rotation(rotation_), + scale(std::nullopt), + from_parent(from_parent_) {} + + /// From scale only. + /// + /// \param scale_ \copydoc TranslationRotationScale3D::scale + /// \param from_parent_ \copydoc TranslationRotationScale3D::from_parent + TranslationRotationScale3D(const Scale3D& scale_, bool from_parent_ = false) + : translation(std::nullopt), + rotation(std::nullopt), + scale(scale_), + from_parent(from_parent_) {} + + public: + TranslationRotationScale3D() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const TranslationRotationScale3D* elements, + size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/uint32.cpp b/rerun_cpp/src/rerun/datatypes/uint32.cpp index 13c462d0c531..4a6f46942998 100644 --- a/rerun_cpp/src/rerun/datatypes/uint32.cpp +++ b/rerun_cpp/src/rerun/datatypes/uint32.cpp @@ -6,45 +6,40 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& UInt32::arrow_datatype() { - static const auto datatype = arrow::uint32(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& UInt32::arrow_datatype() { + static const auto datatype = arrow::uint32(); + return datatype; + } + + Result> UInt32::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> UInt32::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error UInt32::fill_arrow_array_builder( + arrow::UInt32Builder* builder, const UInt32* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error UInt32::fill_arrow_array_builder( - arrow::UInt32Builder* builder, const UInt32* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(*elements) == sizeof(elements->value)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->value, static_cast(num_elements)) + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + static_assert(sizeof(*elements) == sizeof(elements->value)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->value, static_cast(num_elements)) + ); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/uint32.hpp b/rerun_cpp/src/rerun/datatypes/uint32.hpp index 95304f62e449..adaecd73e806 100644 --- a/rerun_cpp/src/rerun/datatypes/uint32.hpp +++ b/rerun_cpp/src/rerun/datatypes/uint32.hpp @@ -19,34 +19,32 @@ namespace arrow { using UInt32Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A 32bit unsigned integer. - struct UInt32 { - uint32_t value; - - public: - UInt32() = default; - - UInt32(uint32_t value_) : value(value_) {} - - UInt32& operator=(uint32_t value_) { - value = value_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::UInt32Builder* builder, const UInt32* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A 32bit unsigned integer. + struct UInt32 { + uint32_t value; + + public: + UInt32() = default; + + UInt32(uint32_t value_) : value(value_) {} + + UInt32& operator=(uint32_t value_) { + value = value_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::UInt32Builder* builder, const UInt32* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/utf8.cpp b/rerun_cpp/src/rerun/datatypes/utf8.cpp index 69af802da91d..c21a1dc00b39 100644 --- a/rerun_cpp/src/rerun/datatypes/utf8.cpp +++ b/rerun_cpp/src/rerun/datatypes/utf8.cpp @@ -6,45 +6,40 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Utf8::arrow_datatype() { - static const auto datatype = arrow::utf8(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Utf8::arrow_datatype() { + static const auto datatype = arrow::utf8(); + return datatype; + } + + Result> Utf8::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Utf8::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error Utf8::fill_arrow_array_builder( + arrow::StringBuilder* builder, const Utf8* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error Utf8::fill_arrow_array_builder( - arrow::StringBuilder* builder, const Utf8* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(builder->Append(elements[elem_idx].value)); - } - - return Error::ok(); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(builder->Append(elements[elem_idx].value)); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/utf8.hpp b/rerun_cpp/src/rerun/datatypes/utf8.hpp index c39d6a08d59a..78aa0a81e788 100644 --- a/rerun_cpp/src/rerun/datatypes/utf8.hpp +++ b/rerun_cpp/src/rerun/datatypes/utf8.hpp @@ -16,44 +16,42 @@ namespace arrow { class StringBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A string of text, encoded as UTF-8. - struct Utf8 { - std::string value; - - public: - // Extensions to generated type defined in 'utf8_ext.cpp' - - /// Construct a `Utf8` from null-terminated UTF-8. - Utf8(const char* str) : value(str) {} - - const char* c_str() const { - return value.c_str(); - } - - public: - Utf8() = default; - - Utf8(std::string value_) : value(std::move(value_)) {} - - Utf8& operator=(std::string value_) { - value = std::move(value_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StringBuilder* builder, const Utf8* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A string of text, encoded as UTF-8. + struct Utf8 { + std::string value; + + public: + // Extensions to generated type defined in 'utf8_ext.cpp' + + /// Construct a `Utf8` from null-terminated UTF-8. + Utf8(const char* str) : value(str) {} + + const char* c_str() const { + return value.c_str(); + } + + public: + Utf8() = default; + + Utf8(std::string value_) : value(std::move(value_)) {} + + Utf8& operator=(std::string value_) { + value = std::move(value_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StringBuilder* builder, const Utf8* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/uvec2d.cpp b/rerun_cpp/src/rerun/datatypes/uvec2d.cpp index e94df3f766b0..485591d55285 100644 --- a/rerun_cpp/src/rerun/datatypes/uvec2d.cpp +++ b/rerun_cpp/src/rerun/datatypes/uvec2d.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& UVec2D::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::uint32(), false), 2); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& UVec2D::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::uint32(), false), 2); + return datatype; + } + + Result> UVec2D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> UVec2D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 2 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 2 + )); + } + + rerun::Error UVec2D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const UVec2D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error UVec2D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const UVec2D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].xy) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].xy.data(), - static_cast(num_elements * 2), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].xy) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].xy.data(), + static_cast(num_elements * 2), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/uvec2d.hpp b/rerun_cpp/src/rerun/datatypes/uvec2d.hpp index fe6987a78bbe..2428a407766f 100644 --- a/rerun_cpp/src/rerun/datatypes/uvec2d.hpp +++ b/rerun_cpp/src/rerun/datatypes/uvec2d.hpp @@ -15,34 +15,32 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A uint32 vector in 2D space. - struct UVec2D { - std::array xy; - - public: - UVec2D() = default; - - UVec2D(std::array xy_) : xy(xy_) {} - - UVec2D& operator=(std::array xy_) { - xy = xy_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const UVec2D* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A uint32 vector in 2D space. + struct UVec2D { + std::array xy; + + public: + UVec2D() = default; + + UVec2D(std::array xy_) : xy(xy_) {} + + UVec2D& operator=(std::array xy_) { + xy = xy_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const UVec2D* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/uvec3d.cpp b/rerun_cpp/src/rerun/datatypes/uvec3d.cpp index 33f3ec9217bc..f0e3f4ba392c 100644 --- a/rerun_cpp/src/rerun/datatypes/uvec3d.cpp +++ b/rerun_cpp/src/rerun/datatypes/uvec3d.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& UVec3D::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::uint32(), false), 3); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& UVec3D::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::uint32(), false), 3); + return datatype; + } + + Result> UVec3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> UVec3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 3 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 3 + )); + } + + rerun::Error UVec3D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const UVec3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error UVec3D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const UVec3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].xyz) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].xyz.data(), - static_cast(num_elements * 3), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].xyz) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].xyz.data(), + static_cast(num_elements * 3), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/uvec3d.hpp b/rerun_cpp/src/rerun/datatypes/uvec3d.hpp index 1cb040409cc1..b506f836b6af 100644 --- a/rerun_cpp/src/rerun/datatypes/uvec3d.hpp +++ b/rerun_cpp/src/rerun/datatypes/uvec3d.hpp @@ -15,34 +15,32 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A uint32 vector in 3D space. - struct UVec3D { - std::array xyz; - - public: - UVec3D() = default; - - UVec3D(std::array xyz_) : xyz(xyz_) {} - - UVec3D& operator=(std::array xyz_) { - xyz = xyz_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const UVec3D* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A uint32 vector in 3D space. + struct UVec3D { + std::array xyz; + + public: + UVec3D() = default; + + UVec3D(std::array xyz_) : xyz(xyz_) {} + + UVec3D& operator=(std::array xyz_) { + xyz = xyz_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const UVec3D* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/uvec4d.cpp b/rerun_cpp/src/rerun/datatypes/uvec4d.cpp index 58ea017b650c..de09014811ed 100644 --- a/rerun_cpp/src/rerun/datatypes/uvec4d.cpp +++ b/rerun_cpp/src/rerun/datatypes/uvec4d.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& UVec4D::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::uint32(), false), 4); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& UVec4D::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::uint32(), false), 4); + return datatype; + } + + Result> UVec4D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> UVec4D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 4 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 4 + )); + } + + rerun::Error UVec4D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const UVec4D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error UVec4D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const UVec4D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].xyzw) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].xyzw.data(), - static_cast(num_elements * 4), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].xyzw) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].xyzw.data(), + static_cast(num_elements * 4), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/uvec4d.hpp b/rerun_cpp/src/rerun/datatypes/uvec4d.hpp index 636c1e3311df..3109f405da1d 100644 --- a/rerun_cpp/src/rerun/datatypes/uvec4d.hpp +++ b/rerun_cpp/src/rerun/datatypes/uvec4d.hpp @@ -15,34 +15,32 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A uint vector in 4D space. - struct UVec4D { - std::array xyzw; - - public: - UVec4D() = default; - - UVec4D(std::array xyzw_) : xyzw(xyzw_) {} - - UVec4D& operator=(std::array xyzw_) { - xyzw = xyzw_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const UVec4D* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A uint vector in 4D space. + struct UVec4D { + std::array xyzw; + + public: + UVec4D() = default; + + UVec4D(std::array xyzw_) : xyzw(xyzw_) {} + + UVec4D& operator=(std::array xyzw_) { + xyzw = xyzw_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const UVec4D* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/vec2d.cpp b/rerun_cpp/src/rerun/datatypes/vec2d.cpp index 9683a1bd749f..a006903c2bb7 100644 --- a/rerun_cpp/src/rerun/datatypes/vec2d.cpp +++ b/rerun_cpp/src/rerun/datatypes/vec2d.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Vec2D::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 2); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Vec2D::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 2); + return datatype; + } + + Result> Vec2D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Vec2D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 2 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 2 + )); + } + + rerun::Error Vec2D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Vec2D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error Vec2D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Vec2D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].xy) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].xy.data(), - static_cast(num_elements * 2), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].xy) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].xy.data(), + static_cast(num_elements * 2), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/vec2d.hpp b/rerun_cpp/src/rerun/datatypes/vec2d.hpp index 07de9ac8bbbe..e214f6272ee6 100644 --- a/rerun_cpp/src/rerun/datatypes/vec2d.hpp +++ b/rerun_cpp/src/rerun/datatypes/vec2d.hpp @@ -15,51 +15,49 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A vector in 2D space. - struct Vec2D { - std::array xy; - - public: - // Extensions to generated type defined in 'vec2d_ext.cpp' - - /// Construct Vec2D from x/y values. - Vec2D(float x, float y) : xy{x, y} {} - - /// Construct Vec2D from x/y float pointer. - explicit Vec2D(const float* xy_) : xy{xy_[0], xy_[1]} {} - - float x() const { - return xy[0]; - } - - float y() const { - return xy[1]; - } - - public: - Vec2D() = default; - - Vec2D(std::array xy_) : xy(xy_) {} - - Vec2D& operator=(std::array xy_) { - xy = xy_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Vec2D* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A vector in 2D space. + struct Vec2D { + std::array xy; + + public: + // Extensions to generated type defined in 'vec2d_ext.cpp' + + /// Construct Vec2D from x/y values. + Vec2D(float x, float y) : xy{x, y} {} + + /// Construct Vec2D from x/y float pointer. + explicit Vec2D(const float* xy_) : xy{xy_[0], xy_[1]} {} + + float x() const { + return xy[0]; + } + + float y() const { + return xy[1]; + } + + public: + Vec2D() = default; + + Vec2D(std::array xy_) : xy(xy_) {} + + Vec2D& operator=(std::array xy_) { + xy = xy_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Vec2D* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/vec3d.cpp b/rerun_cpp/src/rerun/datatypes/vec3d.cpp index 2e5c5d484bf9..d55d2e269e8d 100644 --- a/rerun_cpp/src/rerun/datatypes/vec3d.cpp +++ b/rerun_cpp/src/rerun/datatypes/vec3d.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Vec3D::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 3); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Vec3D::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 3); + return datatype; + } + + Result> Vec3D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Vec3D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 3 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 3 + )); + } + + rerun::Error Vec3D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Vec3D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error Vec3D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Vec3D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].xyz) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].xyz.data(), - static_cast(num_elements * 3), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].xyz) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].xyz.data(), + static_cast(num_elements * 3), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/vec3d.hpp b/rerun_cpp/src/rerun/datatypes/vec3d.hpp index a576c03b6857..3315b401da1d 100644 --- a/rerun_cpp/src/rerun/datatypes/vec3d.hpp +++ b/rerun_cpp/src/rerun/datatypes/vec3d.hpp @@ -15,55 +15,53 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A vector in 3D space. - struct Vec3D { - std::array xyz; - - public: - // Extensions to generated type defined in 'vec3d_ext.cpp' - - /// Construct Vec3D from x/y/z values. - Vec3D(float x, float y, float z) : xyz{x, y, z} {} - - /// Construct Vec3D from x/y/z float pointer. - explicit Vec3D(const float* xyz_) : xyz{xyz_[0], xyz_[1], xyz_[2]} {} - - float x() const { - return xyz[0]; - } - - float y() const { - return xyz[1]; - } - - float z() const { - return xyz[2]; - } - - public: - Vec3D() = default; - - Vec3D(std::array xyz_) : xyz(xyz_) {} - - Vec3D& operator=(std::array xyz_) { - xyz = xyz_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Vec3D* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A vector in 3D space. + struct Vec3D { + std::array xyz; + + public: + // Extensions to generated type defined in 'vec3d_ext.cpp' + + /// Construct Vec3D from x/y/z values. + Vec3D(float x, float y, float z) : xyz{x, y, z} {} + + /// Construct Vec3D from x/y/z float pointer. + explicit Vec3D(const float* xyz_) : xyz{xyz_[0], xyz_[1], xyz_[2]} {} + + float x() const { + return xyz[0]; + } + + float y() const { + return xyz[1]; + } + + float z() const { + return xyz[2]; + } + + public: + Vec3D() = default; + + Vec3D(std::array xyz_) : xyz(xyz_) {} + + Vec3D& operator=(std::array xyz_) { + xyz = xyz_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Vec3D* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/vec4d.cpp b/rerun_cpp/src/rerun/datatypes/vec4d.cpp index a8b2026e8bfc..69103dadfebc 100644 --- a/rerun_cpp/src/rerun/datatypes/vec4d.cpp +++ b/rerun_cpp/src/rerun/datatypes/vec4d.cpp @@ -6,55 +6,50 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& Vec4D::arrow_datatype() { - static const auto datatype = - arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 4); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& Vec4D::arrow_datatype() { + static const auto datatype = + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 4); + return datatype; + } + + Result> Vec4D::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> Vec4D::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 4 - )); + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool), + 4 + )); + } + + rerun::Error Vec4D::fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Vec4D* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error Vec4D::fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Vec4D* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); - static_assert(sizeof(elements[0].xyzw) == sizeof(elements[0])); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - elements[0].xyzw.data(), - static_cast(num_elements * 4), - nullptr - )); - - return Error::ok(); + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - } // namespace datatypes -} // namespace rerun + + auto value_builder = static_cast(builder->value_builder()); + + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements))); + static_assert(sizeof(elements[0].xyzw) == sizeof(elements[0])); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + elements[0].xyzw.data(), + static_cast(num_elements * 4), + nullptr + )); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/vec4d.hpp b/rerun_cpp/src/rerun/datatypes/vec4d.hpp index 7537cc5c7d8f..081ca0129012 100644 --- a/rerun_cpp/src/rerun/datatypes/vec4d.hpp +++ b/rerun_cpp/src/rerun/datatypes/vec4d.hpp @@ -15,59 +15,57 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - /// **Datatype**: A vector in 4D space. - struct Vec4D { - std::array xyzw; - - public: - // Extensions to generated type defined in 'vec4d_ext.cpp' - - /// Construct Vec4D from x/y/z/w values. - Vec4D(float x, float y, float z, float w) : xyzw{x, y, z, w} {} - - /// Construct Vec4D from x/y/z/w float pointer. - explicit Vec4D(const float* xyzw_) : xyzw{xyzw_[0], xyzw_[1], xyzw_[2], xyzw_[3]} {} - - float x() const { - return xyzw[0]; - } - - float y() const { - return xyzw[1]; - } - - float z() const { - return xyzw[2]; - } - - float w() const { - return xyzw[3]; - } - - public: - Vec4D() = default; - - Vec4D(std::array xyzw_) : xyzw(xyzw_) {} - - Vec4D& operator=(std::array xyzw_) { - xyzw = xyzw_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FixedSizeListBuilder* builder, const Vec4D* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + /// **Datatype**: A vector in 4D space. + struct Vec4D { + std::array xyzw; + + public: + // Extensions to generated type defined in 'vec4d_ext.cpp' + + /// Construct Vec4D from x/y/z/w values. + Vec4D(float x, float y, float z, float w) : xyzw{x, y, z, w} {} + + /// Construct Vec4D from x/y/z/w float pointer. + explicit Vec4D(const float* xyzw_) : xyzw{xyzw_[0], xyzw_[1], xyzw_[2], xyzw_[3]} {} + + float x() const { + return xyzw[0]; + } + + float y() const { + return xyzw[1]; + } + + float z() const { + return xyzw[2]; + } + + float w() const { + return xyzw[3]; + } + + public: + Vec4D() = default; + + Vec4D(std::array xyzw_) : xyzw(xyzw_) {} + + Vec4D& operator=(std::array xyzw_) { + xyzw = xyzw_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FixedSizeListBuilder* builder, const Vec4D* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.cpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.cpp index de6ac355643b..48f78be799c8 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.cpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.cpp @@ -5,11 +5,12 @@ #include +namespace rerun::archetypes { + const char AffixFuzzer1::INDICATOR_COMPONENT_NAME[] = + "rerun.testing.components.AffixFuzzer1Indicator"; +} + namespace rerun { - namespace archetypes { - const char AffixFuzzer1::INDICATOR_COMPONENT_NAME[] = - "rerun.testing.components.AffixFuzzer1Indicator"; - } Result> AsComponents::serialize( const archetypes::AffixFuzzer1& archetype diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.hpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.hpp index e4d3a7fefcd3..372779b223ac 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.hpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.hpp @@ -33,113 +33,103 @@ #include #include -namespace rerun { - namespace archetypes { - struct AffixFuzzer1 { - rerun::components::AffixFuzzer1 fuzz1001; - - rerun::components::AffixFuzzer2 fuzz1002; +namespace rerun::archetypes { + struct AffixFuzzer1 { + rerun::components::AffixFuzzer1 fuzz1001; + + rerun::components::AffixFuzzer2 fuzz1002; - rerun::components::AffixFuzzer3 fuzz1003; + rerun::components::AffixFuzzer3 fuzz1003; - rerun::components::AffixFuzzer4 fuzz1004; + rerun::components::AffixFuzzer4 fuzz1004; - rerun::components::AffixFuzzer5 fuzz1005; + rerun::components::AffixFuzzer5 fuzz1005; - rerun::components::AffixFuzzer6 fuzz1006; + rerun::components::AffixFuzzer6 fuzz1006; - rerun::components::AffixFuzzer7 fuzz1007; + rerun::components::AffixFuzzer7 fuzz1007; - rerun::components::AffixFuzzer8 fuzz1008; + rerun::components::AffixFuzzer8 fuzz1008; - rerun::components::AffixFuzzer9 fuzz1009; + rerun::components::AffixFuzzer9 fuzz1009; - rerun::components::AffixFuzzer10 fuzz1010; + rerun::components::AffixFuzzer10 fuzz1010; - rerun::components::AffixFuzzer11 fuzz1011; + rerun::components::AffixFuzzer11 fuzz1011; - rerun::components::AffixFuzzer12 fuzz1012; + rerun::components::AffixFuzzer12 fuzz1012; - rerun::components::AffixFuzzer13 fuzz1013; + rerun::components::AffixFuzzer13 fuzz1013; - rerun::components::AffixFuzzer14 fuzz1014; + rerun::components::AffixFuzzer14 fuzz1014; - rerun::components::AffixFuzzer15 fuzz1015; + rerun::components::AffixFuzzer15 fuzz1015; - rerun::components::AffixFuzzer16 fuzz1016; + rerun::components::AffixFuzzer16 fuzz1016; - rerun::components::AffixFuzzer17 fuzz1017; + rerun::components::AffixFuzzer17 fuzz1017; - rerun::components::AffixFuzzer18 fuzz1018; + rerun::components::AffixFuzzer18 fuzz1018; - rerun::components::AffixFuzzer19 fuzz1019; + rerun::components::AffixFuzzer19 fuzz1019; - rerun::components::AffixFuzzer20 fuzz1020; + rerun::components::AffixFuzzer20 fuzz1020; - rerun::components::AffixFuzzer21 fuzz1021; + rerun::components::AffixFuzzer21 fuzz1021; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - public: - AffixFuzzer1() = default; - AffixFuzzer1(AffixFuzzer1&& other) = default; + public: + AffixFuzzer1() = default; + AffixFuzzer1(AffixFuzzer1&& other) = default; - explicit AffixFuzzer1( - rerun::components::AffixFuzzer1 _fuzz1001, - rerun::components::AffixFuzzer2 _fuzz1002, - rerun::components::AffixFuzzer3 _fuzz1003, - rerun::components::AffixFuzzer4 _fuzz1004, - rerun::components::AffixFuzzer5 _fuzz1005, - rerun::components::AffixFuzzer6 _fuzz1006, - rerun::components::AffixFuzzer7 _fuzz1007, - rerun::components::AffixFuzzer8 _fuzz1008, - rerun::components::AffixFuzzer9 _fuzz1009, - rerun::components::AffixFuzzer10 _fuzz1010, - rerun::components::AffixFuzzer11 _fuzz1011, - rerun::components::AffixFuzzer12 _fuzz1012, - rerun::components::AffixFuzzer13 _fuzz1013, - rerun::components::AffixFuzzer14 _fuzz1014, - rerun::components::AffixFuzzer15 _fuzz1015, - rerun::components::AffixFuzzer16 _fuzz1016, - rerun::components::AffixFuzzer17 _fuzz1017, - rerun::components::AffixFuzzer18 _fuzz1018, - rerun::components::AffixFuzzer19 _fuzz1019, - rerun::components::AffixFuzzer20 _fuzz1020, - rerun::components::AffixFuzzer21 _fuzz1021 - ) - : 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)), - fuzz1020(std::move(_fuzz1020)), - fuzz1021(std::move(_fuzz1021)) {} + explicit AffixFuzzer1( + rerun::components::AffixFuzzer1 _fuzz1001, rerun::components::AffixFuzzer2 _fuzz1002, + rerun::components::AffixFuzzer3 _fuzz1003, rerun::components::AffixFuzzer4 _fuzz1004, + rerun::components::AffixFuzzer5 _fuzz1005, rerun::components::AffixFuzzer6 _fuzz1006, + rerun::components::AffixFuzzer7 _fuzz1007, rerun::components::AffixFuzzer8 _fuzz1008, + rerun::components::AffixFuzzer9 _fuzz1009, rerun::components::AffixFuzzer10 _fuzz1010, + rerun::components::AffixFuzzer11 _fuzz1011, rerun::components::AffixFuzzer12 _fuzz1012, + rerun::components::AffixFuzzer13 _fuzz1013, rerun::components::AffixFuzzer14 _fuzz1014, + rerun::components::AffixFuzzer15 _fuzz1015, rerun::components::AffixFuzzer16 _fuzz1016, + rerun::components::AffixFuzzer17 _fuzz1017, rerun::components::AffixFuzzer18 _fuzz1018, + rerun::components::AffixFuzzer19 _fuzz1019, rerun::components::AffixFuzzer20 _fuzz1020, + rerun::components::AffixFuzzer21 _fuzz1021 + ) + : 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)), + fuzz1020(std::move(_fuzz1020)), + fuzz1021(std::move(_fuzz1021)) {} - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 1; - } - }; + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 1; + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.cpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.cpp index dda4a4878e10..ad9c5c5f20d0 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.cpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.cpp @@ -5,11 +5,12 @@ #include +namespace rerun::archetypes { + const char AffixFuzzer2::INDICATOR_COMPONENT_NAME[] = + "rerun.testing.components.AffixFuzzer2Indicator"; +} + namespace rerun { - namespace archetypes { - const char AffixFuzzer2::INDICATOR_COMPONENT_NAME[] = - "rerun.testing.components.AffixFuzzer2Indicator"; - } Result> AsComponents::serialize( const archetypes::AffixFuzzer2& archetype diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.hpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.hpp index 9a36a8b6d346..d726fd1f3b8a 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.hpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.hpp @@ -30,101 +30,101 @@ #include #include -namespace rerun { - namespace archetypes { - struct AffixFuzzer2 { - ComponentBatch fuzz1101; - - ComponentBatch fuzz1102; - - ComponentBatch fuzz1103; - - ComponentBatch fuzz1104; - - ComponentBatch fuzz1105; - - ComponentBatch fuzz1106; - - ComponentBatch fuzz1107; - - ComponentBatch fuzz1108; - - ComponentBatch fuzz1109; - - ComponentBatch fuzz1110; - - ComponentBatch fuzz1111; - - ComponentBatch fuzz1112; - - ComponentBatch fuzz1113; - - ComponentBatch fuzz1114; - - ComponentBatch fuzz1115; - - ComponentBatch fuzz1116; - - ComponentBatch fuzz1117; - - ComponentBatch fuzz1118; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - AffixFuzzer2() = default; - AffixFuzzer2(AffixFuzzer2&& other) = default; - - explicit AffixFuzzer2( - ComponentBatch _fuzz1101, - ComponentBatch _fuzz1102, - ComponentBatch _fuzz1103, - ComponentBatch _fuzz1104, - ComponentBatch _fuzz1105, - ComponentBatch _fuzz1106, - ComponentBatch _fuzz1107, - ComponentBatch _fuzz1108, - ComponentBatch _fuzz1109, - ComponentBatch _fuzz1110, - ComponentBatch _fuzz1111, - ComponentBatch _fuzz1112, - ComponentBatch _fuzz1113, - ComponentBatch _fuzz1114, - ComponentBatch _fuzz1115, - ComponentBatch _fuzz1116, - ComponentBatch _fuzz1117, - ComponentBatch _fuzz1118 - ) - : 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)) {} - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return fuzz1101.size(); - } - }; +namespace rerun::archetypes { + struct AffixFuzzer2 { + ComponentBatch fuzz1101; + + ComponentBatch fuzz1102; + + ComponentBatch fuzz1103; + + ComponentBatch fuzz1104; + + ComponentBatch fuzz1105; + + ComponentBatch fuzz1106; + + ComponentBatch fuzz1107; + + ComponentBatch fuzz1108; + + ComponentBatch fuzz1109; + + ComponentBatch fuzz1110; + + ComponentBatch fuzz1111; + + ComponentBatch fuzz1112; + + ComponentBatch fuzz1113; + + ComponentBatch fuzz1114; + + ComponentBatch fuzz1115; + + ComponentBatch fuzz1116; + + ComponentBatch fuzz1117; + + ComponentBatch fuzz1118; + + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + AffixFuzzer2() = default; + AffixFuzzer2(AffixFuzzer2&& other) = default; + + explicit AffixFuzzer2( + ComponentBatch _fuzz1101, + ComponentBatch _fuzz1102, + ComponentBatch _fuzz1103, + ComponentBatch _fuzz1104, + ComponentBatch _fuzz1105, + ComponentBatch _fuzz1106, + ComponentBatch _fuzz1107, + ComponentBatch _fuzz1108, + ComponentBatch _fuzz1109, + ComponentBatch _fuzz1110, + ComponentBatch _fuzz1111, + ComponentBatch _fuzz1112, + ComponentBatch _fuzz1113, + ComponentBatch _fuzz1114, + ComponentBatch _fuzz1115, + ComponentBatch _fuzz1116, + ComponentBatch _fuzz1117, + ComponentBatch _fuzz1118 + ) + : 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)) {} + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return fuzz1101.size(); + } + }; - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.cpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.cpp index e894fc1e0461..003f6fb372f4 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.cpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.cpp @@ -5,11 +5,12 @@ #include +namespace rerun::archetypes { + const char AffixFuzzer3::INDICATOR_COMPONENT_NAME[] = + "rerun.testing.components.AffixFuzzer3Indicator"; +} + namespace rerun { - namespace archetypes { - const char AffixFuzzer3::INDICATOR_COMPONENT_NAME[] = - "rerun.testing.components.AffixFuzzer3Indicator"; - } Result> AsComponents::serialize( const archetypes::AffixFuzzer3& archetype diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.hpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.hpp index 7b536a092715..95098d1bdaa3 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.hpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.hpp @@ -32,170 +32,170 @@ #include #include -namespace rerun { - namespace archetypes { - struct AffixFuzzer3 { - std::optional fuzz2001; - - std::optional fuzz2002; - - std::optional fuzz2003; - - std::optional fuzz2004; - - std::optional fuzz2005; +namespace rerun::archetypes { + struct AffixFuzzer3 { + std::optional fuzz2001; - std::optional fuzz2006; + std::optional fuzz2002; - std::optional fuzz2007; + std::optional fuzz2003; - std::optional fuzz2008; + std::optional fuzz2004; - std::optional fuzz2009; + std::optional fuzz2005; - std::optional fuzz2010; + std::optional fuzz2006; - std::optional fuzz2011; + std::optional fuzz2007; - std::optional fuzz2012; + std::optional fuzz2008; - std::optional fuzz2013; + std::optional fuzz2009; - std::optional fuzz2014; + std::optional fuzz2010; - std::optional fuzz2015; + std::optional fuzz2011; - std::optional fuzz2016; + std::optional fuzz2012; - std::optional fuzz2017; + std::optional fuzz2013; - std::optional fuzz2018; + std::optional fuzz2014; - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; + std::optional fuzz2015; - public: - AffixFuzzer3() = default; - AffixFuzzer3(AffixFuzzer3&& other) = default; + std::optional fuzz2016; - AffixFuzzer3 with_fuzz2001(rerun::components::AffixFuzzer1 _fuzz2001) && { - fuzz2001 = std::move(_fuzz2001); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2002(rerun::components::AffixFuzzer2 _fuzz2002) && { - fuzz2002 = std::move(_fuzz2002); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2003(rerun::components::AffixFuzzer3 _fuzz2003) && { - fuzz2003 = std::move(_fuzz2003); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } + std::optional fuzz2017; - AffixFuzzer3 with_fuzz2004(rerun::components::AffixFuzzer4 _fuzz2004) && { - fuzz2004 = std::move(_fuzz2004); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } + std::optional fuzz2018; - AffixFuzzer3 with_fuzz2005(rerun::components::AffixFuzzer5 _fuzz2005) && { - fuzz2005 = std::move(_fuzz2005); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; - AffixFuzzer3 with_fuzz2006(rerun::components::AffixFuzzer6 _fuzz2006) && { - fuzz2006 = std::move(_fuzz2006); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } + public: + AffixFuzzer3() = default; + AffixFuzzer3(AffixFuzzer3&& other) = default; - AffixFuzzer3 with_fuzz2007(rerun::components::AffixFuzzer7 _fuzz2007) && { - fuzz2007 = std::move(_fuzz2007); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2008(rerun::components::AffixFuzzer8 _fuzz2008) && { - fuzz2008 = std::move(_fuzz2008); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2009(rerun::components::AffixFuzzer9 _fuzz2009) && { - fuzz2009 = std::move(_fuzz2009); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } + AffixFuzzer3 with_fuzz2001(rerun::components::AffixFuzzer1 _fuzz2001) && { + fuzz2001 = std::move(_fuzz2001); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2002(rerun::components::AffixFuzzer2 _fuzz2002) && { + fuzz2002 = std::move(_fuzz2002); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2003(rerun::components::AffixFuzzer3 _fuzz2003) && { + fuzz2003 = std::move(_fuzz2003); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2004(rerun::components::AffixFuzzer4 _fuzz2004) && { + fuzz2004 = std::move(_fuzz2004); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2005(rerun::components::AffixFuzzer5 _fuzz2005) && { + fuzz2005 = std::move(_fuzz2005); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2006(rerun::components::AffixFuzzer6 _fuzz2006) && { + fuzz2006 = std::move(_fuzz2006); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2007(rerun::components::AffixFuzzer7 _fuzz2007) && { + fuzz2007 = std::move(_fuzz2007); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2008(rerun::components::AffixFuzzer8 _fuzz2008) && { + fuzz2008 = std::move(_fuzz2008); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2009(rerun::components::AffixFuzzer9 _fuzz2009) && { + fuzz2009 = std::move(_fuzz2009); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2010(rerun::components::AffixFuzzer10 _fuzz2010) && { + fuzz2010 = std::move(_fuzz2010); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2011(rerun::components::AffixFuzzer11 _fuzz2011) && { + fuzz2011 = std::move(_fuzz2011); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2012(rerun::components::AffixFuzzer12 _fuzz2012) && { + fuzz2012 = std::move(_fuzz2012); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2013(rerun::components::AffixFuzzer13 _fuzz2013) && { + fuzz2013 = std::move(_fuzz2013); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2014(rerun::components::AffixFuzzer14 _fuzz2014) && { + fuzz2014 = std::move(_fuzz2014); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2015(rerun::components::AffixFuzzer15 _fuzz2015) && { + fuzz2015 = std::move(_fuzz2015); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2016(rerun::components::AffixFuzzer16 _fuzz2016) && { + fuzz2016 = std::move(_fuzz2016); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2017(rerun::components::AffixFuzzer17 _fuzz2017) && { + fuzz2017 = std::move(_fuzz2017); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer3 with_fuzz2018(rerun::components::AffixFuzzer18 _fuzz2018) && { + fuzz2018 = std::move(_fuzz2018); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 0; + } + }; - AffixFuzzer3 with_fuzz2010(rerun::components::AffixFuzzer10 _fuzz2010) && { - fuzz2010 = std::move(_fuzz2010); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2011(rerun::components::AffixFuzzer11 _fuzz2011) && { - fuzz2011 = std::move(_fuzz2011); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2012(rerun::components::AffixFuzzer12 _fuzz2012) && { - fuzz2012 = std::move(_fuzz2012); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2013(rerun::components::AffixFuzzer13 _fuzz2013) && { - fuzz2013 = std::move(_fuzz2013); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2014(rerun::components::AffixFuzzer14 _fuzz2014) && { - fuzz2014 = std::move(_fuzz2014); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2015(rerun::components::AffixFuzzer15 _fuzz2015) && { - fuzz2015 = std::move(_fuzz2015); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2016(rerun::components::AffixFuzzer16 _fuzz2016) && { - fuzz2016 = std::move(_fuzz2016); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2017(rerun::components::AffixFuzzer17 _fuzz2017) && { - fuzz2017 = std::move(_fuzz2017); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer3 with_fuzz2018(rerun::components::AffixFuzzer18 _fuzz2018) && { - fuzz2018 = std::move(_fuzz2018); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 0; - } - }; - - } // namespace archetypes +} // namespace rerun::archetypes +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.cpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.cpp index 6a7b8bdf5efe..c5fe62791d8f 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.cpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.cpp @@ -5,11 +5,12 @@ #include +namespace rerun::archetypes { + const char AffixFuzzer4::INDICATOR_COMPONENT_NAME[] = + "rerun.testing.components.AffixFuzzer4Indicator"; +} + namespace rerun { - namespace archetypes { - const char AffixFuzzer4::INDICATOR_COMPONENT_NAME[] = - "rerun.testing.components.AffixFuzzer4Indicator"; - } Result> AsComponents::serialize( const archetypes::AffixFuzzer4& archetype diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.hpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.hpp index 7c8006dea4f8..cd9e24f42654 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.hpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.hpp @@ -32,188 +32,170 @@ #include #include -namespace rerun { - namespace archetypes { - struct AffixFuzzer4 { - std::optional> fuzz2101; +namespace rerun::archetypes { + struct AffixFuzzer4 { + std::optional> fuzz2101; + + std::optional> fuzz2102; + + std::optional> fuzz2103; + + std::optional> fuzz2104; + + std::optional> fuzz2105; + + std::optional> fuzz2106; - std::optional> fuzz2102; + std::optional> fuzz2107; - std::optional> fuzz2103; + std::optional> fuzz2108; - std::optional> fuzz2104; + std::optional> fuzz2109; - std::optional> fuzz2105; + std::optional> fuzz2110; - std::optional> fuzz2106; + std::optional> fuzz2111; - std::optional> fuzz2107; + std::optional> fuzz2112; - std::optional> fuzz2108; + std::optional> fuzz2113; - std::optional> fuzz2109; + std::optional> fuzz2114; - std::optional> fuzz2110; + std::optional> fuzz2115; - std::optional> fuzz2111; + std::optional> fuzz2116; - std::optional> fuzz2112; + std::optional> fuzz2117; - std::optional> fuzz2113; - - std::optional> fuzz2114; - - std::optional> fuzz2115; - - std::optional> fuzz2116; - - std::optional> fuzz2117; - - std::optional> fuzz2118; - - /// Name of the indicator component, used to identify the archetype when converting to a list of components. - static const char INDICATOR_COMPONENT_NAME[]; - /// Indicator component, used to identify the archetype when converting to a list of components. - using IndicatorComponent = components::IndicatorComponent; - - public: - AffixFuzzer4() = default; - AffixFuzzer4(AffixFuzzer4&& other) = default; - - AffixFuzzer4 with_fuzz2101(ComponentBatch _fuzz2101 - ) && { - fuzz2101 = std::move(_fuzz2101); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2102(ComponentBatch _fuzz2102 - ) && { - fuzz2102 = std::move(_fuzz2102); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2103(ComponentBatch _fuzz2103 - ) && { - fuzz2103 = std::move(_fuzz2103); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2104(ComponentBatch _fuzz2104 - ) && { - fuzz2104 = std::move(_fuzz2104); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2105(ComponentBatch _fuzz2105 - ) && { - fuzz2105 = std::move(_fuzz2105); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2106(ComponentBatch _fuzz2106 - ) && { - fuzz2106 = std::move(_fuzz2106); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2107(ComponentBatch _fuzz2107 - ) && { - fuzz2107 = std::move(_fuzz2107); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2108(ComponentBatch _fuzz2108 - ) && { - fuzz2108 = std::move(_fuzz2108); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2109(ComponentBatch _fuzz2109 - ) && { - fuzz2109 = std::move(_fuzz2109); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2110(ComponentBatch _fuzz2110 - ) && { - fuzz2110 = std::move(_fuzz2110); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2111(ComponentBatch _fuzz2111 - ) && { - fuzz2111 = std::move(_fuzz2111); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2112(ComponentBatch _fuzz2112 - ) && { - fuzz2112 = std::move(_fuzz2112); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2113(ComponentBatch _fuzz2113 - ) && { - fuzz2113 = std::move(_fuzz2113); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2114(ComponentBatch _fuzz2114 - ) && { - fuzz2114 = std::move(_fuzz2114); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2115(ComponentBatch _fuzz2115 - ) && { - fuzz2115 = std::move(_fuzz2115); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2116(ComponentBatch _fuzz2116 - ) && { - fuzz2116 = std::move(_fuzz2116); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2117(ComponentBatch _fuzz2117 - ) && { - fuzz2117 = std::move(_fuzz2117); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - AffixFuzzer4 with_fuzz2118(ComponentBatch _fuzz2118 - ) && { - fuzz2118 = std::move(_fuzz2118); - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } - - /// Returns the number of primary instances of this archetype. - size_t num_instances() const { - return 0; - } - }; - - } // namespace archetypes + std::optional> fuzz2118; + /// Name of the indicator component, used to identify the archetype when converting to a list of components. + static const char INDICATOR_COMPONENT_NAME[]; + /// Indicator component, used to identify the archetype when converting to a list of components. + using IndicatorComponent = components::IndicatorComponent; + + public: + AffixFuzzer4() = default; + AffixFuzzer4(AffixFuzzer4&& other) = default; + + AffixFuzzer4 with_fuzz2101(ComponentBatch _fuzz2101) && { + fuzz2101 = std::move(_fuzz2101); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2102(ComponentBatch _fuzz2102) && { + fuzz2102 = std::move(_fuzz2102); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2103(ComponentBatch _fuzz2103) && { + fuzz2103 = std::move(_fuzz2103); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2104(ComponentBatch _fuzz2104) && { + fuzz2104 = std::move(_fuzz2104); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2105(ComponentBatch _fuzz2105) && { + fuzz2105 = std::move(_fuzz2105); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2106(ComponentBatch _fuzz2106) && { + fuzz2106 = std::move(_fuzz2106); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2107(ComponentBatch _fuzz2107) && { + fuzz2107 = std::move(_fuzz2107); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2108(ComponentBatch _fuzz2108) && { + fuzz2108 = std::move(_fuzz2108); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2109(ComponentBatch _fuzz2109) && { + fuzz2109 = std::move(_fuzz2109); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2110(ComponentBatch _fuzz2110) && { + fuzz2110 = std::move(_fuzz2110); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2111(ComponentBatch _fuzz2111) && { + fuzz2111 = std::move(_fuzz2111); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2112(ComponentBatch _fuzz2112) && { + fuzz2112 = std::move(_fuzz2112); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2113(ComponentBatch _fuzz2113) && { + fuzz2113 = std::move(_fuzz2113); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2114(ComponentBatch _fuzz2114) && { + fuzz2114 = std::move(_fuzz2114); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2115(ComponentBatch _fuzz2115) && { + fuzz2115 = std::move(_fuzz2115); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2116(ComponentBatch _fuzz2116) && { + fuzz2116 = std::move(_fuzz2116); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2117(ComponentBatch _fuzz2117) && { + fuzz2117 = std::move(_fuzz2117); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + AffixFuzzer4 with_fuzz2118(ComponentBatch _fuzz2118) && { + fuzz2118 = std::move(_fuzz2118); + // See: https://github.com/rerun-io/rerun/issues/4027 + WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Returns the number of primary instances of this archetype. + size_t num_instances() const { + return 0; + } + }; + +} // namespace rerun::archetypes + +namespace rerun { /// \private template struct AsComponents; diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer1.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer1.cpp index 7e540c2b35e5..199525bbc577 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer1.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer1.cpp @@ -8,74 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer1::NAME[] = "rerun.testing.components.AffixFuzzer1"; +namespace rerun::components { + const char AffixFuzzer1::NAME[] = "rerun.testing.components.AffixFuzzer1"; - const std::shared_ptr& AffixFuzzer1::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer1::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer1::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer1::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer1::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer1* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer1::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer1* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::AffixFuzzer1) == sizeof(AffixFuzzer1)); - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer1::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::AffixFuzzer1) == sizeof(AffixFuzzer1)); + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer1::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer1::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer1::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer1::NAME, - AffixFuzzer1::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer1::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer1::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer1::NAME, + AffixFuzzer1::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer1.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer1.hpp index 883a8f88414d..f3699d1feded 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer1.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer1.hpp @@ -17,47 +17,45 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer1 { - rerun::datatypes::AffixFuzzer1 single_required; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer1() = default; - - AffixFuzzer1(rerun::datatypes::AffixFuzzer1 single_required_) - : single_required(std::move(single_required_)) {} - - AffixFuzzer1& operator=(rerun::datatypes::AffixFuzzer1 single_required_) { - single_required = std::move(single_required_); - return *this; - } - - /// Cast to the underlying AffixFuzzer1 datatype - operator rerun::datatypes::AffixFuzzer1() const { - return single_required; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer1* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer1 { + rerun::datatypes::AffixFuzzer1 single_required; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer1() = default; + + AffixFuzzer1(rerun::datatypes::AffixFuzzer1 single_required_) + : single_required(std::move(single_required_)) {} + + AffixFuzzer1& operator=(rerun::datatypes::AffixFuzzer1 single_required_) { + single_required = std::move(single_required_); + return *this; + } + + /// Cast to the underlying AffixFuzzer1 datatype + operator rerun::datatypes::AffixFuzzer1() const { + return single_required; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer1* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer10.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer10.cpp index 0ef6a805afcd..fb8908997423 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer10.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer10.cpp @@ -6,76 +6,71 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer10::NAME[] = "rerun.testing.components.AffixFuzzer10"; +namespace rerun::components { + const char AffixFuzzer10::NAME[] = "rerun.testing.components.AffixFuzzer10"; - const std::shared_ptr& AffixFuzzer10::arrow_datatype() { - static const auto datatype = arrow::utf8(); - return datatype; + const std::shared_ptr& AffixFuzzer10::arrow_datatype() { + static const auto datatype = arrow::utf8(); + return datatype; + } + + Result> AffixFuzzer10::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer10::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error AffixFuzzer10::fill_arrow_array_builder( + arrow::StringBuilder* builder, const AffixFuzzer10* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer10::fill_arrow_array_builder( - arrow::StringBuilder* builder, const AffixFuzzer10* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.single_string_optional.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append(element.single_string_optional.value())); - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); - } + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.single_string_optional.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append(element.single_string_optional.value())); + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer10::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer10::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer10::NAME, - AffixFuzzer10::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer10::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer10::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer10::NAME, + AffixFuzzer10::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer10.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer10.hpp index fad180ba2d6b..e72df225d987 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer10.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer10.hpp @@ -17,42 +17,40 @@ namespace arrow { class StringBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer10 { - std::optional single_string_optional; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer10() = default; - - AffixFuzzer10(std::optional single_string_optional_) - : single_string_optional(std::move(single_string_optional_)) {} - - AffixFuzzer10& operator=(std::optional single_string_optional_) { - single_string_optional = std::move(single_string_optional_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer10* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer10 { + std::optional single_string_optional; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer10() = default; + + AffixFuzzer10(std::optional single_string_optional_) + : single_string_optional(std::move(single_string_optional_)) {} + + AffixFuzzer10& operator=(std::optional single_string_optional_) { + single_string_optional = std::move(single_string_optional_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer10* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer11.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer11.cpp index b2d666c5c311..762a3cd5c787 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer11.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer11.cpp @@ -6,87 +6,82 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer11::NAME[] = "rerun.testing.components.AffixFuzzer11"; +namespace rerun::components { + const char AffixFuzzer11::NAME[] = "rerun.testing.components.AffixFuzzer11"; - const std::shared_ptr& AffixFuzzer11::arrow_datatype() { - static const auto datatype = arrow::list(arrow::field("item", arrow::float32(), false)); - return datatype; + const std::shared_ptr& AffixFuzzer11::arrow_datatype() { + static const auto datatype = arrow::list(arrow::field("item", arrow::float32(), false)); + return datatype; + } + + Result> AffixFuzzer11::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer11::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool) + )); + } - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool) - )); + rerun::Error AffixFuzzer11::fill_arrow_array_builder( + arrow::ListBuilder* builder, const AffixFuzzer11* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer11::fill_arrow_array_builder( - arrow::ListBuilder* builder, const AffixFuzzer11* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.many_floats_optional.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - element.many_floats_optional.value().data(), - static_cast(element.many_floats_optional.value().size()), - nullptr - )); - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.many_floats_optional.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + element.many_floats_optional.value().data(), + static_cast(element.many_floats_optional.value().size()), + nullptr + )); + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer11::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer11::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer11::NAME, - AffixFuzzer11::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer11::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer11::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer11::NAME, + AffixFuzzer11::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer11.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer11.hpp index 17c0633d0d19..4fec10280b6b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer11.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer11.hpp @@ -17,42 +17,40 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer11 { - std::optional> many_floats_optional; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer11() = default; - - AffixFuzzer11(std::optional> many_floats_optional_) - : many_floats_optional(std::move(many_floats_optional_)) {} - - AffixFuzzer11& operator=(std::optional> many_floats_optional_) { - many_floats_optional = std::move(many_floats_optional_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer11* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer11 { + std::optional> many_floats_optional; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer11() = default; + + AffixFuzzer11(std::optional> many_floats_optional_) + : many_floats_optional(std::move(many_floats_optional_)) {} + + AffixFuzzer11& operator=(std::optional> many_floats_optional_) { + many_floats_optional = std::move(many_floats_optional_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer11* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer12.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer12.cpp index fb7665ee0649..dbdefbe4bbfc 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer12.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer12.cpp @@ -6,84 +6,77 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer12::NAME[] = "rerun.testing.components.AffixFuzzer12"; +namespace rerun::components { + const char AffixFuzzer12::NAME[] = "rerun.testing.components.AffixFuzzer12"; - const std::shared_ptr& AffixFuzzer12::arrow_datatype() { - static const auto datatype = arrow::list(arrow::field("item", arrow::utf8(), false)); - return datatype; + const std::shared_ptr& AffixFuzzer12::arrow_datatype() { + static const auto datatype = arrow::list(arrow::field("item", arrow::utf8(), false)); + return datatype; + } + + Result> AffixFuzzer12::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer12::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool) + )); + } - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool) - )); + rerun::Error AffixFuzzer12::fill_arrow_array_builder( + arrow::ListBuilder* builder, const AffixFuzzer12* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer12::fill_arrow_array_builder( - arrow::ListBuilder* builder, const AffixFuzzer12* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append()); - for (size_t item_idx = 0; item_idx < element.many_strings_required.size(); - item_idx += 1) { - ARROW_RETURN_NOT_OK( - value_builder->Append(element.many_strings_required[item_idx]) - ); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append()); + for (size_t item_idx = 0; item_idx < element.many_strings_required.size(); + item_idx += 1) { + ARROW_RETURN_NOT_OK(value_builder->Append(element.many_strings_required[item_idx])); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer12::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer12::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer12::NAME, - AffixFuzzer12::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer12::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer12::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer12::NAME, + AffixFuzzer12::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer12.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer12.hpp index 0276bf4e2aed..15730c1cac57 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer12.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer12.hpp @@ -17,42 +17,40 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer12 { - std::vector many_strings_required; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer12() = default; - - AffixFuzzer12(std::vector many_strings_required_) - : many_strings_required(std::move(many_strings_required_)) {} - - AffixFuzzer12& operator=(std::vector many_strings_required_) { - many_strings_required = std::move(many_strings_required_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer12* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer12 { + std::vector many_strings_required; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer12() = default; + + AffixFuzzer12(std::vector many_strings_required_) + : many_strings_required(std::move(many_strings_required_)) {} + + AffixFuzzer12& operator=(std::vector many_strings_required_) { + many_strings_required = std::move(many_strings_required_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer12* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer13.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer13.cpp index e831288d4a1d..e77bf6b9f76b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer13.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer13.cpp @@ -6,89 +6,82 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer13::NAME[] = "rerun.testing.components.AffixFuzzer13"; +namespace rerun::components { + const char AffixFuzzer13::NAME[] = "rerun.testing.components.AffixFuzzer13"; - const std::shared_ptr& AffixFuzzer13::arrow_datatype() { - static const auto datatype = arrow::list(arrow::field("item", arrow::utf8(), false)); - return datatype; + const std::shared_ptr& AffixFuzzer13::arrow_datatype() { + static const auto datatype = arrow::list(arrow::field("item", arrow::utf8(), false)); + return datatype; + } + + Result> AffixFuzzer13::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer13::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + std::make_shared(memory_pool) + )); + } - return Result(std::make_shared( - memory_pool, - std::make_shared(memory_pool) - )); + rerun::Error AffixFuzzer13::fill_arrow_array_builder( + arrow::ListBuilder* builder, const AffixFuzzer13* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer13::fill_arrow_array_builder( - arrow::ListBuilder* builder, const AffixFuzzer13* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.many_strings_optional.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append()); - for (size_t item_idx = 0; - item_idx < element.many_strings_optional.value().size(); - item_idx += 1) { - ARROW_RETURN_NOT_OK( - value_builder->Append(element.many_strings_optional.value()[item_idx]) - ); - } - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.many_strings_optional.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append()); + for (size_t item_idx = 0; item_idx < element.many_strings_optional.value().size(); + item_idx += 1) { + ARROW_RETURN_NOT_OK(value_builder->Append(element.many_strings_optional.value( + )[item_idx])); } + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer13::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer13::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer13::NAME, - AffixFuzzer13::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer13::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer13::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer13::NAME, + AffixFuzzer13::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer13.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer13.hpp index ae32f71ee08b..03ada841ca05 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer13.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer13.hpp @@ -18,43 +18,40 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer13 { - std::optional> many_strings_optional; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer13() = default; - - AffixFuzzer13(std::optional> many_strings_optional_) - : many_strings_optional(std::move(many_strings_optional_)) {} - - AffixFuzzer13& operator=(std::optional> many_strings_optional_ - ) { - many_strings_optional = std::move(many_strings_optional_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer13* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer13 { + std::optional> many_strings_optional; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer13() = default; + + AffixFuzzer13(std::optional> many_strings_optional_) + : many_strings_optional(std::move(many_strings_optional_)) {} + + AffixFuzzer13& operator=(std::optional> many_strings_optional_) { + many_strings_optional = std::move(many_strings_optional_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer13* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer14.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer14.cpp index 42902b2c752e..cfbb15e5fb0c 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer14.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer14.cpp @@ -8,74 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer14::NAME[] = "rerun.testing.components.AffixFuzzer14"; +namespace rerun::components { + const char AffixFuzzer14::NAME[] = "rerun.testing.components.AffixFuzzer14"; - const std::shared_ptr& AffixFuzzer14::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer3::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer14::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer3::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer14::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer14::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer14::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const AffixFuzzer14* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer14::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const AffixFuzzer14* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::AffixFuzzer3) == sizeof(AffixFuzzer14)); - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer3::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::AffixFuzzer3) == sizeof(AffixFuzzer14)); + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer3::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer14::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer14::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer14::NAME, - AffixFuzzer14::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer14::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer14::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer14::NAME, + AffixFuzzer14::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer14.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer14.hpp index c577385862b9..dcd01e8eef97 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer14.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer14.hpp @@ -17,48 +17,45 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer14 { - rerun::datatypes::AffixFuzzer3 single_required_union; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer14() = default; - - AffixFuzzer14(rerun::datatypes::AffixFuzzer3 single_required_union_) - : single_required_union(std::move(single_required_union_)) {} - - AffixFuzzer14& operator=(rerun::datatypes::AffixFuzzer3 single_required_union_) { - single_required_union = std::move(single_required_union_); - return *this; - } - - /// Cast to the underlying AffixFuzzer3 datatype - operator rerun::datatypes::AffixFuzzer3() const { - return single_required_union; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const AffixFuzzer14* elements, - size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of AffixFuzzer14 components. - static Result to_data_cell( - const AffixFuzzer14* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer14 { + rerun::datatypes::AffixFuzzer3 single_required_union; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer14() = default; + + AffixFuzzer14(rerun::datatypes::AffixFuzzer3 single_required_union_) + : single_required_union(std::move(single_required_union_)) {} + + AffixFuzzer14& operator=(rerun::datatypes::AffixFuzzer3 single_required_union_) { + single_required_union = std::move(single_required_union_); + return *this; + } + + /// Cast to the underlying AffixFuzzer3 datatype + operator rerun::datatypes::AffixFuzzer3() const { + return single_required_union; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const AffixFuzzer14* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer14 components. + static Result to_data_cell( + const AffixFuzzer14* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer15.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer15.cpp index b4251fabc075..c413690ce691 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer15.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer15.cpp @@ -8,75 +8,69 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer15::NAME[] = "rerun.testing.components.AffixFuzzer15"; +namespace rerun::components { + const char AffixFuzzer15::NAME[] = "rerun.testing.components.AffixFuzzer15"; - const std::shared_ptr& AffixFuzzer15::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer3::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer15::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer3::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer15::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer15::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer15::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const AffixFuzzer15* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer15::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const AffixFuzzer15* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - (void)num_elements; - if (true) { - return rerun::Error( - ErrorCode::NotImplemented, - "TODO(andreas) Handle nullable extensions" - ); - } - - return Error::ok(); + (void)num_elements; + if (true) { + return rerun::Error( + ErrorCode::NotImplemented, + "TODO(andreas) Handle nullable extensions" + ); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer15::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer15::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer15::NAME, - AffixFuzzer15::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer15::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer15::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer15::NAME, + AffixFuzzer15::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer15.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer15.hpp index 2d5f49c27776..408105ac8884 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer15.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer15.hpp @@ -18,50 +18,47 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer15 { - std::optional single_optional_union; +namespace rerun::components { + struct AffixFuzzer15 { + std::optional single_optional_union; - /// Name of the component, used for serialization. - static const char NAME[]; + /// Name of the component, used for serialization. + static const char NAME[]; - public: - AffixFuzzer15() = default; + public: + AffixFuzzer15() = default; - AffixFuzzer15(std::optional single_optional_union_) - : single_optional_union(std::move(single_optional_union_)) {} + AffixFuzzer15(std::optional single_optional_union_) + : single_optional_union(std::move(single_optional_union_)) {} - AffixFuzzer15& operator=( - std::optional single_optional_union_ - ) { - single_optional_union = std::move(single_optional_union_); - return *this; - } + AffixFuzzer15& operator=( + std::optional single_optional_union_ + ) { + single_optional_union = std::move(single_optional_union_); + return *this; + } - /// Cast to the underlying AffixFuzzer3 datatype - operator std::optional() const { - return single_optional_union; - } + /// Cast to the underlying AffixFuzzer3 datatype + operator std::optional() const { + return single_optional_union; + } - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const AffixFuzzer15* elements, - size_t num_elements - ); + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const AffixFuzzer15* elements, size_t num_elements + ); - /// Creates a Rerun DataCell from an array of AffixFuzzer15 components. - static Result to_data_cell( - const AffixFuzzer15* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun + /// Creates a Rerun DataCell from an array of AffixFuzzer15 components. + static Result to_data_cell( + const AffixFuzzer15* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer16.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer16.cpp index 460de258ff87..460d60ba1a4a 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer16.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer16.cpp @@ -8,87 +8,82 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer16::NAME[] = "rerun.testing.components.AffixFuzzer16"; +namespace rerun::components { + const char AffixFuzzer16::NAME[] = "rerun.testing.components.AffixFuzzer16"; - const std::shared_ptr& AffixFuzzer16::arrow_datatype() { - static const auto datatype = arrow::list( - arrow::field("item", rerun::datatypes::AffixFuzzer3::arrow_datatype(), false) - ); - return datatype; + const std::shared_ptr& AffixFuzzer16::arrow_datatype() { + static const auto datatype = arrow::list( + arrow::field("item", rerun::datatypes::AffixFuzzer3::arrow_datatype(), false) + ); + return datatype; + } + + Result> AffixFuzzer16::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer16::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value + )); + } - return Result(std::make_shared( - memory_pool, - rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value - )); + rerun::Error AffixFuzzer16::fill_arrow_array_builder( + arrow::ListBuilder* builder, const AffixFuzzer16* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer16::fill_arrow_array_builder( - arrow::ListBuilder* builder, const AffixFuzzer16* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append()); - if (element.many_required_unions.data()) { - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer3::fill_arrow_array_builder( - value_builder, - element.many_required_unions.data(), - element.many_required_unions.size() - )); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append()); + if (element.many_required_unions.data()) { + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer3::fill_arrow_array_builder( + value_builder, + element.many_required_unions.data(), + element.many_required_unions.size() + )); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer16::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer16::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer16::NAME, - AffixFuzzer16::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer16::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer16::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer16::NAME, + AffixFuzzer16::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer16.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer16.hpp index 7914b989550e..a2e8a64cdac4 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer16.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer16.hpp @@ -18,44 +18,41 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer16 { - std::vector many_required_unions; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer16() = default; - - AffixFuzzer16(std::vector many_required_unions_) - : many_required_unions(std::move(many_required_unions_)) {} - - AffixFuzzer16& operator=( - std::vector many_required_unions_ - ) { - many_required_unions = std::move(many_required_unions_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer16* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer16 { + std::vector many_required_unions; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer16() = default; + + AffixFuzzer16(std::vector many_required_unions_) + : many_required_unions(std::move(many_required_unions_)) {} + + AffixFuzzer16& operator=(std::vector many_required_unions_ + ) { + many_required_unions = std::move(many_required_unions_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer16* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer17.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer17.cpp index 8017598a3294..e550225a1d30 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer17.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer17.cpp @@ -8,91 +8,86 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer17::NAME[] = "rerun.testing.components.AffixFuzzer17"; +namespace rerun::components { + const char AffixFuzzer17::NAME[] = "rerun.testing.components.AffixFuzzer17"; - const std::shared_ptr& AffixFuzzer17::arrow_datatype() { - static const auto datatype = arrow::list( - arrow::field("item", rerun::datatypes::AffixFuzzer3::arrow_datatype(), false) - ); - return datatype; + const std::shared_ptr& AffixFuzzer17::arrow_datatype() { + static const auto datatype = arrow::list( + arrow::field("item", rerun::datatypes::AffixFuzzer3::arrow_datatype(), false) + ); + return datatype; + } + + Result> AffixFuzzer17::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer17::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value + )); + } - return Result(std::make_shared( - memory_pool, - rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value - )); + rerun::Error AffixFuzzer17::fill_arrow_array_builder( + arrow::ListBuilder* builder, const AffixFuzzer17* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer17::fill_arrow_array_builder( - arrow::ListBuilder* builder, const AffixFuzzer17* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.many_optional_unions.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append()); - if (element.many_optional_unions.value().data()) { - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer3::fill_arrow_array_builder( - value_builder, - element.many_optional_unions.value().data(), - element.many_optional_unions.value().size() - )); - } - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.many_optional_unions.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append()); + if (element.many_optional_unions.value().data()) { + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer3::fill_arrow_array_builder( + value_builder, + element.many_optional_unions.value().data(), + element.many_optional_unions.value().size() + )); } + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer17::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer17::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer17::NAME, - AffixFuzzer17::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer17::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer17::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer17::NAME, + AffixFuzzer17::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer17.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer17.hpp index 7915a171b9bd..039b5499ff51 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer17.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer17.hpp @@ -19,46 +19,44 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer17 { - std::optional> many_optional_unions; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer17() = default; - - AffixFuzzer17( - std::optional> many_optional_unions_ - ) - : many_optional_unions(std::move(many_optional_unions_)) {} - - AffixFuzzer17& operator=( - std::optional> many_optional_unions_ - ) { - many_optional_unions = std::move(many_optional_unions_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer17* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer17 { + std::optional> many_optional_unions; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer17() = default; + + AffixFuzzer17( + std::optional> many_optional_unions_ + ) + : many_optional_unions(std::move(many_optional_unions_)) {} + + AffixFuzzer17& operator=( + std::optional> many_optional_unions_ + ) { + many_optional_unions = std::move(many_optional_unions_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer17* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer18.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer18.cpp index 25d108a3acba..feb1067389e2 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer18.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer18.cpp @@ -8,91 +8,86 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer18::NAME[] = "rerun.testing.components.AffixFuzzer18"; +namespace rerun::components { + const char AffixFuzzer18::NAME[] = "rerun.testing.components.AffixFuzzer18"; - const std::shared_ptr& AffixFuzzer18::arrow_datatype() { - static const auto datatype = arrow::list( - arrow::field("item", rerun::datatypes::AffixFuzzer4::arrow_datatype(), false) - ); - return datatype; + const std::shared_ptr& AffixFuzzer18::arrow_datatype() { + static const auto datatype = arrow::list( + arrow::field("item", rerun::datatypes::AffixFuzzer4::arrow_datatype(), false) + ); + return datatype; + } + + Result> AffixFuzzer18::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer18::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + rerun::datatypes::AffixFuzzer4::new_arrow_array_builder(memory_pool).value + )); + } - return Result(std::make_shared( - memory_pool, - rerun::datatypes::AffixFuzzer4::new_arrow_array_builder(memory_pool).value - )); + rerun::Error AffixFuzzer18::fill_arrow_array_builder( + arrow::ListBuilder* builder, const AffixFuzzer18* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer18::fill_arrow_array_builder( - arrow::ListBuilder* builder, const AffixFuzzer18* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.many_optional_unions.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append()); - if (element.many_optional_unions.value().data()) { - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer4::fill_arrow_array_builder( - value_builder, - element.many_optional_unions.value().data(), - element.many_optional_unions.value().size() - )); - } - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.many_optional_unions.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append()); + if (element.many_optional_unions.value().data()) { + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer4::fill_arrow_array_builder( + value_builder, + element.many_optional_unions.value().data(), + element.many_optional_unions.value().size() + )); } + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer18::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer18::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer18::NAME, - AffixFuzzer18::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer18::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer18::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer18::NAME, + AffixFuzzer18::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer18.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer18.hpp index 9afbd6b7e981..5f3796b1d762 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer18.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer18.hpp @@ -19,46 +19,44 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer18 { - std::optional> many_optional_unions; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer18() = default; - - AffixFuzzer18( - std::optional> many_optional_unions_ - ) - : many_optional_unions(std::move(many_optional_unions_)) {} - - AffixFuzzer18& operator=( - std::optional> many_optional_unions_ - ) { - many_optional_unions = std::move(many_optional_unions_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer18* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer18 { + std::optional> many_optional_unions; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer18() = default; + + AffixFuzzer18( + std::optional> many_optional_unions_ + ) + : many_optional_unions(std::move(many_optional_unions_)) {} + + AffixFuzzer18& operator=( + std::optional> many_optional_unions_ + ) { + many_optional_unions = std::move(many_optional_unions_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer18* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer19.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer19.cpp index 962768335fbb..93476f3a948f 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer19.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer19.cpp @@ -8,74 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer19::NAME[] = "rerun.testing.components.AffixFuzzer19"; +namespace rerun::components { + const char AffixFuzzer19::NAME[] = "rerun.testing.components.AffixFuzzer19"; - const std::shared_ptr& AffixFuzzer19::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer5::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer19::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer5::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer19::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer19::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer5::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer5::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer19::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer19* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer19::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer19* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::AffixFuzzer5) == sizeof(AffixFuzzer19)); - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer5::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::AffixFuzzer5) == sizeof(AffixFuzzer19)); + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer5::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer19::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer19::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer19::NAME, - AffixFuzzer19::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer19::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer19::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer19::NAME, + AffixFuzzer19::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer19.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer19.hpp index 6cac404f79a6..6a8ec5ca868c 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer19.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer19.hpp @@ -19,57 +19,55 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer19 { - rerun::datatypes::AffixFuzzer5 just_a_table_nothing_shady; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer19() = default; - - AffixFuzzer19(rerun::datatypes::AffixFuzzer5 just_a_table_nothing_shady_) - : just_a_table_nothing_shady(std::move(just_a_table_nothing_shady_)) {} - - AffixFuzzer19& operator=(rerun::datatypes::AffixFuzzer5 just_a_table_nothing_shady_) { - just_a_table_nothing_shady = std::move(just_a_table_nothing_shady_); - return *this; - } - - AffixFuzzer19(std::optional single_optional_union_) - : just_a_table_nothing_shady(std::move(single_optional_union_)) {} - - AffixFuzzer19& operator=( - std::optional single_optional_union_ - ) { - just_a_table_nothing_shady = std::move(single_optional_union_); - return *this; - } - - /// Cast to the underlying AffixFuzzer5 datatype - operator rerun::datatypes::AffixFuzzer5() const { - return just_a_table_nothing_shady; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer19* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer19 { + rerun::datatypes::AffixFuzzer5 just_a_table_nothing_shady; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer19() = default; + + AffixFuzzer19(rerun::datatypes::AffixFuzzer5 just_a_table_nothing_shady_) + : just_a_table_nothing_shady(std::move(just_a_table_nothing_shady_)) {} + + AffixFuzzer19& operator=(rerun::datatypes::AffixFuzzer5 just_a_table_nothing_shady_) { + just_a_table_nothing_shady = std::move(just_a_table_nothing_shady_); + return *this; + } + + AffixFuzzer19(std::optional single_optional_union_) + : just_a_table_nothing_shady(std::move(single_optional_union_)) {} + + AffixFuzzer19& operator=( + std::optional single_optional_union_ + ) { + just_a_table_nothing_shady = std::move(single_optional_union_); + return *this; + } + + /// Cast to the underlying AffixFuzzer5 datatype + operator rerun::datatypes::AffixFuzzer5() const { + return just_a_table_nothing_shady; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer19* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer2.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer2.cpp index 7dadad7dfd6a..e78d1b0fb1f8 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer2.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer2.cpp @@ -8,74 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer2::NAME[] = "rerun.testing.components.AffixFuzzer2"; +namespace rerun::components { + const char AffixFuzzer2::NAME[] = "rerun.testing.components.AffixFuzzer2"; - const std::shared_ptr& AffixFuzzer2::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer2::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer2::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer2::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer2::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer2* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer2::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer2* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::AffixFuzzer1) == sizeof(AffixFuzzer2)); - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer1::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::AffixFuzzer1) == sizeof(AffixFuzzer2)); + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer1::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer2::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer2::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer2::NAME, - AffixFuzzer2::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer2::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer2::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer2::NAME, + AffixFuzzer2::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer2.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer2.hpp index d1895adc4810..386abc26d332 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer2.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer2.hpp @@ -17,47 +17,45 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer2 { - rerun::datatypes::AffixFuzzer1 single_required; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer2() = default; - - AffixFuzzer2(rerun::datatypes::AffixFuzzer1 single_required_) - : single_required(std::move(single_required_)) {} - - AffixFuzzer2& operator=(rerun::datatypes::AffixFuzzer1 single_required_) { - single_required = std::move(single_required_); - return *this; - } - - /// Cast to the underlying AffixFuzzer1 datatype - operator rerun::datatypes::AffixFuzzer1() const { - return single_required; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer2* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer2 { + rerun::datatypes::AffixFuzzer1 single_required; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer2() = default; + + AffixFuzzer2(rerun::datatypes::AffixFuzzer1 single_required_) + : single_required(std::move(single_required_)) {} + + AffixFuzzer2& operator=(rerun::datatypes::AffixFuzzer1 single_required_) { + single_required = std::move(single_required_); + return *this; + } + + /// Cast to the underlying AffixFuzzer1 datatype + operator rerun::datatypes::AffixFuzzer1() const { + return single_required; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer2* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer20.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer20.cpp index 083f4e91edc3..97a397ee59f6 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer20.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer20.cpp @@ -8,75 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer20::NAME[] = "rerun.testing.components.AffixFuzzer20"; +namespace rerun::components { + const char AffixFuzzer20::NAME[] = "rerun.testing.components.AffixFuzzer20"; - const std::shared_ptr& AffixFuzzer20::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer20::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer20::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer20::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer20::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer20::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer20::new_arrow_array_builder(memory_pool).value); + } - return Result( - rerun::datatypes::AffixFuzzer20::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer20::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer20* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer20::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer20* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::AffixFuzzer20) == sizeof(AffixFuzzer20)); - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer20::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::AffixFuzzer20) == sizeof(AffixFuzzer20)); + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer20::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - Result AffixFuzzer20::to_data_cell( - const AffixFuzzer20* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = AffixFuzzer20::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer20::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result AffixFuzzer20::to_data_cell( + const AffixFuzzer20* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - AffixFuzzer20::NAME, - AffixFuzzer20::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer20::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer20::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer20::NAME, + AffixFuzzer20::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer20.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer20.hpp index 5d0a140c15fc..b71d077b9c30 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer20.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer20.hpp @@ -17,47 +17,45 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer20 { - rerun::datatypes::AffixFuzzer20 nested_transparent; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer20() = default; - - AffixFuzzer20(rerun::datatypes::AffixFuzzer20 nested_transparent_) - : nested_transparent(std::move(nested_transparent_)) {} - - AffixFuzzer20& operator=(rerun::datatypes::AffixFuzzer20 nested_transparent_) { - nested_transparent = std::move(nested_transparent_); - return *this; - } - - /// Cast to the underlying AffixFuzzer20 datatype - operator rerun::datatypes::AffixFuzzer20() const { - return nested_transparent; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer20* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of AffixFuzzer20 components. - static Result to_data_cell( - const AffixFuzzer20* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer20 { + rerun::datatypes::AffixFuzzer20 nested_transparent; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer20() = default; + + AffixFuzzer20(rerun::datatypes::AffixFuzzer20 nested_transparent_) + : nested_transparent(std::move(nested_transparent_)) {} + + AffixFuzzer20& operator=(rerun::datatypes::AffixFuzzer20 nested_transparent_) { + nested_transparent = std::move(nested_transparent_); + return *this; + } + + /// Cast to the underlying AffixFuzzer20 datatype + operator rerun::datatypes::AffixFuzzer20() const { + return nested_transparent; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer20* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer20 components. + static Result to_data_cell( + const AffixFuzzer20* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer21.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer21.cpp index 932c2c36e8ef..80be81ea7583 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer21.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer21.cpp @@ -8,75 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer21::NAME[] = "rerun.testing.components.AffixFuzzer21"; +namespace rerun::components { + const char AffixFuzzer21::NAME[] = "rerun.testing.components.AffixFuzzer21"; - const std::shared_ptr& AffixFuzzer21::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer21::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer21::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer21::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer21::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer21::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer21::new_arrow_array_builder(memory_pool).value); + } - return Result( - rerun::datatypes::AffixFuzzer21::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer21::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer21* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer21::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer21* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::AffixFuzzer21) == sizeof(AffixFuzzer21)); - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer21::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::AffixFuzzer21) == sizeof(AffixFuzzer21)); + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer21::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - Result AffixFuzzer21::to_data_cell( - const AffixFuzzer21* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); + return Error::ok(); + } - auto builder_result = AffixFuzzer21::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer21::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + Result AffixFuzzer21::to_data_cell( + const AffixFuzzer21* instances, size_t num_instances + ) { + // TODO(andreas): Allow configuring the memory pool. + arrow::MemoryPool* pool = arrow::default_memory_pool(); - return rerun::DataCell::create( - AffixFuzzer21::NAME, - AffixFuzzer21::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer21::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer21::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer21::NAME, + AffixFuzzer21::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer21.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer21.hpp index 282d4a02ea56..c5239a9f4137 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer21.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer21.hpp @@ -17,47 +17,45 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer21 { - rerun::datatypes::AffixFuzzer21 nested_halves; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer21() = default; - - AffixFuzzer21(rerun::datatypes::AffixFuzzer21 nested_halves_) - : nested_halves(std::move(nested_halves_)) {} - - AffixFuzzer21& operator=(rerun::datatypes::AffixFuzzer21 nested_halves_) { - nested_halves = std::move(nested_halves_); - return *this; - } - - /// Cast to the underlying AffixFuzzer21 datatype - operator rerun::datatypes::AffixFuzzer21() const { - return nested_halves; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer21* elements, size_t num_elements - ); - - /// Creates a Rerun DataCell from an array of AffixFuzzer21 components. - static Result to_data_cell( - const AffixFuzzer21* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer21 { + rerun::datatypes::AffixFuzzer21 nested_halves; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer21() = default; + + AffixFuzzer21(rerun::datatypes::AffixFuzzer21 nested_halves_) + : nested_halves(std::move(nested_halves_)) {} + + AffixFuzzer21& operator=(rerun::datatypes::AffixFuzzer21 nested_halves_) { + nested_halves = std::move(nested_halves_); + return *this; + } + + /// Cast to the underlying AffixFuzzer21 datatype + operator rerun::datatypes::AffixFuzzer21() const { + return nested_halves; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer21* elements, size_t num_elements + ); + + /// Creates a Rerun DataCell from an array of AffixFuzzer21 components. + static Result to_data_cell( + const AffixFuzzer21* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer3.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer3.cpp index f6e61e15b834..522cb7c94f3b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer3.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer3.cpp @@ -8,74 +8,68 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer3::NAME[] = "rerun.testing.components.AffixFuzzer3"; +namespace rerun::components { + const char AffixFuzzer3::NAME[] = "rerun.testing.components.AffixFuzzer3"; - const std::shared_ptr& AffixFuzzer3::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer3::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer3::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer3::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer3::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer3* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer3::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer3* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(rerun::datatypes::AffixFuzzer1) == sizeof(AffixFuzzer3)); - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer1::fill_arrow_array_builder( - builder, - reinterpret_cast(elements), - num_elements - )); + static_assert(sizeof(rerun::datatypes::AffixFuzzer1) == sizeof(AffixFuzzer3)); + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer1::fill_arrow_array_builder( + builder, + reinterpret_cast(elements), + num_elements + )); - return Error::ok(); - } - - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer3::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer3::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer3::NAME, - AffixFuzzer3::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer3::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer3::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer3::NAME, + AffixFuzzer3::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer3.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer3.hpp index 4db26f065c2f..6069a501a32b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer3.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer3.hpp @@ -17,47 +17,45 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer3 { - rerun::datatypes::AffixFuzzer1 single_required; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer3() = default; - - AffixFuzzer3(rerun::datatypes::AffixFuzzer1 single_required_) - : single_required(std::move(single_required_)) {} - - AffixFuzzer3& operator=(rerun::datatypes::AffixFuzzer1 single_required_) { - single_required = std::move(single_required_); - return *this; - } - - /// Cast to the underlying AffixFuzzer1 datatype - operator rerun::datatypes::AffixFuzzer1() const { - return single_required; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer3* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer3 { + rerun::datatypes::AffixFuzzer1 single_required; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer3() = default; + + AffixFuzzer3(rerun::datatypes::AffixFuzzer1 single_required_) + : single_required(std::move(single_required_)) {} + + AffixFuzzer3& operator=(rerun::datatypes::AffixFuzzer1 single_required_) { + single_required = std::move(single_required_); + return *this; + } + + /// Cast to the underlying AffixFuzzer1 datatype + operator rerun::datatypes::AffixFuzzer1() const { + return single_required; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer3* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer4.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer4.cpp index 48ea80002ed0..f7494e72dd11 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer4.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer4.cpp @@ -8,75 +8,69 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer4::NAME[] = "rerun.testing.components.AffixFuzzer4"; +namespace rerun::components { + const char AffixFuzzer4::NAME[] = "rerun.testing.components.AffixFuzzer4"; - const std::shared_ptr& AffixFuzzer4::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer4::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer4::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer4::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer4::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer4* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer4::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer4* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - (void)num_elements; - if (true) { - return rerun::Error( - ErrorCode::NotImplemented, - "TODO(andreas) Handle nullable extensions" - ); - } - - return Error::ok(); + (void)num_elements; + if (true) { + return rerun::Error( + ErrorCode::NotImplemented, + "TODO(andreas) Handle nullable extensions" + ); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer4::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer4::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer4::NAME, - AffixFuzzer4::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer4::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer4::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer4::NAME, + AffixFuzzer4::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer4.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer4.hpp index 3402f9ea284a..331881526397 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer4.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer4.hpp @@ -18,48 +18,45 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer4 { - std::optional single_optional; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer4() = default; - - AffixFuzzer4(std::optional single_optional_) - : single_optional(std::move(single_optional_)) {} - - AffixFuzzer4& operator=(std::optional single_optional_ - ) { - single_optional = std::move(single_optional_); - return *this; - } - - /// Cast to the underlying AffixFuzzer1 datatype - operator std::optional() const { - return single_optional; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer4* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer4 { + std::optional single_optional; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer4() = default; + + AffixFuzzer4(std::optional single_optional_) + : single_optional(std::move(single_optional_)) {} + + AffixFuzzer4& operator=(std::optional single_optional_) { + single_optional = std::move(single_optional_); + return *this; + } + + /// Cast to the underlying AffixFuzzer1 datatype + operator std::optional() const { + return single_optional; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer4* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer5.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer5.cpp index 7055c368ae45..b3e55ffe8393 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer5.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer5.cpp @@ -8,75 +8,69 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer5::NAME[] = "rerun.testing.components.AffixFuzzer5"; +namespace rerun::components { + const char AffixFuzzer5::NAME[] = "rerun.testing.components.AffixFuzzer5"; - const std::shared_ptr& AffixFuzzer5::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer5::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer5::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer5::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer5::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer5* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer5::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer5* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - (void)num_elements; - if (true) { - return rerun::Error( - ErrorCode::NotImplemented, - "TODO(andreas) Handle nullable extensions" - ); - } - - return Error::ok(); + (void)num_elements; + if (true) { + return rerun::Error( + ErrorCode::NotImplemented, + "TODO(andreas) Handle nullable extensions" + ); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer5::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer5::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer5::NAME, - AffixFuzzer5::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer5::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer5::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer5::NAME, + AffixFuzzer5::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer5.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer5.hpp index 604461ac7451..8e998e90a373 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer5.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer5.hpp @@ -18,48 +18,45 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer5 { - std::optional single_optional; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer5() = default; - - AffixFuzzer5(std::optional single_optional_) - : single_optional(std::move(single_optional_)) {} - - AffixFuzzer5& operator=(std::optional single_optional_ - ) { - single_optional = std::move(single_optional_); - return *this; - } - - /// Cast to the underlying AffixFuzzer1 datatype - operator std::optional() const { - return single_optional; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer5* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer5 { + std::optional single_optional; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer5() = default; + + AffixFuzzer5(std::optional single_optional_) + : single_optional(std::move(single_optional_)) {} + + AffixFuzzer5& operator=(std::optional single_optional_) { + single_optional = std::move(single_optional_); + return *this; + } + + /// Cast to the underlying AffixFuzzer1 datatype + operator std::optional() const { + return single_optional; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer5* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer6.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer6.cpp index 82c0d135fb84..5a2db8cf21f2 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer6.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer6.cpp @@ -8,75 +8,69 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer6::NAME[] = "rerun.testing.components.AffixFuzzer6"; +namespace rerun::components { + const char AffixFuzzer6::NAME[] = "rerun.testing.components.AffixFuzzer6"; - const std::shared_ptr& AffixFuzzer6::arrow_datatype() { - static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); - return datatype; + const std::shared_ptr& AffixFuzzer6::arrow_datatype() { + static const auto datatype = rerun::datatypes::AffixFuzzer1::arrow_datatype(); + return datatype; + } + + Result> AffixFuzzer6::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer6::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value); + } - return Result(rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value + rerun::Error AffixFuzzer6::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer6* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); } - rerun::Error AffixFuzzer6::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer6* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - (void)num_elements; - if (true) { - return rerun::Error( - ErrorCode::NotImplemented, - "TODO(andreas) Handle nullable extensions" - ); - } - - return Error::ok(); + (void)num_elements; + if (true) { + return rerun::Error( + ErrorCode::NotImplemented, + "TODO(andreas) Handle nullable extensions" + ); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer6::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer6::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer6::NAME, - AffixFuzzer6::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer6::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer6::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer6::NAME, + AffixFuzzer6::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer6.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer6.hpp index e7a8f0a5092b..78210bf4399b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer6.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer6.hpp @@ -18,48 +18,45 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer6 { - std::optional single_optional; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer6() = default; - - AffixFuzzer6(std::optional single_optional_) - : single_optional(std::move(single_optional_)) {} - - AffixFuzzer6& operator=(std::optional single_optional_ - ) { - single_optional = std::move(single_optional_); - return *this; - } - - /// Cast to the underlying AffixFuzzer1 datatype - operator std::optional() const { - return single_optional; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer6* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer6 { + std::optional single_optional; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer6() = default; + + AffixFuzzer6(std::optional single_optional_) + : single_optional(std::move(single_optional_)) {} + + AffixFuzzer6& operator=(std::optional single_optional_) { + single_optional = std::move(single_optional_); + return *this; + } + + /// Cast to the underlying AffixFuzzer1 datatype + operator std::optional() const { + return single_optional; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer6* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer7.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer7.cpp index d84a886958bb..b93c91c728e1 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer7.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer7.cpp @@ -8,91 +8,86 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer7::NAME[] = "rerun.testing.components.AffixFuzzer7"; +namespace rerun::components { + const char AffixFuzzer7::NAME[] = "rerun.testing.components.AffixFuzzer7"; - const std::shared_ptr& AffixFuzzer7::arrow_datatype() { - static const auto datatype = arrow::list( - arrow::field("item", rerun::datatypes::AffixFuzzer1::arrow_datatype(), false) - ); - return datatype; + const std::shared_ptr& AffixFuzzer7::arrow_datatype() { + static const auto datatype = arrow::list( + arrow::field("item", rerun::datatypes::AffixFuzzer1::arrow_datatype(), false) + ); + return datatype; + } + + Result> AffixFuzzer7::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer7::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value + )); + } - return Result(std::make_shared( - memory_pool, - rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value - )); + rerun::Error AffixFuzzer7::fill_arrow_array_builder( + arrow::ListBuilder* builder, const AffixFuzzer7* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer7::fill_arrow_array_builder( - arrow::ListBuilder* builder, const AffixFuzzer7* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - auto value_builder = static_cast(builder->value_builder()); - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); + auto value_builder = static_cast(builder->value_builder()); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.many_optional.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append()); - if (element.many_optional.value().data()) { - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer1::fill_arrow_array_builder( - value_builder, - element.many_optional.value().data(), - element.many_optional.value().size() - )); - } - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.many_optional.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append()); + if (element.many_optional.value().data()) { + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer1::fill_arrow_array_builder( + value_builder, + element.many_optional.value().data(), + element.many_optional.value().size() + )); } + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer7::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer7::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer7::NAME, - AffixFuzzer7::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer7::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer7::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer7::NAME, + AffixFuzzer7::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer7.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer7.hpp index 86919251e04e..8cfa6764649e 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer7.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer7.hpp @@ -19,44 +19,42 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer7 { - std::optional> many_optional; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer7() = default; - - AffixFuzzer7(std::optional> many_optional_) - : many_optional(std::move(many_optional_)) {} - - AffixFuzzer7& operator=( - std::optional> many_optional_ - ) { - many_optional = std::move(many_optional_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer7* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer7 { + std::optional> many_optional; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer7() = default; + + AffixFuzzer7(std::optional> many_optional_) + : many_optional(std::move(many_optional_)) {} + + AffixFuzzer7& operator=( + std::optional> many_optional_ + ) { + many_optional = std::move(many_optional_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer7* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer8.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer8.cpp index 2d21afac0857..19a14a309a9b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer8.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer8.cpp @@ -6,76 +6,71 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer8::NAME[] = "rerun.testing.components.AffixFuzzer8"; +namespace rerun::components { + const char AffixFuzzer8::NAME[] = "rerun.testing.components.AffixFuzzer8"; - const std::shared_ptr& AffixFuzzer8::arrow_datatype() { - static const auto datatype = arrow::float32(); - return datatype; + const std::shared_ptr& AffixFuzzer8::arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; + } + + Result> AffixFuzzer8::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer8::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error AffixFuzzer8::fill_arrow_array_builder( + arrow::FloatBuilder* builder, const AffixFuzzer8* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer8::fill_arrow_array_builder( - arrow::FloatBuilder* builder, const AffixFuzzer8* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.single_float_optional.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append(element.single_float_optional.value())); - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); - } + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.single_float_optional.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append(element.single_float_optional.value())); + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer8::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer8::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer8::NAME, - AffixFuzzer8::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer8::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer8::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer8::NAME, + AffixFuzzer8::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer8.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer8.hpp index 59b1dfd5e74c..bb9e7ca33b3b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer8.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer8.hpp @@ -20,42 +20,40 @@ namespace arrow { using FloatBuilder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer8 { - std::optional single_float_optional; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer8() = default; - - AffixFuzzer8(std::optional single_float_optional_) - : single_float_optional(single_float_optional_) {} - - AffixFuzzer8& operator=(std::optional single_float_optional_) { - single_float_optional = single_float_optional_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer8* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer8 { + std::optional single_float_optional; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer8() = default; + + AffixFuzzer8(std::optional single_float_optional_) + : single_float_optional(single_float_optional_) {} + + AffixFuzzer8& operator=(std::optional single_float_optional_) { + single_float_optional = single_float_optional_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer8* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer9.cpp b/rerun_cpp/tests/generated/components/affix_fuzzer9.cpp index 0c41ca22696e..8b25b996262c 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer9.cpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer9.cpp @@ -6,71 +6,66 @@ #include #include -namespace rerun { - namespace components { - const char AffixFuzzer9::NAME[] = "rerun.testing.components.AffixFuzzer9"; +namespace rerun::components { + const char AffixFuzzer9::NAME[] = "rerun.testing.components.AffixFuzzer9"; - const std::shared_ptr& AffixFuzzer9::arrow_datatype() { - static const auto datatype = arrow::utf8(); - return datatype; - } - - Result> AffixFuzzer9::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + const std::shared_ptr& AffixFuzzer9::arrow_datatype() { + static const auto datatype = arrow::utf8(); + return datatype; + } - return Result(std::make_shared(memory_pool)); + Result> AffixFuzzer9::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - rerun::Error AffixFuzzer9::fill_arrow_array_builder( - arrow::StringBuilder* builder, const AffixFuzzer9* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + return Result(std::make_shared(memory_pool)); + } - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(builder->Append(elements[elem_idx].single_string_required)); - } + rerun::Error AffixFuzzer9::fill_arrow_array_builder( + arrow::StringBuilder* builder, const AffixFuzzer9* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } - return Error::ok(); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(builder->Append(elements[elem_idx].single_string_required)); } - 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(); + return Error::ok(); + } - auto builder_result = AffixFuzzer9::new_arrow_array_builder(pool); - RR_RETURN_NOT_OK(builder_result.error); - auto builder = std::move(builder_result.value); - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK( - AffixFuzzer9::fill_arrow_array_builder(builder.get(), instances, num_instances) - ); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); + 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(); - return rerun::DataCell::create( - AffixFuzzer9::NAME, - AffixFuzzer9::arrow_datatype(), - std::move(array) + auto builder_result = AffixFuzzer9::new_arrow_array_builder(pool); + RR_RETURN_NOT_OK(builder_result.error); + auto builder = std::move(builder_result.value); + if (instances && num_instances > 0) { + RR_RETURN_NOT_OK( + AffixFuzzer9::fill_arrow_array_builder(builder.get(), instances, num_instances) ); } - } // namespace components -} // namespace rerun + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder->Finish(&array)); + + return rerun::DataCell::create( + AffixFuzzer9::NAME, + AffixFuzzer9::arrow_datatype(), + std::move(array) + ); + } +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer9.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer9.hpp index eb91c836a6e9..1464466272c0 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer9.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer9.hpp @@ -16,42 +16,40 @@ namespace arrow { class StringBuilder; } // namespace arrow -namespace rerun { - namespace components { - struct AffixFuzzer9 { - std::string single_string_required; - - /// Name of the component, used for serialization. - static const char NAME[]; - - public: - AffixFuzzer9() = default; - - AffixFuzzer9(std::string single_string_required_) - : single_string_required(std::move(single_string_required_)) {} - - AffixFuzzer9& operator=(std::string single_string_required_) { - single_string_required = std::move(single_string_required_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error 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 Result to_data_cell( - const AffixFuzzer9* instances, size_t num_instances - ); - }; - } // namespace components -} // namespace rerun +namespace rerun::components { + struct AffixFuzzer9 { + std::string single_string_required; + + /// Name of the component, used for serialization. + static const char NAME[]; + + public: + AffixFuzzer9() = default; + + AffixFuzzer9(std::string single_string_required_) + : single_string_required(std::move(single_string_required_)) {} + + AffixFuzzer9& operator=(std::string single_string_required_) { + single_string_required = std::move(single_string_required_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error 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 Result to_data_cell( + const AffixFuzzer9* instances, size_t num_instances + ); + }; +} // namespace rerun::components diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.cpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.cpp index 3c5ae0564698..140d2d09788f 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.cpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.cpp @@ -8,220 +8,209 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& AffixFuzzer1::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("single_float_optional", arrow::float32(), true), - arrow::field("single_string_required", arrow::utf8(), false), - arrow::field("single_string_optional", arrow::utf8(), true), - arrow::field( - "many_floats_optional", - arrow::list(arrow::field("item", arrow::float32(), false)), - true - ), - arrow::field( - "many_strings_required", - arrow::list(arrow::field("item", arrow::utf8(), false)), - false +namespace rerun::datatypes { + const std::shared_ptr& AffixFuzzer1::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("single_float_optional", arrow::float32(), true), + arrow::field("single_string_required", arrow::utf8(), false), + arrow::field("single_string_optional", arrow::utf8(), true), + arrow::field( + "many_floats_optional", + arrow::list(arrow::field("item", arrow::float32(), false)), + true + ), + arrow::field( + "many_strings_required", + arrow::list(arrow::field("item", arrow::utf8(), false)), + false + ), + arrow::field( + "many_strings_optional", + arrow::list(arrow::field("item", arrow::utf8(), false)), + true + ), + arrow::field("flattened_scalar", arrow::float32(), false), + arrow::field( + "almost_flattened_scalar", + rerun::datatypes::FlattenedScalar::arrow_datatype(), + false + ), + arrow::field("from_parent", arrow::boolean(), true), + }); + return datatype; + } + + Result> AffixFuzzer1::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); + } + + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared(memory_pool), + std::make_shared(memory_pool), + std::make_shared(memory_pool), + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field( - "many_strings_optional", - arrow::list(arrow::field("item", arrow::utf8(), false)), - true + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field("flattened_scalar", arrow::float32(), false), - arrow::field( - "almost_flattened_scalar", - rerun::datatypes::FlattenedScalar::arrow_datatype(), - false + std::make_shared( + memory_pool, + std::make_shared(memory_pool) ), - arrow::field("from_parent", arrow::boolean(), true), - }); - return datatype; + std::make_shared(memory_pool), + rerun::datatypes::FlattenedScalar::new_arrow_array_builder(memory_pool).value, + std::make_shared(memory_pool), + }) + )); + } + + rerun::Error AffixFuzzer1::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer1* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - Result> AffixFuzzer1::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.single_float_optional.has_value()) { + ARROW_RETURN_NOT_OK(field_builder->Append(element.single_float_optional.value()) + ); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); + } } - - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared(memory_pool), - std::make_shared(memory_pool), - std::make_shared(memory_pool), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - std::make_shared(memory_pool), - rerun::datatypes::FlattenedScalar::new_arrow_array_builder(memory_pool).value, - std::make_shared(memory_pool), - }) - )); } - - rerun::Error AffixFuzzer1::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer1* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].single_string_required) ); } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); + } + { + auto field_builder = static_cast(builder->field_builder(2)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.single_string_optional.has_value()) { + ARROW_RETURN_NOT_OK(field_builder->Append(element.single_string_optional.value() + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); + } } + } + { + auto field_builder = static_cast(builder->field_builder(3)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.single_float_optional.has_value()) { - ARROW_RETURN_NOT_OK( - field_builder->Append(element.single_float_optional.value()) - ); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.many_floats_optional.has_value()) { + ARROW_RETURN_NOT_OK(field_builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + element.many_floats_optional.value().data(), + static_cast(element.many_floats_optional.value().size()), + nullptr + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - { - auto field_builder = static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + } + { + auto field_builder = static_cast(builder->field_builder(4)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(field_builder->Append()); + for (size_t item_idx = 0; item_idx < element.many_strings_required.size(); + item_idx += 1) { ARROW_RETURN_NOT_OK( - field_builder->Append(elements[elem_idx].single_string_required) + value_builder->Append(element.many_strings_required[item_idx]) ); } } - { - auto field_builder = static_cast(builder->field_builder(2)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.single_string_optional.has_value()) { - ARROW_RETURN_NOT_OK( - field_builder->Append(element.single_string_optional.value()) - ); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } - } - } - { - auto field_builder = static_cast(builder->field_builder(3)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.many_floats_optional.has_value()) { - ARROW_RETURN_NOT_OK(field_builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - element.many_floats_optional.value().data(), - static_cast(element.many_floats_optional.value().size()), - nullptr - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } - } - } - { - auto field_builder = static_cast(builder->field_builder(4)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + } + { + auto field_builder = static_cast(builder->field_builder(5)); + auto value_builder = static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.many_strings_optional.has_value()) { ARROW_RETURN_NOT_OK(field_builder->Append()); - for (size_t item_idx = 0; item_idx < element.many_strings_required.size(); + for (size_t item_idx = 0; + item_idx < element.many_strings_optional.value().size(); item_idx += 1) { ARROW_RETURN_NOT_OK( - value_builder->Append(element.many_strings_required[item_idx]) + value_builder->Append(element.many_strings_optional.value()[item_idx]) ); } + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - { - auto field_builder = static_cast(builder->field_builder(5)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 1))); - - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.many_strings_optional.has_value()) { - ARROW_RETURN_NOT_OK(field_builder->Append()); - for (size_t item_idx = 0; - item_idx < element.many_strings_optional.value().size(); - item_idx += 1) { - ARROW_RETURN_NOT_OK(value_builder->Append( - element.many_strings_optional.value()[item_idx] - )); - } - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } - } - } - { - auto field_builder = static_cast(builder->field_builder(6)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].flattened_scalar)); - } + } + { + auto field_builder = static_cast(builder->field_builder(6)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].flattened_scalar)); } - { - auto field_builder = static_cast(builder->field_builder(7)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::FlattenedScalar::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].almost_flattened_scalar, - 1 - )); - } + } + { + auto field_builder = static_cast(builder->field_builder(7)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::FlattenedScalar::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].almost_flattened_scalar, + 1 + )); } - { - auto field_builder = static_cast(builder->field_builder(8)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.from_parent.has_value()) { - ARROW_RETURN_NOT_OK(field_builder->Append(element.from_parent.value())); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + } + { + auto field_builder = static_cast(builder->field_builder(8)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.from_parent.has_value()) { + ARROW_RETURN_NOT_OK(field_builder->Append(element.from_parent.value())); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.hpp index 90b82084be48..e92440c1d3c7 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.hpp @@ -18,42 +18,40 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - struct AffixFuzzer1 { - std::optional single_float_optional; +namespace rerun::datatypes { + struct AffixFuzzer1 { + std::optional single_float_optional; - std::string single_string_required; + std::string single_string_required; - std::optional single_string_optional; + std::optional single_string_optional; - std::optional> many_floats_optional; + std::optional> many_floats_optional; - std::vector many_strings_required; + std::vector many_strings_required; - std::optional> many_strings_optional; + std::optional> many_strings_optional; - float flattened_scalar; + float flattened_scalar; - rerun::datatypes::FlattenedScalar almost_flattened_scalar; + rerun::datatypes::FlattenedScalar almost_flattened_scalar; - std::optional from_parent; + std::optional from_parent; - public: - AffixFuzzer1() = default; + public: + AffixFuzzer1() = default; - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer1* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer1* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer2.cpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer2.cpp index 1ab6b519affb..717cacf21e1d 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer2.cpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer2.cpp @@ -6,50 +6,45 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& AffixFuzzer2::arrow_datatype() { - static const auto datatype = arrow::float32(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& AffixFuzzer2::arrow_datatype() { + static const auto datatype = arrow::float32(); + return datatype; + } + + Result> AffixFuzzer2::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer2::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error AffixFuzzer2::fill_arrow_array_builder( + arrow::FloatBuilder* builder, const AffixFuzzer2* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer2::fill_arrow_array_builder( - arrow::FloatBuilder* builder, const AffixFuzzer2* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.single_float_optional.has_value()) { - ARROW_RETURN_NOT_OK(builder->Append(element.single_float_optional.value())); - } else { - ARROW_RETURN_NOT_OK(builder->AppendNull()); - } + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.single_float_optional.has_value()) { + ARROW_RETURN_NOT_OK(builder->Append(element.single_float_optional.value())); + } else { + ARROW_RETURN_NOT_OK(builder->AppendNull()); } - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer2.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer2.hpp index ab5d4ec65bb6..d70776a966a4 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer2.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer2.hpp @@ -19,34 +19,32 @@ namespace arrow { using FloatBuilder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - struct AffixFuzzer2 { - std::optional single_float_optional; - - public: - AffixFuzzer2() = default; - - AffixFuzzer2(std::optional single_float_optional_) - : single_float_optional(single_float_optional_) {} - - AffixFuzzer2& operator=(std::optional single_float_optional_) { - single_float_optional = single_float_optional_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::FloatBuilder* builder, const AffixFuzzer2* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + struct AffixFuzzer2 { + std::optional single_float_optional; + + public: + AffixFuzzer2() = default; + + AffixFuzzer2(std::optional single_float_optional_) + : single_float_optional(single_float_optional_) {} + + AffixFuzzer2& operator=(std::optional single_float_optional_) { + single_float_optional = single_float_optional_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::FloatBuilder* builder, const AffixFuzzer2* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer20.cpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer20.cpp index 8f4001165020..3c9bc3d93244 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer20.cpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer20.cpp @@ -9,75 +9,69 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& AffixFuzzer20::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("p", rerun::datatypes::PrimitiveComponent::arrow_datatype(), false), - arrow::field("s", rerun::datatypes::StringComponent::arrow_datatype(), false), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& AffixFuzzer20::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("p", rerun::datatypes::PrimitiveComponent::arrow_datatype(), false), + arrow::field("s", rerun::datatypes::StringComponent::arrow_datatype(), false), + }); + return datatype; + } + + Result> AffixFuzzer20::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer20::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::PrimitiveComponent::new_arrow_array_builder(memory_pool).value, + rerun::datatypes::StringComponent::new_arrow_array_builder(memory_pool).value, + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::PrimitiveComponent::new_arrow_array_builder(memory_pool) - .value, - rerun::datatypes::StringComponent::new_arrow_array_builder(memory_pool).value, - }) - )); + rerun::Error AffixFuzzer20::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer20* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer20::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer20* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::PrimitiveComponent::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].p, - 1 - )); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::PrimitiveComponent::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].p, + 1 + )); } - { - auto field_builder = static_cast(builder->field_builder(1)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - RR_RETURN_NOT_OK(rerun::datatypes::StringComponent::fill_arrow_array_builder( - field_builder, - &elements[elem_idx].s, - 1 - )); - } + } + { + auto field_builder = static_cast(builder->field_builder(1)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + RR_RETURN_NOT_OK(rerun::datatypes::StringComponent::fill_arrow_array_builder( + field_builder, + &elements[elem_idx].s, + 1 + )); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer20.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer20.hpp index 560e59984d5e..1a7a0693746f 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer20.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer20.hpp @@ -16,28 +16,26 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - struct AffixFuzzer20 { - rerun::datatypes::PrimitiveComponent p; - - rerun::datatypes::StringComponent s; - - public: - AffixFuzzer20() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer20* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + struct AffixFuzzer20 { + rerun::datatypes::PrimitiveComponent p; + + rerun::datatypes::StringComponent s; + + public: + AffixFuzzer20() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer20* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.cpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.cpp index c1da476fbff1..6980419624b8 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.cpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.cpp @@ -6,86 +6,80 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& AffixFuzzer21::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("single_half", arrow::float16(), false), - arrow::field( - "many_halves", - arrow::list(arrow::field("item", arrow::float16(), false)), - false - ), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& AffixFuzzer21::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("single_half", arrow::float16(), false), + arrow::field( + "many_halves", + arrow::list(arrow::field("item", arrow::float16(), false)), + false + ), + }); + return datatype; + } + + Result> AffixFuzzer21::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer21::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared(memory_pool), + std::make_shared( + memory_pool, + std::make_shared(memory_pool) + ), + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared(memory_pool), - std::make_shared( - memory_pool, - std::make_shared(memory_pool) - ), - }) - )); + rerun::Error AffixFuzzer21::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer21* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer21::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer21* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = - static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append( - *reinterpret_cast(&(elements[elem_idx].single_half)) - )); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append( + *reinterpret_cast(&(elements[elem_idx].single_half)) + )); } - { - auto field_builder = static_cast(builder->field_builder(1)); - auto value_builder = - static_cast(field_builder->value_builder()); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); + } + { + auto field_builder = static_cast(builder->field_builder(1)); + auto value_builder = + static_cast(field_builder->value_builder()); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + ARROW_RETURN_NOT_OK(value_builder->Reserve(static_cast(num_elements * 2))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - ARROW_RETURN_NOT_OK(field_builder->Append()); - ARROW_RETURN_NOT_OK(value_builder->AppendValues( - reinterpret_cast(element.many_halves.data()), - static_cast(element.many_halves.size()), - nullptr - )); - } + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + ARROW_RETURN_NOT_OK(field_builder->Append()); + ARROW_RETURN_NOT_OK(value_builder->AppendValues( + reinterpret_cast(element.many_halves.data()), + static_cast(element.many_halves.size()), + nullptr + )); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.hpp index 43fe6ccbae78..dfa57ac64b99 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.hpp @@ -15,28 +15,26 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - struct AffixFuzzer21 { - rerun::half single_half; - - std::vector many_halves; - - public: - AffixFuzzer21() = default; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer21* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + struct AffixFuzzer21 { + rerun::half single_half; + + std::vector many_halves; + + public: + AffixFuzzer21() = default; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer21* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.cpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.cpp index 4f6508b92dde..5aa63c396dea 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.cpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.cpp @@ -8,124 +8,117 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& AffixFuzzer3::arrow_datatype() { - static const auto datatype = arrow::dense_union({ - arrow::field("_null_markers", arrow::null(), true, nullptr), - arrow::field("degrees", arrow::float32(), false), - arrow::field("radians", arrow::float32(), true), - arrow::field( - "craziness", - arrow::list(arrow::field( - "item", - rerun::datatypes::AffixFuzzer1::arrow_datatype(), - false - )), - false +namespace rerun::datatypes { + const std::shared_ptr& AffixFuzzer3::arrow_datatype() { + static const auto datatype = arrow::dense_union({ + arrow::field("_null_markers", arrow::null(), true, nullptr), + arrow::field("degrees", arrow::float32(), false), + arrow::field("radians", arrow::float32(), true), + arrow::field( + "craziness", + arrow::list( + arrow::field("item", rerun::datatypes::AffixFuzzer1::arrow_datatype(), false) ), - arrow::field( - "fixed_size_shenanigans", - arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 3), - false - ), - }); - return datatype; - } + false + ), + arrow::field( + "fixed_size_shenanigans", + arrow::fixed_size_list(arrow::field("item", arrow::float32(), false), 3), + false + ), + }); + return datatype; + } - Result> AffixFuzzer3::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + Result> AffixFuzzer3::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); + } - return Result(std::make_shared( - memory_pool, - // Children: - std::vector>({ - std::make_shared(memory_pool), - std::make_shared(memory_pool), + return Result(std::make_shared( + memory_pool, + // Children: + std::vector>({ + std::make_shared(memory_pool), + std::make_shared(memory_pool), + std::make_shared(memory_pool), + std::make_shared( + memory_pool, + rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value + ), + std::make_shared( + memory_pool, std::make_shared(memory_pool), - std::make_shared( - memory_pool, - rerun::datatypes::AffixFuzzer1::new_arrow_array_builder(memory_pool).value - ), - std::make_shared( - memory_pool, - std::make_shared(memory_pool), - 3 - ), - }), - arrow_datatype() - )); - } + 3 + ), + }), + arrow_datatype() + )); + } - rerun::Error AffixFuzzer3::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const AffixFuzzer3* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } + rerun::Error AffixFuzzer3::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const AffixFuzzer3* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); + } - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& union_instance = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& union_instance = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); - auto variant_index = static_cast(union_instance._tag); - auto variant_builder_untyped = builder->child_builder(variant_index).get(); + auto variant_index = static_cast(union_instance._tag); + auto variant_builder_untyped = builder->child_builder(variant_index).get(); - switch (union_instance._tag) { - case detail::AffixFuzzer3Tag::None: { - ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); - } break; - case detail::AffixFuzzer3Tag::degrees: { - auto variant_builder = - static_cast(variant_builder_untyped); - ARROW_RETURN_NOT_OK(variant_builder->Append(union_instance._data.degrees)); - } break; - case detail::AffixFuzzer3Tag::radians: { - auto variant_builder = - static_cast(variant_builder_untyped); - const auto& element = union_instance._data; - if (element.radians.has_value()) { - ARROW_RETURN_NOT_OK(variant_builder->Append(element.radians.value())); - } else { - ARROW_RETURN_NOT_OK(variant_builder->AppendNull()); - } - } break; - case detail::AffixFuzzer3Tag::craziness: { - auto variant_builder = - static_cast(variant_builder_untyped); - (void)variant_builder; - return rerun::Error( - ErrorCode::NotImplemented, - "Failed to serialize AffixFuzzer3::craziness: objects (Object(\"rerun.testing.datatypes.AffixFuzzer1\")) in unions not yet implemented" - ); - } break; - case detail::AffixFuzzer3Tag::fixed_size_shenanigans: { - auto variant_builder = - static_cast(variant_builder_untyped); - (void)variant_builder; - return rerun::Error( - ErrorCode::NotImplemented, - "Failed to serialize AffixFuzzer3::fixed_size_shenanigans: FixedSizeListBuilder in unions not yet implemented" - ); - } break; - } + switch (union_instance._tag) { + case detail::AffixFuzzer3Tag::None: { + ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); + } break; + case detail::AffixFuzzer3Tag::degrees: { + auto variant_builder = + static_cast(variant_builder_untyped); + ARROW_RETURN_NOT_OK(variant_builder->Append(union_instance._data.degrees)); + } break; + case detail::AffixFuzzer3Tag::radians: { + auto variant_builder = + static_cast(variant_builder_untyped); + const auto& element = union_instance._data; + if (element.radians.has_value()) { + ARROW_RETURN_NOT_OK(variant_builder->Append(element.radians.value())); + } else { + ARROW_RETURN_NOT_OK(variant_builder->AppendNull()); + } + } break; + case detail::AffixFuzzer3Tag::craziness: { + auto variant_builder = + static_cast(variant_builder_untyped); + (void)variant_builder; + return rerun::Error( + ErrorCode::NotImplemented, + "Failed to serialize AffixFuzzer3::craziness: objects (Object(\"rerun.testing.datatypes.AffixFuzzer1\")) in unions not yet implemented" + ); + } break; + case detail::AffixFuzzer3Tag::fixed_size_shenanigans: { + auto variant_builder = + static_cast(variant_builder_untyped); + (void)variant_builder; + return rerun::Error( + ErrorCode::NotImplemented, + "Failed to serialize AffixFuzzer3::fixed_size_shenanigans: FixedSizeListBuilder in unions not yet implemented" + ); + } break; } - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.hpp index ecf20ecf9e91..00b6dfaf4be5 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.hpp @@ -21,193 +21,190 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - namespace detail { - /// \private - enum class AffixFuzzer3Tag : uint8_t { - /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. - None = 0, - degrees, - radians, - craziness, - fixed_size_shenanigans, - }; - - /// \private - union AffixFuzzer3Data { - float degrees; - - std::optional radians; - - std::vector craziness; - - std::array fixed_size_shenanigans; - - AffixFuzzer3Data() { - std::memset(reinterpret_cast(this), 0, sizeof(AffixFuzzer3Data)); - } - - ~AffixFuzzer3Data() {} - - void swap(AffixFuzzer3Data& other) noexcept { - // This bitwise swap would fail for self-referential types, but we don't have any of those. - char temp[sizeof(AffixFuzzer3Data)]; - void* otherbytes = reinterpret_cast(&other); - void* thisbytes = reinterpret_cast(this); - std::memcpy(temp, thisbytes, sizeof(AffixFuzzer3Data)); - std::memcpy(thisbytes, otherbytes, sizeof(AffixFuzzer3Data)); - std::memcpy(otherbytes, temp, sizeof(AffixFuzzer3Data)); - } - }; - } // namespace detail - - struct AffixFuzzer3 { - AffixFuzzer3() : _tag(detail::AffixFuzzer3Tag::None) {} - - /// Copy constructor - AffixFuzzer3(const AffixFuzzer3& other) : _tag(other._tag) { - switch (other._tag) { - case detail::AffixFuzzer3Tag::craziness: { - using TypeAlias = std::vector; - new (&_data.craziness) TypeAlias(other._data.craziness); - } break; - case detail::AffixFuzzer3Tag::degrees: - case detail::AffixFuzzer3Tag::radians: - case detail::AffixFuzzer3Tag::fixed_size_shenanigans: { - const void* otherbytes = reinterpret_cast(&other._data); - void* thisbytes = reinterpret_cast(&this->_data); - std::memcpy(thisbytes, otherbytes, sizeof(detail::AffixFuzzer3Data)); - } break; - case detail::AffixFuzzer3Tag::None: { - } break; - } - } +namespace rerun::datatypes { + namespace detail { + /// \private + enum class AffixFuzzer3Tag : uint8_t { + /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. + None = 0, + degrees, + radians, + craziness, + fixed_size_shenanigans, + }; - AffixFuzzer3& operator=(const AffixFuzzer3& other) noexcept { - AffixFuzzer3 tmp(other); - this->swap(tmp); - return *this; - } + /// \private + union AffixFuzzer3Data { + float degrees; - AffixFuzzer3(AffixFuzzer3&& other) noexcept : AffixFuzzer3() { - this->swap(other); - } + std::optional radians; - AffixFuzzer3& operator=(AffixFuzzer3&& other) noexcept { - this->swap(other); - return *this; - } + std::vector craziness; - ~AffixFuzzer3() { - switch (this->_tag) { - case detail::AffixFuzzer3Tag::None: { - // Nothing to destroy - } break; - case detail::AffixFuzzer3Tag::degrees: { - // has a trivial destructor - } break; - case detail::AffixFuzzer3Tag::radians: { - // has a trivial destructor - } break; - case detail::AffixFuzzer3Tag::craziness: { - using TypeAlias = std::vector; - _data.craziness.~TypeAlias(); - } break; - case detail::AffixFuzzer3Tag::fixed_size_shenanigans: { - // has a trivial destructor - } break; - } - } + std::array fixed_size_shenanigans; - void swap(AffixFuzzer3& other) noexcept { - std::swap(this->_tag, other._tag); - this->_data.swap(other._data); + AffixFuzzer3Data() { + std::memset(reinterpret_cast(this), 0, sizeof(AffixFuzzer3Data)); } - static AffixFuzzer3 degrees(float degrees) { - AffixFuzzer3 self; - self._tag = detail::AffixFuzzer3Tag::degrees; - new (&self._data.degrees) float(std::move(degrees)); - return self; - } + ~AffixFuzzer3Data() {} - static AffixFuzzer3 radians(std::optional radians) { - AffixFuzzer3 self; - self._tag = detail::AffixFuzzer3Tag::radians; - new (&self._data.radians) std::optional(std::move(radians)); - return self; + void swap(AffixFuzzer3Data& other) noexcept { + // This bitwise swap would fail for self-referential types, but we don't have any of those. + char temp[sizeof(AffixFuzzer3Data)]; + void* otherbytes = reinterpret_cast(&other); + void* thisbytes = reinterpret_cast(this); + std::memcpy(temp, thisbytes, sizeof(AffixFuzzer3Data)); + std::memcpy(thisbytes, otherbytes, sizeof(AffixFuzzer3Data)); + std::memcpy(otherbytes, temp, sizeof(AffixFuzzer3Data)); } - - static AffixFuzzer3 craziness(std::vector craziness) { - AffixFuzzer3 self; - self._tag = detail::AffixFuzzer3Tag::craziness; - new (&self._data.craziness) - std::vector(std::move(craziness)); - return self; + }; + } // namespace detail + + struct AffixFuzzer3 { + AffixFuzzer3() : _tag(detail::AffixFuzzer3Tag::None) {} + + /// Copy constructor + AffixFuzzer3(const AffixFuzzer3& other) : _tag(other._tag) { + switch (other._tag) { + case detail::AffixFuzzer3Tag::craziness: { + using TypeAlias = std::vector; + new (&_data.craziness) TypeAlias(other._data.craziness); + } break; + case detail::AffixFuzzer3Tag::degrees: + case detail::AffixFuzzer3Tag::radians: + case detail::AffixFuzzer3Tag::fixed_size_shenanigans: { + const void* otherbytes = reinterpret_cast(&other._data); + void* thisbytes = reinterpret_cast(&this->_data); + std::memcpy(thisbytes, otherbytes, sizeof(detail::AffixFuzzer3Data)); + } break; + case detail::AffixFuzzer3Tag::None: { + } break; } - - static AffixFuzzer3 fixed_size_shenanigans(std::array fixed_size_shenanigans - ) { - AffixFuzzer3 self; - self._tag = detail::AffixFuzzer3Tag::fixed_size_shenanigans; - new (&self._data.fixed_size_shenanigans) - std::array(std::move(fixed_size_shenanigans)); - return self; + } + + AffixFuzzer3& operator=(const AffixFuzzer3& other) noexcept { + AffixFuzzer3 tmp(other); + this->swap(tmp); + return *this; + } + + AffixFuzzer3(AffixFuzzer3&& other) noexcept : AffixFuzzer3() { + this->swap(other); + } + + AffixFuzzer3& operator=(AffixFuzzer3&& other) noexcept { + this->swap(other); + return *this; + } + + ~AffixFuzzer3() { + switch (this->_tag) { + case detail::AffixFuzzer3Tag::None: { + // Nothing to destroy + } break; + case detail::AffixFuzzer3Tag::degrees: { + // has a trivial destructor + } break; + case detail::AffixFuzzer3Tag::radians: { + // has a trivial destructor + } break; + case detail::AffixFuzzer3Tag::craziness: { + using TypeAlias = std::vector; + _data.craziness.~TypeAlias(); + } break; + case detail::AffixFuzzer3Tag::fixed_size_shenanigans: { + // has a trivial destructor + } break; } - - /// Return a pointer to degrees if the union is in that state, otherwise `nullptr`. - const float* get_degrees() const { - if (_tag == detail::AffixFuzzer3Tag::degrees) { - return &_data.degrees; - } else { - return nullptr; - } + } + + void swap(AffixFuzzer3& other) noexcept { + std::swap(this->_tag, other._tag); + this->_data.swap(other._data); + } + + static AffixFuzzer3 degrees(float degrees) { + AffixFuzzer3 self; + self._tag = detail::AffixFuzzer3Tag::degrees; + new (&self._data.degrees) float(std::move(degrees)); + return self; + } + + static AffixFuzzer3 radians(std::optional radians) { + AffixFuzzer3 self; + self._tag = detail::AffixFuzzer3Tag::radians; + new (&self._data.radians) std::optional(std::move(radians)); + return self; + } + + static AffixFuzzer3 craziness(std::vector craziness) { + AffixFuzzer3 self; + self._tag = detail::AffixFuzzer3Tag::craziness; + new (&self._data.craziness) + std::vector(std::move(craziness)); + return self; + } + + static AffixFuzzer3 fixed_size_shenanigans(std::array fixed_size_shenanigans) { + AffixFuzzer3 self; + self._tag = detail::AffixFuzzer3Tag::fixed_size_shenanigans; + new (&self._data.fixed_size_shenanigans) + std::array(std::move(fixed_size_shenanigans)); + return self; + } + + /// Return a pointer to degrees if the union is in that state, otherwise `nullptr`. + const float* get_degrees() const { + if (_tag == detail::AffixFuzzer3Tag::degrees) { + return &_data.degrees; + } else { + return nullptr; } - - /// Return a pointer to radians if the union is in that state, otherwise `nullptr`. - const std::optional* get_radians() const { - if (_tag == detail::AffixFuzzer3Tag::radians) { - return &_data.radians; - } else { - return nullptr; - } + } + + /// Return a pointer to radians if the union is in that state, otherwise `nullptr`. + const std::optional* get_radians() const { + if (_tag == detail::AffixFuzzer3Tag::radians) { + return &_data.radians; + } else { + return nullptr; } - - /// Return a pointer to craziness if the union is in that state, otherwise `nullptr`. - const std::vector* get_craziness() const { - if (_tag == detail::AffixFuzzer3Tag::craziness) { - return &_data.craziness; - } else { - return nullptr; - } + } + + /// Return a pointer to craziness if the union is in that state, otherwise `nullptr`. + const std::vector* get_craziness() const { + if (_tag == detail::AffixFuzzer3Tag::craziness) { + return &_data.craziness; + } else { + return nullptr; } - - /// Return a pointer to fixed_size_shenanigans if the union is in that state, otherwise `nullptr`. - const std::array* get_fixed_size_shenanigans() const { - if (_tag == detail::AffixFuzzer3Tag::fixed_size_shenanigans) { - return &_data.fixed_size_shenanigans; - } else { - return nullptr; - } + } + + /// Return a pointer to fixed_size_shenanigans if the union is in that state, otherwise `nullptr`. + const std::array* get_fixed_size_shenanigans() const { + if (_tag == detail::AffixFuzzer3Tag::fixed_size_shenanigans) { + return &_data.fixed_size_shenanigans; + } else { + return nullptr; } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const AffixFuzzer3* elements, size_t num_elements - ); - - private: - detail::AffixFuzzer3Tag _tag; - detail::AffixFuzzer3Data _data; - }; - } // namespace datatypes -} // namespace rerun + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const AffixFuzzer3* elements, size_t num_elements + ); + + private: + detail::AffixFuzzer3Tag _tag; + detail::AffixFuzzer3Data _data; + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.cpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.cpp index feaaf8d43c9f..130e15087670 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.cpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.cpp @@ -8,123 +8,114 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& AffixFuzzer4::arrow_datatype() { - static const auto datatype = arrow::dense_union({ - arrow::field("_null_markers", arrow::null(), true, nullptr), - arrow::field( - "single_required", - rerun::datatypes::AffixFuzzer3::arrow_datatype(), - false +namespace rerun::datatypes { + const std::shared_ptr& AffixFuzzer4::arrow_datatype() { + static const auto datatype = arrow::dense_union({ + arrow::field("_null_markers", arrow::null(), true, nullptr), + arrow::field( + "single_required", + rerun::datatypes::AffixFuzzer3::arrow_datatype(), + false + ), + arrow::field( + "many_required", + arrow::list( + arrow::field("item", rerun::datatypes::AffixFuzzer3::arrow_datatype(), false) ), - arrow::field( - "many_required", - arrow::list(arrow::field( - "item", - rerun::datatypes::AffixFuzzer3::arrow_datatype(), - false - )), - false + false + ), + arrow::field( + "many_optional", + arrow::list( + arrow::field("item", rerun::datatypes::AffixFuzzer3::arrow_datatype(), false) ), - arrow::field( - "many_optional", - arrow::list(arrow::field( - "item", - rerun::datatypes::AffixFuzzer3::arrow_datatype(), - false - )), - true - ), - }); - return datatype; + true + ), + }); + return datatype; + } + + Result> AffixFuzzer4::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer4::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + memory_pool, + // Children: + std::vector>({ + std::make_shared(memory_pool), + rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value, + std::make_shared( + memory_pool, + rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value + ), + std::make_shared( + memory_pool, + rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value + ), + }), + arrow_datatype() + )); + } - return Result(std::make_shared( - memory_pool, - // Children: - std::vector>({ - std::make_shared(memory_pool), - rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value, - std::make_shared( - memory_pool, - rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value - ), - std::make_shared( - memory_pool, - rerun::datatypes::AffixFuzzer3::new_arrow_array_builder(memory_pool).value - ), - }), - arrow_datatype() - )); + rerun::Error AffixFuzzer4::fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const AffixFuzzer4* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer4::fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const AffixFuzzer4* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& union_instance = elements[elem_idx]; - ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& union_instance = elements[elem_idx]; + ARROW_RETURN_NOT_OK(builder->Append(static_cast(union_instance._tag))); - auto variant_index = static_cast(union_instance._tag); - auto variant_builder_untyped = builder->child_builder(variant_index).get(); + auto variant_index = static_cast(union_instance._tag); + auto variant_builder_untyped = builder->child_builder(variant_index).get(); - switch (union_instance._tag) { - case detail::AffixFuzzer4Tag::None: { - ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); - } break; - case detail::AffixFuzzer4Tag::single_required: { - auto variant_builder = - static_cast(variant_builder_untyped); - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer3::fill_arrow_array_builder( - variant_builder, - &union_instance._data.single_required, - 1 - )); - } break; - case detail::AffixFuzzer4Tag::many_required: { - auto variant_builder = - static_cast(variant_builder_untyped); - (void)variant_builder; - return rerun::Error( - ErrorCode::NotImplemented, - "Failed to serialize AffixFuzzer4::many_required: objects (Object(\"rerun.testing.datatypes.AffixFuzzer3\")) in unions not yet implemented" - ); - } break; - case detail::AffixFuzzer4Tag::many_optional: { - auto variant_builder = - static_cast(variant_builder_untyped); - (void)variant_builder; - return rerun::Error( - ErrorCode::NotImplemented, - "Failed to serialize AffixFuzzer4::many_optional: nullable list types in unions not yet implemented" - ); - } break; - } + switch (union_instance._tag) { + case detail::AffixFuzzer4Tag::None: { + ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull()); + } break; + case detail::AffixFuzzer4Tag::single_required: { + auto variant_builder = + static_cast(variant_builder_untyped); + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer3::fill_arrow_array_builder( + variant_builder, + &union_instance._data.single_required, + 1 + )); + } break; + case detail::AffixFuzzer4Tag::many_required: { + auto variant_builder = + static_cast(variant_builder_untyped); + (void)variant_builder; + return rerun::Error( + ErrorCode::NotImplemented, + "Failed to serialize AffixFuzzer4::many_required: objects (Object(\"rerun.testing.datatypes.AffixFuzzer3\")) in unions not yet implemented" + ); + } break; + case detail::AffixFuzzer4Tag::many_optional: { + auto variant_builder = + static_cast(variant_builder_untyped); + (void)variant_builder; + return rerun::Error( + ErrorCode::NotImplemented, + "Failed to serialize AffixFuzzer4::many_optional: nullable list types in unions not yet implemented" + ); + } break; } - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.hpp index 871b8c6dc4d9..9f1760eadf4e 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.hpp @@ -20,182 +20,176 @@ namespace arrow { class MemoryPool; } // namespace arrow -namespace rerun { - namespace datatypes { - namespace detail { - /// \private - enum class AffixFuzzer4Tag : uint8_t { - /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. - None = 0, - single_required, - many_required, - many_optional, - }; - - /// \private - union AffixFuzzer4Data { - rerun::datatypes::AffixFuzzer3 single_required; - - std::vector many_required; - - std::optional> many_optional; - - AffixFuzzer4Data() { - std::memset(reinterpret_cast(this), 0, sizeof(AffixFuzzer4Data)); - } - - ~AffixFuzzer4Data() {} - - void swap(AffixFuzzer4Data& other) noexcept { - // This bitwise swap would fail for self-referential types, but we don't have any of those. - char temp[sizeof(AffixFuzzer4Data)]; - void* otherbytes = reinterpret_cast(&other); - void* thisbytes = reinterpret_cast(this); - std::memcpy(temp, thisbytes, sizeof(AffixFuzzer4Data)); - std::memcpy(thisbytes, otherbytes, sizeof(AffixFuzzer4Data)); - std::memcpy(otherbytes, temp, sizeof(AffixFuzzer4Data)); - } - }; - } // namespace detail - - struct AffixFuzzer4 { - AffixFuzzer4() : _tag(detail::AffixFuzzer4Tag::None) {} - - /// Copy constructor - AffixFuzzer4(const AffixFuzzer4& other) : _tag(other._tag) { - switch (other._tag) { - case detail::AffixFuzzer4Tag::single_required: { - using TypeAlias = rerun::datatypes::AffixFuzzer3; - new (&_data.single_required) TypeAlias(other._data.single_required); - } break; - case detail::AffixFuzzer4Tag::many_required: { - using TypeAlias = std::vector; - new (&_data.many_required) TypeAlias(other._data.many_required); - } break; - case detail::AffixFuzzer4Tag::many_optional: { - using TypeAlias = - std::optional>; - new (&_data.many_optional) TypeAlias(other._data.many_optional); - } break; - case detail::AffixFuzzer4Tag::None: { - } break; - } - } +namespace rerun::datatypes { + namespace detail { + /// \private + enum class AffixFuzzer4Tag : uint8_t { + /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on. + None = 0, + single_required, + many_required, + many_optional, + }; - AffixFuzzer4& operator=(const AffixFuzzer4& other) noexcept { - AffixFuzzer4 tmp(other); - this->swap(tmp); - return *this; - } + /// \private + union AffixFuzzer4Data { + rerun::datatypes::AffixFuzzer3 single_required; - AffixFuzzer4(AffixFuzzer4&& other) noexcept : AffixFuzzer4() { - this->swap(other); - } + std::vector many_required; - AffixFuzzer4& operator=(AffixFuzzer4&& other) noexcept { - this->swap(other); - return *this; - } + std::optional> many_optional; - ~AffixFuzzer4() { - switch (this->_tag) { - case detail::AffixFuzzer4Tag::None: { - // Nothing to destroy - } break; - case detail::AffixFuzzer4Tag::single_required: { - using TypeAlias = rerun::datatypes::AffixFuzzer3; - _data.single_required.~TypeAlias(); - } break; - case detail::AffixFuzzer4Tag::many_required: { - using TypeAlias = std::vector; - _data.many_required.~TypeAlias(); - } break; - case detail::AffixFuzzer4Tag::many_optional: { - using TypeAlias = - std::optional>; - _data.many_optional.~TypeAlias(); - } break; - } + AffixFuzzer4Data() { + std::memset(reinterpret_cast(this), 0, sizeof(AffixFuzzer4Data)); } - void swap(AffixFuzzer4& other) noexcept { - std::swap(this->_tag, other._tag); - this->_data.swap(other._data); - } + ~AffixFuzzer4Data() {} - static AffixFuzzer4 single_required(rerun::datatypes::AffixFuzzer3 single_required) { - AffixFuzzer4 self; - self._tag = detail::AffixFuzzer4Tag::single_required; - new (&self._data.single_required) - rerun::datatypes::AffixFuzzer3(std::move(single_required)); - return self; + void swap(AffixFuzzer4Data& other) noexcept { + // This bitwise swap would fail for self-referential types, but we don't have any of those. + char temp[sizeof(AffixFuzzer4Data)]; + void* otherbytes = reinterpret_cast(&other); + void* thisbytes = reinterpret_cast(this); + std::memcpy(temp, thisbytes, sizeof(AffixFuzzer4Data)); + std::memcpy(thisbytes, otherbytes, sizeof(AffixFuzzer4Data)); + std::memcpy(otherbytes, temp, sizeof(AffixFuzzer4Data)); } - - static AffixFuzzer4 many_required( - std::vector many_required - ) { - AffixFuzzer4 self; - self._tag = detail::AffixFuzzer4Tag::many_required; - new (&self._data.many_required) - std::vector(std::move(many_required)); - return self; + }; + } // namespace detail + + struct AffixFuzzer4 { + AffixFuzzer4() : _tag(detail::AffixFuzzer4Tag::None) {} + + /// Copy constructor + AffixFuzzer4(const AffixFuzzer4& other) : _tag(other._tag) { + switch (other._tag) { + case detail::AffixFuzzer4Tag::single_required: { + using TypeAlias = rerun::datatypes::AffixFuzzer3; + new (&_data.single_required) TypeAlias(other._data.single_required); + } break; + case detail::AffixFuzzer4Tag::many_required: { + using TypeAlias = std::vector; + new (&_data.many_required) TypeAlias(other._data.many_required); + } break; + case detail::AffixFuzzer4Tag::many_optional: { + using TypeAlias = std::optional>; + new (&_data.many_optional) TypeAlias(other._data.many_optional); + } break; + case detail::AffixFuzzer4Tag::None: { + } break; } - - static AffixFuzzer4 many_optional( - std::optional> many_optional - ) { - AffixFuzzer4 self; - self._tag = detail::AffixFuzzer4Tag::many_optional; - new (&self._data.many_optional - ) std::optional>(std::move(many_optional - )); - return self; + } + + AffixFuzzer4& operator=(const AffixFuzzer4& other) noexcept { + AffixFuzzer4 tmp(other); + this->swap(tmp); + return *this; + } + + AffixFuzzer4(AffixFuzzer4&& other) noexcept : AffixFuzzer4() { + this->swap(other); + } + + AffixFuzzer4& operator=(AffixFuzzer4&& other) noexcept { + this->swap(other); + return *this; + } + + ~AffixFuzzer4() { + switch (this->_tag) { + case detail::AffixFuzzer4Tag::None: { + // Nothing to destroy + } break; + case detail::AffixFuzzer4Tag::single_required: { + using TypeAlias = rerun::datatypes::AffixFuzzer3; + _data.single_required.~TypeAlias(); + } break; + case detail::AffixFuzzer4Tag::many_required: { + using TypeAlias = std::vector; + _data.many_required.~TypeAlias(); + } break; + case detail::AffixFuzzer4Tag::many_optional: { + using TypeAlias = std::optional>; + _data.many_optional.~TypeAlias(); + } break; } - - /// Return a pointer to single_required if the union is in that state, otherwise `nullptr`. - const rerun::datatypes::AffixFuzzer3* get_single_required() const { - if (_tag == detail::AffixFuzzer4Tag::single_required) { - return &_data.single_required; - } else { - return nullptr; - } + } + + void swap(AffixFuzzer4& other) noexcept { + std::swap(this->_tag, other._tag); + this->_data.swap(other._data); + } + + static AffixFuzzer4 single_required(rerun::datatypes::AffixFuzzer3 single_required) { + AffixFuzzer4 self; + self._tag = detail::AffixFuzzer4Tag::single_required; + new (&self._data.single_required) + rerun::datatypes::AffixFuzzer3(std::move(single_required)); + return self; + } + + static AffixFuzzer4 many_required(std::vector many_required + ) { + AffixFuzzer4 self; + self._tag = detail::AffixFuzzer4Tag::many_required; + new (&self._data.many_required) + std::vector(std::move(many_required)); + return self; + } + + static AffixFuzzer4 many_optional( + std::optional> many_optional + ) { + AffixFuzzer4 self; + self._tag = detail::AffixFuzzer4Tag::many_optional; + new (&self._data.many_optional + ) std::optional>(std::move(many_optional)); + return self; + } + + /// Return a pointer to single_required if the union is in that state, otherwise `nullptr`. + const rerun::datatypes::AffixFuzzer3* get_single_required() const { + if (_tag == detail::AffixFuzzer4Tag::single_required) { + return &_data.single_required; + } else { + return nullptr; } - - /// Return a pointer to many_required if the union is in that state, otherwise `nullptr`. - const std::vector* get_many_required() const { - if (_tag == detail::AffixFuzzer4Tag::many_required) { - return &_data.many_required; - } else { - return nullptr; - } + } + + /// Return a pointer to many_required if the union is in that state, otherwise `nullptr`. + const std::vector* get_many_required() const { + if (_tag == detail::AffixFuzzer4Tag::many_required) { + return &_data.many_required; + } else { + return nullptr; } - - /// Return a pointer to many_optional if the union is in that state, otherwise `nullptr`. - const std::optional>* get_many_optional( - ) const { - if (_tag == detail::AffixFuzzer4Tag::many_optional) { - return &_data.many_optional; - } else { - return nullptr; - } + } + + /// Return a pointer to many_optional if the union is in that state, otherwise `nullptr`. + const std::optional>* get_many_optional( + ) const { + if (_tag == detail::AffixFuzzer4Tag::many_optional) { + return &_data.many_optional; + } else { + return nullptr; } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::DenseUnionBuilder* builder, const AffixFuzzer4* elements, size_t num_elements - ); - - private: - detail::AffixFuzzer4Tag _tag; - detail::AffixFuzzer4Data _data; - }; - } // namespace datatypes -} // namespace rerun + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::DenseUnionBuilder* builder, const AffixFuzzer4* elements, size_t num_elements + ); + + private: + detail::AffixFuzzer4Tag _tag; + detail::AffixFuzzer4Data _data; + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer5.cpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer5.cpp index 743a7342e75b..714151ba6a0d 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer5.cpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer5.cpp @@ -8,71 +8,65 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& AffixFuzzer5::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field( - "single_optional_union", - rerun::datatypes::AffixFuzzer4::arrow_datatype(), - true - ), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& AffixFuzzer5::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field( + "single_optional_union", + rerun::datatypes::AffixFuzzer4::arrow_datatype(), + true + ), + }); + return datatype; + } + + Result> AffixFuzzer5::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> AffixFuzzer5::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + rerun::datatypes::AffixFuzzer4::new_arrow_array_builder(memory_pool).value, + }) + )); + } - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - rerun::datatypes::AffixFuzzer4::new_arrow_array_builder(memory_pool).value, - }) - )); + rerun::Error AffixFuzzer5::fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer5* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error AffixFuzzer5::fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer5* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = - static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.single_optional_union.has_value()) { - RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer4::fill_arrow_array_builder( - field_builder, - &element.single_optional_union.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + const auto& element = elements[elem_idx]; + if (element.single_optional_union.has_value()) { + RR_RETURN_NOT_OK(rerun::datatypes::AffixFuzzer4::fill_arrow_array_builder( + field_builder, + &element.single_optional_union.value(), + 1 + )); + } else { + ARROW_RETURN_NOT_OK(field_builder->AppendNull()); } } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer5.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer5.hpp index b28530843f4b..6550f682f390 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer5.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer5.hpp @@ -17,36 +17,33 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - struct AffixFuzzer5 { - std::optional single_optional_union; - - public: - AffixFuzzer5() = default; - - AffixFuzzer5(std::optional single_optional_union_) - : single_optional_union(std::move(single_optional_union_)) {} - - AffixFuzzer5& operator=( - std::optional single_optional_union_ - ) { - single_optional_union = std::move(single_optional_union_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const AffixFuzzer5* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + struct AffixFuzzer5 { + std::optional single_optional_union; + + public: + AffixFuzzer5() = default; + + AffixFuzzer5(std::optional single_optional_union_) + : single_optional_union(std::move(single_optional_union_)) {} + + AffixFuzzer5& operator=(std::optional single_optional_union_ + ) { + single_optional_union = std::move(single_optional_union_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const AffixFuzzer5* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/flattened_scalar.cpp b/rerun_cpp/tests/generated/datatypes/flattened_scalar.cpp index f3d72fba5396..63be5187c338 100644 --- a/rerun_cpp/tests/generated/datatypes/flattened_scalar.cpp +++ b/rerun_cpp/tests/generated/datatypes/flattened_scalar.cpp @@ -6,57 +6,52 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& FlattenedScalar::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field("value", arrow::float32(), false), - }); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& FlattenedScalar::arrow_datatype() { + static const auto datatype = arrow::struct_({ + arrow::field("value", arrow::float32(), false), + }); + return datatype; + } + + Result> FlattenedScalar::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> FlattenedScalar::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } - - return Result(std::make_shared( - arrow_datatype(), - memory_pool, - std::vector>({ - std::make_shared(memory_pool), - }) - )); + return Result(std::make_shared( + arrow_datatype(), + memory_pool, + std::vector>({ + std::make_shared(memory_pool), + }) + )); + } + + rerun::Error FlattenedScalar::fill_arrow_array_builder( + arrow::StructBuilder* builder, const FlattenedScalar* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error FlattenedScalar::fill_arrow_array_builder( - arrow::StructBuilder* builder, const FlattenedScalar* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].value)); - } + { + auto field_builder = static_cast(builder->field_builder(0)); + ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(field_builder->Append(elements[elem_idx].value)); } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/flattened_scalar.hpp b/rerun_cpp/tests/generated/datatypes/flattened_scalar.hpp index fe5ace39358a..6e356ca4a433 100644 --- a/rerun_cpp/tests/generated/datatypes/flattened_scalar.hpp +++ b/rerun_cpp/tests/generated/datatypes/flattened_scalar.hpp @@ -13,33 +13,31 @@ namespace arrow { class StructBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - struct FlattenedScalar { - float value; - - public: - FlattenedScalar() = default; - - FlattenedScalar(float value_) : value(value_) {} - - FlattenedScalar& operator=(float value_) { - value = value_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const FlattenedScalar* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + struct FlattenedScalar { + float value; + + public: + FlattenedScalar() = default; + + FlattenedScalar(float value_) : value(value_) {} + + FlattenedScalar& operator=(float value_) { + value = value_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StructBuilder* builder, const FlattenedScalar* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/primitive_component.cpp b/rerun_cpp/tests/generated/datatypes/primitive_component.cpp index b933e993e0a4..ebbda492b0da 100644 --- a/rerun_cpp/tests/generated/datatypes/primitive_component.cpp +++ b/rerun_cpp/tests/generated/datatypes/primitive_component.cpp @@ -6,45 +6,40 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& PrimitiveComponent::arrow_datatype() { - static const auto datatype = arrow::uint32(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& PrimitiveComponent::arrow_datatype() { + static const auto datatype = arrow::uint32(); + return datatype; + } + + Result> PrimitiveComponent::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> PrimitiveComponent::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error PrimitiveComponent::fill_arrow_array_builder( + arrow::UInt32Builder* builder, const PrimitiveComponent* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); } - - rerun::Error PrimitiveComponent::fill_arrow_array_builder( - arrow::UInt32Builder* builder, const PrimitiveComponent* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - static_assert(sizeof(*elements) == sizeof(elements->value)); - ARROW_RETURN_NOT_OK( - builder->AppendValues(&elements->value, static_cast(num_elements)) + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." ); - - return Error::ok(); } - } // namespace datatypes -} // namespace rerun + + static_assert(sizeof(*elements) == sizeof(elements->value)); + ARROW_RETURN_NOT_OK( + builder->AppendValues(&elements->value, static_cast(num_elements)) + ); + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/primitive_component.hpp b/rerun_cpp/tests/generated/datatypes/primitive_component.hpp index 97901b0d1939..b1991fda9303 100644 --- a/rerun_cpp/tests/generated/datatypes/primitive_component.hpp +++ b/rerun_cpp/tests/generated/datatypes/primitive_component.hpp @@ -18,34 +18,31 @@ namespace arrow { using UInt32Builder = NumericBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - struct PrimitiveComponent { - uint32_t value; - - public: - PrimitiveComponent() = default; - - PrimitiveComponent(uint32_t value_) : value(value_) {} - - PrimitiveComponent& operator=(uint32_t value_) { - value = value_; - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::UInt32Builder* builder, const PrimitiveComponent* elements, - size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + struct PrimitiveComponent { + uint32_t value; + + public: + PrimitiveComponent() = default; + + PrimitiveComponent(uint32_t value_) : value(value_) {} + + PrimitiveComponent& operator=(uint32_t value_) { + value = value_; + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::UInt32Builder* builder, const PrimitiveComponent* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/string_component.cpp b/rerun_cpp/tests/generated/datatypes/string_component.cpp index 86a3c8243dfa..2bbd528d43c6 100644 --- a/rerun_cpp/tests/generated/datatypes/string_component.cpp +++ b/rerun_cpp/tests/generated/datatypes/string_component.cpp @@ -6,45 +6,40 @@ #include #include -namespace rerun { - namespace datatypes { - const std::shared_ptr& StringComponent::arrow_datatype() { - static const auto datatype = arrow::utf8(); - return datatype; +namespace rerun::datatypes { + const std::shared_ptr& StringComponent::arrow_datatype() { + static const auto datatype = arrow::utf8(); + return datatype; + } + + Result> StringComponent::new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ) { + if (memory_pool == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); } - Result> StringComponent::new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ) { - if (memory_pool == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null."); - } + return Result(std::make_shared(memory_pool)); + } - return Result(std::make_shared(memory_pool)); + rerun::Error StringComponent::fill_arrow_array_builder( + arrow::StringBuilder* builder, const StringComponent* elements, size_t num_elements + ) { + if (builder == nullptr) { + return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); + } + if (elements == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Cannot serialize null pointer to arrow array." + ); } - rerun::Error StringComponent::fill_arrow_array_builder( - arrow::StringBuilder* builder, const StringComponent* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Passed array builder is null." - ); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - ARROW_RETURN_NOT_OK(builder->Append(elements[elem_idx].value)); - } - - return Error::ok(); + ARROW_RETURN_NOT_OK(builder->Reserve(static_cast(num_elements))); + for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { + ARROW_RETURN_NOT_OK(builder->Append(elements[elem_idx].value)); } - } // namespace datatypes -} // namespace rerun + + return Error::ok(); + } +} // namespace rerun::datatypes diff --git a/rerun_cpp/tests/generated/datatypes/string_component.hpp b/rerun_cpp/tests/generated/datatypes/string_component.hpp index b9cac7bf145e..5f3a92acaea6 100644 --- a/rerun_cpp/tests/generated/datatypes/string_component.hpp +++ b/rerun_cpp/tests/generated/datatypes/string_component.hpp @@ -15,33 +15,31 @@ namespace arrow { class StringBuilder; } // namespace arrow -namespace rerun { - namespace datatypes { - struct StringComponent { - std::string value; - - public: - StringComponent() = default; - - StringComponent(std::string value_) : value(std::move(value_)) {} - - StringComponent& operator=(std::string value_) { - value = std::move(value_); - return *this; - } - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Creates a new array builder with an array of this type. - static Result> new_arrow_array_builder( - arrow::MemoryPool* memory_pool - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StringBuilder* builder, const StringComponent* elements, size_t num_elements - ); - }; - } // namespace datatypes -} // namespace rerun +namespace rerun::datatypes { + struct StringComponent { + std::string value; + + public: + StringComponent() = default; + + StringComponent(std::string value_) : value(std::move(value_)) {} + + StringComponent& operator=(std::string value_) { + value = std::move(value_); + return *this; + } + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype(); + + /// Creates a new array builder with an array of this type. + static Result> new_arrow_array_builder( + arrow::MemoryPool* memory_pool + ); + + /// Fills an arrow array builder with an array of this type. + static rerun::Error fill_arrow_array_builder( + arrow::StringBuilder* builder, const StringComponent* elements, size_t num_elements + ); + }; +} // namespace rerun::datatypes