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