/// Demonstrates how to implement custom archetypes and components, and extend existing ones. #include #include /// A custom component type. struct Confidence { float value; }; template <> struct rerun::Loggable { static constexpr std::string_view ComponentType = "user.Confidence"; static const std::shared_ptr& arrow_datatype() { return rerun::Loggable::arrow_datatype(); } // TODO(#4257) should take a rerun::Collection instead of pointer and size. static rerun::Result> to_arrow( const Confidence* instances, size_t num_instances ) { return rerun::Loggable::to_arrow( reinterpret_cast(instances), num_instances ); } }; /// A custom archetype that extends Rerun's builtin `rerun::Points3D` archetype with a custom component. struct CustomPoints3D { rerun::Points3D points; // Using a rerun::Collection is not strictly necessary, you could also use an std::vector for example, // but useful for avoiding allocations since `rerun::Collection` can borrow data from other containers. std::optional> confidences; }; template <> struct rerun::AsComponents { static Result> as_batches( const CustomPoints3D& archetype ) { auto batches = AsComponents::as_batches(archetype.points) .value_or_throw() .to_vector(); // Add custom confidence components if present. if (archetype.confidences) { auto descriptor = rerun::ComponentDescriptor("user.CustomPoints3D:confidences") .or_with_archetype("user.CustomPoints3D") .or_with_component_type( rerun::Loggable::ComponentType ); batches.push_back(ComponentBatch::from_loggable( *archetype.confidences, descriptor ) .value_or_throw()); } return rerun::take_ownership(std::move(batches)); } }; // --- int main(int argc, char* argv[]) { const auto rec = rerun::RecordingStream("rerun_example_custom_data"); rec.spawn().exit_on_failure(); auto grid = rerun::demo::grid3d(-5.0f, 5.0f, 3); rec.log( "left/my_confident_point_cloud", CustomPoints3D{ rerun::Points3D(grid), Confidence{42.0f}, } ); std::vector confidences; for (auto i = 0; i < 27; ++i) { confidences.emplace_back(Confidence{static_cast(i)}); } rec.log( "right/my_polarized_point_cloud", CustomPoints3D{ rerun::Points3D(grid), confidences, } ); }