Rerun C++ SDK
Loading...
Searching...
No Matches
graph_nodes.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/graph_nodes.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/graph_node.hpp"
12#include "../components/position2d.hpp"
13#include "../components/radius.hpp"
14#include "../components/show_labels.hpp"
15#include "../components/text.hpp"
16#include "../result.hpp"
17
18#include <cstdint>
19#include <optional>
20#include <utility>
21#include <vector>
22
23namespace rerun::archetypes {
24 /// **Archetype**: A list of nodes in a graph with optional labels, colors, etc.
25 ///
26 /// ## Example
27 ///
28 /// ### Simple directed graph
29 /// ![image](https://static.rerun.io/graph_directed/ca29a37b65e1e0b6482251dce401982a0bc568fa/full.png)
30 ///
31 /// ```cpp
32 /// #include <rerun.hpp>
33 ///
34 /// int main(int argc, char* argv[]) {
35 /// const auto rec = rerun::RecordingStream("rerun_example_graph_directed");
36 /// rec.spawn().exit_on_failure();
37 ///
38 /// rec.log(
39 /// "simple",
40 /// rerun::GraphNodes({"a", "b", "c"})
41 /// .with_positions({{0.0, 100.0}, {-100.0, 0.0}, {100.0, 0.0}})
42 /// .with_labels({"A", "B", "C"}),
43 /// rerun::GraphEdges({{"a", "b"}, {"b", "c"}, {"c", "a"}})
44 /// // Graphs are undirected by default.
45 /// .with_graph_type(rerun::GraphType::Directed)
46 /// );
47 /// }
48 /// ```
49 struct GraphNodes {
50 /// A list of node IDs.
51 std::optional<ComponentBatch> node_ids;
52
53 /// Optional center positions of the nodes.
54 std::optional<ComponentBatch> positions;
55
56 /// Optional colors for the boxes.
57 std::optional<ComponentBatch> colors;
58
59 /// Optional text labels for the node.
60 std::optional<ComponentBatch> labels;
61
62 /// Whether the text labels should be shown.
63 ///
64 /// If not set, labels will automatically appear when there is exactly one label for this entity
65 /// or the number of instances on this entity is under a certain threshold.
66 std::optional<ComponentBatch> show_labels;
67
68 /// Optional radii for nodes.
69 std::optional<ComponentBatch> radii;
70
71 public:
72 /// The name of the archetype as used in `ComponentDescriptor`s.
73 static constexpr const char ArchetypeName[] = "rerun.archetypes.GraphNodes";
74
75 /// `ComponentDescriptor` for the `node_ids` field.
77 ArchetypeName, "GraphNodes:node_ids",
79 );
80 /// `ComponentDescriptor` for the `positions` field.
82 ArchetypeName, "GraphNodes:positions",
84 );
85 /// `ComponentDescriptor` for the `colors` field.
86 static constexpr auto Descriptor_colors = ComponentDescriptor(
88 );
89 /// `ComponentDescriptor` for the `labels` field.
90 static constexpr auto Descriptor_labels = ComponentDescriptor(
92 );
93 /// `ComponentDescriptor` for the `show_labels` field.
95 ArchetypeName, "GraphNodes:show_labels",
97 );
98 /// `ComponentDescriptor` for the `radii` field.
99 static constexpr auto Descriptor_radii = ComponentDescriptor(
101 );
102
103 public:
104 GraphNodes() = default;
105 GraphNodes(GraphNodes&& other) = default;
106 GraphNodes(const GraphNodes& other) = default;
107 GraphNodes& operator=(const GraphNodes& other) = default;
108 GraphNodes& operator=(GraphNodes&& other) = default;
109
111 : node_ids(ComponentBatch::from_loggable(std::move(_node_ids), Descriptor_node_ids)
112 .value_or_throw()) {}
113
114 /// Update only some specific fields of a `GraphNodes`.
116 return GraphNodes();
117 }
118
119 /// Clear all the fields of a `GraphNodes`.
121
122 /// A list of node IDs.
124 node_ids =
125 ComponentBatch::from_loggable(_node_ids, Descriptor_node_ids).value_or_throw();
126 return std::move(*this);
127 }
128
129 /// Optional center positions of the nodes.
131 positions =
132 ComponentBatch::from_loggable(_positions, Descriptor_positions).value_or_throw();
133 return std::move(*this);
134 }
135
136 /// Optional colors for the boxes.
138 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
139 return std::move(*this);
140 }
141
142 /// Optional text labels for the node.
144 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
145 return std::move(*this);
146 }
147
148 /// Whether the text labels should be shown.
149 ///
150 /// If not set, labels will automatically appear when there is exactly one label for this entity
151 /// or the number of instances on this entity is under a certain threshold.
154 .value_or_throw();
155 return std::move(*this);
156 }
157
158 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
159 ///
160 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
161 /// be used when logging a single row's worth of data.
164 ) && {
166 .value_or_throw();
167 return std::move(*this);
168 }
169
170 /// Optional radii for nodes.
172 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
173 return std::move(*this);
174 }
175
176 /// Partitions the component data into multiple sub-batches.
177 ///
178 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
179 /// instead, via `ComponentBatch::partitioned`.
180 ///
181 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
182 ///
183 /// The specified `lengths` must sum to the total length of the component batch.
185 return detail::partition_batches(
187 lengths_
188 )
189 .value_or_throw();
190 }
191
192 /// Partitions the component data into unit-length sub-batches.
193 ///
194 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
195 /// where `n` is automatically guessed.
197 return detail::partition_batches_of_unit_length(
199 )
200 .value_or_throw();
201 }
202 };
203
204} // namespace rerun::archetypes
205
206namespace rerun {
207 /// \private
208 template <typename T>
209 struct AsComponents;
210
211 /// \private
212 template <>
213 struct AsComponents<archetypes::GraphNodes> {
214 /// Serialize all set component batches.
215 static Result<Collection<ComponentBatch>> as_batches(const archetypes::GraphNodes& archetype
216 ) {
217 return detail::collect_batches(
218 {&archetype.node_ids,
219 &archetype.positions,
220 &archetype.colors,
221 &archetype.labels,
222 &archetype.show_labels,
223 &archetype.radii}
224 );
225 }
226 };
227} // 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
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)
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: A list of nodes in a graph with optional labels, colors, etc.
Definition graph_nodes.hpp:49
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition graph_nodes.hpp:90
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition graph_nodes.hpp:184
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition graph_nodes.hpp:86
std::optional< ComponentBatch > labels
Optional text labels for the node.
Definition graph_nodes.hpp:60
static GraphNodes clear_fields()
Clear all the fields of a GraphNodes.
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition graph_nodes.hpp:94
GraphNodes with_show_labels(const rerun::components::ShowLabels &_show_labels) &&
Whether the text labels should be shown.
Definition graph_nodes.hpp:152
static GraphNodes update_fields()
Update only some specific fields of a GraphNodes.
Definition graph_nodes.hpp:115
static constexpr auto Descriptor_positions
ComponentDescriptor for the positions field.
Definition graph_nodes.hpp:81
static constexpr auto Descriptor_node_ids
ComponentDescriptor for the node_ids field.
Definition graph_nodes.hpp:76
std::optional< ComponentBatch > radii
Optional radii for nodes.
Definition graph_nodes.hpp:69
std::optional< ComponentBatch > colors
Optional colors for the boxes.
Definition graph_nodes.hpp:57
std::optional< ComponentBatch > show_labels
Whether the text labels should be shown.
Definition graph_nodes.hpp:66
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition graph_nodes.hpp:196
GraphNodes with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the node.
Definition graph_nodes.hpp:143
GraphNodes with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the boxes.
Definition graph_nodes.hpp:137
static constexpr auto Descriptor_radii
ComponentDescriptor for the radii field.
Definition graph_nodes.hpp:99
GraphNodes with_positions(const Collection< rerun::components::Position2D > &_positions) &&
Optional center positions of the nodes.
Definition graph_nodes.hpp:130
std::optional< ComponentBatch > node_ids
A list of node IDs.
Definition graph_nodes.hpp:51
GraphNodes with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for nodes.
Definition graph_nodes.hpp:171
GraphNodes with_many_show_labels(const Collection< rerun::components::ShowLabels > &_show_labels) &&
This method makes it possible to pack multiple show_labels in a single component batch.
Definition graph_nodes.hpp:162
GraphNodes with_node_ids(const Collection< rerun::components::GraphNode > &_node_ids) &&
A list of node IDs.
Definition graph_nodes.hpp:123
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition graph_nodes.hpp:73
std::optional< ComponentBatch > positions
Optional center positions of the nodes.
Definition graph_nodes.hpp:54
Component: Whether the entity's components::Text label is shown.
Definition show_labels.hpp:18