Rerun C++ SDK
Loading...
Searching...
No Matches
depth_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_sdk_types/definitions/rerun/archetypes/depth_image.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/colormap.hpp"
10#include "../components/depth_meter.hpp"
11#include "../components/draw_order.hpp"
12#include "../components/fill_ratio.hpp"
13#include "../components/image_buffer.hpp"
14#include "../components/image_format.hpp"
15#include "../components/value_range.hpp"
16#include "../image_utils.hpp"
17#include "../result.hpp"
18
19#include <cstdint>
20#include <optional>
21#include <utility>
22#include <vector>
23
24namespace rerun::archetypes {
25 /// **Archetype**: A depth image, i.e. as captured by a depth camera.
26 ///
27 /// Each pixel corresponds to a depth value in units specified by `components::DepthMeter`.
28 ///
29 /// Since the underlying `rerun::datatypes::ImageBuffer` uses `rerun::Collection` internally,
30 /// data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
31 /// If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
32 ///
33 /// ## Example
34 ///
35 /// ### Depth to 3D example
36 /// ![image](https://static.rerun.io/depth_image_3d/924e9d4d6a39d63d4fdece82582855fdaa62d15e/full.png)
37 ///
38 /// ```cpp
39 /// #include <rerun.hpp>
40 ///
41 /// #include <algorithm> // fill_n
42 /// #include <vector>
43 ///
44 /// int main() {
45 /// const auto rec = rerun::RecordingStream("rerun_example_depth_image_3d");
46 /// rec.spawn().exit_on_failure();
47 ///
48 /// // Create a synthetic depth image.
49 /// const int HEIGHT = 200;
50 /// const int WIDTH = 300;
51 /// std::vector<uint16_t> data(WIDTH * HEIGHT, 65535);
52 /// for (auto y = 50; y <150; ++y) {
53 /// std::fill_n(data.begin() + y * WIDTH + 50, 100, static_cast<uint16_t>(20000));
54 /// }
55 /// for (auto y = 130; y <180; ++y) {
56 /// std::fill_n(data.begin() + y * WIDTH + 100, 180, static_cast<uint16_t>(45000));
57 /// }
58 ///
59 /// // If we log a pinhole camera model, the depth gets automatically back-projected to 3D
60 /// rec.log(
61 /// "world/camera",
62 /// rerun::Pinhole::from_focal_length_and_resolution(
63 /// 200.0f,
64 /// {static_cast<float>(WIDTH), static_cast<float>(HEIGHT)}
65 /// )
66 /// );
67 ///
68 /// rec.log(
69 /// "world/camera/depth",
70 /// rerun::DepthImage(data.data(), {WIDTH, HEIGHT})
71 /// .with_meter(10000.0)
72 /// .with_colormap(rerun::components::Colormap::Viridis)
73 /// );
74 /// }
75 /// ```
76 struct DepthImage {
77 /// The raw depth image data.
78 std::optional<ComponentBatch> buffer;
79
80 /// The format of the image.
81 std::optional<ComponentBatch> format;
82
83 /// An optional floating point value that specifies how long a meter is in the native depth units.
84 ///
85 /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision
86 /// and a range of up to ~65 meters (2^16 / 1000).
87 ///
88 /// If omitted, the Viewer defaults to `1.0` for floating-point depth formats and `1000.0` for integer formats (millimeters).
89 ///
90 /// Note that the only effect on 2D views is the physical depth values shown when hovering the image.
91 /// In 3D views on the other hand, this affects where the points of the point cloud are placed.
92 std::optional<ComponentBatch> meter;
93
94 /// Colormap to use for rendering the depth image.
95 ///
96 /// If not set, the depth image will be rendered using the Turbo colormap.
97 std::optional<ComponentBatch> colormap;
98
99 /// The expected range of depth values.
100 ///
101 /// This is typically the expected range of valid values.
102 /// Everything outside of the range is clamped to the range for the purpose of colormpaping.
103 /// Note that point clouds generated from this image will still display all points, regardless of this range.
104 ///
105 /// If not specified, the range will be automatically estimated from the data.
106 /// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
107 /// in the contents of the depth image.
108 /// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
109 /// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
110 std::optional<ComponentBatch> depth_range;
111
112 /// Scale the radii of the points in the point cloud generated from this image.
113 ///
114 /// A fill ratio of 1.0 (the default) means that each point is as big as to touch the center of its neighbor
115 /// if it is at the same depth, leaving no gaps.
116 /// A fill ratio of 0.5 means that each point touches the edge of its neighbor if it has the same depth.
117 ///
118 /// TODO(#6744): This applies only to 3D views!
119 std::optional<ComponentBatch> point_fill_ratio;
120
121 /// An optional floating point value that specifies the 2D drawing order, used only if the depth image is shown as a 2D image.
122 ///
123 /// Objects with higher values are drawn on top of those with lower values.
124 /// Defaults to `-20.0`.
125 std::optional<ComponentBatch> draw_order;
126
127 public:
128 /// The name of the archetype as used in `ComponentDescriptor`s.
129 static constexpr const char ArchetypeName[] = "rerun.archetypes.DepthImage";
130
131 /// `ComponentDescriptor` for the `buffer` field.
132 static constexpr auto Descriptor_buffer = ComponentDescriptor(
133 ArchetypeName, "DepthImage:buffer",
135 );
136 /// `ComponentDescriptor` for the `format` field.
137 static constexpr auto Descriptor_format = ComponentDescriptor(
138 ArchetypeName, "DepthImage:format",
140 );
141 /// `ComponentDescriptor` for the `meter` field.
142 static constexpr auto Descriptor_meter = ComponentDescriptor(
143 ArchetypeName, "DepthImage:meter",
145 );
146 /// `ComponentDescriptor` for the `colormap` field.
148 ArchetypeName, "DepthImage:colormap",
150 );
151 /// `ComponentDescriptor` for the `depth_range` field.
153 ArchetypeName, "DepthImage:depth_range",
155 );
156 /// `ComponentDescriptor` for the `point_fill_ratio` field.
158 ArchetypeName, "DepthImage:point_fill_ratio",
160 );
161 /// `ComponentDescriptor` for the `draw_order` field.
163 ArchetypeName, "DepthImage:draw_order",
165 );
166
167 public: // START of extensions from depth_image_ext.cpp:
168 /// Constructs image from pointer + resolution, inferring the datatype from the pointer type.
169 ///
170 /// @param pixels The raw image data.
171 /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image.
172 /// The number of elements is assumed to be `W * H`.
173 /// @param resolution The resolution of the image as {width, height}.
174 template <typename TElement>
175 DepthImage(const TElement* pixels, WidthHeight resolution)
176 : DepthImage{
177 reinterpret_cast<const uint8_t*>(pixels), resolution, get_datatype(pixels)} {}
178
179 /// Constructs image from pixel data + resolution with datatype inferred from the passed collection.
180 ///
181 /// @param pixels The raw image data.
182 /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection`
183 /// explicitly ahead of time with `rerun::Collection::take_ownership`.
184 /// The length of the data should be `W * H`.
185 /// @param resolution The resolution of the image as {width, height}.
186 template <typename TElement>
188 : DepthImage{pixels.to_uint8(), resolution, get_datatype(pixels.data())} {}
189
190 /// Constructs image from pixel data + resolution with explicit datatype. Borrows data from a pointer (i.e. data must outlive the image!).
191 ///
192 /// @param bytes The raw image data.
193 /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image.
194 /// The byte size of the data is assumed to be `W * H * datatype.size`
195 /// @param resolution The resolution of the image as {width, height}.
196 /// @param datatype How the data should be interpreted.
197 DepthImage(const void* bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
198 : DepthImage{
199 Collection<uint8_t>::borrow(bytes, num_bytes(resolution, datatype)),
200 resolution,
201 datatype} {}
202
203 /// Constructs image from pixel data + resolution + datatype.
204 ///
205 /// @param bytes The raw image data as bytes.
206 /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection`
207 /// explicitly ahead of time with `rerun::Collection::take_ownership`.
208 /// The length of the data should be `W * H`.
209 /// @param resolution The resolution of the image as {width, height}.
210 /// @param datatype How the data should be interpreted.
213 ) {
214 auto image_format = datatypes::ImageFormat{resolution, datatype};
215 if (bytes.size() != image_format.num_bytes()) {
216 Error(
217 ErrorCode::InvalidTensorDimension,
218 "DepthImage buffer has the wrong size. Got " + std::to_string(bytes.size()) +
219 " bytes, expected " + std::to_string(image_format.num_bytes())
220 )
221 .handle();
222 }
223 *this = std::move(*this).with_buffer(bytes).with_format(image_format);
224 }
225
226 // END of extensions from depth_image_ext.cpp, start of generated code:
227
228 public:
229 DepthImage() = default;
230 DepthImage(DepthImage&& other) = default;
231 DepthImage(const DepthImage& other) = default;
232 DepthImage& operator=(const DepthImage& other) = default;
233 DepthImage& operator=(DepthImage&& other) = default;
234
235 /// Update only some specific fields of a `DepthImage`.
237 return DepthImage();
238 }
239
240 /// Clear all the fields of a `DepthImage`.
242
243 /// The raw depth image data.
245 buffer = ComponentBatch::from_loggable(_buffer, Descriptor_buffer).value_or_throw();
246 return std::move(*this);
247 }
248
249 /// This method makes it possible to pack multiple `buffer` in a single component batch.
250 ///
251 /// This only makes sense when used in conjunction with `columns`. `with_buffer` should
252 /// be used when logging a single row's worth of data.
254 buffer = ComponentBatch::from_loggable(_buffer, Descriptor_buffer).value_or_throw();
255 return std::move(*this);
256 }
257
258 /// The format of the image.
260 format = ComponentBatch::from_loggable(_format, Descriptor_format).value_or_throw();
261 return std::move(*this);
262 }
263
264 /// This method makes it possible to pack multiple `format` in a single component batch.
265 ///
266 /// This only makes sense when used in conjunction with `columns`. `with_format` should
267 /// be used when logging a single row's worth of data.
269 format = ComponentBatch::from_loggable(_format, Descriptor_format).value_or_throw();
270 return std::move(*this);
271 }
272
273 /// An optional floating point value that specifies how long a meter is in the native depth units.
274 ///
275 /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision
276 /// and a range of up to ~65 meters (2^16 / 1000).
277 ///
278 /// If omitted, the Viewer defaults to `1.0` for floating-point depth formats and `1000.0` for integer formats (millimeters).
279 ///
280 /// Note that the only effect on 2D views is the physical depth values shown when hovering the image.
281 /// In 3D views on the other hand, this affects where the points of the point cloud are placed.
283 meter = ComponentBatch::from_loggable(_meter, Descriptor_meter).value_or_throw();
284 return std::move(*this);
285 }
286
287 /// This method makes it possible to pack multiple `meter` in a single component batch.
288 ///
289 /// This only makes sense when used in conjunction with `columns`. `with_meter` should
290 /// be used when logging a single row's worth of data.
292 meter = ComponentBatch::from_loggable(_meter, Descriptor_meter).value_or_throw();
293 return std::move(*this);
294 }
295
296 /// Colormap to use for rendering the depth image.
297 ///
298 /// If not set, the depth image will be rendered using the Turbo colormap.
300 colormap =
301 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
302 return std::move(*this);
303 }
304
305 /// This method makes it possible to pack multiple `colormap` in a single component batch.
306 ///
307 /// This only makes sense when used in conjunction with `columns`. `with_colormap` should
308 /// be used when logging a single row's worth of data.
310 colormap =
311 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
312 return std::move(*this);
313 }
314
315 /// The expected range of depth values.
316 ///
317 /// This is typically the expected range of valid values.
318 /// Everything outside of the range is clamped to the range for the purpose of colormpaping.
319 /// Note that point clouds generated from this image will still display all points, regardless of this range.
320 ///
321 /// If not specified, the range will be automatically estimated from the data.
322 /// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
323 /// in the contents of the depth image.
324 /// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
325 /// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
328 .value_or_throw();
329 return std::move(*this);
330 }
331
332 /// This method makes it possible to pack multiple `depth_range` in a single component batch.
333 ///
334 /// This only makes sense when used in conjunction with `columns`. `with_depth_range` should
335 /// be used when logging a single row's worth of data.
338 ) && {
340 .value_or_throw();
341 return std::move(*this);
342 }
343
344 /// Scale the radii of the points in the point cloud generated from this image.
345 ///
346 /// A fill ratio of 1.0 (the default) means that each point is as big as to touch the center of its neighbor
347 /// if it is at the same depth, leaving no gaps.
348 /// A fill ratio of 0.5 means that each point touches the edge of its neighbor if it has the same depth.
349 ///
350 /// TODO(#6744): This applies only to 3D views!
354 .value_or_throw();
355 return std::move(*this);
356 }
357
358 /// This method makes it possible to pack multiple `point_fill_ratio` in a single component batch.
359 ///
360 /// This only makes sense when used in conjunction with `columns`. `with_point_fill_ratio` should
361 /// be used when logging a single row's worth of data.
363 const Collection<rerun::components::FillRatio>& _point_fill_ratio
364 ) && {
367 .value_or_throw();
368 return std::move(*this);
369 }
370
371 /// An optional floating point value that specifies the 2D drawing order, used only if the depth image is shown as a 2D image.
372 ///
373 /// Objects with higher values are drawn on top of those with lower values.
374 /// Defaults to `-20.0`.
376 draw_order =
377 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
378 return std::move(*this);
379 }
380
381 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
382 ///
383 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
384 /// be used when logging a single row's worth of data.
386 ) && {
387 draw_order =
388 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
389 return std::move(*this);
390 }
391
392 /// Partitions the component data into multiple sub-batches.
393 ///
394 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
395 /// instead, via `ComponentBatch::partitioned`.
396 ///
397 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
398 ///
399 /// The specified `lengths` must sum to the total length of the component batch.
401
402 /// Partitions the component data into unit-length sub-batches.
403 ///
404 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
405 /// where `n` is automatically guessed.
407 };
408
409} // namespace rerun::archetypes
410
411namespace rerun {
412 /// \private
413 template <typename T>
414 struct AsComponents;
415
416 /// \private
417 template <>
418 struct AsComponents<archetypes::DepthImage> {
419 /// Serialize all set component batches.
420 static Result<Collection<ComponentBatch>> as_batches(const archetypes::DepthImage& archetype
421 );
422 };
423} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
size_t size() const
Returns the number of instances in this collection.
Definition collection.hpp:291
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:103
void handle() const
Handle this error based on the set log handler.
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
Colormap
Component: Colormap for mapping scalar values within a given range to a color.
Definition colormap.hpp:28
ChannelDatatype
Datatype: The innermost datatype of an image.
Definition channel_datatype.hpp:26
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Collection< TElement > borrow(const TElement *data, size_t num_instances=1)
Borrows binary data into a Collection from a pointer.
Definition collection.hpp:462
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
The width and height of an image.
Definition image_utils.hpp:13
Archetype: A depth image, i.e.
Definition depth_image.hpp:76
DepthImage with_colormap(const rerun::components::Colormap &_colormap) &&
Colormap to use for rendering the depth image.
Definition depth_image.hpp:299
DepthImage with_meter(const rerun::components::DepthMeter &_meter) &&
An optional floating point value that specifies how long a meter is in the native depth units.
Definition depth_image.hpp:282
std::optional< ComponentBatch > format
The format of the image.
Definition depth_image.hpp:81
static constexpr auto Descriptor_depth_range
ComponentDescriptor for the depth_range field.
Definition depth_image.hpp:152
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition depth_image.hpp:129
DepthImage(Collection< uint8_t > bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
Constructs image from pixel data + resolution + datatype.
Definition depth_image.hpp:211
DepthImage with_point_fill_ratio(const rerun::components::FillRatio &_point_fill_ratio) &&
Scale the radii of the points in the point cloud generated from this image.
Definition depth_image.hpp:351
static constexpr auto Descriptor_point_fill_ratio
ComponentDescriptor for the point_fill_ratio field.
Definition depth_image.hpp:157
DepthImage 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 depth_image.hpp:385
static DepthImage update_fields()
Update only some specific fields of a DepthImage.
Definition depth_image.hpp:236
std::optional< ComponentBatch > colormap
Colormap to use for rendering the depth image.
Definition depth_image.hpp:97
std::optional< ComponentBatch > depth_range
The expected range of depth values.
Definition depth_image.hpp:110
static constexpr auto Descriptor_format
ComponentDescriptor for the format field.
Definition depth_image.hpp:137
DepthImage with_depth_range(const rerun::components::ValueRange &_depth_range) &&
The expected range of depth values.
Definition depth_image.hpp:326
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static constexpr auto Descriptor_colormap
ComponentDescriptor for the colormap field.
Definition depth_image.hpp:147
std::optional< ComponentBatch > meter
An optional floating point value that specifies how long a meter is in the native depth units.
Definition depth_image.hpp:92
DepthImage(Collection< TElement > pixels, WidthHeight resolution)
Constructs image from pixel data + resolution with datatype inferred from the passed collection.
Definition depth_image.hpp:187
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order, used only if the depth image is...
Definition depth_image.hpp:125
static constexpr auto Descriptor_draw_order
ComponentDescriptor for the draw_order field.
Definition depth_image.hpp:162
DepthImage with_many_point_fill_ratio(const Collection< rerun::components::FillRatio > &_point_fill_ratio) &&
This method makes it possible to pack multiple point_fill_ratio in a single component batch.
Definition depth_image.hpp:362
static constexpr auto Descriptor_buffer
ComponentDescriptor for the buffer field.
Definition depth_image.hpp:132
DepthImage(const void *bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
Constructs image from pixel data + resolution with explicit datatype.
Definition depth_image.hpp:197
DepthImage with_many_colormap(const Collection< rerun::components::Colormap > &_colormap) &&
This method makes it possible to pack multiple colormap in a single component batch.
Definition depth_image.hpp:309
DepthImage(const TElement *pixels, WidthHeight resolution)
Constructs image from pointer + resolution, inferring the datatype from the pointer type.
Definition depth_image.hpp:175
DepthImage with_many_meter(const Collection< rerun::components::DepthMeter > &_meter) &&
This method makes it possible to pack multiple meter in a single component batch.
Definition depth_image.hpp:291
std::optional< ComponentBatch > point_fill_ratio
Scale the radii of the points in the point cloud generated from this image.
Definition depth_image.hpp:119
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
DepthImage with_format(const rerun::components::ImageFormat &_format) &&
The format of the image.
Definition depth_image.hpp:259
DepthImage with_many_depth_range(const Collection< rerun::components::ValueRange > &_depth_range) &&
This method makes it possible to pack multiple depth_range in a single component batch.
Definition depth_image.hpp:336
DepthImage with_buffer(const rerun::components::ImageBuffer &_buffer) &&
The raw depth image data.
Definition depth_image.hpp:244
DepthImage with_many_format(const Collection< rerun::components::ImageFormat > &_format) &&
This method makes it possible to pack multiple format in a single component batch.
Definition depth_image.hpp:268
DepthImage with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
An optional floating point value that specifies the 2D drawing order, used only if the depth image is...
Definition depth_image.hpp:375
static DepthImage clear_fields()
Clear all the fields of a DepthImage.
DepthImage with_many_buffer(const Collection< rerun::components::ImageBuffer > &_buffer) &&
This method makes it possible to pack multiple buffer in a single component batch.
Definition depth_image.hpp:253
static constexpr auto Descriptor_meter
ComponentDescriptor for the meter field.
Definition depth_image.hpp:142
std::optional< ComponentBatch > buffer
The raw depth image data.
Definition depth_image.hpp:78
Component: The world->depth map scaling factor.
Definition depth_meter.hpp:24
Component: Draw order of 2D elements.
Definition draw_order.hpp:19
Component: How much a primitive fills out the available space.
Definition fill_ratio.hpp:19
Component: A buffer that is known to store image data.
Definition image_buffer.hpp:18
Component: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:14
Component: Range of expected or valid values, specifying a lower and upper bound.
Definition value_range.hpp:18
Datatype: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:24