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