Rerun C++ SDK
Loading...
Searching...
No Matches
encoded_image.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_sdk_types/definitions/rerun/archetypes/encoded_image.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/blob.hpp"
10#include "../components/draw_order.hpp"
11#include "../components/magnification_filter.hpp"
12#include "../components/media_type.hpp"
13#include "../components/opacity.hpp"
14#include "../result.hpp"
15
16#include <cstdint>
17#include <filesystem>
18#include <optional>
19#include <utility>
20#include <vector>
21
22namespace rerun::archetypes {
23 /// **Archetype**: An image encoded as e.g. a JPEG or PNG.
24 ///
25 /// Rerun also supports uncompressed images with the `archetypes::Image`.
26 /// For images that refer to video frames see `archetypes::VideoFrameReference`.
27 ///
28 /// ## Example
29 ///
30 /// ### Encoded image
31 /// ![image](https://static.rerun.io/encoded_image/6e92868b6533be5fb2dfd9e26938eb7a256bfb01/full.png)
32 ///
33 /// ```cpp
34 /// #include <rerun.hpp>
35 ///
36 /// #include <filesystem>
37 /// #include <fstream>
38 /// #include <iostream>
39 /// #include <vector>
40 ///
41 /// namespace fs = std::filesystem;
42 ///
43 /// int main(int argc, char* argv[]) {
44 /// const auto rec = rerun::RecordingStream("rerun_example_encoded_image");
45 /// rec.spawn().exit_on_failure();
46 ///
47 /// fs::path image_filepath = fs::path(__FILE__).parent_path() / "ferris.png";
48 ///
49 /// rec.log("image", rerun::EncodedImage::from_file(image_filepath).value_or_throw());
50 /// }
51 /// ```
52 struct EncodedImage {
53 /// The encoded content of some image file, e.g. a PNG or JPEG.
54 std::optional<ComponentBatch> blob;
55
56 /// The Media Type of the asset.
57 ///
58 /// Supported values:
59 /// * `image/jpeg`
60 /// * `image/png`
61 ///
62 /// If omitted, the viewer will try to guess from the data blob.
63 /// If it cannot guess, it won't be able to render the asset.
64 std::optional<ComponentBatch> media_type;
65
66 /// Opacity of the image, useful for layering several media.
67 ///
68 /// Defaults to 1.0 (fully opaque).
69 std::optional<ComponentBatch> opacity;
70
71 /// An optional floating point value that specifies the 2D drawing order.
72 ///
73 /// Objects with higher values are drawn on top of those with lower values.
74 std::optional<ComponentBatch> draw_order;
75
76 /// Optional filter used when a texel is magnified (displayed larger than a screen pixel).
77 std::optional<ComponentBatch> magnification_filter;
78
79 public:
80 /// The name of the archetype as used in `ComponentDescriptor`s.
81 static constexpr const char ArchetypeName[] = "rerun.archetypes.EncodedImage";
82
83 /// `ComponentDescriptor` for the `blob` field.
84 static constexpr auto Descriptor_blob = ComponentDescriptor(
86 );
87 /// `ComponentDescriptor` for the `media_type` field.
89 ArchetypeName, "EncodedImage:media_type",
91 );
92 /// `ComponentDescriptor` for the `opacity` field.
93 static constexpr auto Descriptor_opacity = ComponentDescriptor(
94 ArchetypeName, "EncodedImage:opacity",
96 );
97 /// `ComponentDescriptor` for the `draw_order` field.
99 ArchetypeName, "EncodedImage:draw_order",
101 );
102 /// `ComponentDescriptor` for the `magnification_filter` field.
104 ArchetypeName, "EncodedImage:magnification_filter",
106 );
107
108 public: // START of extensions from encoded_image_ext.cpp:
109 /// Create a new `EncodedImage` from the contents of a file on disk, e.g. a PNG or JPEG.
110 static Result<EncodedImage> from_file(const std::filesystem::path& filepath);
111
112 /// Create a new `EncodedImage` from the contents of an image file, like a PNG or JPEG.
113 ///
114 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
115 /// at render-time. If it can't, rendering will fail with an error.
117 rerun::Collection<uint8_t> image_contents,
118 std::optional<rerun::components::MediaType> media_type = {}
119 ) {
120 auto encoded_image = EncodedImage().with_blob(image_contents);
121 if (media_type.has_value()) {
122 return std::move(encoded_image).with_media_type(media_type.value());
123 }
124 return encoded_image;
125 }
126
127 // END of extensions from encoded_image_ext.cpp, start of generated code:
128
129 public:
130 EncodedImage() = default;
131 EncodedImage(EncodedImage&& other) = default;
132 EncodedImage(const EncodedImage& other) = default;
133 EncodedImage& operator=(const EncodedImage& other) = default;
134 EncodedImage& operator=(EncodedImage&& other) = default;
135
136 /// Update only some specific fields of a `EncodedImage`.
138 return EncodedImage();
139 }
140
141 /// Clear all the fields of a `EncodedImage`.
143
144 /// The encoded content of some image file, e.g. a PNG or JPEG.
146 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
147 return std::move(*this);
148 }
149
150 /// This method makes it possible to pack multiple `blob` in a single component batch.
151 ///
152 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
153 /// be used when logging a single row's worth of data.
155 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
156 return std::move(*this);
157 }
158
159 /// The Media Type of the asset.
160 ///
161 /// Supported values:
162 /// * `image/jpeg`
163 /// * `image/png`
164 ///
165 /// If omitted, the viewer will try to guess from the data blob.
166 /// If it cannot guess, it won't be able to render the asset.
168 media_type =
169 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
170 return std::move(*this);
171 }
172
173 /// This method makes it possible to pack multiple `media_type` in a single component batch.
174 ///
175 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
176 /// be used when logging a single row's worth of data.
179 ) && {
180 media_type =
181 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
182 return std::move(*this);
183 }
184
185 /// Opacity of the image, useful for layering several media.
186 ///
187 /// Defaults to 1.0 (fully opaque).
189 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
190 return std::move(*this);
191 }
192
193 /// This method makes it possible to pack multiple `opacity` in a single component batch.
194 ///
195 /// This only makes sense when used in conjunction with `columns`. `with_opacity` should
196 /// be used when logging a single row's worth of data.
198 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
199 return std::move(*this);
200 }
201
202 /// An optional floating point value that specifies the 2D drawing order.
203 ///
204 /// Objects with higher values are drawn on top of those with lower values.
206 draw_order =
207 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
208 return std::move(*this);
209 }
210
211 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
212 ///
213 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
214 /// be used when logging a single row's worth of data.
217 ) && {
218 draw_order =
219 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
220 return std::move(*this);
221 }
222
223 /// Optional filter used when a texel is magnified (displayed larger than a screen pixel).
225 const rerun::components::MagnificationFilter& _magnification_filter
226 ) && {
228 _magnification_filter,
230 )
231 .value_or_throw();
232 return std::move(*this);
233 }
234
235 /// This method makes it possible to pack multiple `magnification_filter` in a single component batch.
236 ///
237 /// This only makes sense when used in conjunction with `columns`. `with_magnification_filter` should
238 /// be used when logging a single row's worth of data.
240 const Collection<rerun::components::MagnificationFilter>& _magnification_filter
241 ) && {
243 _magnification_filter,
245 )
246 .value_or_throw();
247 return std::move(*this);
248 }
249
250 /// Partitions the component data into multiple sub-batches.
251 ///
252 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
253 /// instead, via `ComponentBatch::partitioned`.
254 ///
255 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
256 ///
257 /// The specified `lengths` must sum to the total length of the component batch.
259
260 /// Partitions the component data into unit-length sub-batches.
261 ///
262 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
263 /// where `n` is automatically guessed.
265 };
266
267} // namespace rerun::archetypes
268
269namespace rerun {
270 /// \private
271 template <typename T>
272 struct AsComponents;
273
274 /// \private
275 template <>
276 struct AsComponents<archetypes::EncodedImage> {
277 /// Serialize all set component batches.
278 static Result<Collection<ComponentBatch>> as_batches(
279 const archetypes::EncodedImage& archetype
280 );
281 };
282} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:76
MagnificationFilter
Component: Filter used when a single texel/pixel of an image is displayed larger than a single screen...
Definition magnification_filter.hpp:27
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: An image encoded as e.g.
Definition encoded_image.hpp:52
static Result< EncodedImage > from_file(const std::filesystem::path &filepath)
Create a new EncodedImage from the contents of a file on disk, e.g. a PNG or JPEG.
EncodedImage with_many_draw_order(const Collection< rerun::components::DrawOrder > &_draw_order) &&
This method makes it possible to pack multiple draw_order in a single component batch.
Definition encoded_image.hpp:215
EncodedImage with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition encoded_image.hpp:205
static constexpr auto Descriptor_media_type
ComponentDescriptor for the media_type field.
Definition encoded_image.hpp:88
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition encoded_image.hpp:74
std::optional< ComponentBatch > opacity
Opacity of the image, useful for layering several media.
Definition encoded_image.hpp:69
std::optional< ComponentBatch > media_type
The Media Type of the asset.
Definition encoded_image.hpp:64
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition encoded_image.hpp:81
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
static constexpr auto Descriptor_draw_order
ComponentDescriptor for the draw_order field.
Definition encoded_image.hpp:98
EncodedImage with_many_blob(const Collection< rerun::components::Blob > &_blob) &&
This method makes it possible to pack multiple blob in a single component batch.
Definition encoded_image.hpp:154
std::optional< ComponentBatch > blob
The encoded content of some image file, e.g. a PNG or JPEG.
Definition encoded_image.hpp:54
static EncodedImage clear_fields()
Clear all the fields of a EncodedImage.
std::optional< ComponentBatch > magnification_filter
Optional filter used when a texel is magnified (displayed larger than a screen pixel).
Definition encoded_image.hpp:77
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
EncodedImage with_media_type(const rerun::components::MediaType &_media_type) &&
The Media Type of the asset.
Definition encoded_image.hpp:167
static EncodedImage update_fields()
Update only some specific fields of a EncodedImage.
Definition encoded_image.hpp:137
EncodedImage with_many_opacity(const Collection< rerun::components::Opacity > &_opacity) &&
This method makes it possible to pack multiple opacity in a single component batch.
Definition encoded_image.hpp:197
EncodedImage with_magnification_filter(const rerun::components::MagnificationFilter &_magnification_filter) &&
Optional filter used when a texel is magnified (displayed larger than a screen pixel).
Definition encoded_image.hpp:224
static constexpr auto Descriptor_blob
ComponentDescriptor for the blob field.
Definition encoded_image.hpp:84
EncodedImage with_opacity(const rerun::components::Opacity &_opacity) &&
Opacity of the image, useful for layering several media.
Definition encoded_image.hpp:188
EncodedImage with_blob(const rerun::components::Blob &_blob) &&
The encoded content of some image file, e.g. a PNG or JPEG.
Definition encoded_image.hpp:145
static constexpr auto Descriptor_opacity
ComponentDescriptor for the opacity field.
Definition encoded_image.hpp:93
static EncodedImage from_bytes(rerun::Collection< uint8_t > image_contents, std::optional< rerun::components::MediaType > media_type={})
Create a new EncodedImage from the contents of an image file, like a PNG or JPEG.
Definition encoded_image.hpp:116
EncodedImage with_many_media_type(const Collection< rerun::components::MediaType > &_media_type) &&
This method makes it possible to pack multiple media_type in a single component batch.
Definition encoded_image.hpp:177
static constexpr auto Descriptor_magnification_filter
ComponentDescriptor for the magnification_filter field.
Definition encoded_image.hpp:103
EncodedImage with_many_magnification_filter(const Collection< rerun::components::MagnificationFilter > &_magnification_filter) &&
This method makes it possible to pack multiple magnification_filter in a single component batch.
Definition encoded_image.hpp:239
Component: A binary blob of data.
Definition blob.hpp:16
Component: Draw order of 2D elements.
Definition draw_order.hpp:19
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:20
Component: Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
Definition opacity.hpp:17