Rerun C++ SDK
Loading...
Searching...
No Matches
component_column.hpp
1#pragma once
2
3#include <memory> // shared_ptr
4
5#include "collection.hpp"
6#include "component_batch.hpp"
7#include "component_type.hpp"
8#include "error.hpp"
9#include "loggable.hpp"
10
11struct rr_component_column;
12
13namespace rerun {
14 /// Arrow-encoded data of a column of components.
15 ///
16 /// This is essentially an array of `rerun::ComponentBatch` with all batches
17 /// continuously in a single array.
18 ///
19 /// \see `rerun::RecordingStream::send_columns`
21 /// Arrow-encoded list array of component batches.
22 std::shared_ptr<arrow::Array> array;
23
24 /// The type of the component instances in array.
26
27 public:
28 /// Creates a new component column from a collection of component instances.
29 ///
30 /// Automatically registers the component type the first time this type is encountered.
31 ///
32 /// \param components Continuous collection of components which is about to be partitioned.
33 /// \param lengths The number of components in each run. for `rerun::RecordingStream::send_columns`,
34 /// this specifies the number of components at each time point.
35 /// The sum of the lengths must be equal to the number of components in the batch.
36 /// \param descriptor Descriptor of the component type for this column.
37 template <typename T>
39 const Collection<T>& components, const Collection<uint32_t>& lengths,
41 ) {
42 auto component_batch_result = ComponentBatch::from_loggable(components, descriptor);
43 if (component_batch_result.is_err()) {
44 return component_batch_result.error;
45 }
46 return from_batch_with_lengths(component_batch_result.value, lengths);
47 }
48
49 /// Creates a new component column from a collection of component instances where each run has a length of one.
50 ///
51 /// When used with `rerun::RecordingStream::send_columns`, this is equivalent to `from_loggable(components, std::vector{1, 1, ...})`.
52 /// I.e. there's a single component for each time point.
53 ///
54 /// Automatically registers the component type the first time this type is encountered.
55 ///
56 /// \param components Continuous collection of components which is about to be partitioned into runs of length one.
57 /// \param descriptor Descriptor of the component type for this column.
58 template <typename T>
60 const Collection<T>& components,
62 ) {
64 components,
65 Collection<uint32_t>::take_ownership(std::vector<uint32_t>(components.size(), 1)),
66 descriptor
67 );
68 }
69
70 /// Creates a new component column with a given number of archetype indicators for a given archetype type.
71 template <typename Archetype>
72 static Result<ComponentColumn> from_indicators(uint32_t num_indicators) {
73 auto component_batch_result = ComponentBatch::from_indicator<Archetype>();
74 if (component_batch_result.is_err()) {
75 return component_batch_result.error;
76 }
78 component_batch_result.value,
79 Collection<uint32_t>::take_ownership(std::vector<uint32_t>(num_indicators, 0))
80 );
81 }
82
83 /// Creates a new component batch partition from a batch and a collection of run lengths.
84 ///
85 /// \param batch A batch of components which is about to be partitioned.
86 /// \param lengths The number of components in each run. for `rerun::RecordingStream::send_columns`,
87 /// this specifies the number of components at each time point.
88 /// The sum of the lengths must be equal to the number of components in the batch.
90 ComponentBatch batch, const Collection<uint32_t>& lengths
91 );
92
93 /// Creates a new component batch partition from a batch and a collection of component offsets.
94 ///
95 /// \param batch A batch of components which is about to be partitioned.
96 /// \param offsets An offset within `batch` for each array of components.
97 /// The last offset is the total number of components in the batch. Meaning that this array has to be
98 /// one element longer than the number of component runs.
99 /// E.g. a `ParitionedComponentBatch` with a single component would have an offset array of `[0, 1]`.
100 /// A `ComponentColumn` with 5 components divided into runs of length 2 and 3
101 // would have an offset array of `[0, 2, 5]`.
104 );
105
106 /// To rerun C API component batch.
107 ///
108 /// The resulting `rr_component_column` keeps the `arrow::Array` alive until it is released.
109 Error to_c_ffi_struct(rr_component_column& out_component_batch) const;
110 };
111} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
size_t size() const
Returns the number of instances in this collection.
Definition collection.hpp:291
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:96
A class for representing either a usable value, or an error.
Definition result.hpp:14
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
uint32_t ComponentTypeHandle
Handle to a registered component types.
Definition component_type.hpp:14
Arrow-encoded data of a single batch of components together with a component descriptor.
Definition component_batch.hpp:28
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor=rerun::Loggable< T >::Descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
Arrow-encoded data of a column of components.
Definition component_column.hpp:20
static Result< ComponentColumn > from_loggable(const Collection< T > &components, const ComponentDescriptor &descriptor=rerun::Loggable< T >::Descriptor)
Creates a new component column from a collection of component instances where each run has a length o...
Definition component_column.hpp:59
static Result< ComponentColumn > from_loggable_with_lengths(const Collection< T > &components, const Collection< uint32_t > &lengths, const ComponentDescriptor &descriptor=rerun::Loggable< T >::Descriptor)
Creates a new component column from a collection of component instances.
Definition component_column.hpp:38
ComponentTypeHandle component_type
The type of the component instances in array.
Definition component_column.hpp:25
static Result< ComponentColumn > from_batch_with_lengths(ComponentBatch batch, const Collection< uint32_t > &lengths)
Creates a new component batch partition from a batch and a collection of run lengths.
std::shared_ptr< arrow::Array > array
Arrow-encoded list array of component batches.
Definition component_column.hpp:22
static Result< ComponentColumn > from_batch_with_offsets(ComponentBatch batch, Collection< uint32_t > offsets)
Creates a new component batch partition from a batch and a collection of component offsets.
Error to_c_ffi_struct(rr_component_column &out_component_batch) const
To rerun C API component batch.
static Result< ComponentColumn > from_indicators(uint32_t num_indicators)
Creates a new component column with a given number of archetype indicators for a given archetype type...
Definition component_column.hpp:72
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:14
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11