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