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