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/build/re_type_definitions/rerun/archetypes/annotation_context.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/annotation_context.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 `encodings::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(int argc, char* argv[]) {
41 /// const auto rec =
42 /// rerun::RecordingStream("rerun_example_annotation_context_segmentation");
43 /// rec.spawn().exit_on_failure();
44 ///
45 /// // create an annotation context to describe the classes
46 /// rec.log_static(
47 /// "segmentation",
48 /// rerun::AnnotationContext({
49 /// rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)),
50 /// rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)),
51 /// })
52 /// );
53 ///
54 /// // create a segmentation image
55 /// const int HEIGHT = 200;
56 /// const int WIDTH = 300;
57 /// std::vector<uint8_t> data(WIDTH * HEIGHT, 0);
58 /// for (auto y = 50; y <100; ++y) {
59 /// std::fill_n(data.begin() + y * WIDTH + 50, 70, static_cast<uint8_t>(1));
60 /// }
61 /// for (auto y = 100; y <180; ++y) {
62 /// std::fill_n(
63 /// data.begin() + y * WIDTH + 130,
64 /// 150,
65 /// static_cast<uint8_t>(2)
66 /// );
67 /// }
68 ///
69 /// rec.log(
70 /// "segmentation/image",
71 /// rerun::SegmentationImage(data.data(), {WIDTH, HEIGHT})
72 /// );
73 /// }
74 /// ```
75 ///
76 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
77 ///
79 /// List of class descriptions, mapping class indices to class names, colors etc.
80 std::optional<ComponentBatch> context;
81
82 public:
83 /// The name of the archetype as used in `ComponentDescriptor`s.
84 static constexpr const char ArchetypeName[] = "rerun.archetypes.AnnotationContext";
85
86 /// `ComponentDescriptor` for the `context` field.
87 static constexpr auto Descriptor_context = ComponentDescriptor(
88 ArchetypeName, "AnnotationContext:context",
90 );
91
92 public:
93 AnnotationContext() = default;
94 AnnotationContext(AnnotationContext&& other) = default;
95 AnnotationContext(const AnnotationContext& other) = default;
96 AnnotationContext& operator=(const AnnotationContext& other) = default;
97 AnnotationContext& operator=(AnnotationContext&& other) = default;
98
100 : context(ComponentBatch::from_loggable(std::move(_context), Descriptor_context)
101 .value_or_throw()) {}
102
103 /// Update only some specific fields of a `AnnotationContext`.
105 return AnnotationContext();
106 }
107
108 /// Clear all the fields of a `AnnotationContext`.
110
111 /// List of class descriptions, mapping class indices to class names, colors etc.
113 context = ComponentBatch::from_loggable(_context, Descriptor_context).value_or_throw();
114 return std::move(*this);
115 }
116
117 /// This method makes it possible to pack multiple `context` in a single component batch.
118 ///
119 /// This only makes sense when used in conjunction with `columns`. `with_context` should
120 /// be used when logging a single row's worth of data.
123 ) && {
124 context = ComponentBatch::from_loggable(_context, Descriptor_context).value_or_throw();
125 return std::move(*this);
126 }
127
128 /// Partitions the component data into multiple sub-batches.
129 ///
130 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
131 /// instead, via `ComponentBatch::partitioned`.
132 ///
133 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
134 ///
135 /// The specified `lengths` must sum to the total length of the component batch.
137 return detail::partition_batches({&context}, lengths_).value_or_throw();
138 }
139
140 /// Partitions the component data into unit-length sub-batches.
141 ///
142 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
143 /// where `n` is automatically guessed.
145 return detail::partition_batches_of_unit_length({&context}).value_or_throw();
146 }
147 };
148
149} // namespace rerun::archetypes
150
151namespace rerun {
152 /// \private
153 template <typename T>
154 struct AsComponents;
155
156 /// \private
157 template <>
158 struct AsComponents<archetypes::AnnotationContext> {
159 /// Serialize all set component batches.
160 static Result<Collection<ComponentBatch>> as_batches(
161 const archetypes::AnnotationContext& archetype
162 ) {
163 return detail::collect_batches({&archetype.context});
164 }
165 };
166} // 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: The annotation context provides additional information on how to display entities.
Definition annotation_context.hpp:78
std::optional< ComponentBatch > context
List of class descriptions, mapping class indices to class names, colors etc.
Definition annotation_context.hpp:80
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition annotation_context.hpp:144
static AnnotationContext update_fields()
Update only some specific fields of a AnnotationContext.
Definition annotation_context.hpp:104
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition annotation_context.hpp:84
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition annotation_context.hpp:136
static constexpr auto Descriptor_context
ComponentDescriptor for the context field.
Definition annotation_context.hpp:87
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:121
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:112
Component: The annotation context provides additional information on how to display entities.
Definition annotation_context.hpp:32