Rerun C++ SDK
Loading...
Searching...
No Matches
scalars.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/scalars.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/scalar.hpp"
10#include "../result.hpp"
11
12#include <cstdint>
13#include <optional>
14#include <utility>
15#include <vector>
16
17namespace rerun::archetypes {
18 /// **Archetype**: One or more double-precision scalar values, e.g. for use for time-series plots.
19 ///
20 /// The current timeline value will be used for the time/X-axis, hence scalars
21 /// should not be static.
22 /// Number of scalars per timestamp is expected to be the same over time.
23 ///
24 /// When used to produce a plot, this archetype is used to provide the data that
25 /// is referenced by `archetypes::SeriesLines` or `archetypes::SeriesPoints`. You can do
26 /// this by logging both archetypes to the same path, or alternatively configuring
27 /// the plot-specific archetypes through the blueprint.
28 ///
29 /// ## Examples
30 ///
31 /// ### Update a scalar over time
32 /// ![image](https://static.rerun.io/transform3d_column_updates/2b7ccfd29349b2b107fcf7eb8a1291a92cf1cafc/full.png)
33 ///
34 /// ```cpp
35 /// #include <cmath>
36 ///
37 /// #include <rerun.hpp>
38 ///
39 /// int main() {
40 /// const auto rec = rerun::RecordingStream("rerun_example_scalar_row_updates");
41 /// rec.spawn().exit_on_failure();
42 ///
43 /// for (int step = 0; step <64; ++step) {
44 /// rec.set_time_sequence("step", step);
45 /// rec.log("scalars", rerun::Scalars(sin(static_cast<double>(step) / 10.0)));
46 /// }
47 /// }
48 /// ```
49 ///
50 /// ### Update a scalar over time, in a single operation
51 /// ![image](https://static.rerun.io/transform3d_column_updates/2b7ccfd29349b2b107fcf7eb8a1291a92cf1cafc/full.png)
52 ///
53 /// ```cpp
54 /// #include <cmath>
55 /// #include <numeric>
56 /// #include <vector>
57 ///
58 /// #include <rerun.hpp>
59 ///
60 /// int main() {
61 /// const auto rec = rerun::RecordingStream("rerun_example_scalar_column_updates");
62 /// rec.spawn().exit_on_failure();
63 ///
64 /// // Native scalars & times.
65 /// std::vector<double> scalar_data(64);
66 /// for (size_t i = 0; i <64; ++i) {
67 /// scalar_data[i] = sin(static_cast<double>(i) / 10.0);
68 /// }
69 /// std::vector<int64_t> times(64);
70 /// std::iota(times.begin(), times.end(), 0);
71 ///
72 /// // Serialize to columns and send.
73 /// rec.send_columns(
74 /// "scalars",
75 /// rerun::TimeColumn::from_sequence("step", std::move(times)),
76 /// rerun::Scalars(std::move(scalar_data)).columns()
77 /// );
78 /// }
79 /// ```
80 struct Scalars {
81 /// The scalar values to log.
82 std::optional<ComponentBatch> scalars;
83
84 public:
85 /// The name of the archetype as used in `ComponentDescriptor`s.
86 static constexpr const char ArchetypeName[] = "rerun.archetypes.Scalars";
87
88 /// `ComponentDescriptor` for the `scalars` field.
89 static constexpr auto Descriptor_scalars = ComponentDescriptor(
91 );
92
93 public:
94 Scalars() = default;
95 Scalars(Scalars&& other) = default;
96 Scalars(const Scalars& other) = default;
97 Scalars& operator=(const Scalars& other) = default;
98 Scalars& operator=(Scalars&& other) = default;
99
101 : scalars(ComponentBatch::from_loggable(std::move(_scalars), Descriptor_scalars)
102 .value_or_throw()) {}
103
104 /// Update only some specific fields of a `Scalars`.
106 return Scalars();
107 }
108
109 /// Clear all the fields of a `Scalars`.
111
112 /// The scalar values to log.
114 scalars = ComponentBatch::from_loggable(_scalars, Descriptor_scalars).value_or_throw();
115 return std::move(*this);
116 }
117
118 /// Partitions the component data into multiple sub-batches.
119 ///
120 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
121 /// instead, via `ComponentBatch::partitioned`.
122 ///
123 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
124 ///
125 /// The specified `lengths` must sum to the total length of the component batch.
127
128 /// Partitions the component data into unit-length sub-batches.
129 ///
130 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
131 /// where `n` is automatically guessed.
133 };
134
135} // namespace rerun::archetypes
136
137namespace rerun {
138 /// \private
139 template <typename T>
140 struct AsComponents;
141
142 /// \private
143 template <>
144 struct AsComponents<archetypes::Scalars> {
145 /// Serialize all set component batches.
146 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Scalars& archetype);
147 };
148} // 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: One or more double-precision scalar values, e.g.
Definition scalars.hpp:80
Scalars with_scalars(const Collection< rerun::components::Scalar > &_scalars) &&
The scalar values to log.
Definition scalars.hpp:113
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition scalars.hpp:86
static Scalars clear_fields()
Clear all the fields of a Scalars.
std::optional< ComponentBatch > scalars
The scalar values to log.
Definition scalars.hpp:82
static Scalars update_fields()
Update only some specific fields of a Scalars.
Definition scalars.hpp:105
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
static constexpr auto Descriptor_scalars
ComponentDescriptor for the scalars field.
Definition scalars.hpp:89