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