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 =
43 /// rerun::RecordingStream("rerun_example_state_configuration");
44 /// rec.spawn().exit_on_failure();
45 ///
46 /// // Configure how each raw state value is displayed (label, color, visibility).
47 /// rec.log_static(
48 /// "door",
49 /// rerun::StateConfiguration()
50 /// .with_values({"open", "closed"})
51 /// .with_labels({"Open", "Closed"})
52 /// .with_colors({0x4CAF50FF, 0xEF5350FF})
53 /// );
54 ///
55 /// rec.set_time_sequence("step", 0);
56 /// rec.log("door", rerun::StateChange().with_state("open"));
57 ///
58 /// rec.set_time_sequence("step", 1);
59 /// rec.log("door", rerun::StateChange().with_state("closed"));
60 ///
61 /// rec.set_time_sequence("step", 2);
62 /// rec.log("door", rerun::StateChange().with_state("open"));
63 /// }
64 /// ```
65 ///
66 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
67 ///
69 /// The raw state values that this configuration applies to.
70 ///
71 /// Each entry defines a known state value. The order determines the mapping to
72 /// `labels`, `colors`, and `visible` (by index).
73 std::optional<ComponentBatch> values;
74
75 /// Display labels for each state value.
76 ///
77 /// If provided, the label at index `i` is shown instead of the raw value at index `i`.
78 /// If not provided or shorter than `values`, the raw value is used as the label.
79 std::optional<ComponentBatch> labels;
80
81 /// Colors for each state value.
82 ///
83 /// If provided, the color at index `i` is used for the state at index `i`.
84 /// If not provided, colors are assigned automatically from a built-in palette.
85 std::optional<ComponentBatch> colors;
86
87 /// Visibility for each state value.
88 ///
89 /// If provided, the visibility at index `i` controls whether the state at index `i` is shown.
90 /// If not provided, all state values are visible.
91 std::optional<ComponentBatch> visible;
92
93 public:
94 /// The name of the archetype as used in `ComponentDescriptor`s.
95 static constexpr const char ArchetypeName[] = "rerun.archetypes.StateConfiguration";
96
97 /// `ComponentDescriptor` for the `values` field.
98 static constexpr auto Descriptor_values = ComponentDescriptor(
99 ArchetypeName, "StateConfiguration:values",
101 );
102 /// `ComponentDescriptor` for the `labels` field.
103 static constexpr auto Descriptor_labels = ComponentDescriptor(
104 ArchetypeName, "StateConfiguration:labels",
106 );
107 /// `ComponentDescriptor` for the `colors` field.
108 static constexpr auto Descriptor_colors = ComponentDescriptor(
109 ArchetypeName, "StateConfiguration:colors",
111 );
112 /// `ComponentDescriptor` for the `visible` field.
114 ArchetypeName, "StateConfiguration:visible",
116 );
117
118 public:
119 StateConfiguration() = default;
120 StateConfiguration(StateConfiguration&& other) = default;
121 StateConfiguration(const StateConfiguration& other) = default;
122 StateConfiguration& operator=(const StateConfiguration& other) = default;
123 StateConfiguration& operator=(StateConfiguration&& other) = default;
124
125 /// Update only some specific fields of a `StateConfiguration`.
127 return StateConfiguration();
128 }
129
130 /// Clear all the fields of a `StateConfiguration`.
132
133 /// The raw state values that this configuration applies to.
134 ///
135 /// Each entry defines a known state value. The order determines the mapping to
136 /// `labels`, `colors`, and `visible` (by index).
138 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
139 return std::move(*this);
140 }
141
142 /// Display labels for each state value.
143 ///
144 /// If provided, the label at index `i` is shown instead of the raw value at index `i`.
145 /// If not provided or shorter than `values`, the raw value is used as the label.
147 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
148 return std::move(*this);
149 }
150
151 /// Colors for each state value.
152 ///
153 /// If provided, the color at index `i` is used for the state at index `i`.
154 /// If not provided, colors are assigned automatically from a built-in palette.
156 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
157 return std::move(*this);
158 }
159
160 /// Visibility for each state value.
161 ///
162 /// If provided, the visibility at index `i` controls whether the state at index `i` is shown.
163 /// If not provided, all state values are visible.
165 visible = ComponentBatch::from_loggable(_visible, Descriptor_visible).value_or_throw();
166 return std::move(*this);
167 }
168
169 /// Partitions the component data into multiple sub-batches.
170 ///
171 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
172 /// instead, via `ComponentBatch::partitioned`.
173 ///
174 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
175 ///
176 /// The specified `lengths` must sum to the total length of the component batch.
178
179 /// Partitions the component data into unit-length sub-batches.
180 ///
181 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
182 /// where `n` is automatically guessed.
184 };
185
186} // namespace rerun::archetypes
187
188namespace rerun {
189 /// \private
190 template <typename T>
191 struct AsComponents;
192
193 /// \private
194 template <>
195 struct AsComponents<archetypes::StateConfiguration> {
196 /// Serialize all set component batches.
197 static Result<Collection<ComponentBatch>> as_batches(
198 const archetypes::StateConfiguration& archetype
199 );
200 };
201} // 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:87
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:68
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition state_configuration.hpp:95
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:155
StateConfiguration with_values(const Collection< rerun::components::Text > &_values) &&
The raw state values that this configuration applies to.
Definition state_configuration.hpp:137
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:164
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:73
std::optional< ComponentBatch > colors
Colors for each state value.
Definition state_configuration.hpp:85
static constexpr auto Descriptor_values
ComponentDescriptor for the values field.
Definition state_configuration.hpp:98
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition state_configuration.hpp:108
StateConfiguration with_labels(const Collection< rerun::components::Text > &_labels) &&
Display labels for each state value.
Definition state_configuration.hpp:146
static StateConfiguration update_fields()
Update only some specific fields of a StateConfiguration.
Definition state_configuration.hpp:126
std::optional< ComponentBatch > visible
Visibility for each state value.
Definition state_configuration.hpp:91
static constexpr auto Descriptor_visible
ComponentDescriptor for the visible field.
Definition state_configuration.hpp:113
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition state_configuration.hpp:103
std::optional< ComponentBatch > labels
Display labels for each state value.
Definition state_configuration.hpp:79