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 /// ```
68 /// List of class descriptions, mapping class indices to class names, colors etc.
69 std::optional<ComponentBatch> context;
70
71 public:
72 static constexpr const char IndicatorComponentName[] =
73 "rerun.components.AnnotationContextIndicator";
74
75 /// Indicator component, used to identify the archetype when converting to a list of components.
77 /// The name of the archetype as used in `ComponentDescriptor`s.
78 static constexpr const char ArchetypeName[] = "rerun.archetypes.AnnotationContext";
79
80 /// `ComponentDescriptor` for the `context` field.
81 static constexpr auto Descriptor_context = ComponentDescriptor(
82 ArchetypeName, "context",
84 );
85
86 public:
87 AnnotationContext() = default;
88 AnnotationContext(AnnotationContext&& other) = default;
89 AnnotationContext(const AnnotationContext& other) = default;
90 AnnotationContext& operator=(const AnnotationContext& other) = default;
91 AnnotationContext& operator=(AnnotationContext&& other) = default;
92
94 : context(ComponentBatch::from_loggable(std::move(_context), Descriptor_context)
95 .value_or_throw()) {}
96
97 /// Update only some specific fields of a `AnnotationContext`.
99 return AnnotationContext();
100 }
101
102 /// Clear all the fields of a `AnnotationContext`.
104
105 /// List of class descriptions, mapping class indices to class names, colors etc.
107 context = ComponentBatch::from_loggable(_context, Descriptor_context).value_or_throw();
108 return std::move(*this);
109 }
110
111 /// This method makes it possible to pack multiple `context` in a single component batch.
112 ///
113 /// This only makes sense when used in conjunction with `columns`. `with_context` should
114 /// be used when logging a single row's worth of data.
117 ) && {
118 context = ComponentBatch::from_loggable(_context, Descriptor_context).value_or_throw();
119 return std::move(*this);
120 }
121
122 /// Partitions the component data into multiple sub-batches.
123 ///
124 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
125 /// instead, via `ComponentBatch::partitioned`.
126 ///
127 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
128 ///
129 /// The specified `lengths` must sum to the total length of the component batch.
131
132 /// Partitions the component data into unit-length sub-batches.
133 ///
134 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
135 /// where `n` is automatically guessed.
137 };
138
139} // namespace rerun::archetypes
140
141namespace rerun {
142 /// \private
143 template <typename T>
144 struct AsComponents;
145
146 /// \private
147 template <>
148 struct AsComponents<archetypes::AnnotationContext> {
149 /// Serialize all set component batches.
150 static Result<Collection<ComponentBatch>> as_batches(
151 const archetypes::AnnotationContext& archetype
152 );
153 };
154} // 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:67
std::optional< ComponentBatch > context
List of class descriptions, mapping class indices to class names, colors etc.
Definition annotation_context.hpp:69
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:98
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition annotation_context.hpp:78
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:81
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:115
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:106
Component: The annotation context provides additional information on how to display entities.
Definition annotation_context.hpp:30
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32