Rerun C++ SDK
Loading...
Searching...
No Matches
measurements.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/measurements.def.rs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/aggregation_policy.hpp"
10#include "../components/color.hpp"
11#include "../components/interpolation_mode.hpp"
12#include "../components/name.hpp"
13#include "../components/scalar.hpp"
14#include "../components/stroke_width.hpp"
15#include "../components/unit.hpp"
16#include "../components/variance.hpp"
17#include "../components/visible.hpp"
18#include "../result.hpp"
19
20#include <cstdint>
21#include <optional>
22#include <utility>
23#include <vector>
24
25namespace rerun::archetypes {
26 /// **Archetype**: One or more scalar measurements, each with a variance and a unit.
27 ///
28 /// Use this for sensors that report a value together with its uncertainty:
29 /// pressure, temperature, illuminance, relative humidity, range, and so on.
30 ///
31 /// In a `views::TimeSeriesView` each series is drawn as a line with a translucent
32 /// band around it, one standard deviation (the square root of the variance) wide in each direction.
33 /// Leave `variances` unset if the uncertainty is unknown.
34 ///
35 /// The current timeline value is used for the time/X-axis, so measurements should not be
36 /// static. Number of values per timestamp is expected to be the same over time.
37 ///
38 /// Unlike `archetypes::Scalars`, this archetype carries its own styling, so values and style
39 /// are logged together.
40 /// Changes over time are supported for most but not all styling fields (see respective fields for details).
41 ///
42 /// ## Example
43 ///
44 /// ### Pressure with variance
45 /// ![image](https://static.rerun.io/measurements/2388490ab2b487bb6c47a2be3e7d5e7aa17c08f3/full.png)
46 ///
47 /// ```cpp
48 /// #include <rerun.hpp>
49 ///
50 /// #include <cmath>
51 ///
52 /// int main(int argc, char* argv[]) {
53 /// const auto rec =
54 /// rerun::RecordingStream("rerun_example_measurements_simple");
55 /// rec.spawn().exit_on_failure();
56 ///
57 /// // Two parallel pressure sensors (in Pa), each with slowly drifting variance.
58 /// for (int step = 0; step <64; ++step) {
59 /// rec.set_time_sequence("step", step);
60 /// const auto s = static_cast<double>(step);
61 /// const std::array<double, 2> pressures = {
62 /// 101325.0 + 50.0 * std::sin(s / 10.0),
63 /// 101300.0 + 30.0 * std::cos(s / 8.0),
64 /// };
65 /// const std::array<double, 2> variances = {
66 /// 100.0 + 25.0 * std::sin(s / 7.0),
67 /// 80.0 + 15.0 * std::cos(s / 11.0),
68 /// };
69 /// rec.log(
70 /// "pressure",
71 /// rerun::Measurements(pressures).with_variances(variances).with_units(
72 /// {"Pa"}
73 /// )
74 /// );
75 /// }
76 /// }
77 /// ```
78 ///
79 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
80 ///
81 struct Measurements {
82 /// The measured scalar values.
83 std::optional<ComponentBatch> values;
84
85 /// Variances of the measurements (σ², in the units of `values` squared).
86 ///
87 /// When set, length is expected to match `values`.
88 std::optional<ComponentBatch> variances;
89
90 /// Units of the measurements, shown in the legend and in tooltips.
91 ///
92 /// When set, length is expected to match `values`.
93 /// Expected to be unchanging over time.
94 std::optional<ComponentBatch> units;
95
96 /// Color for the corresponding series.
97 ///
98 /// May change over time, but can cause discontinuities in the line.
99 std::optional<ComponentBatch> colors;
100
101 /// Stroke width for the corresponding series.
102 ///
103 /// May change over time, but can cause discontinuities in the line.
104 std::optional<ComponentBatch> widths;
105
106 /// Display name of the series.
107 ///
108 /// Used in the legend. Expected to be unchanging over time.
109 std::optional<ComponentBatch> names;
110
111 /// Which series are visible.
112 ///
113 /// If not set, all series on this entity are visible.
114 /// Unlike with the regular visibility property of the entire entity, any series that is hidden
115 /// via this property will still be visible in the legend.
116 ///
117 /// May change over time, but can cause discontinuities in the line.
118 std::optional<ComponentBatch> visible_series;
119
120 /// Configures the zoom-dependent scalar aggregation.
121 ///
122 /// This is done only if steps on the X axis go below a single pixel,
123 /// i.e. a single pixel covers more than one tick worth of data. It can greatly improve performance
124 /// (and readability) in such situations as it prevents overdraw.
125 ///
126 /// Expected to be unchanging over time.
127 std::optional<ComponentBatch> aggregation_policy;
128
129 /// Specifies how values between data points are interpolated.
130 ///
131 /// Defaults to linear interpolation. Use one of the `Step*` variants for a stepped (staircase) line.
132 ///
133 /// Expected to be unchanging over time.
134 std::optional<ComponentBatch> interpolation_mode;
135
136 public:
137 /// The name of the archetype as used in `ComponentDescriptor`s.
138 static constexpr const char ArchetypeName[] = "rerun.archetypes.Measurements";
139
140 /// `ComponentDescriptor` for the `values` field.
141 static constexpr auto Descriptor_values = ComponentDescriptor(
143 );
144 /// `ComponentDescriptor` for the `variances` field.
146 ArchetypeName, "Measurements:variances",
148 );
149 /// `ComponentDescriptor` for the `units` field.
150 static constexpr auto Descriptor_units = ComponentDescriptor(
152 );
153 /// `ComponentDescriptor` for the `colors` field.
154 static constexpr auto Descriptor_colors = ComponentDescriptor(
156 );
157 /// `ComponentDescriptor` for the `widths` field.
158 static constexpr auto Descriptor_widths = ComponentDescriptor(
159 ArchetypeName, "Measurements:widths",
161 );
162 /// `ComponentDescriptor` for the `names` field.
163 static constexpr auto Descriptor_names = ComponentDescriptor(
165 );
166 /// `ComponentDescriptor` for the `visible_series` field.
168 ArchetypeName, "Measurements:visible_series",
170 );
171 /// `ComponentDescriptor` for the `aggregation_policy` field.
173 ArchetypeName, "Measurements:aggregation_policy",
175 );
176 /// `ComponentDescriptor` for the `interpolation_mode` field.
178 ArchetypeName, "Measurements:interpolation_mode",
180 );
181
182 public:
183 Measurements() = default;
184 Measurements(Measurements&& other) = default;
185 Measurements(const Measurements& other) = default;
186 Measurements& operator=(const Measurements& other) = default;
187 Measurements& operator=(Measurements&& other) = default;
188
190 : values(ComponentBatch::from_loggable(std::move(_values), Descriptor_values)
191 .value_or_throw()) {}
192
193 /// Update only some specific fields of a `Measurements`.
195 return Measurements();
196 }
197
198 /// Clear all the fields of a `Measurements`.
200
201 /// The measured scalar values.
203 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
204 return std::move(*this);
205 }
206
207 /// Variances of the measurements (σ², in the units of `values` squared).
208 ///
209 /// When set, length is expected to match `values`.
211 variances =
212 ComponentBatch::from_loggable(_variances, Descriptor_variances).value_or_throw();
213 return std::move(*this);
214 }
215
216 /// Units of the measurements, shown in the legend and in tooltips.
217 ///
218 /// When set, length is expected to match `values`.
219 /// Expected to be unchanging over time.
221 units = ComponentBatch::from_loggable(_units, Descriptor_units).value_or_throw();
222 return std::move(*this);
223 }
224
225 /// Color for the corresponding series.
226 ///
227 /// May change over time, but can cause discontinuities in the line.
229 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
230 return std::move(*this);
231 }
232
233 /// Stroke width for the corresponding series.
234 ///
235 /// May change over time, but can cause discontinuities in the line.
237 widths = ComponentBatch::from_loggable(_widths, Descriptor_widths).value_or_throw();
238 return std::move(*this);
239 }
240
241 /// Display name of the series.
242 ///
243 /// Used in the legend. Expected to be unchanging over time.
245 names = ComponentBatch::from_loggable(_names, Descriptor_names).value_or_throw();
246 return std::move(*this);
247 }
248
249 /// Which series are visible.
250 ///
251 /// If not set, all series on this entity are visible.
252 /// Unlike with the regular visibility property of the entire entity, any series that is hidden
253 /// via this property will still be visible in the legend.
254 ///
255 /// May change over time, but can cause discontinuities in the line.
257 const Collection<rerun::components::Visible>& _visible_series
258 ) && {
261 .value_or_throw();
262 return std::move(*this);
263 }
264
265 /// Configures the zoom-dependent scalar aggregation.
266 ///
267 /// This is done only if steps on the X axis go below a single pixel,
268 /// i.e. a single pixel covers more than one tick worth of data. It can greatly improve performance
269 /// (and readability) in such situations as it prevents overdraw.
270 ///
271 /// Expected to be unchanging over time.
273 const rerun::components::AggregationPolicy& _aggregation_policy
274 ) && {
277 .value_or_throw();
278 return std::move(*this);
279 }
280
281 /// This method makes it possible to pack multiple `aggregation_policy` in a single component batch.
282 ///
283 /// This only makes sense when used in conjunction with `columns`. `with_aggregation_policy` should
284 /// be used when logging a single row's worth of data.
286 const Collection<rerun::components::AggregationPolicy>& _aggregation_policy
287 ) && {
290 .value_or_throw();
291 return std::move(*this);
292 }
293
294 /// Specifies how values between data points are interpolated.
295 ///
296 /// Defaults to linear interpolation. Use one of the `Step*` variants for a stepped (staircase) line.
297 ///
298 /// Expected to be unchanging over time.
300 const rerun::components::InterpolationMode& _interpolation_mode
301 ) && {
304 .value_or_throw();
305 return std::move(*this);
306 }
307
308 /// This method makes it possible to pack multiple `interpolation_mode` in a single component batch.
309 ///
310 /// This only makes sense when used in conjunction with `columns`. `with_interpolation_mode` should
311 /// be used when logging a single row's worth of data.
313 const Collection<rerun::components::InterpolationMode>& _interpolation_mode
314 ) && {
317 .value_or_throw();
318 return std::move(*this);
319 }
320
321 /// Partitions the component data into multiple sub-batches.
322 ///
323 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
324 /// instead, via `ComponentBatch::partitioned`.
325 ///
326 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
327 ///
328 /// The specified `lengths` must sum to the total length of the component batch.
330
331 /// Partitions the component data into unit-length sub-batches.
332 ///
333 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
334 /// where `n` is automatically guessed.
336 };
337
338} // namespace rerun::archetypes
339
340namespace rerun {
341 /// \private
342 template <typename T>
343 struct AsComponents;
344
345 /// \private
346 template <>
347 struct AsComponents<archetypes::Measurements> {
348 /// Serialize all set component batches.
349 static Result<Collection<ComponentBatch>> as_batches(
350 const archetypes::Measurements& archetype
351 );
352 };
353} // 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:90
AggregationPolicy
Component: Policy for aggregation of multiple scalar plot values.
Definition aggregation_policy.hpp:28
InterpolationMode
Component: Specifies how values between data points are interpolated in time series.
Definition interpolation_mode.hpp:24
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: One or more scalar measurements, each with a variance and a unit.
Definition measurements.hpp:81
static constexpr auto Descriptor_units
ComponentDescriptor for the units field.
Definition measurements.hpp:150
static Measurements clear_fields()
Clear all the fields of a Measurements.
static constexpr auto Descriptor_names
ComponentDescriptor for the names field.
Definition measurements.hpp:163
std::optional< ComponentBatch > widths
Stroke width for the corresponding series.
Definition measurements.hpp:104
std::optional< ComponentBatch > units
Units of the measurements, shown in the legend and in tooltips.
Definition measurements.hpp:94
Measurements with_colors(const Collection< rerun::components::Color > &_colors) &&
Color for the corresponding series.
Definition measurements.hpp:228
static constexpr auto Descriptor_variances
ComponentDescriptor for the variances field.
Definition measurements.hpp:145
std::optional< ComponentBatch > variances
Variances of the measurements (σ², in the units of values squared).
Definition measurements.hpp:88
std::optional< ComponentBatch > colors
Color for the corresponding series.
Definition measurements.hpp:99
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
std::optional< ComponentBatch > aggregation_policy
Configures the zoom-dependent scalar aggregation.
Definition measurements.hpp:127
std::optional< ComponentBatch > visible_series
Which series are visible.
Definition measurements.hpp:118
Measurements with_interpolation_mode(const rerun::components::InterpolationMode &_interpolation_mode) &&
Specifies how values between data points are interpolated.
Definition measurements.hpp:299
static constexpr auto Descriptor_interpolation_mode
ComponentDescriptor for the interpolation_mode field.
Definition measurements.hpp:177
Measurements with_variances(const Collection< rerun::components::Variance > &_variances) &&
Variances of the measurements (σ², in the units of values squared).
Definition measurements.hpp:210
static Measurements update_fields()
Update only some specific fields of a Measurements.
Definition measurements.hpp:194
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition measurements.hpp:138
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition measurements.hpp:154
Measurements with_aggregation_policy(const rerun::components::AggregationPolicy &_aggregation_policy) &&
Configures the zoom-dependent scalar aggregation.
Definition measurements.hpp:272
std::optional< ComponentBatch > values
The measured scalar values.
Definition measurements.hpp:83
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Measurements with_widths(const Collection< rerun::components::StrokeWidth > &_widths) &&
Stroke width for the corresponding series.
Definition measurements.hpp:236
static constexpr auto Descriptor_values
ComponentDescriptor for the values field.
Definition measurements.hpp:141
Measurements with_many_interpolation_mode(const Collection< rerun::components::InterpolationMode > &_interpolation_mode) &&
This method makes it possible to pack multiple interpolation_mode in a single component batch.
Definition measurements.hpp:312
Measurements with_names(const Collection< rerun::components::Name > &_names) &&
Display name of the series.
Definition measurements.hpp:244
Measurements with_units(const Collection< rerun::components::Unit > &_units) &&
Units of the measurements, shown in the legend and in tooltips.
Definition measurements.hpp:220
static constexpr auto Descriptor_aggregation_policy
ComponentDescriptor for the aggregation_policy field.
Definition measurements.hpp:172
Measurements with_many_aggregation_policy(const Collection< rerun::components::AggregationPolicy > &_aggregation_policy) &&
This method makes it possible to pack multiple aggregation_policy in a single component batch.
Definition measurements.hpp:285
Measurements with_visible_series(const Collection< rerun::components::Visible > &_visible_series) &&
Which series are visible.
Definition measurements.hpp:256
static constexpr auto Descriptor_visible_series
ComponentDescriptor for the visible_series field.
Definition measurements.hpp:167
static constexpr auto Descriptor_widths
ComponentDescriptor for the widths field.
Definition measurements.hpp:158
std::optional< ComponentBatch > names
Display name of the series.
Definition measurements.hpp:109
Measurements with_values(const Collection< rerun::components::Scalar > &_values) &&
The measured scalar values.
Definition measurements.hpp:202
std::optional< ComponentBatch > interpolation_mode
Specifies how values between data points are interpolated.
Definition measurements.hpp:134