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