Rerun C++ SDK
Loading...
Searching...
No Matches
annotation_context.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_types/definitions/rerun/archetypes/annotation_context.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/annotation_context.hpp"
10#include "../indicator_component.hpp"
11#include "../result.hpp"
12
13#include <cstdint>
14#include <optional>
15#include <utility>
16#include <vector>
17
18namespace rerun::archetypes {
19 /// **Archetype**: The annotation context provides additional information on how to display entities.
20 ///
21 /// Entities can use `components::ClassId`s and `components::KeypointId`s to provide annotations, and
22 /// the labels and colors will be looked up in the appropriate
23 /// annotation context. We use the *first* annotation context we find in the
24 /// path-hierarchy when searching up through the ancestors of a given entity
25 /// path.
26 ///
27 /// See also `datatypes::ClassDescription`.
28 ///
29 /// ## Example
30 ///
31 /// ### Segmentation
32 /// ![image](https://static.rerun.io/annotation_context_segmentation/6c9e88fc9d44a08031cadd444c2e58a985cc1208/full.png)
33 ///
34 /// ```cpp
35 /// #include <rerun.hpp>
36 ///
37 /// #include <algorithm> // fill_n
38 /// #include <vector>
39 ///
40 /// int main() {
41 /// const auto rec = rerun::RecordingStream("rerun_example_annotation_context_segmentation");
42 /// rec.spawn().exit_on_failure();
43 ///
44 /// // create an annotation context to describe the classes
45 /// rec.log_static(
46 /// "segmentation",
47 /// rerun::AnnotationContext({
48 /// rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)),
49 /// rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)),
50 /// })
51 /// );
52 ///
53 /// // create a segmentation image
54 /// const int HEIGHT = 200;
55 /// const int WIDTH = 300;
56 /// std::vector<uint8_t> data(WIDTH * HEIGHT, 0);
57 /// for (auto y = 50; y <100; ++y) {
58 /// std::fill_n(data.begin() + y * WIDTH + 50, 70, static_cast<uint8_t>(1));
59 /// }
60 /// for (auto y = 100; y <180; ++y) {
61 /// std::fill_n(data.begin() + y * WIDTH + 130, 150, static_cast<uint8_t>(2));
62 /// }
63 ///
64 /// rec.log("segmentation/image", rerun::SegmentationImage(data.data(), {WIDTH, HEIGHT}));
65 /// }
66 /// ```
67 ///
68 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
69 ///
71 /// List of class descriptions, mapping class indices to class names, colors etc.
72 std::optional<ComponentBatch> context;
73
74 public:
75 static constexpr const char IndicatorComponentName[] =
76 "rerun.components.AnnotationContextIndicator";
77
78 /// Indicator component, used to identify the archetype when converting to a list of components.
80 /// The name of the archetype as used in `ComponentDescriptor`s.
81 static constexpr const char ArchetypeName[] = "rerun.archetypes.AnnotationContext";
82
83 /// `ComponentDescriptor` for the `context` field.
84 static constexpr auto Descriptor_context = ComponentDescriptor(
85 ArchetypeName, "context",
87 );
88
89 public:
90 AnnotationContext() = default;
91 AnnotationContext(AnnotationContext&& other) = default;
92 AnnotationContext(const AnnotationContext& other) = default;
93 AnnotationContext& operator=(const AnnotationContext& other) = default;
94 AnnotationContext& operator=(AnnotationContext&& other) = default;
95
97 : context(ComponentBatch::from_loggable(std::move(_context), Descriptor_context)
98 .value_or_throw()) {}
99
100 /// Update only some specific fields of a `AnnotationContext`.
102 return AnnotationContext();
103 }
104
105 /// Clear all the fields of a `AnnotationContext`.
107
108 /// List of class descriptions, mapping class indices to class names, colors etc.
110 context = ComponentBatch::from_loggable(_context, Descriptor_context).value_or_throw();
111 return std::move(*this);
112 }
113
114 /// This method makes it possible to pack multiple `context` in a single component batch.
115 ///
116 /// This only makes sense when used in conjunction with `columns`. `with_context` should
117 /// be used when logging a single row's worth of data.
120 ) && {
121 context = ComponentBatch::from_loggable(_context, Descriptor_context).value_or_throw();
122 return std::move(*this);
123 }
124
125 /// Partitions the component data into multiple sub-batches.
126 ///
127 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
128 /// instead, via `ComponentBatch::partitioned`.
129 ///
130 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
131 ///
132 /// The specified `lengths` must sum to the total length of the component batch.
134
135 /// Partitions the component data into unit-length sub-batches.
136 ///
137 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
138 /// where `n` is automatically guessed.
140 };
141
142} // namespace rerun::archetypes
143
144namespace rerun {
145 /// \private
146 template <typename T>
147 struct AsComponents;
148
149 /// \private
150 template <>
151 struct AsComponents<archetypes::AnnotationContext> {
152 /// Serialize all set component batches.
153 static Result<Collection<ComponentBatch>> as_batches(
154 const archetypes::AnnotationContext& archetype
155 );
156 };
157} // 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:76
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
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=rerun::Loggable< T >::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:14
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: The annotation context provides additional information on how to display entities.
Definition annotation_context.hpp:70
std::optional< ComponentBatch > context
List of class descriptions, mapping class indices to class names, colors etc.
Definition annotation_context.hpp:72
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
static AnnotationContext update_fields()
Update only some specific fields of a AnnotationContext.
Definition annotation_context.hpp:101
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition annotation_context.hpp:81
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static constexpr auto Descriptor_context
ComponentDescriptor for the context field.
Definition annotation_context.hpp:84
AnnotationContext with_many_context(const Collection< rerun::components::AnnotationContext > &_context) &&
This method makes it possible to pack multiple context in a single component batch.
Definition annotation_context.hpp:118
static AnnotationContext clear_fields()
Clear all the fields of a AnnotationContext.
AnnotationContext with_context(const rerun::components::AnnotationContext &_context) &&
List of class descriptions, mapping class indices to class names, colors etc.
Definition annotation_context.hpp:109
Component: The annotation context provides additional information on how to display entities.
Definition annotation_context.hpp:33
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32