Rerun C++ SDK
Loading...
Searching...
No Matches
segmentation_image.hpp
1// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/re_types/definitions/rerun/archetypes/segmentation_image.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../components/draw_order.hpp"
9#include "../components/tensor_data.hpp"
10#include "../data_cell.hpp"
11#include "../indicator_component.hpp"
12#include "../result.hpp"
13
14#include <cstdint>
15#include <optional>
16#include <utility>
17#include <vector>
18
19namespace rerun::archetypes {
20 /// **Archetype**: An image made up of integer class-ids.
21 ///
22 /// The shape of the `TensorData` must be mappable to an `HxW` tensor.
23 /// Each pixel corresponds to a class-id that will be mapped to a color based on annotation context.
24 ///
25 /// In the case of floating point images, the label will be looked up based on rounding to the nearest
26 /// integer value.
27 ///
28 /// Leading and trailing unit-dimensions are ignored, so that
29 /// `1x640x480x1` is treated as a `640x480` image.
30 ///
31 /// Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
32 /// data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
33 /// If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
34 ///
35 /// ## Example
36 ///
37 /// ### Simple segmentation image
38 /// ![image](https://static.rerun.io/segmentation_image_simple/eb49e0b8cb870c75a69e2a47a2d202e5353115f6/full.png)
39 ///
40 /// ```cpp
41 /// #include <rerun.hpp>
42 ///
43 /// #include <algorithm> // std::fill_n
44 /// #include <vector>
45 ///
46 /// int main() {
47 /// const auto rec = rerun::RecordingStream("rerun_example_segmentation_image");
48 /// rec.spawn().exit_on_failure();
49 ///
50 /// // Create a segmentation image
51 /// const int HEIGHT = 8;
52 /// const int WIDTH = 12;
53 /// std::vector<uint8_t> data(WIDTH * HEIGHT, 0);
54 /// for (auto y = 0; y <4; ++y) { // top half
55 /// std::fill_n(data.begin() + y * WIDTH, 6, static_cast<uint8_t>(1)); // left half
56 /// }
57 /// for (auto y = 4; y <8; ++y) { // bottom half
58 /// std::fill_n(data.begin() + y * WIDTH + 6, 6, static_cast<uint8_t>(2)); // right half
59 /// }
60 ///
61 /// // create an annotation context to describe the classes
62 /// rec.log_static(
63 /// "/",
64 /// rerun::AnnotationContext({
65 /// rerun::AnnotationInfo(1, "red", rerun::Rgba32(255, 0, 0)),
66 /// rerun::AnnotationInfo(2, "green", rerun::Rgba32(0, 255, 0)),
67 /// })
68 /// );
69 ///
70 /// rec.log("image", rerun::SegmentationImage({HEIGHT, WIDTH}, data));
71 /// }
72 /// ```
74 /// The image data. Should always be a rank-2 tensor.
76
77 /// An optional floating point value that specifies the 2D drawing order.
78 ///
79 /// Objects with higher values are drawn on top of those with lower values.
80 std::optional<rerun::components::DrawOrder> draw_order;
81
82 public:
83 static constexpr const char IndicatorComponentName[] =
84 "rerun.components.SegmentationImageIndicator";
85
86 /// Indicator component, used to identify the archetype when converting to a list of components.
88
89 public:
90 // Extensions to generated type defined in 'segmentation_image_ext.cpp'
91
92 /// New segmentation image from height/width and tensor buffer.
93 ///
94 /// \param shape
95 /// Shape of the image. Calls `Error::handle()` if the shape is not rank 2.
96 /// Sets the dimension names to "height" and "width" if they are not specified.
97 /// \param buffer
98 /// The tensor buffer containing the segmentation image data.
101 )
102 : SegmentationImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {}
103
104 /// New segmentation image from tensor data.
105 ///
106 /// \param data_
107 /// The tensor buffer containing the segmentation image data.
108 /// Sets the dimension names to "height" and "width" if they are not specified.
109 /// Calls `Error::handle()` if the shape is not rank 2.
111
112 /// New segmentation image from dimensions and pointer to segmentation image data.
113 ///
114 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
115 /// \param shape
116 /// Shape of the image. Calls `Error::handle()` if the shape is not rank 2.
117 /// Sets the dimension names to "height", "width" and "channel" if they are not specified.
118 /// Determines the number of elements expected to be in `data`.
119 /// \param data_
120 /// Target of the pointer must outlive the archetype.
121 template <typename TElement>
123 Collection<datatypes::TensorDimension> shape, const TElement* data_
124 )
125 : SegmentationImage(datatypes::TensorData(std::move(shape), data_)) {}
126
127 public:
128 SegmentationImage() = default;
129 SegmentationImage(SegmentationImage&& other) = default;
130
131 /// An optional floating point value that specifies the 2D drawing order.
132 ///
133 /// Objects with higher values are drawn on top of those with lower values.
135 draw_order = std::move(_draw_order);
136 // See: https://github.com/rerun-io/rerun/issues/4027
137 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
138 }
139 };
140
141} // namespace rerun::archetypes
142
143namespace rerun {
144 /// \private
145 template <typename T>
146 struct AsComponents;
147
148 /// \private
149 template <>
150 struct AsComponents<archetypes::SegmentationImage> {
151 /// Serialize all set component batches.
152 static Result<std::vector<DataCell>> serialize(
153 const archetypes::SegmentationImage& archetype
154 );
155 };
156} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:46
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:72
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:21
Archetype: An image made up of integer class-ids.
Definition segmentation_image.hpp:73
std::optional< rerun::components::DrawOrder > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition segmentation_image.hpp:80
SegmentationImage(Collection< datatypes::TensorDimension > shape, datatypes::TensorBuffer buffer)
New segmentation image from height/width and tensor buffer.
Definition segmentation_image.hpp:99
SegmentationImage(Collection< datatypes::TensorDimension > shape, const TElement *data_)
New segmentation image from dimensions and pointer to segmentation image data.
Definition segmentation_image.hpp:122
SegmentationImage(components::TensorData data_)
New segmentation image from tensor data.
rerun::components::TensorData data
The image data. Should always be a rank-2 tensor.
Definition segmentation_image.hpp:75
SegmentationImage with_draw_order(rerun::components::DrawOrder _draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition segmentation_image.hpp:134
Component: Draw order used for the display order of 2D elements.
Definition draw_order.hpp:30
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:23
Component: A multi-dimensional Tensor of data.
Definition tensor_data.hpp:27
Datatype: The underlying storage for a Tensor.
Definition tensor_buffer.hpp:114
Datatype: A multi-dimensional Tensor of data.
Definition tensor_data.hpp:34