Rerun C++ SDK
Loading...
Searching...
No Matches
video_frame_reference.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/video_frame_reference.def.rs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/draw_order.hpp"
10#include "../components/entity_path.hpp"
11#include "../components/opacity.hpp"
12#include "../components/video_timestamp.hpp"
13#include "../result.hpp"
14
15#include <cstdint>
16#include <optional>
17#include <utility>
18#include <vector>
19
20namespace rerun::archetypes {
21 /// **Archetype**: References a single video frame.
22 ///
23 /// Used to display individual video frames from an `archetypes::AssetVideo` or `archetypes::VideoStream`.
24 /// To show an entire video, a video frame reference for each frame of the video should be logged.
25 /// References to a `archetypes::VideoStream` use the active Viewer timeline.
26 ///
27 /// See <https://rerun.io/docs/reference/video> for details of what is and isn't supported.
28 ///
29 /// ## Examples
30 ///
31 /// ### Video with automatically determined frames
32 /// ![image](https://static.rerun.io/video_manual_frames/320a44e1e06b8b3a3161ecbbeae3e04d1ccb9589/full.png)
33 ///
34 /// ```cpp
35 /// #include <rerun.hpp>
36 ///
37 /// #include <iostream>
38 ///
39 /// using namespace std::chrono_literals;
40 ///
41 /// int main(int argc, char* argv[]) {
42 /// if (argc <2) {
43 /// // TODO(#7354): Only mp4 is supported for now.
44 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_video.[mp4]>"
45 /// <<std::endl;
46 /// return 1;
47 /// }
48 ///
49 /// const auto path = argv[1];
50 ///
51 /// const auto rec =
52 /// rerun::RecordingStream("rerun_example_asset_video_auto_frames");
53 /// rec.spawn().exit_on_failure();
54 ///
55 /// // Log video asset which is referred to by frame references.
56 /// auto video_asset = rerun::AssetVideo::from_file(path).value_or_throw();
57 /// rec.log_static("video", video_asset);
58 ///
59 /// // Send automatically determined video frame timestamps.
60 /// std::vector<std::chrono::nanoseconds> frame_timestamps_ns =
61 /// video_asset.read_frame_timestamps_nanos().value_or_throw();
62 /// // Note timeline values don't have to be the same as the video timestamps.
63 /// auto time_column = rerun::TimeColumn::from_durations(
64 /// "video_time",
65 /// rerun::borrow(frame_timestamps_ns)
66 /// );
67 ///
68 /// std::vector<rerun::components::VideoTimestamp> video_timestamps(
69 /// frame_timestamps_ns.size()
70 /// );
71 /// for (size_t i = 0; i <frame_timestamps_ns.size(); i++) {
72 /// video_timestamps[i] =
73 /// rerun::components::VideoTimestamp(frame_timestamps_ns[i]);
74 /// }
75 ///
76 /// rec.send_columns(
77 /// "video",
78 /// time_column,
79 /// rerun::VideoFrameReference()
80 /// .with_many_timestamp(rerun::borrow(video_timestamps))
81 /// .columns()
82 /// );
83 /// }
84 /// ```
85 ///
86 /// ### Demonstrates manual use of video frame references
87 /// ![image](https://static.rerun.io/video_manual_frames/9f41c00f84a98cc3f26875fba7c1d2fa2bad7151/full.png)
88 ///
89 /// ```cpp
90 /// #include <rerun.hpp>
91 ///
92 /// #include <iostream>
93 ///
94 /// using namespace std::chrono_literals;
95 ///
96 /// int main(int argc, char* argv[]) {
97 /// if (argc <2) {
98 /// // TODO(#7354): Only mp4 is supported for now.
99 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_video.[mp4]>"
100 /// <<std::endl;
101 /// return 1;
102 /// }
103 ///
104 /// const auto path = argv[1];
105 ///
106 /// const auto rec =
107 /// rerun::RecordingStream("rerun_example_asset_video_manual_frames");
108 /// rec.spawn().exit_on_failure();
109 ///
110 /// // Log video asset which is referred to by frame references.
111 /// rec.log_static(
112 /// "video_asset",
113 /// rerun::AssetVideo::from_file(path).value_or_throw()
114 /// );
115 ///
116 /// // Create two entities, showing the same video frozen at different times.
117 /// rec.log(
118 /// "frame_1s",
119 /// rerun::VideoFrameReference(1.0s).with_video_reference("video_asset")
120 /// );
121 /// rec.log(
122 /// "frame_2s",
123 /// rerun::VideoFrameReference(2.0s).with_video_reference("video_asset")
124 /// );
125 ///
126 /// // TODO(#5520): log blueprint once supported
127 /// }
128 /// ```
130 /// References the closest video frame to this timestamp.
131 ///
132 /// Note that this uses the closest video frame instead of the latest at this timestamp
133 /// in order to be more forgiving of rounding errors for inprecise timestamp types.
134 ///
135 /// Timestamps are relative to the start of the video, i.e. a timestamp of 0 always corresponds to the first frame.
136 /// This is oftentimes equivalent to presentation timestamps (known as PTS), but in the presence of B-frames
137 /// (bidirectionally predicted frames) there may be an offset on the first presentation timestamp in the video.
138 std::optional<ComponentBatch> timestamp;
139
140 /// Optional reference to an entity with an `archetypes::AssetVideo` or `archetypes::VideoStream`.
141 ///
142 /// If none is specified, the video is assumed to be at the same entity.
143 /// Note that blueprint overrides on the referenced video will be ignored regardless,
144 /// as this is always interpreted as a reference to the data store.
145 ///
146 /// For a series of video frame references, it is recommended to specify this path only once
147 /// at the beginning of the series and then rely on latest-at query semantics to
148 /// keep the video reference active.
149 std::optional<ComponentBatch> video_reference;
150
151 /// Opacity of the video, useful for layering several media.
152 ///
153 /// Defaults to 1.0 (fully opaque).
154 std::optional<ComponentBatch> opacity;
155
156 /// An optional floating point value that specifies the 2D drawing order.
157 ///
158 /// Objects with higher values are drawn on top of those with lower values.
159 /// Defaults to `-15.0`.
160 std::optional<ComponentBatch> draw_order;
161
162 public:
163 /// The name of the archetype as used in `ComponentDescriptor`s.
164 static constexpr const char ArchetypeName[] = "rerun.archetypes.VideoFrameReference";
165
166 /// `ComponentDescriptor` for the `timestamp` field.
168 ArchetypeName, "VideoFrameReference:timestamp",
170 );
171 /// `ComponentDescriptor` for the `video_reference` field.
173 ArchetypeName, "VideoFrameReference:video_reference",
175 );
176 /// `ComponentDescriptor` for the `opacity` field.
178 ArchetypeName, "VideoFrameReference:opacity",
180 );
181 /// `ComponentDescriptor` for the `draw_order` field.
183 ArchetypeName, "VideoFrameReference:draw_order",
185 );
186
187 public:
188 VideoFrameReference() = default;
189 VideoFrameReference(VideoFrameReference&& other) = default;
190 VideoFrameReference(const VideoFrameReference& other) = default;
191 VideoFrameReference& operator=(const VideoFrameReference& other) = default;
192 VideoFrameReference& operator=(VideoFrameReference&& other) = default;
193
195 : timestamp(ComponentBatch::from_loggable(std::move(_timestamp), Descriptor_timestamp)
196 .value_or_throw()) {}
197
198 /// Update only some specific fields of a `VideoFrameReference`.
200 return VideoFrameReference();
201 }
202
203 /// Clear all the fields of a `VideoFrameReference`.
205
206 /// References the closest video frame to this timestamp.
207 ///
208 /// Note that this uses the closest video frame instead of the latest at this timestamp
209 /// in order to be more forgiving of rounding errors for inprecise timestamp types.
210 ///
211 /// Timestamps are relative to the start of the video, i.e. a timestamp of 0 always corresponds to the first frame.
212 /// This is oftentimes equivalent to presentation timestamps (known as PTS), but in the presence of B-frames
213 /// (bidirectionally predicted frames) there may be an offset on the first presentation timestamp in the video.
215 timestamp =
216 ComponentBatch::from_loggable(_timestamp, Descriptor_timestamp).value_or_throw();
217 return std::move(*this);
218 }
219
220 /// This method makes it possible to pack multiple `timestamp` in a single component batch.
221 ///
222 /// This only makes sense when used in conjunction with `columns`. `with_timestamp` should
223 /// be used when logging a single row's worth of data.
226 ) && {
227 timestamp =
228 ComponentBatch::from_loggable(_timestamp, Descriptor_timestamp).value_or_throw();
229 return std::move(*this);
230 }
231
232 /// Optional reference to an entity with an `archetypes::AssetVideo` or `archetypes::VideoStream`.
233 ///
234 /// If none is specified, the video is assumed to be at the same entity.
235 /// Note that blueprint overrides on the referenced video will be ignored regardless,
236 /// as this is always interpreted as a reference to the data store.
237 ///
238 /// For a series of video frame references, it is recommended to specify this path only once
239 /// at the beginning of the series and then rely on latest-at query semantics to
240 /// keep the video reference active.
242 const rerun::components::EntityPath& _video_reference
243 ) && {
246 .value_or_throw();
247 return std::move(*this);
248 }
249
250 /// This method makes it possible to pack multiple `video_reference` in a single component batch.
251 ///
252 /// This only makes sense when used in conjunction with `columns`. `with_video_reference` should
253 /// be used when logging a single row's worth of data.
255 const Collection<rerun::components::EntityPath>& _video_reference
256 ) && {
259 .value_or_throw();
260 return std::move(*this);
261 }
262
263 /// Opacity of the video, useful for layering several media.
264 ///
265 /// Defaults to 1.0 (fully opaque).
267 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
268 return std::move(*this);
269 }
270
271 /// This method makes it possible to pack multiple `opacity` in a single component batch.
272 ///
273 /// This only makes sense when used in conjunction with `columns`. `with_opacity` should
274 /// be used when logging a single row's worth of data.
276 ) && {
277 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
278 return std::move(*this);
279 }
280
281 /// An optional floating point value that specifies the 2D drawing order.
282 ///
283 /// Objects with higher values are drawn on top of those with lower values.
284 /// Defaults to `-15.0`.
286 draw_order =
287 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
288 return std::move(*this);
289 }
290
291 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
292 ///
293 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
294 /// be used when logging a single row's worth of data.
297 ) && {
298 draw_order =
299 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
300 return std::move(*this);
301 }
302
303 /// Partitions the component data into multiple sub-batches.
304 ///
305 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
306 /// instead, via `ComponentBatch::partitioned`.
307 ///
308 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
309 ///
310 /// The specified `lengths` must sum to the total length of the component batch.
312
313 /// Partitions the component data into unit-length sub-batches.
314 ///
315 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
316 /// where `n` is automatically guessed.
318 };
319
320} // namespace rerun::archetypes
321
322namespace rerun {
323 /// \private
324 template <typename T>
325 struct AsComponents;
326
327 /// \private
328 template <>
329 struct AsComponents<archetypes::VideoFrameReference> {
330 /// Serialize all set component batches.
331 static Result<Collection<ComponentBatch>> as_batches(
332 const archetypes::VideoFrameReference& archetype
333 );
334 };
335} // 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
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
Arrow-encoded data of a single batch of components together with a component descriptor.
Definition component_batch.hpp:28
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: References a single video frame.
Definition video_frame_reference.hpp:129
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 video_frame_reference.hpp:182
VideoFrameReference 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 video_frame_reference.hpp:295
VideoFrameReference with_timestamp(const rerun::components::VideoTimestamp &_timestamp) &&
References the closest video frame to this timestamp.
Definition video_frame_reference.hpp:214
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition video_frame_reference.hpp:160
VideoFrameReference with_many_timestamp(const Collection< rerun::components::VideoTimestamp > &_timestamp) &&
This method makes it possible to pack multiple timestamp in a single component batch.
Definition video_frame_reference.hpp:224
std::optional< ComponentBatch > timestamp
References the closest video frame to this timestamp.
Definition video_frame_reference.hpp:138
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition video_frame_reference.hpp:164
VideoFrameReference with_many_opacity(const Collection< rerun::components::Opacity > &_opacity) &&
This method makes it possible to pack multiple opacity in a single component batch.
Definition video_frame_reference.hpp:275
VideoFrameReference with_opacity(const rerun::components::Opacity &_opacity) &&
Opacity of the video, useful for layering several media.
Definition video_frame_reference.hpp:266
static constexpr auto Descriptor_video_reference
ComponentDescriptor for the video_reference field.
Definition video_frame_reference.hpp:172
std::optional< ComponentBatch > opacity
Opacity of the video, useful for layering several media.
Definition video_frame_reference.hpp:154
static constexpr auto Descriptor_timestamp
ComponentDescriptor for the timestamp field.
Definition video_frame_reference.hpp:167
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static constexpr auto Descriptor_opacity
ComponentDescriptor for the opacity field.
Definition video_frame_reference.hpp:177
VideoFrameReference with_video_reference(const rerun::components::EntityPath &_video_reference) &&
Optional reference to an entity with an archetypes::AssetVideo or archetypes::VideoStream.
Definition video_frame_reference.hpp:241
std::optional< ComponentBatch > video_reference
Optional reference to an entity with an archetypes::AssetVideo or archetypes::VideoStream.
Definition video_frame_reference.hpp:149
VideoFrameReference with_many_video_reference(const Collection< rerun::components::EntityPath > &_video_reference) &&
This method makes it possible to pack multiple video_reference in a single component batch.
Definition video_frame_reference.hpp:254
static VideoFrameReference update_fields()
Update only some specific fields of a VideoFrameReference.
Definition video_frame_reference.hpp:199
static VideoFrameReference clear_fields()
Clear all the fields of a VideoFrameReference.
VideoFrameReference with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition video_frame_reference.hpp:285
Component: Draw order of 2D elements.
Definition draw_order.hpp:19
Component: A path to an entity, usually to reference some data that is part of the target entity.
Definition entity_path.hpp:16
Component: Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
Definition opacity.hpp:17
Component: Timestamp inside a archetypes::AssetVideo.
Definition video_timestamp.hpp:15