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_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 "../indicator_component.hpp"
18#include "../result.hpp"
19
20#include <cstdint>
21#include <optional>
22#include <utility>
23#include <vector>
24
25namespace rerun::archetypes {
26 /// **Archetype**: A depth image, i.e. as captured by a depth camera.
27 ///
28 /// Each pixel corresponds to a depth value in units specified by `components::DepthMeter`.
29 ///
30 /// Since the underlying `rerun::datatypes::ImageBuffer` uses `rerun::Collection` internally,
31 /// data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
32 /// If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
33 ///
34 /// ## Example
35 ///
36 /// ### Depth to 3D example
37 /// ![image](https://static.rerun.io/depth_image_3d/924e9d4d6a39d63d4fdece82582855fdaa62d15e/full.png)
38 ///
39 /// ```cpp
40 /// #include <rerun.hpp>
41 ///
42 /// #include <algorithm> // fill_n
43 /// #include <vector>
44 ///
45 /// int main() {
46 /// const auto rec = rerun::RecordingStream("rerun_example_depth_image_3d");
47 /// rec.spawn().exit_on_failure();
48 ///
49 /// // Create a synthetic depth image.
50 /// const int HEIGHT = 200;
51 /// const int WIDTH = 300;
52 /// std::vector<uint16_t> data(WIDTH * HEIGHT, 65535);
53 /// for (auto y = 50; y <150; ++y) {
54 /// std::fill_n(data.begin() + y * WIDTH + 50, 100, static_cast<uint16_t>(20000));
55 /// }
56 /// for (auto y = 130; y <180; ++y) {
57 /// std::fill_n(data.begin() + y * WIDTH + 100, 180, static_cast<uint16_t>(45000));
58 /// }
59 ///
60 /// // If we log a pinhole camera model, the depth gets automatically back-projected to 3D
61 /// rec.log(
62 /// "world/camera",
63 /// rerun::Pinhole::from_focal_length_and_resolution(
64 /// 200.0f,
65 /// {static_cast<float>(WIDTH), static_cast<float>(HEIGHT)}
66 /// )
67 /// );
68 ///
69 /// rec.log(
70 /// "world/camera/depth",
71 /// rerun::DepthImage(data.data(), {WIDTH, HEIGHT})
72 /// .with_meter(10000.0)
73 /// .with_colormap(rerun::components::Colormap::Viridis)
74 /// );
75 /// }
76 /// ```
77 struct DepthImage {
78 /// The raw depth image data.
79 std::optional<ComponentBatch> buffer;
80
81 /// The format of the image.
82 std::optional<ComponentBatch> format;
83
84 /// An optional floating point value that specifies how long a meter is in the native depth units.
85 ///
86 /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision
87 /// and a range of up to ~65 meters (2^16 / 1000).
88 ///
89 /// Note that the only effect on 2D views is the physical depth values shown when hovering the image.
90 /// In 3D views on the other hand, this affects where the points of the point cloud are placed.
91 std::optional<ComponentBatch> meter;
92
93 /// Colormap to use for rendering the depth image.
94 ///
95 /// If not set, the depth image will be rendered using the Turbo colormap.
96 std::optional<ComponentBatch> colormap;
97
98 /// The expected range of depth values.
99 ///
100 /// This is typically the expected range of valid values.
101 /// Everything outside of the range is clamped to the range for the purpose of colormpaping.
102 /// Note that point clouds generated from this image will still display all points, regardless of this range.
103 ///
104 /// If not specified, the range will be automatically estimated from the data.
105 /// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
106 /// in the contents of the depth image.
107 /// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
108 /// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
109 std::optional<ComponentBatch> depth_range;
110
111 /// Scale the radii of the points in the point cloud generated from this image.
112 ///
113 /// A fill ratio of 1.0 (the default) means that each point is as big as to touch the center of its neighbor
114 /// if it is at the same depth, leaving no gaps.
115 /// A fill ratio of 0.5 means that each point touches the edge of its neighbor if it has the same depth.
116 ///
117 /// TODO(#6744): This applies only to 3D views!
118 std::optional<ComponentBatch> point_fill_ratio;
119
120 /// An optional floating point value that specifies the 2D drawing order, used only if the depth image is shown as a 2D image.
121 ///
122 /// Objects with higher values are drawn on top of those with lower values.
123 std::optional<ComponentBatch> draw_order;
124
125 public:
126 static constexpr const char IndicatorComponentName[] =
127 "rerun.components.DepthImageIndicator";
128
129 /// Indicator component, used to identify the archetype when converting to a list of components.
131 /// The name of the archetype as used in `ComponentDescriptor`s.
132 static constexpr const char ArchetypeName[] = "rerun.archetypes.DepthImage";
133
134 /// `ComponentDescriptor` for the `buffer` field.
135 static constexpr auto Descriptor_buffer = ComponentDescriptor(
136 ArchetypeName, "buffer",
138 );
139 /// `ComponentDescriptor` for the `format` field.
140 static constexpr auto Descriptor_format = ComponentDescriptor(
141 ArchetypeName, "format",
143 );
144 /// `ComponentDescriptor` for the `meter` field.
145 static constexpr auto Descriptor_meter = ComponentDescriptor(
146 ArchetypeName, "meter",
148 );
149 /// `ComponentDescriptor` for the `colormap` field.
151 ArchetypeName, "colormap",
153 );
154 /// `ComponentDescriptor` for the `depth_range` field.
156 ArchetypeName, "depth_range",
158 );
159 /// `ComponentDescriptor` for the `point_fill_ratio` field.
161 ArchetypeName, "point_fill_ratio",
163 );
164 /// `ComponentDescriptor` for the `draw_order` field.
166 ArchetypeName, "draw_order",
168 );
169
170 public: // START of extensions from depth_image_ext.cpp:
171 /// Constructs image from pointer + resolution, inferring the datatype from the pointer type.
172 ///
173 /// @param pixels The raw image data.
174 /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image.
175 /// The number of elements is assumed to be `W * H`.
176 /// @param resolution The resolution of the image as {width, height}.
177 template <typename TElement>
178 DepthImage(const TElement* pixels, WidthHeight resolution)
179 : DepthImage{
180 reinterpret_cast<const uint8_t*>(pixels), resolution, get_datatype(pixels)} {}
181
182 /// Constructs image from pixel data + resolution with datatype inferred from the passed collection.
183 ///
184 /// @param pixels The raw image data.
185 /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection`
186 /// explicitly ahead of time with `rerun::Collection::take_ownership`.
187 /// The length of the data should be `W * H`.
188 /// @param resolution The resolution of the image as {width, height}.
189 template <typename TElement>
191 : DepthImage{pixels.to_uint8(), resolution, get_datatype(pixels.data())} {}
192
193 /// Constructs image from pixel data + resolution with explicit datatype. Borrows data from a pointer (i.e. data must outlive the image!).
194 ///
195 /// @param bytes The raw image data.
196 /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image.
197 /// The byte size of the data is assumed to be `W * H * datatype.size`
198 /// @param resolution The resolution of the image as {width, height}.
199 /// @param datatype How the data should be interpreted.
200 DepthImage(const void* bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
201 : DepthImage{
202 Collection<uint8_t>::borrow(bytes, num_bytes(resolution, datatype)),
203 resolution,
204 datatype} {}
205
206 /// Constructs image from pixel data + resolution + datatype.
207 ///
208 /// @param bytes The raw image data as bytes.
209 /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection`
210 /// explicitly ahead of time with `rerun::Collection::take_ownership`.
211 /// The length of the data should be `W * H`.
212 /// @param resolution The resolution of the image as {width, height}.
213 /// @param datatype How the data should be interpreted.
216 ) {
217 auto image_format = datatypes::ImageFormat{resolution, datatype};
218 if (bytes.size() != image_format.num_bytes()) {
219 Error(
220 ErrorCode::InvalidTensorDimension,
221 "DepthImage buffer has the wrong size. Got " + std::to_string(bytes.size()) +
222 " bytes, expected " + std::to_string(image_format.num_bytes())
223 )
224 .handle();
225 }
226 *this = std::move(*this).with_buffer(bytes).with_format(image_format);
227 }
228
229 // END of extensions from depth_image_ext.cpp, start of generated code:
230
231 public:
232 DepthImage() = default;
233 DepthImage(DepthImage&& other) = default;
234 DepthImage(const DepthImage& other) = default;
235 DepthImage& operator=(const DepthImage& other) = default;
236 DepthImage& operator=(DepthImage&& other) = default;
237
238 /// Update only some specific fields of a `DepthImage`.
240 return DepthImage();
241 }
242
243 /// Clear all the fields of a `DepthImage`.
245
246 /// The raw depth image data.
248 buffer = ComponentBatch::from_loggable(_buffer, Descriptor_buffer).value_or_throw();
249 return std::move(*this);
250 }
251
252 /// This method makes it possible to pack multiple `buffer` in a single component batch.
253 ///
254 /// This only makes sense when used in conjunction with `columns`. `with_buffer` should
255 /// be used when logging a single row's worth of data.
257 buffer = ComponentBatch::from_loggable(_buffer, Descriptor_buffer).value_or_throw();
258 return std::move(*this);
259 }
260
261 /// The format of the image.
263 format = ComponentBatch::from_loggable(_format, Descriptor_format).value_or_throw();
264 return std::move(*this);
265 }
266
267 /// This method makes it possible to pack multiple `format` in a single component batch.
268 ///
269 /// This only makes sense when used in conjunction with `columns`. `with_format` should
270 /// be used when logging a single row's worth of data.
272 format = ComponentBatch::from_loggable(_format, Descriptor_format).value_or_throw();
273 return std::move(*this);
274 }
275
276 /// An optional floating point value that specifies how long a meter is in the native depth units.
277 ///
278 /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision
279 /// and a range of up to ~65 meters (2^16 / 1000).
280 ///
281 /// Note that the only effect on 2D views is the physical depth values shown when hovering the image.
282 /// In 3D views on the other hand, this affects where the points of the point cloud are placed.
284 meter = ComponentBatch::from_loggable(_meter, Descriptor_meter).value_or_throw();
285 return std::move(*this);
286 }
287
288 /// This method makes it possible to pack multiple `meter` in a single component batch.
289 ///
290 /// This only makes sense when used in conjunction with `columns`. `with_meter` should
291 /// be used when logging a single row's worth of data.
293 meter = ComponentBatch::from_loggable(_meter, Descriptor_meter).value_or_throw();
294 return std::move(*this);
295 }
296
297 /// Colormap to use for rendering the depth image.
298 ///
299 /// If not set, the depth image will be rendered using the Turbo colormap.
301 colormap =
302 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
303 return std::move(*this);
304 }
305
306 /// This method makes it possible to pack multiple `colormap` in a single component batch.
307 ///
308 /// This only makes sense when used in conjunction with `columns`. `with_colormap` should
309 /// be used when logging a single row's worth of data.
311 colormap =
312 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
313 return std::move(*this);
314 }
315
316 /// The expected range of depth values.
317 ///
318 /// This is typically the expected range of valid values.
319 /// Everything outside of the range is clamped to the range for the purpose of colormpaping.
320 /// Note that point clouds generated from this image will still display all points, regardless of this range.
321 ///
322 /// If not specified, the range will be automatically estimated from the data.
323 /// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
324 /// in the contents of the depth image.
325 /// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
326 /// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
329 .value_or_throw();
330 return std::move(*this);
331 }
332
333 /// This method makes it possible to pack multiple `depth_range` in a single component batch.
334 ///
335 /// This only makes sense when used in conjunction with `columns`. `with_depth_range` should
336 /// be used when logging a single row's worth of data.
339 ) && {
341 .value_or_throw();
342 return std::move(*this);
343 }
344
345 /// Scale the radii of the points in the point cloud generated from this image.
346 ///
347 /// A fill ratio of 1.0 (the default) means that each point is as big as to touch the center of its neighbor
348 /// if it is at the same depth, leaving no gaps.
349 /// A fill ratio of 0.5 means that each point touches the edge of its neighbor if it has the same depth.
350 ///
351 /// TODO(#6744): This applies only to 3D views!
355 .value_or_throw();
356 return std::move(*this);
357 }
358
359 /// This method makes it possible to pack multiple `point_fill_ratio` in a single component batch.
360 ///
361 /// This only makes sense when used in conjunction with `columns`. `with_point_fill_ratio` should
362 /// be used when logging a single row's worth of data.
364 const Collection<rerun::components::FillRatio>& _point_fill_ratio
365 ) && {
368 .value_or_throw();
369 return std::move(*this);
370 }
371
372 /// An optional floating point value that specifies the 2D drawing order, used only if the depth image is shown as a 2D image.
373 ///
374 /// Objects with higher values are drawn on top of those with lower values.
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:96
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:29
ChannelDatatype
Datatype: The innermost datatype of an image.
Definition channel_datatype.hpp:27
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=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
The width and height of an image.
Definition image_utils.hpp:13
Archetype: A depth image, i.e.
Definition depth_image.hpp:77
DepthImage with_colormap(const rerun::components::Colormap &_colormap) &&
Colormap to use for rendering the depth image.
Definition depth_image.hpp:300
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:283
std::optional< ComponentBatch > format
The format of the image.
Definition depth_image.hpp:82
static constexpr auto Descriptor_depth_range
ComponentDescriptor for the depth_range field.
Definition depth_image.hpp:155
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition depth_image.hpp:132
DepthImage(Collection< uint8_t > bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
Constructs image from pixel data + resolution + datatype.
Definition depth_image.hpp:214
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:352
static constexpr auto Descriptor_point_fill_ratio
ComponentDescriptor for the point_fill_ratio field.
Definition depth_image.hpp:160
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:239
std::optional< ComponentBatch > colormap
Colormap to use for rendering the depth image.
Definition depth_image.hpp:96
std::optional< ComponentBatch > depth_range
The expected range of depth values.
Definition depth_image.hpp:109
static constexpr auto Descriptor_format
ComponentDescriptor for the format field.
Definition depth_image.hpp:140
DepthImage with_depth_range(const rerun::components::ValueRange &_depth_range) &&
The expected range of depth values.
Definition depth_image.hpp:327
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:150
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:91
DepthImage(Collection< TElement > pixels, WidthHeight resolution)
Constructs image from pixel data + resolution with datatype inferred from the passed collection.
Definition depth_image.hpp:190
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:123
static constexpr auto Descriptor_draw_order
ComponentDescriptor for the draw_order field.
Definition depth_image.hpp:165
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:363
static constexpr auto Descriptor_buffer
ComponentDescriptor for the buffer field.
Definition depth_image.hpp:135
DepthImage(const void *bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
Constructs image from pixel data + resolution with explicit datatype.
Definition depth_image.hpp:200
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:310
DepthImage(const TElement *pixels, WidthHeight resolution)
Constructs image from pointer + resolution, inferring the datatype from the pointer type.
Definition depth_image.hpp:178
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:292
std::optional< ComponentBatch > point_fill_ratio
Scale the radii of the points in the point cloud generated from this image.
Definition depth_image.hpp:118
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:262
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:337
DepthImage with_buffer(const rerun::components::ImageBuffer &_buffer) &&
The raw depth image data.
Definition depth_image.hpp:247
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:271
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:256
static constexpr auto Descriptor_meter
ComponentDescriptor for the meter field.
Definition depth_image.hpp:145
std::optional< ComponentBatch > buffer
The raw depth image data.
Definition depth_image.hpp:79
Component: The world->depth map scaling factor.
Definition depth_meter.hpp:22
Component: Draw order of 2D elements.
Definition draw_order.hpp:20
Component: How much a primitive fills out the available space.
Definition fill_ratio.hpp:20
Component: A buffer that is known to store image data.
Definition image_buffer.hpp:19
Component: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:15
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: Range of expected or valid values, specifying a lower and upper bound.
Definition value_range.hpp:16
Datatype: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:25