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 "../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**: A double-precision scalar, 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 /// cannot be static.
23 ///
24 /// When used to produce a plot, this archetype is used to provide the data that
25 /// is referenced by `archetypes::SeriesLine` or `archetypes::SeriesPoint`. 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() {
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("scalars", rerun::Scalar(sin(static_cast<double>(step) / 10.0)));
46 /// }
47 /// }
48 /// ```
49 ///
50 /// ### Update a scalar over time, in a single operation
51 /// ![image](https://static.rerun.io/transform3d_column_updates/2b7ccfd29349b2b107fcf7eb8a1291a92cf1cafc/full.png)
52 ///
53 /// ```cpp
54 /// #include <cmath>
55 /// #include <numeric>
56 /// #include <vector>
57 ///
58 /// #include <rerun.hpp>
59 ///
60 /// int main() {
61 /// const auto rec = rerun::RecordingStream("rerun_example_scalar_column_updates");
62 /// rec.spawn().exit_on_failure();
63 ///
64 /// // Native scalars & times.
65 /// std::vector<double> scalar_data(64);
66 /// for (size_t i = 0; i <64; ++i) {
67 /// scalar_data[i] = sin(static_cast<double>(i) / 10.0);
68 /// }
69 /// std::vector<int64_t> times(64);
70 /// std::iota(times.begin(), times.end(), 0);
71 ///
72 /// // Serialize to columns and send.
73 /// rec.send_columns(
74 /// "scalars",
75 /// rerun::TimeColumn::from_sequence("step", std::move(times)),
76 /// rerun::Scalar().with_many_scalar(std::move(scalar_data)).columns()
77 /// );
78 /// }
79 /// ```
80 struct Scalar {
81 /// The scalar value to log.
82 std::optional<ComponentBatch> scalar;
83
84 public:
85 static constexpr const char IndicatorComponentName[] = "rerun.components.ScalarIndicator";
86
87 /// Indicator component, used to identify the archetype when converting to a list of components.
89 /// The name of the archetype as used in `ComponentDescriptor`s.
90 static constexpr const char ArchetypeName[] = "rerun.archetypes.Scalar";
91
92 /// `ComponentDescriptor` for the `scalar` field.
93 static constexpr auto Descriptor_scalar = ComponentDescriptor(
95 );
96
97 public:
98 Scalar() = default;
99 Scalar(Scalar&& other) = default;
100 Scalar(const Scalar& other) = default;
101 Scalar& operator=(const Scalar& other) = default;
102 Scalar& operator=(Scalar&& other) = default;
103
104 explicit Scalar(rerun::components::Scalar _scalar)
105 : scalar(ComponentBatch::from_loggable(std::move(_scalar), Descriptor_scalar)
106 .value_or_throw()) {}
107
108 /// Update only some specific fields of a `Scalar`.
110 return Scalar();
111 }
112
113 /// Clear all the fields of a `Scalar`.
115
116 /// The scalar value to log.
118 scalar = ComponentBatch::from_loggable(_scalar, Descriptor_scalar).value_or_throw();
119 return std::move(*this);
120 }
121
122 /// This method makes it possible to pack multiple `scalar` in a single component batch.
123 ///
124 /// This only makes sense when used in conjunction with `columns`. `with_scalar` should
125 /// be used when logging a single row's worth of data.
127 scalar = ComponentBatch::from_loggable(_scalar, Descriptor_scalar).value_or_throw();
128 return std::move(*this);
129 }
130
131 /// Partitions the component data into multiple sub-batches.
132 ///
133 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
134 /// instead, via `ComponentBatch::partitioned`.
135 ///
136 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
137 ///
138 /// The specified `lengths` must sum to the total length of the component batch.
140
141 /// Partitions the component data into unit-length sub-batches.
142 ///
143 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
144 /// where `n` is automatically guessed.
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::Scalar> {
158 /// Serialize all set component batches.
159 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Scalar& archetype);
160 };
161} // 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: A double-precision scalar, e.g.
Definition scalar.hpp:80
std::optional< ComponentBatch > scalar
The scalar value to log.
Definition scalar.hpp:82
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:109
Scalar with_scalar(const rerun::components::Scalar &_scalar) &&
The scalar value to log.
Definition scalar.hpp:117
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition scalar.hpp:90
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:126
static constexpr auto Descriptor_scalar
ComponentDescriptor for the scalar field.
Definition scalar.hpp:93
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