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_sdk_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(int argc, char* argv[]) {
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(
46 /// "scalars",
47 /// rerun::Scalars(sin(static_cast<double>(step) / 10.0))
48 /// );
49 /// }
50 /// }
51 /// ```
52 ///
53 /// ### Update a scalar over time, in a single operation
54 /// ![image](https://static.rerun.io/transform3d_column_updates/2b7ccfd29349b2b107fcf7eb8a1291a92cf1cafc/full.png)
55 ///
56 /// ```cpp
57 /// #include <cmath>
58 /// #include <numeric>
59 /// #include <vector>
60 ///
61 /// #include <rerun.hpp>
62 ///
63 /// int main(int argc, char* argv[]) {
64 /// const auto rec =
65 /// rerun::RecordingStream("rerun_example_scalar_column_updates");
66 /// rec.spawn().exit_on_failure();
67 ///
68 /// // Native scalars & times.
69 /// std::vector<double> scalar_data(64);
70 /// for (size_t i = 0; i <64; ++i) {
71 /// scalar_data[i] = sin(static_cast<double>(i) / 10.0);
72 /// }
73 /// std::vector<int64_t> times(64);
74 /// std::iota(times.begin(), times.end(), 0);
75 ///
76 /// // Serialize to columns and send.
77 /// rec.send_columns(
78 /// "scalars",
79 /// rerun::TimeColumn::from_sequence("step", std::move(times)),
80 /// rerun::Scalars(std::move(scalar_data)).columns()
81 /// );
82 /// }
83 /// ```
84 struct Scalars {
85 /// The scalar values to log.
86 std::optional<ComponentBatch> scalars;
87
88 public:
89 /// The name of the archetype as used in `ComponentDescriptor`s.
90 static constexpr const char ArchetypeName[] = "rerun.archetypes.Scalars";
91
92 /// `ComponentDescriptor` for the `scalars` field.
93 static constexpr auto Descriptor_scalars = ComponentDescriptor(
95 );
96
97 public:
98 Scalars() = default;
99 Scalars(Scalars&& other) = default;
100 Scalars(const Scalars& other) = default;
101 Scalars& operator=(const Scalars& other) = default;
102 Scalars& operator=(Scalars&& other) = default;
103
105 : scalars(ComponentBatch::from_loggable(std::move(_scalars), Descriptor_scalars)
106 .value_or_throw()) {}
107
108 /// Update only some specific fields of a `Scalars`.
110 return Scalars();
111 }
112
113 /// Clear all the fields of a `Scalars`.
115
116 /// The scalar values to log.
118 scalars = ComponentBatch::from_loggable(_scalars, Descriptor_scalars).value_or_throw();
119 return std::move(*this);
120 }
121
122 /// Partitions the component data into multiple sub-batches.
123 ///
124 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
125 /// instead, via `ComponentBatch::partitioned`.
126 ///
127 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
128 ///
129 /// The specified `lengths` must sum to the total length of the component batch.
131
132 /// Partitions the component data into unit-length sub-batches.
133 ///
134 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
135 /// where `n` is automatically guessed.
137 };
138
139} // namespace rerun::archetypes
140
141namespace rerun {
142 /// \private
143 template <typename T>
144 struct AsComponents;
145
146 /// \private
147 template <>
148 struct AsComponents<archetypes::Scalars> {
149 /// Serialize all set component batches.
150 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Scalars& archetype);
151 };
152} // 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:87
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:84
Scalars with_scalars(const Collection< rerun::components::Scalar > &_scalars) &&
The scalar values to log.
Definition scalars.hpp:117
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition scalars.hpp:90
static Scalars clear_fields()
Clear all the fields of a Scalars.
std::optional< ComponentBatch > scalars
The scalar values to log.
Definition scalars.hpp:86
static Scalars update_fields()
Update only some specific fields of a Scalars.
Definition scalars.hpp:109
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:93