Rerun C++ SDK
Loading...
Searching...
No Matches
bar_chart.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_sdk_types/definitions/rerun/archetypes/bar_chart.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/color.hpp"
10#include "../components/length.hpp"
11#include "../components/tensor_data.hpp"
12#include "../result.hpp"
13
14#include <cstdint>
15#include <optional>
16#include <utility>
17#include <vector>
18
19namespace rerun::archetypes {
20 /// **Archetype**: A bar chart.
21 ///
22 /// The bar heights will be the provided values, and the x coordinates of the bars will be the provided abscissa or default to the index of the provided values.
23 ///
24 /// ## Example
25 ///
26 /// ### Simple bar chart
27 /// ![image](https://static.rerun.io/bar_chart/ba274527813ccb9049f6760d82f36c8da6a6f2ff/full.png)
28 ///
29 /// ```cpp
30 /// #include <rerun.hpp>
31 /// #include <vector>
32 ///
33 /// int main(int argc, char* argv[]) {
34 /// const auto rec = rerun::RecordingStream("rerun_example_bar_chart");
35 /// rec.spawn().exit_on_failure();
36 ///
37 /// rec.log("bar_chart", rerun::BarChart::i64({8, 4, 0, 9, 1, 4, 1, 6, 9, 0}));
38 ///
39 /// auto abscissa = std::vector<int64_t>{0, 1, 3, 4, 7, 11};
40 /// auto abscissa_data =
41 /// rerun::TensorData(rerun::Collection{abscissa.size()}, abscissa);
42 /// rec.log(
43 /// "bar_chart_custom_abscissa",
44 /// rerun::BarChart::i64({8, 4, 0, 9, 1, 4}).with_abscissa(abscissa_data)
45 /// );
46 ///
47 /// auto widths = std::vector<float>{1, 2, 1, 3, 4, 1};
48 /// rec.log(
49 /// "bar_chart_custom_abscissa_and_widths",
50 /// rerun::BarChart::i64({8, 4, 0, 9, 1, 4})
51 /// .with_abscissa(abscissa_data)
52 /// .with_widths(widths)
53 /// );
54 /// }
55 /// ```
56 struct BarChart {
57 /// The values. Should always be a 1-dimensional tensor (i.e. a vector).
58 std::optional<ComponentBatch> values;
59
60 /// The color of the bar chart
61 std::optional<ComponentBatch> color;
62
63 /// The abscissa corresponding to each value. Should be a 1-dimensional tensor (i.e. a vector) in same length as values.
64 std::optional<ComponentBatch> abscissa;
65
66 /// The width of the bins, defined in x-axis units and defaults to 1. Should be a 1-dimensional tensor (i.e. a vector) in same length as values.
67 std::optional<ComponentBatch> widths;
68
69 public:
70 /// The name of the archetype as used in `ComponentDescriptor`s.
71 static constexpr const char ArchetypeName[] = "rerun.archetypes.BarChart";
72
73 /// `ComponentDescriptor` for the `values` field.
74 static constexpr auto Descriptor_values = ComponentDescriptor(
76 );
77 /// `ComponentDescriptor` for the `color` field.
78 static constexpr auto Descriptor_color = ComponentDescriptor(
80 );
81 /// `ComponentDescriptor` for the `abscissa` field.
83 ArchetypeName, "BarChart:abscissa",
85 );
86 /// `ComponentDescriptor` for the `widths` field.
87 static constexpr auto Descriptor_widths = ComponentDescriptor(
89 );
90
91 public: // START of extensions from bar_chart_ext.cpp:
93 // Forwarding like this can spuriously fail, since the move might be evaluated before `num_elems`:
94 //BarChart(rerun::components::TensorData({buffer.num_elems()}, std::move(buffer)));
95
96 auto num_elems = buffer.num_elems();
97 *this = std::move(*this).with_values(
98 rerun::components::TensorData({num_elems}, std::move(buffer))
99 );
100 }
101
102 // --------------------------------------------------------------------
103 // Implicit constructors:
104
105 /// Construct a `BarChart` from a `Collection<uint8_t>`.
107 : BarChart(rerun::datatypes::TensorBuffer::u8(std::move(u8))) {}
108
109 /// Construct a `BarChart` from a `Collection<uint16_t>`.
111 : BarChart(rerun::datatypes::TensorBuffer::u16(std::move(u16))) {}
112
113 /// Construct a `BarChart` from a `Collection<uint32_t>`.
115 : BarChart(rerun::datatypes::TensorBuffer::u32(std::move(u32))) {}
116
117 /// Construct a `BarChart` from a `Collection<uint64_t>`.
119 : BarChart(rerun::datatypes::TensorBuffer::u64(std::move(u64))) {}
120
121 /// Construct a `BarChart` from a `Collection<int8_t>`.
123 : BarChart(rerun::datatypes::TensorBuffer::i8(std::move(i8))) {}
124
125 /// Construct a `BarChart` from a `Collection<int16_t>`.
127 : BarChart(rerun::datatypes::TensorBuffer::i16(std::move(i16))) {}
128
129 /// Construct a `BarChart` from a `Collection<int32_t>`.
131 : BarChart(rerun::datatypes::TensorBuffer::i32(std::move(i32))) {}
132
133 /// Construct a `BarChart` from a `Collection<int64_t>`.
135 : BarChart(rerun::datatypes::TensorBuffer::i64(std::move(i64))) {}
136
137 /// Construct aBarChart` from a `Collection<half>`.
139 : BarChart(rerun::datatypes::TensorBuffer::f16(std::move(f16))) {}
140
141 /// Construct a `BarChart` from a `Collection<float>`.
143 : BarChart(rerun::datatypes::TensorBuffer::f32(std::move(f32))) {}
144
145 /// Construct a `BarChart` from a `Collection<double>`.
147 : BarChart(rerun::datatypes::TensorBuffer::f64(std::move(f64))) {}
148
149 // --------------------------------------------------------------------
150 // Explicit static constructors:
151
152 /// Construct a `BarChart` from a `Collection<uint8_t>`.
154 return BarChart(std::move(u8));
155 }
156
157 /// Construct a `BarChart` from a `Collection<uint16_t>`.
159 return BarChart(std::move(u16));
160 }
161
162 /// Construct a `BarChart` from a `Collection<uint32_t>`.
164 return BarChart(std::move(u32));
165 }
166
167 /// Construct a `BarChart` from a `Collection<uint64_t>`.
169 return BarChart(std::move(u64));
170 }
171
172 /// Construct a `BarChart` from a `Collection<int8_t>`.
174 return BarChart(std::move(i8));
175 }
176
177 /// Construct a `BarChart` from a `Collection<int16_t>`.
179 return BarChart(std::move(i16));
180 }
181
182 /// Construct a `BarChart` from a `Collection<int32_t>`.
184 return BarChart(std::move(i32));
185 }
186
187 /// Construct a `BarChart` from a `Collection<int64_t>`.
189 return BarChart(std::move(i64));
190 }
191
192 /// Construct a `BarChart` from a `Collection<half>`.
194 return BarChart(std::move(f16));
195 }
196
197 /// Construct a `BarChart` from a `Collection<float>`.
199 return BarChart(std::move(f32));
200 }
201
202 /// Construct a `BarChart` from a `Collection<double>`.
204 return BarChart(std::move(f64));
205 }
206
207 // END of extensions from bar_chart_ext.cpp, start of generated code:
208
209 public:
210 BarChart() = default;
211 BarChart(BarChart&& other) = default;
212 BarChart(const BarChart& other) = default;
213 BarChart& operator=(const BarChart& other) = default;
214 BarChart& operator=(BarChart&& other) = default;
215
217 : values(ComponentBatch::from_loggable(std::move(_values), Descriptor_values)
218 .value_or_throw()) {}
219
220 /// Update only some specific fields of a `BarChart`.
222 return BarChart();
223 }
224
225 /// Clear all the fields of a `BarChart`.
227
228 /// The values. Should always be a 1-dimensional tensor (i.e. a vector).
230 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
231 return std::move(*this);
232 }
233
234 /// This method makes it possible to pack multiple `values` in a single component batch.
235 ///
236 /// This only makes sense when used in conjunction with `columns`. `with_values` should
237 /// be used when logging a single row's worth of data.
239 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
240 return std::move(*this);
241 }
242
243 /// The color of the bar chart
245 color = ComponentBatch::from_loggable(_color, Descriptor_color).value_or_throw();
246 return std::move(*this);
247 }
248
249 /// This method makes it possible to pack multiple `color` in a single component batch.
250 ///
251 /// This only makes sense when used in conjunction with `columns`. `with_color` should
252 /// be used when logging a single row's worth of data.
254 color = ComponentBatch::from_loggable(_color, Descriptor_color).value_or_throw();
255 return std::move(*this);
256 }
257
258 /// The abscissa corresponding to each value. Should be a 1-dimensional tensor (i.e. a vector) in same length as values.
260 abscissa =
261 ComponentBatch::from_loggable(_abscissa, Descriptor_abscissa).value_or_throw();
262 return std::move(*this);
263 }
264
265 /// This method makes it possible to pack multiple `abscissa` in a single component batch.
266 ///
267 /// This only makes sense when used in conjunction with `columns`. `with_abscissa` should
268 /// be used when logging a single row's worth of data.
270 abscissa =
271 ComponentBatch::from_loggable(_abscissa, Descriptor_abscissa).value_or_throw();
272 return std::move(*this);
273 }
274
275 /// The width of the bins, defined in x-axis units and defaults to 1. Should be a 1-dimensional tensor (i.e. a vector) in same length as values.
277 widths = ComponentBatch::from_loggable(_widths, Descriptor_widths).value_or_throw();
278 return std::move(*this);
279 }
280
281 /// Partitions the component data into multiple sub-batches.
282 ///
283 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
284 /// instead, via `ComponentBatch::partitioned`.
285 ///
286 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
287 ///
288 /// The specified `lengths` must sum to the total length of the component batch.
290
291 /// Partitions the component data into unit-length sub-batches.
292 ///
293 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
294 /// where `n` is automatically guessed.
296 };
297
298} // namespace rerun::archetypes
299
300namespace rerun {
301 /// \private
302 template <typename T>
303 struct AsComponents;
304
305 /// \private
306 template <>
307 struct AsComponents<archetypes::BarChart> {
308 /// Serialize all set component batches.
309 static Result<Collection<ComponentBatch>> as_batches(const archetypes::BarChart& archetype);
310 };
311} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:87
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
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)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: A bar chart.
Definition bar_chart.hpp:56
BarChart(Collection< double > f64)
Construct a BarChart from a Collection<double>.
Definition bar_chart.hpp:146
BarChart with_many_values(const Collection< rerun::components::TensorData > &_values) &&
This method makes it possible to pack multiple values in a single component batch.
Definition bar_chart.hpp:238
static constexpr auto Descriptor_abscissa
ComponentDescriptor for the abscissa field.
Definition bar_chart.hpp:82
BarChart(Collection< int64_t > i64)
Construct a BarChart from a Collection<int64_t>.
Definition bar_chart.hpp:134
static BarChart update_fields()
Update only some specific fields of a BarChart.
Definition bar_chart.hpp:221
static BarChart u32(Collection< uint32_t > u32)
Construct a BarChart from a Collection<uint32_t>.
Definition bar_chart.hpp:163
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static BarChart f16(Collection< rerun::half > f16)
Construct a BarChart from a Collection<half>.
Definition bar_chart.hpp:193
static constexpr auto Descriptor_values
ComponentDescriptor for the values field.
Definition bar_chart.hpp:74
BarChart(Collection< int32_t > i32)
Construct a BarChart from a Collection<int32_t>.
Definition bar_chart.hpp:130
static BarChart i64(Collection< int64_t > i64)
Construct a BarChart from a Collection<int64_t>.
Definition bar_chart.hpp:188
static BarChart i16(Collection< int16_t > i16)
Construct a BarChart from a Collection<int16_t>.
Definition bar_chart.hpp:178
static BarChart f64(Collection< double > f64)
Construct a BarChart from a Collection<double>.
Definition bar_chart.hpp:203
static BarChart u64(Collection< uint64_t > u64)
Construct a BarChart from a Collection<uint64_t>.
Definition bar_chart.hpp:168
std::optional< ComponentBatch > abscissa
The abscissa corresponding to each value. Should be a 1-dimensional tensor (i.e. a vector) in same le...
Definition bar_chart.hpp:64
static BarChart f32(Collection< float > f32)
Construct a BarChart from a Collection<float>.
Definition bar_chart.hpp:198
BarChart with_many_abscissa(const Collection< rerun::components::TensorData > &_abscissa) &&
This method makes it possible to pack multiple abscissa in a single component batch.
Definition bar_chart.hpp:269
BarChart with_color(const rerun::components::Color &_color) &&
The color of the bar chart.
Definition bar_chart.hpp:244
static BarChart u16(Collection< uint16_t > u16)
Construct a BarChart from a Collection<uint16_t>.
Definition bar_chart.hpp:158
static BarChart clear_fields()
Clear all the fields of a BarChart.
static constexpr auto Descriptor_widths
ComponentDescriptor for the widths field.
Definition bar_chart.hpp:87
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition bar_chart.hpp:71
BarChart with_many_color(const Collection< rerun::components::Color > &_color) &&
This method makes it possible to pack multiple color in a single component batch.
Definition bar_chart.hpp:253
BarChart(Collection< rerun::half > f16)
Construct aBarChartfrom aCollection<half>`.
Definition bar_chart.hpp:138
BarChart(Collection< uint16_t > u16)
Construct a BarChart from a Collection<uint16_t>.
Definition bar_chart.hpp:110
std::optional< ComponentBatch > widths
The width of the bins, defined in x-axis units and defaults to 1. Should be a 1-dimensional tensor (i...
Definition bar_chart.hpp:67
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
static BarChart u8(Collection< uint8_t > u8)
Construct a BarChart from a Collection<uint8_t>.
Definition bar_chart.hpp:153
BarChart(Collection< uint8_t > u8)
Construct a BarChart from a Collection<uint8_t>.
Definition bar_chart.hpp:106
BarChart(Collection< float > f32)
Construct a BarChart from a Collection<float>.
Definition bar_chart.hpp:142
BarChart(Collection< int8_t > i8)
Construct a BarChart from a Collection<int8_t>.
Definition bar_chart.hpp:122
BarChart with_values(const rerun::components::TensorData &_values) &&
The values. Should always be a 1-dimensional tensor (i.e. a vector).
Definition bar_chart.hpp:229
BarChart(Collection< uint32_t > u32)
Construct a BarChart from a Collection<uint32_t>.
Definition bar_chart.hpp:114
BarChart with_abscissa(const rerun::components::TensorData &_abscissa) &&
The abscissa corresponding to each value. Should be a 1-dimensional tensor (i.e. a vector) in same le...
Definition bar_chart.hpp:259
static BarChart i32(Collection< int32_t > i32)
Construct a BarChart from a Collection<int32_t>.
Definition bar_chart.hpp:183
BarChart(Collection< uint64_t > u64)
Construct a BarChart from a Collection<uint64_t>.
Definition bar_chart.hpp:118
BarChart(Collection< int16_t > i16)
Construct a BarChart from a Collection<int16_t>.
Definition bar_chart.hpp:126
static constexpr auto Descriptor_color
ComponentDescriptor for the color field.
Definition bar_chart.hpp:78
static BarChart i8(Collection< int8_t > i8)
Construct a BarChart from a Collection<int8_t>.
Definition bar_chart.hpp:173
std::optional< ComponentBatch > color
The color of the bar chart.
Definition bar_chart.hpp:61
std::optional< ComponentBatch > values
The values. Should always be a 1-dimensional tensor (i.e. a vector).
Definition bar_chart.hpp:58
BarChart with_widths(const Collection< rerun::components::Length > &_widths) &&
The width of the bins, defined in x-axis units and defaults to 1. Should be a 1-dimensional tensor (i...
Definition bar_chart.hpp:276
Component: An RGBA color with unmultiplied/separate alpha, in sRGB gamma space with linear alpha.
Definition color.hpp:17
Component: An N-dimensional array of numbers.
Definition tensor_data.hpp:22
Datatype: The underlying storage for archetypes::Tensor.
Definition tensor_buffer.hpp:98
size_t num_elems() const
Number of elements in the buffer.