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