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_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/tensor_data.hpp"
11#include "../result.hpp"
12
13#include <cstdint>
14#include <optional>
15#include <utility>
16#include <vector>
17
18namespace rerun::archetypes {
19 /// **Archetype**: A bar chart.
20 ///
21 /// 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.
22 ///
23 /// ## Example
24 ///
25 /// ### Simple bar chart
26 /// ![image](https://static.rerun.io/bar_chart/ba274527813ccb9049f6760d82f36c8da6a6f2ff/full.png)
27 ///
28 /// ```cpp
29 /// #include <rerun.hpp>
30 /// #include <vector>
31 ///
32 /// int main() {
33 /// const auto rec = rerun::RecordingStream("rerun_example_bar_chart");
34 /// rec.spawn().exit_on_failure();
35 ///
36 /// rec.log("bar_chart", rerun::BarChart::i64({8, 4, 0, 9, 1, 4, 1, 6, 9, 0}));
37 ///
38 /// auto abscissa = std::vector<int64_t>{0, 1, 3, 4, 7, 11};
39 /// auto abscissa_data = rerun::TensorData(rerun::Collection{abscissa.size()}, abscissa);
40 /// rec.log(
41 /// "bar_chart_custom_abscissa",
42 /// rerun::BarChart::i64({8, 4, 0, 9, 1, 4}).with_abscissa(abscissa_data)
43 /// );
44 /// }
45 /// ```
46 struct BarChart {
47 /// The values. Should always be a 1-dimensional tensor (i.e. a vector).
48 std::optional<ComponentBatch> values;
49
50 /// The color of the bar chart
51 std::optional<ComponentBatch> color;
52
53 /// The abscissa corresponding to each value. Should be a 1-dimensional tensor (i.e. a vector) in same length as values.
54 std::optional<ComponentBatch> abscissa;
55
56 public:
57 /// The name of the archetype as used in `ComponentDescriptor`s.
58 static constexpr const char ArchetypeName[] = "rerun.archetypes.BarChart";
59
60 /// `ComponentDescriptor` for the `values` field.
61 static constexpr auto Descriptor_values = ComponentDescriptor(
63 );
64 /// `ComponentDescriptor` for the `color` field.
65 static constexpr auto Descriptor_color = ComponentDescriptor(
67 );
68 /// `ComponentDescriptor` for the `abscissa` field.
70 ArchetypeName, "BarChart:abscissa",
72 );
73
74 public: // START of extensions from bar_chart_ext.cpp:
76 // Forwarding like this can spuriously fail, since the move might be evaluated before `num_elems`:
77 //BarChart(rerun::components::TensorData({buffer.num_elems()}, std::move(buffer)));
78
79 auto num_elems = buffer.num_elems();
80 *this = std::move(*this).with_values(
81 rerun::components::TensorData({num_elems}, std::move(buffer))
82 );
83 }
84
85 // --------------------------------------------------------------------
86 // Implicit constructors:
87
88 /// Construct a `BarChart` from a `Collection<uint8_t>`.
90 : BarChart(rerun::datatypes::TensorBuffer::u8(std::move(u8))) {}
91
92 /// Construct a `BarChart` from a `Collection<uint16_t>`.
94 : BarChart(rerun::datatypes::TensorBuffer::u16(std::move(u16))) {}
95
96 /// Construct a `BarChart` from a `Collection<uint32_t>`.
98 : BarChart(rerun::datatypes::TensorBuffer::u32(std::move(u32))) {}
99
100 /// Construct a `BarChart` from a `Collection<uint64_t>`.
102 : BarChart(rerun::datatypes::TensorBuffer::u64(std::move(u64))) {}
103
104 /// Construct a `BarChart` from a `Collection<int8_t>`.
106 : BarChart(rerun::datatypes::TensorBuffer::i8(std::move(i8))) {}
107
108 /// Construct a `BarChart` from a `Collection<int16_t>`.
110 : BarChart(rerun::datatypes::TensorBuffer::i16(std::move(i16))) {}
111
112 /// Construct a `BarChart` from a `Collection<int32_t>`.
114 : BarChart(rerun::datatypes::TensorBuffer::i32(std::move(i32))) {}
115
116 /// Construct a `BarChart` from a `Collection<int64_t>`.
118 : BarChart(rerun::datatypes::TensorBuffer::i64(std::move(i64))) {}
119
120 /// Construct aBarChart` from a `Collection<half>`.
122 : BarChart(rerun::datatypes::TensorBuffer::f16(std::move(f16))) {}
123
124 /// Construct a `BarChart` from a `Collection<float>`.
126 : BarChart(rerun::datatypes::TensorBuffer::f32(std::move(f32))) {}
127
128 /// Construct a `BarChart` from a `Collection<double>`.
130 : BarChart(rerun::datatypes::TensorBuffer::f64(std::move(f64))) {}
131
132 // --------------------------------------------------------------------
133 // Explicit static constructors:
134
135 /// Construct a `BarChart` from a `Collection<uint8_t>`.
137 return BarChart(std::move(u8));
138 }
139
140 /// Construct a `BarChart` from a `Collection<uint16_t>`.
142 return BarChart(std::move(u16));
143 }
144
145 /// Construct a `BarChart` from a `Collection<uint32_t>`.
147 return BarChart(std::move(u32));
148 }
149
150 /// Construct a `BarChart` from a `Collection<uint64_t>`.
152 return BarChart(std::move(u64));
153 }
154
155 /// Construct a `BarChart` from a `Collection<int8_t>`.
157 return BarChart(std::move(i8));
158 }
159
160 /// Construct a `BarChart` from a `Collection<int16_t>`.
162 return BarChart(std::move(i16));
163 }
164
165 /// Construct a `BarChart` from a `Collection<int32_t>`.
167 return BarChart(std::move(i32));
168 }
169
170 /// Construct a `BarChart` from a `Collection<int64_t>`.
172 return BarChart(std::move(i64));
173 }
174
175 /// Construct a `BarChart` from a `Collection<half>`.
177 return BarChart(std::move(f16));
178 }
179
180 /// Construct a `BarChart` from a `Collection<float>`.
182 return BarChart(std::move(f32));
183 }
184
185 /// Construct a `BarChart` from a `Collection<double>`.
187 return BarChart(std::move(f64));
188 }
189
190 // END of extensions from bar_chart_ext.cpp, start of generated code:
191
192 public:
193 BarChart() = default;
194 BarChart(BarChart&& other) = default;
195 BarChart(const BarChart& other) = default;
196 BarChart& operator=(const BarChart& other) = default;
197 BarChart& operator=(BarChart&& other) = default;
198
200 : values(ComponentBatch::from_loggable(std::move(_values), Descriptor_values)
201 .value_or_throw()) {}
202
203 /// Update only some specific fields of a `BarChart`.
205 return BarChart();
206 }
207
208 /// Clear all the fields of a `BarChart`.
210
211 /// The values. Should always be a 1-dimensional tensor (i.e. a vector).
213 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
214 return std::move(*this);
215 }
216
217 /// This method makes it possible to pack multiple `values` in a single component batch.
218 ///
219 /// This only makes sense when used in conjunction with `columns`. `with_values` should
220 /// be used when logging a single row's worth of data.
222 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
223 return std::move(*this);
224 }
225
226 /// The color of the bar chart
228 color = ComponentBatch::from_loggable(_color, Descriptor_color).value_or_throw();
229 return std::move(*this);
230 }
231
232 /// This method makes it possible to pack multiple `color` in a single component batch.
233 ///
234 /// This only makes sense when used in conjunction with `columns`. `with_color` should
235 /// be used when logging a single row's worth of data.
237 color = ComponentBatch::from_loggable(_color, Descriptor_color).value_or_throw();
238 return std::move(*this);
239 }
240
241 /// The abscissa corresponding to each value. Should be a 1-dimensional tensor (i.e. a vector) in same length as values.
243 abscissa =
244 ComponentBatch::from_loggable(_abscissa, Descriptor_abscissa).value_or_throw();
245 return std::move(*this);
246 }
247
248 /// This method makes it possible to pack multiple `abscissa` in a single component batch.
249 ///
250 /// This only makes sense when used in conjunction with `columns`. `with_abscissa` should
251 /// be used when logging a single row's worth of data.
253 abscissa =
254 ComponentBatch::from_loggable(_abscissa, Descriptor_abscissa).value_or_throw();
255 return std::move(*this);
256 }
257
258 /// Partitions the component data into multiple sub-batches.
259 ///
260 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
261 /// instead, via `ComponentBatch::partitioned`.
262 ///
263 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
264 ///
265 /// The specified `lengths` must sum to the total length of the component batch.
267
268 /// Partitions the component data into unit-length sub-batches.
269 ///
270 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
271 /// where `n` is automatically guessed.
273 };
274
275} // namespace rerun::archetypes
276
277namespace rerun {
278 /// \private
279 template <typename T>
280 struct AsComponents;
281
282 /// \private
283 template <>
284 struct AsComponents<archetypes::BarChart> {
285 /// Serialize all set component batches.
286 static Result<Collection<ComponentBatch>> as_batches(const archetypes::BarChart& archetype);
287 };
288} // 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:76
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:46
BarChart(Collection< double > f64)
Construct a BarChart from a Collection<double>.
Definition bar_chart.hpp:129
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:221
static constexpr auto Descriptor_abscissa
ComponentDescriptor for the abscissa field.
Definition bar_chart.hpp:69
BarChart(Collection< int64_t > i64)
Construct a BarChart from a Collection<int64_t>.
Definition bar_chart.hpp:117
static BarChart update_fields()
Update only some specific fields of a BarChart.
Definition bar_chart.hpp:204
static BarChart u32(Collection< uint32_t > u32)
Construct a BarChart from a Collection<uint32_t>.
Definition bar_chart.hpp:146
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:176
static constexpr auto Descriptor_values
ComponentDescriptor for the values field.
Definition bar_chart.hpp:61
BarChart(Collection< int32_t > i32)
Construct a BarChart from a Collection<int32_t>.
Definition bar_chart.hpp:113
static BarChart i64(Collection< int64_t > i64)
Construct a BarChart from a Collection<int64_t>.
Definition bar_chart.hpp:171
static BarChart i16(Collection< int16_t > i16)
Construct a BarChart from a Collection<int16_t>.
Definition bar_chart.hpp:161
static BarChart f64(Collection< double > f64)
Construct a BarChart from a Collection<double>.
Definition bar_chart.hpp:186
static BarChart u64(Collection< uint64_t > u64)
Construct a BarChart from a Collection<uint64_t>.
Definition bar_chart.hpp:151
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:54
static BarChart f32(Collection< float > f32)
Construct a BarChart from a Collection<float>.
Definition bar_chart.hpp:181
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:252
BarChart with_color(const rerun::components::Color &_color) &&
The color of the bar chart.
Definition bar_chart.hpp:227
static BarChart u16(Collection< uint16_t > u16)
Construct a BarChart from a Collection<uint16_t>.
Definition bar_chart.hpp:141
static BarChart clear_fields()
Clear all the fields of a BarChart.
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition bar_chart.hpp:58
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:236
BarChart(Collection< rerun::half > f16)
Construct aBarChartfrom aCollection<half>`.
Definition bar_chart.hpp:121
BarChart(Collection< uint16_t > u16)
Construct a BarChart from a Collection<uint16_t>.
Definition bar_chart.hpp:93
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:136
BarChart(Collection< uint8_t > u8)
Construct a BarChart from a Collection<uint8_t>.
Definition bar_chart.hpp:89
BarChart(Collection< float > f32)
Construct a BarChart from a Collection<float>.
Definition bar_chart.hpp:125
BarChart(Collection< int8_t > i8)
Construct a BarChart from a Collection<int8_t>.
Definition bar_chart.hpp:105
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:212
BarChart(Collection< uint32_t > u32)
Construct a BarChart from a Collection<uint32_t>.
Definition bar_chart.hpp:97
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:242
static BarChart i32(Collection< int32_t > i32)
Construct a BarChart from a Collection<int32_t>.
Definition bar_chart.hpp:166
BarChart(Collection< uint64_t > u64)
Construct a BarChart from a Collection<uint64_t>.
Definition bar_chart.hpp:101
BarChart(Collection< int16_t > i16)
Construct a BarChart from a Collection<int16_t>.
Definition bar_chart.hpp:109
static constexpr auto Descriptor_color
ComponentDescriptor for the color field.
Definition bar_chart.hpp:65
static BarChart i8(Collection< int8_t > i8)
Construct a BarChart from a Collection<int8_t>.
Definition bar_chart.hpp:156
std::optional< ComponentBatch > color
The color of the bar chart.
Definition bar_chart.hpp:51
std::optional< ComponentBatch > values
The values. Should always be a 1-dimensional tensor (i.e. a vector).
Definition bar_chart.hpp:48
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.