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