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