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(
50 /// "image",
51 /// rerun::EncodedImage::from_file(image_filepath).value_or_throw()
52 /// );
53 /// }
54 /// ```
55 struct EncodedImage {
56 /// The encoded content of some image file, e.g. a PNG or JPEG.
57 std::optional<ComponentBatch> blob;
58
59 /// The Media Type of the asset.
60 ///
61 /// Supported values:
62 /// * `image/jpeg`
63 /// * `image/png`
64 ///
65 /// If omitted, the viewer will try to guess from the data blob.
66 /// If it cannot guess, it won't be able to render the asset.
67 std::optional<ComponentBatch> media_type;
68
69 /// Opacity of the image, useful for layering several media.
70 ///
71 /// Defaults to 1.0 (fully opaque).
72 std::optional<ComponentBatch> opacity;
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<ComponentBatch> draw_order;
78
79 /// Optional filter used when a texel is magnified (displayed larger than a screen pixel).
80 std::optional<ComponentBatch> magnification_filter;
81
82 public:
83 /// The name of the archetype as used in `ComponentDescriptor`s.
84 static constexpr const char ArchetypeName[] = "rerun.archetypes.EncodedImage";
85
86 /// `ComponentDescriptor` for the `blob` field.
87 static constexpr auto Descriptor_blob = ComponentDescriptor(
89 );
90 /// `ComponentDescriptor` for the `media_type` field.
92 ArchetypeName, "EncodedImage:media_type",
94 );
95 /// `ComponentDescriptor` for the `opacity` field.
96 static constexpr auto Descriptor_opacity = ComponentDescriptor(
97 ArchetypeName, "EncodedImage:opacity",
99 );
100 /// `ComponentDescriptor` for the `draw_order` field.
102 ArchetypeName, "EncodedImage:draw_order",
104 );
105 /// `ComponentDescriptor` for the `magnification_filter` field.
107 ArchetypeName, "EncodedImage:magnification_filter",
109 );
110
111 public: // START of extensions from encoded_image_ext.cpp:
112 /// Create a new `EncodedImage` from the contents of a file on disk, e.g. a PNG or JPEG.
113 static Result<EncodedImage> from_file(const std::filesystem::path& filepath);
114
115 /// Create a new `EncodedImage` from the contents of an image file, like a PNG or JPEG.
116 ///
117 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
118 /// at render-time. If it can't, rendering will fail with an error.
120 rerun::Collection<uint8_t> image_contents,
121 std::optional<rerun::components::MediaType> media_type = {}
122 ) {
123 auto encoded_image = EncodedImage().with_blob(image_contents);
124 if (media_type.has_value()) {
125 return std::move(encoded_image).with_media_type(media_type.value());
126 }
127 return encoded_image;
128 }
129
130 // END of extensions from encoded_image_ext.cpp, start of generated code:
131
132 public:
133 EncodedImage() = default;
134 EncodedImage(EncodedImage&& other) = default;
135 EncodedImage(const EncodedImage& other) = default;
136 EncodedImage& operator=(const EncodedImage& other) = default;
137 EncodedImage& operator=(EncodedImage&& other) = default;
138
139 /// Update only some specific fields of a `EncodedImage`.
141 return EncodedImage();
142 }
143
144 /// Clear all the fields of a `EncodedImage`.
146
147 /// The encoded content of some image file, e.g. a PNG or JPEG.
149 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
150 return std::move(*this);
151 }
152
153 /// This method makes it possible to pack multiple `blob` in a single component batch.
154 ///
155 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
156 /// be used when logging a single row's worth of data.
158 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
159 return std::move(*this);
160 }
161
162 /// The Media Type of the asset.
163 ///
164 /// Supported values:
165 /// * `image/jpeg`
166 /// * `image/png`
167 ///
168 /// If omitted, the viewer will try to guess from the data blob.
169 /// If it cannot guess, it won't be able to render the asset.
171 media_type =
172 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
173 return std::move(*this);
174 }
175
176 /// This method makes it possible to pack multiple `media_type` in a single component batch.
177 ///
178 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
179 /// be used when logging a single row's worth of data.
182 ) && {
183 media_type =
184 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
185 return std::move(*this);
186 }
187
188 /// Opacity of the image, useful for layering several media.
189 ///
190 /// Defaults to 1.0 (fully opaque).
192 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
193 return std::move(*this);
194 }
195
196 /// This method makes it possible to pack multiple `opacity` in a single component batch.
197 ///
198 /// This only makes sense when used in conjunction with `columns`. `with_opacity` should
199 /// be used when logging a single row's worth of data.
201 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
202 return std::move(*this);
203 }
204
205 /// An optional floating point value that specifies the 2D drawing order.
206 ///
207 /// Objects with higher values are drawn on top of those with lower values.
209 draw_order =
210 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
211 return std::move(*this);
212 }
213
214 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
215 ///
216 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
217 /// be used when logging a single row's worth of data.
220 ) && {
221 draw_order =
222 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
223 return std::move(*this);
224 }
225
226 /// Optional filter used when a texel is magnified (displayed larger than a screen pixel).
228 const rerun::components::MagnificationFilter& _magnification_filter
229 ) && {
231 _magnification_filter,
233 )
234 .value_or_throw();
235 return std::move(*this);
236 }
237
238 /// This method makes it possible to pack multiple `magnification_filter` in a single component batch.
239 ///
240 /// This only makes sense when used in conjunction with `columns`. `with_magnification_filter` should
241 /// be used when logging a single row's worth of data.
243 const Collection<rerun::components::MagnificationFilter>& _magnification_filter
244 ) && {
246 _magnification_filter,
248 )
249 .value_or_throw();
250 return std::move(*this);
251 }
252
253 /// Partitions the component data into multiple sub-batches.
254 ///
255 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
256 /// instead, via `ComponentBatch::partitioned`.
257 ///
258 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
259 ///
260 /// The specified `lengths` must sum to the total length of the component batch.
262
263 /// Partitions the component data into unit-length sub-batches.
264 ///
265 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
266 /// where `n` is automatically guessed.
268 };
269
270} // namespace rerun::archetypes
271
272namespace rerun {
273 /// \private
274 template <typename T>
275 struct AsComponents;
276
277 /// \private
278 template <>
279 struct AsComponents<archetypes::EncodedImage> {
280 /// Serialize all set component batches.
281 static Result<Collection<ComponentBatch>> as_batches(
282 const archetypes::EncodedImage& archetype
283 );
284 };
285} // 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:87
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:55
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:218
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:208
static constexpr auto Descriptor_media_type
ComponentDescriptor for the media_type field.
Definition encoded_image.hpp:91
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition encoded_image.hpp:77
std::optional< ComponentBatch > opacity
Opacity of the image, useful for layering several media.
Definition encoded_image.hpp:72
std::optional< ComponentBatch > media_type
The Media Type of the asset.
Definition encoded_image.hpp:67
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition encoded_image.hpp:84
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:101
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:157
std::optional< ComponentBatch > blob
The encoded content of some image file, e.g. a PNG or JPEG.
Definition encoded_image.hpp:57
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:80
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:170
static EncodedImage update_fields()
Update only some specific fields of a EncodedImage.
Definition encoded_image.hpp:140
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:200
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:227
static constexpr auto Descriptor_blob
ComponentDescriptor for the blob field.
Definition encoded_image.hpp:87
EncodedImage with_opacity(const rerun::components::Opacity &_opacity) &&
Opacity of the image, useful for layering several media.
Definition encoded_image.hpp:191
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:148
static constexpr auto Descriptor_opacity
ComponentDescriptor for the opacity field.
Definition encoded_image.hpp:96
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:119
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:180
static constexpr auto Descriptor_magnification_filter
ComponentDescriptor for the magnification_filter field.
Definition encoded_image.hpp:106
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:242
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