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