Rerun C++ SDK
Loading...
Searching...
No Matches
state_configuration.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_sdk_types/definitions/rerun/archetypes/state_configuration.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/color.hpp"
10#include "../components/text.hpp"
11#include "../components/visible.hpp"
12#include "../result.hpp"
13
14#include <cstdint>
15#include <optional>
16#include <utility>
17#include <vector>
18
19namespace rerun::archetypes {
20 /// **Archetype**: Define the style and mapping for state values in a state timeline view.
21 ///
22 /// This archetype provides configuration for how state values are displayed.
23 /// It maps raw state values to display labels, colors, and visibility.
24 ///
25 /// `values`, `labels`, `colors`, and `visible` are parallel arrays: the entry
26 /// at index `i` of each describes the same state value, and only the
27 /// per-index pairing is meaningful. The four arrays should have matching
28 /// length; any secondary array (`labels`, `colors`, `visible`) that is shorter
29 /// than `values` falls back to defaults for the missing entries.
30 ///
31 /// It's generally recommended to log this type as static.
32 ///
33 /// The underlying data needs to be logged to the same entity path using `archetypes::StateChange`.
34 ///
35 /// ## Example
36 ///
37 /// ### State changes with a custom style
38 /// ```cpp
39 /// #include <rerun.hpp>
40 ///
41 /// int main(int argc, char* argv[]) {
42 /// const auto rec = rerun::RecordingStream("rerun_example_state_configuration");
43 /// rec.spawn().exit_on_failure();
44 ///
45 /// // Configure how each raw state value is displayed (label, color, visibility).
46 /// rec.log_static(
47 /// "door",
48 /// rerun::StateConfiguration()
49 /// .with_values({"open", "closed"})
50 /// .with_labels({"Open", "Closed"})
51 /// .with_colors({0x4CAF50FF, 0xEF5350FF})
52 /// );
53 ///
54 /// rec.set_time_sequence("step", 0);
55 /// rec.log("door", rerun::StateChange().with_state("open"));
56 ///
57 /// rec.set_time_sequence("step", 1);
58 /// rec.log("door", rerun::StateChange().with_state("closed"));
59 ///
60 /// rec.set_time_sequence("step", 2);
61 /// rec.log("door", rerun::StateChange().with_state("open"));
62 /// }
63 /// ```
64 ///
65 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
66 ///
68 /// The raw state values that this configuration applies to.
69 ///
70 /// Each entry defines a known state value. The order determines the mapping to
71 /// `labels`, `colors`, and `visible` (by index).
72 std::optional<ComponentBatch> values;
73
74 /// Display labels for each state value.
75 ///
76 /// If provided, the label at index `i` is shown instead of the raw value at index `i`.
77 /// If not provided or shorter than `values`, the raw value is used as the label.
78 std::optional<ComponentBatch> labels;
79
80 /// Colors for each state value.
81 ///
82 /// If provided, the color at index `i` is used for the state at index `i`.
83 /// If not provided, colors are assigned automatically from a built-in palette.
84 std::optional<ComponentBatch> colors;
85
86 /// Visibility for each state value.
87 ///
88 /// If provided, the visibility at index `i` controls whether the state at index `i` is shown.
89 /// If not provided, all state values are visible.
90 std::optional<ComponentBatch> visible;
91
92 public:
93 /// The name of the archetype as used in `ComponentDescriptor`s.
94 static constexpr const char ArchetypeName[] = "rerun.archetypes.StateConfiguration";
95
96 /// `ComponentDescriptor` for the `values` field.
97 static constexpr auto Descriptor_values = ComponentDescriptor(
98 ArchetypeName, "StateConfiguration:values",
100 );
101 /// `ComponentDescriptor` for the `labels` field.
102 static constexpr auto Descriptor_labels = ComponentDescriptor(
103 ArchetypeName, "StateConfiguration:labels",
105 );
106 /// `ComponentDescriptor` for the `colors` field.
107 static constexpr auto Descriptor_colors = ComponentDescriptor(
108 ArchetypeName, "StateConfiguration:colors",
110 );
111 /// `ComponentDescriptor` for the `visible` field.
113 ArchetypeName, "StateConfiguration:visible",
115 );
116
117 public:
118 StateConfiguration() = default;
119 StateConfiguration(StateConfiguration&& other) = default;
120 StateConfiguration(const StateConfiguration& other) = default;
121 StateConfiguration& operator=(const StateConfiguration& other) = default;
122 StateConfiguration& operator=(StateConfiguration&& other) = default;
123
124 /// Update only some specific fields of a `StateConfiguration`.
126 return StateConfiguration();
127 }
128
129 /// Clear all the fields of a `StateConfiguration`.
131
132 /// The raw state values that this configuration applies to.
133 ///
134 /// Each entry defines a known state value. The order determines the mapping to
135 /// `labels`, `colors`, and `visible` (by index).
137 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
138 return std::move(*this);
139 }
140
141 /// Display labels for each state value.
142 ///
143 /// If provided, the label at index `i` is shown instead of the raw value at index `i`.
144 /// If not provided or shorter than `values`, the raw value is used as the label.
146 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
147 return std::move(*this);
148 }
149
150 /// Colors for each state value.
151 ///
152 /// If provided, the color at index `i` is used for the state at index `i`.
153 /// If not provided, colors are assigned automatically from a built-in palette.
155 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
156 return std::move(*this);
157 }
158
159 /// Visibility for each state value.
160 ///
161 /// If provided, the visibility at index `i` controls whether the state at index `i` is shown.
162 /// If not provided, all state values are visible.
164 visible = ComponentBatch::from_loggable(_visible, Descriptor_visible).value_or_throw();
165 return std::move(*this);
166 }
167
168 /// Partitions the component data into multiple sub-batches.
169 ///
170 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
171 /// instead, via `ComponentBatch::partitioned`.
172 ///
173 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
174 ///
175 /// The specified `lengths` must sum to the total length of the component batch.
177
178 /// Partitions the component data into unit-length sub-batches.
179 ///
180 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
181 /// where `n` is automatically guessed.
183 };
184
185} // namespace rerun::archetypes
186
187namespace rerun {
188 /// \private
189 template <typename T>
190 struct AsComponents;
191
192 /// \private
193 template <>
194 struct AsComponents<archetypes::StateConfiguration> {
195 /// Serialize all set component batches.
196 static Result<Collection<ComponentBatch>> as_batches(
197 const archetypes::StateConfiguration& archetype
198 );
199 };
200} // 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:81
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
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: Define the style and mapping for state values in a state timeline view.
Definition state_configuration.hpp:67
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition state_configuration.hpp:94
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
StateConfiguration with_colors(const Collection< rerun::components::Color > &_colors) &&
Colors for each state value.
Definition state_configuration.hpp:154
StateConfiguration with_values(const Collection< rerun::components::Text > &_values) &&
The raw state values that this configuration applies to.
Definition state_configuration.hpp:136
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
StateConfiguration with_visible(const Collection< rerun::components::Visible > &_visible) &&
Visibility for each state value.
Definition state_configuration.hpp:163
static StateConfiguration clear_fields()
Clear all the fields of a StateConfiguration.
std::optional< ComponentBatch > values
The raw state values that this configuration applies to.
Definition state_configuration.hpp:72
std::optional< ComponentBatch > colors
Colors for each state value.
Definition state_configuration.hpp:84
static constexpr auto Descriptor_values
ComponentDescriptor for the values field.
Definition state_configuration.hpp:97
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition state_configuration.hpp:107
StateConfiguration with_labels(const Collection< rerun::components::Text > &_labels) &&
Display labels for each state value.
Definition state_configuration.hpp:145
static StateConfiguration update_fields()
Update only some specific fields of a StateConfiguration.
Definition state_configuration.hpp:125
std::optional< ComponentBatch > visible
Visibility for each state value.
Definition state_configuration.hpp:90
static constexpr auto Descriptor_visible
ComponentDescriptor for the visible field.
Definition state_configuration.hpp:112
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition state_configuration.hpp:102
std::optional< ComponentBatch > labels
Display labels for each state value.
Definition state_configuration.hpp:78