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