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