Rerun C++ SDK
Loading...
Searching...
No Matches
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/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/opacity.hpp"
10#include "../components/tensor_data.hpp"
11#include "../data_cell.hpp"
12#include "../indicator_component.hpp"
13#include "../result.hpp"
14
15#include <cstdint>
16#include <optional>
17#include <utility>
18#include <vector>
19
20namespace rerun::archetypes {
21 /// **Archetype**: A monochrome or color image.
22 ///
23 /// The order of dimensions in the underlying `TensorData` follows the typical
24 /// row-major, interleaved-pixel image format. Additionally, Rerun orders the
25 /// `TensorDimension`s within the shape description from outer-most to inner-most.
26 ///
27 /// As such, the shape of the `TensorData` must be mappable to:
28 /// - A `HxW` tensor, treated as a grayscale image.
29 /// - A `HxWx3` tensor, treated as an RGB image.
30 /// - A `HxWx4` tensor, treated as an RGBA image.
31 ///
32 /// Leading and trailing unit-dimensions are ignored, so that
33 /// `1x480x640x3x1` is treated as a `480x640x3` RGB image.
34 ///
35 /// Rerun also supports compressed image encoded as JPEG, N12, and YUY2.
36 /// Using these formats can save a lot of bandwidth and memory.
37 /// See [`rerun::datatypes::TensorBuffer`] for more.
38 ///
39 /// Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
40 /// data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
41 /// If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
42 ///
43 /// ## Example
44 ///
45 /// ### image_simple:
46 /// ![image](https://static.rerun.io/image_simple/06ba7f8582acc1ffb42a7fd0006fad7816f3e4e4/full.png)
47 ///
48 /// ```cpp
49 /// #include <rerun.hpp>
50 ///
51 /// #include <vector>
52 ///
53 /// int main() {
54 /// const auto rec = rerun::RecordingStream("rerun_example_image");
55 /// rec.spawn().exit_on_failure();
56 ///
57 /// // Create a synthetic image.
58 /// const int HEIGHT = 200;
59 /// const int WIDTH = 300;
60 /// std::vector<uint8_t> data(WIDTH * HEIGHT * 3, 0);
61 /// for (size_t i = 0; i <data.size(); i += 3) {
62 /// data[i] = 255;
63 /// }
64 /// for (size_t y = 50; y <150; ++y) {
65 /// for (size_t x = 50; x <150; ++x) {
66 /// data[(y * WIDTH + x) * 3 + 0] = 0;
67 /// data[(y * WIDTH + x) * 3 + 1] = 255;
68 /// data[(y * WIDTH + x) * 3 + 2] = 0;
69 /// }
70 /// }
71 ///
72 /// rec.log("image", rerun::Image({HEIGHT, WIDTH, 3}, data));
73 /// }
74 /// ```
75 struct Image {
76 /// The image data. Should always be a 2- or 3-dimensional tensor.
78
79 /// Opacity of the image, useful for layering several images.
80 ///
81 /// Defaults to 1.0 (fully opaque).
82 std::optional<rerun::components::Opacity> opacity;
83
84 /// An optional floating point value that specifies the 2D drawing order.
85 ///
86 /// Objects with higher values are drawn on top of those with lower values.
87 std::optional<rerun::components::DrawOrder> draw_order;
88
89 public:
90 static constexpr const char IndicatorComponentName[] = "rerun.components.ImageIndicator";
91
92 /// Indicator component, used to identify the archetype when converting to a list of components.
94
95 public:
96 // Extensions to generated type defined in 'image_ext.cpp'
97
98 /// New Image from height/width/channel and tensor buffer.
99 ///
100 /// \param shape
101 /// Shape of the image. Calls `Error::handle()` if the tensor is not 2- or 3-dimensional.
102 /// Sets the dimension names to "height", "width" and "channel" if they are not specified.
103 /// \param buffer
104 /// The tensor buffer containing the image data.
106 : Image(datatypes::TensorData(std::move(shape), std::move(buffer))) {}
107
108 /// New depth image from tensor data.
109 ///
110 /// \param data_
111 /// The tensor buffer containing the image data.
112 /// Sets the dimension names to "height", "width" and "channel" if they are not specified.
113 /// Calls `Error::handle()` if the tensor is not 2- or 3-dimensional.
115
116 /// New image from dimensions and pointer to image data.
117 ///
118 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
119 /// \param shape
120 /// Shape of the image. Calls `Error::handle()` if the tensor is not 2- or 3-dimensional.
121 /// Sets the dimension names to "height", "width" and "channel" if they are not specified.
122 /// Determines the number of elements expected to be in `data`.
123 /// \param data_
124 /// Target of the pointer must outlive the archetype.
125 template <typename TElement>
126 explicit Image(Collection<datatypes::TensorDimension> shape, const TElement* data_)
127 : Image(datatypes::TensorData(std::move(shape), data_)) {}
128
129 public:
130 Image() = default;
131 Image(Image&& other) = default;
132
133 /// Opacity of the image, useful for layering several images.
134 ///
135 /// Defaults to 1.0 (fully opaque).
137 opacity = std::move(_opacity);
138 // See: https://github.com/rerun-io/rerun/issues/4027
139 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
140 }
141
142 /// An optional floating point value that specifies the 2D drawing order.
143 ///
144 /// Objects with higher values are drawn on top of those with lower values.
146 draw_order = std::move(_draw_order);
147 // See: https://github.com/rerun-io/rerun/issues/4027
148 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
149 }
150 };
151
152} // namespace rerun::archetypes
153
154namespace rerun {
155 /// \private
156 template <typename T>
157 struct AsComponents;
158
159 /// \private
160 template <>
161 struct AsComponents<archetypes::Image> {
162 /// Serialize all set component batches.
163 static Result<std::vector<DataCell>> serialize(const archetypes::Image& archetype);
164 };
165} // 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: A monochrome or color image.
Definition image.hpp:75
Image(rerun::components::TensorData data_)
New depth image from tensor data.
Image with_opacity(rerun::components::Opacity _opacity) &&
Opacity of the image, useful for layering several images.
Definition image.hpp:136
Image(Collection< datatypes::TensorDimension > shape, datatypes::TensorBuffer buffer)
New Image from height/width/channel and tensor buffer.
Definition image.hpp:105
std::optional< rerun::components::DrawOrder > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition image.hpp:87
rerun::components::TensorData data
The image data. Should always be a 2- or 3-dimensional tensor.
Definition image.hpp:77
std::optional< rerun::components::Opacity > opacity
Opacity of the image, useful for layering several images.
Definition image.hpp:82
Image(Collection< datatypes::TensorDimension > shape, const TElement *data_)
New image from dimensions and pointer to image data.
Definition image.hpp:126
Image with_draw_order(rerun::components::DrawOrder _draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition image.hpp:145
Component: Draw order of 2D elements.
Definition draw_order.hpp:29
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:23
Component: Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
Definition opacity.hpp:17
Component: An N-dimensional array of numbers.
Definition tensor_data.hpp:27
Datatype: The underlying storage for a Tensor.
Definition tensor_buffer.hpp:114
Datatype: An N-dimensional array of numbers.
Definition tensor_data.hpp:34