Rerun C++ SDK
Loading...
Searching...
No Matches
scalar.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/scalar.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/scalar.hpp"
11#include "../indicator_component.hpp"
12#include "../result.hpp"
13
14#include <cstdint>
15#include <optional>
16#include <utility>
17#include <vector>
18
19RR_PUSH_WARNINGS
20RR_DISABLE_DEPRECATION_WARNING
21
22namespace rerun::archetypes {
23 /// **Archetype**: A double-precision scalar, e.g. for use for time-series plots.
24 ///
25 /// The current timeline value will be used for the time/X-axis, hence scalars
26 /// should not be static.
27 ///
28 /// When used to produce a plot, this archetype is used to provide the data that
29 /// is referenced by `archetypes::SeriesLines` or `archetypes::SeriesPoints`. You can do
30 /// this by logging both archetypes to the same path, or alternatively configuring
31 /// the plot-specific archetypes through the blueprint.
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() {
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("scalars", rerun::Scalars(sin(static_cast<double>(step) / 10.0)));
50 /// }
51 /// }
52 /// ```
53 ///
54 /// ### Update a scalar over time, in a single operation
55 /// ![image](https://static.rerun.io/transform3d_column_updates/2b7ccfd29349b2b107fcf7eb8a1291a92cf1cafc/full.png)
56 ///
57 /// ```cpp
58 /// #include <cmath>
59 /// #include <numeric>
60 /// #include <vector>
61 ///
62 /// #include <rerun.hpp>
63 ///
64 /// int main() {
65 /// const auto rec = 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 ///
85 /// ⚠ **Deprecated since 0.23.0**: Use `Scalars` instead.
86 ///
87 struct [[deprecated("since 0.23.0: Use `Scalars` instead.")]] Scalar {
88 /// The scalar value to log.
89 std::optional<ComponentBatch> scalar;
90
91 public:
92 static constexpr const char IndicatorComponentName[] = "rerun.components.ScalarIndicator";
93
94 /// Indicator component, used to identify the archetype when converting to a list of components.
96 /// The name of the archetype as used in `ComponentDescriptor`s.
97 static constexpr const char ArchetypeName[] = "rerun.archetypes.Scalar";
98
99 /// `ComponentDescriptor` for the `scalar` field.
100 static constexpr auto Descriptor_scalar = ComponentDescriptor(
101 ArchetypeName, "scalar", Loggable<rerun::components::Scalar>::Descriptor.component_name
102 );
103
104 public:
105 Scalar() = default;
106 Scalar(Scalar&& other) = default;
107 Scalar(const Scalar& other) = default;
108 Scalar& operator=(const Scalar& other) = default;
109 Scalar& operator=(Scalar&& other) = default;
110
111 explicit Scalar(rerun::components::Scalar _scalar)
112 : scalar(ComponentBatch::from_loggable(std::move(_scalar), Descriptor_scalar)
113 .value_or_throw()) {}
114
115 /// Update only some specific fields of a `Scalar`.
117 return Scalar();
118 }
119
120 /// Clear all the fields of a `Scalar`.
122
123 /// The scalar value to log.
125 scalar = ComponentBatch::from_loggable(_scalar, Descriptor_scalar).value_or_throw();
126 return std::move(*this);
127 }
128
129 /// This method makes it possible to pack multiple `scalar` in a single component batch.
130 ///
131 /// This only makes sense when used in conjunction with `columns`. `with_scalar` should
132 /// be used when logging a single row's worth of data.
134 scalar = ComponentBatch::from_loggable(_scalar, Descriptor_scalar).value_or_throw();
135 return std::move(*this);
136 }
137
138 /// Partitions the component data into multiple sub-batches.
139 ///
140 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
141 /// instead, via `ComponentBatch::partitioned`.
142 ///
143 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
144 ///
145 /// The specified `lengths` must sum to the total length of the component batch.
147
148 /// Partitions the component data into unit-length sub-batches.
149 ///
150 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
151 /// where `n` is automatically guessed.
153 };
154
155} // namespace rerun::archetypes
156
157namespace rerun {
158 /// \private
159 template <typename T>
160 struct AsComponents;
161 RR_PUSH_WARNINGS
162 RR_DISABLE_DEPRECATION_WARNING
163
164 /// \private
165 template <>
166 struct AsComponents<archetypes::Scalar> {
167 /// Serialize all set component batches.
168 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Scalar& archetype);
169 };
170} // namespace rerun
171
172RR_POP_WARNINGS
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
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: A double-precision scalar, e.g.
Definition scalar.hpp:87
std::optional< ComponentBatch > scalar
The scalar value to log.
Definition scalar.hpp:89
static Scalar clear_fields()
Clear all the fields of a Scalar.
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static Scalar update_fields()
Update only some specific fields of a Scalar.
Definition scalar.hpp:116
Scalar with_scalar(const rerun::components::Scalar &_scalar) &&
The scalar value to log.
Definition scalar.hpp:124
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Scalar with_many_scalar(const Collection< rerun::components::Scalar > &_scalar) &&
This method makes it possible to pack multiple scalar in a single component batch.
Definition scalar.hpp:133
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: A scalar value, encoded as a 64-bit floating point.
Definition scalar.hpp:17