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