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