Rerun C++ SDK
Loading...
Searching...
No Matches
segmentation_image.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/segmentation_image.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../component_batch.hpp"
9#include "../components/draw_order.hpp"
10#include "../components/image_buffer.hpp"
11#include "../components/image_format.hpp"
12#include "../components/opacity.hpp"
13#include "../image_utils.hpp"
14#include "../indicator_component.hpp"
15#include "../result.hpp"
16
17#include <cstdint>
18#include <optional>
19#include <utility>
20#include <vector>
21
22namespace rerun::archetypes {
23 /// **Archetype**: An image made up of integer `components::ClassId`s.
24 ///
25 /// Each pixel corresponds to a `components::ClassId` that will be mapped to a color based on annotation context.
26 ///
27 /// In the case of floating point images, the label will be looked up based on rounding to the nearest
28 /// integer value.
29 ///
30 /// See also `archetypes::AnnotationContext` to associate each class with a color and a label.
31 ///
32 /// Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
33 /// data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
34 /// If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
35 ///
36 /// ## Example
37 ///
38 /// ### Simple segmentation image
39 /// ![image](https://static.rerun.io/segmentation_image_simple/f8aac62abcf4c59c5d62f9ebc2d86fd0285c1736/full.png)
40 ///
41 /// ```cpp
42 /// #include <rerun.hpp>
43 ///
44 /// #include <algorithm> // std::fill_n
45 /// #include <vector>
46 ///
47 /// int main() {
48 /// const auto rec = rerun::RecordingStream("rerun_example_segmentation_image");
49 /// rec.spawn().exit_on_failure();
50 ///
51 /// // Create a segmentation image
52 /// const int HEIGHT = 8;
53 /// const int WIDTH = 12;
54 /// std::vector<uint8_t> data(WIDTH * HEIGHT, 0);
55 /// for (auto y = 0; y <4; ++y) { // top half
56 /// std::fill_n(data.begin() + y * WIDTH, 6, static_cast<uint8_t>(1)); // left half
57 /// }
58 /// for (auto y = 4; y <8; ++y) { // bottom half
59 /// std::fill_n(data.begin() + y * WIDTH + 6, 6, static_cast<uint8_t>(2)); // right half
60 /// }
61 ///
62 /// // create an annotation context to describe the classes
63 /// rec.log_static(
64 /// "/",
65 /// rerun::AnnotationContext({
66 /// rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)),
67 /// rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)),
68 /// })
69 /// );
70 ///
71 /// rec.log("image", rerun::SegmentationImage(data.data(), {WIDTH, HEIGHT}));
72 /// }
73 /// ```
75 /// The raw image data.
77
78 /// The format of the image.
80
81 /// Opacity of the image, useful for layering the segmentation image on top of another image.
82 ///
83 /// Defaults to 0.5 if there's any other images in the scene, otherwise 1.0.
84 std::optional<rerun::components::Opacity> opacity;
85
86 /// An optional floating point value that specifies the 2D drawing order.
87 ///
88 /// Objects with higher values are drawn on top of those with lower values.
89 std::optional<rerun::components::DrawOrder> draw_order;
90
91 public:
92 static constexpr const char IndicatorComponentName[] =
93 "rerun.components.SegmentationImageIndicator";
94
95 /// Indicator component, used to identify the archetype when converting to a list of components.
97
98 public: // START of extensions from segmentation_image_ext.cpp:
99 /// Constructs image from pointer + resolution, inferring the datatype from the pointer type.
100 ///
101 /// @param pixels The raw image data.
102 /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image.
103 /// The number of elements is assumed to be `W * H`.
104 /// @param resolution The resolution of the image as {width, height}.
105 template <typename TElement>
106 SegmentationImage(const TElement* pixels, WidthHeight resolution)
108 reinterpret_cast<const uint8_t*>(pixels), resolution, get_datatype(pixels)} {}
109
110 /// Constructs image from pixel data + resolution with datatype inferred from the passed collection.
111 ///
112 /// @param pixels The raw image data.
113 /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection`
114 /// explicitly ahead of time with `rerun::Collection::take_ownership`.
115 /// The length of the data should be `W * H`.
116 /// @param resolution The resolution of the image as {width, height}.
117 template <typename TElement>
119 : SegmentationImage{pixels.to_uint8(), resolution, get_datatype(pixels.data())} {}
120
121 /// Constructs image from pixel data + resolution with explicit datatype. Borrows data from a pointer (i.e. data must outlive the image!).
122 ///
123 /// @param bytes The raw image data.
124 /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image.
125 /// The byte size of the data is assumed to be `W * H * datatype.size`
126 /// @param resolution The resolution of the image as {width, height}.
127 /// @param datatype How the data should be interpreted.
129 const void* bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype
130 )
132 Collection<uint8_t>::borrow(bytes, num_bytes(resolution, datatype)),
133 resolution,
134 datatype} {}
135
136 /// Constructs image from pixel data + resolution + datatype.
137 ///
138 /// @param bytes The raw image data as bytes.
139 /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection`
140 /// explicitly ahead of time with `rerun::Collection::take_ownership`.
141 /// The length of the data should be `W * H`.
142 /// @param resolution The resolution of the image as {width, height}.
143 /// @param datatype How the data should be interpreted.
146 )
147 : buffer{bytes}, format{datatypes::ImageFormat{resolution, datatype}} {
148 if (buffer.size() != format.image_format.num_bytes()) {
149 Error(
150 ErrorCode::InvalidTensorDimension,
151 "SegmentationImage buffer has the wrong size. Got " +
152 std::to_string(buffer.size()) + " bytes, expected " +
153 std::to_string(format.image_format.num_bytes())
154 )
155 .handle();
156 }
157 }
158
159 // END of extensions from segmentation_image_ext.cpp, start of generated code:
160
161 public:
162 SegmentationImage() = default;
163 SegmentationImage(SegmentationImage&& other) = default;
164
165 /// Opacity of the image, useful for layering the segmentation image on top of another image.
166 ///
167 /// Defaults to 0.5 if there's any other images in the scene, otherwise 1.0.
169 opacity = std::move(_opacity);
170 // See: https://github.com/rerun-io/rerun/issues/4027
171 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
172 }
173
174 /// An optional floating point value that specifies the 2D drawing order.
175 ///
176 /// Objects with higher values are drawn on top of those with lower values.
178 draw_order = std::move(_draw_order);
179 // See: https://github.com/rerun-io/rerun/issues/4027
180 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
181 }
182 };
183
184} // namespace rerun::archetypes
185
186namespace rerun {
187 /// \private
188 template <typename T>
189 struct AsComponents;
190
191 /// \private
192 template <>
193 struct AsComponents<archetypes::SegmentationImage> {
194 /// Serialize all set component batches.
195 static Result<std::vector<ComponentBatch>> serialize(
196 const archetypes::SegmentationImage& archetype
197 );
198 };
199} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:95
void handle() const
Handle this error based on the set log handler.
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:76
ChannelDatatype
Datatype: The innermost datatype of an image.
Definition channel_datatype.hpp:26
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:22
Collection< TElement > borrow(const TElement *data, size_t num_instances=1)
Borrows binary data into a Collection from a pointer.
Definition collection.hpp:461
The width and height of an image.
Definition image_utils.hpp:13
Archetype: An image made up of integer components::ClassIds.
Definition segmentation_image.hpp:74
std::optional< rerun::components::DrawOrder > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition segmentation_image.hpp:89
SegmentationImage(Collection< uint8_t > bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
Constructs image from pixel data + resolution + datatype.
Definition segmentation_image.hpp:144
SegmentationImage(Collection< TElement > pixels, WidthHeight resolution)
Constructs image from pixel data + resolution with datatype inferred from the passed collection.
Definition segmentation_image.hpp:118
SegmentationImage with_opacity(rerun::components::Opacity _opacity) &&
Opacity of the image, useful for layering the segmentation image on top of another image.
Definition segmentation_image.hpp:168
SegmentationImage(const TElement *pixels, WidthHeight resolution)
Constructs image from pointer + resolution, inferring the datatype from the pointer type.
Definition segmentation_image.hpp:106
std::optional< rerun::components::Opacity > opacity
Opacity of the image, useful for layering the segmentation image on top of another image.
Definition segmentation_image.hpp:84
SegmentationImage(const void *bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
Constructs image from pixel data + resolution with explicit datatype.
Definition segmentation_image.hpp:128
SegmentationImage with_draw_order(rerun::components::DrawOrder _draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition segmentation_image.hpp:177
rerun::components::ImageBuffer buffer
The raw image data.
Definition segmentation_image.hpp:76
rerun::components::ImageFormat format
The format of the image.
Definition segmentation_image.hpp:79
Component: Draw order of 2D elements.
Definition draw_order.hpp:19
Component: A buffer that is known to store image data.
Definition image_buffer.hpp:18
size_t size() const
Number of bytes.
Definition image_buffer.hpp:23
Component: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:14
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:30
Component: Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
Definition opacity.hpp:17
size_t num_bytes() const
How many bytes will this image occupy?
Definition image_format.hpp:65