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