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