Rerun C++ SDK
Loading...
Searching...
No Matches
depth_image.hpp
1// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/re_types/definitions/rerun/archetypes/depth_image.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../components/depth_meter.hpp"
9#include "../components/draw_order.hpp"
10#include "../components/tensor_data.hpp"
11#include "../data_cell.hpp"
12#include "../indicator_component.hpp"
13#include "../result.hpp"
14
15#include <cstdint>
16#include <optional>
17#include <utility>
18#include <vector>
19
20namespace rerun::archetypes {
21 /// **Archetype**: A depth image.
22 ///
23 /// The shape of the `TensorData` must be mappable to an `HxW` tensor.
24 /// Each pixel corresponds to a depth value in units specified by `meter`.
25 ///
26 /// Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
27 /// data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
28 /// If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
29 ///
30 /// ## Example
31 ///
32 /// ### Depth to 3D example
33 /// ![image](https://static.rerun.io/depth_image_3d/f78674bdae0eb25786c6173307693c5338f38b87/full.png)
34 ///
35 /// ```cpp
36 /// #include <rerun.hpp>
37 ///
38 /// #include <algorithm> // fill_n
39 /// #include <vector>
40 ///
41 /// int main() {
42 /// const auto rec = rerun::RecordingStream("rerun_example_depth_image");
43 /// rec.spawn().exit_on_failure();
44 ///
45 /// // Create a synthetic depth image.
46 /// const int HEIGHT = 200;
47 /// const int WIDTH = 300;
48 /// std::vector<uint16_t> data(WIDTH * HEIGHT, 65535);
49 /// for (auto y = 50; y <150; ++y) {
50 /// std::fill_n(data.begin() + y * WIDTH + 50, 100, static_cast<uint16_t>(20000));
51 /// }
52 /// for (auto y = 130; y <180; ++y) {
53 /// std::fill_n(data.begin() + y * WIDTH + 100, 180, static_cast<uint16_t>(45000));
54 /// }
55 ///
56 /// // If we log a pinhole camera model, the depth gets automatically back-projected to 3D
57 /// rec.log(
58 /// "world/camera",
59 /// rerun::Pinhole::from_focal_length_and_resolution(
60 /// 200.0f,
61 /// {static_cast<float>(WIDTH), static_cast<float>(HEIGHT)}
62 /// )
63 /// );
64 ///
65 /// rec.log("world/camera/depth", rerun::DepthImage({HEIGHT, WIDTH}, data).with_meter(10000.0));
66 /// }
67 /// ```
68 struct DepthImage {
69 /// The depth-image data. Should always be a rank-2 tensor.
71
72 /// An optional floating point value that specifies how long a meter is in the native depth units.
73 ///
74 /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision
75 /// and a range of up to ~65 meters (2^16 / 1000).
76 std::optional<rerun::components::DepthMeter> meter;
77
78 /// An optional floating point value that specifies the 2D drawing order.
79 ///
80 /// Objects with higher values are drawn on top of those with lower values.
81 std::optional<rerun::components::DrawOrder> draw_order;
82
83 public:
84 static constexpr const char IndicatorComponentName[] =
85 "rerun.components.DepthImageIndicator";
86
87 /// Indicator component, used to identify the archetype when converting to a list of components.
89
90 public:
91 // Extensions to generated type defined in 'depth_image_ext.cpp'
92
93 /// New depth image from height/width and tensor buffer.
94 ///
95 /// \param shape
96 /// Shape of the image. Calls `Error::handle()` if the shape is not rank 2.
97 /// Sets the dimension names to "height" and "width" if they are not specified.
98 /// \param buffer
99 /// The tensor buffer containing the depth image data.
101 : DepthImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {}
102
103 /// New depth image from tensor data.
104 ///
105 /// \param data_
106 /// The tensor buffer containing the depth image data.
107 /// Sets the dimension names to "height" and "width" if they are not specified.
108 /// Calls `Error::handle()` if the shape is not rank 2.
110
111 /// New depth image from dimensions and pointer to depth image data.
112 ///
113 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
114 /// \param shape
115 /// Shape of the image. Calls `Error::handle()` if the shape is not rank 2.
116 /// Sets the dimension names to "height", "width" and "channel" if they are not specified.
117 /// Determines the number of elements expected to be in `data`.
118 /// \param data_
119 /// Target of the pointer must outlive the archetype.
120 template <typename TElement>
121 explicit DepthImage(Collection<datatypes::TensorDimension> shape, const TElement* data_)
122 : DepthImage(datatypes::TensorData(std::move(shape), data_)) {}
123
124 public:
125 DepthImage() = default;
126 DepthImage(DepthImage&& other) = default;
127
128 /// An optional floating point value that specifies how long a meter is in the native depth units.
129 ///
130 /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision
131 /// and a range of up to ~65 meters (2^16 / 1000).
133 meter = std::move(_meter);
134 // See: https://github.com/rerun-io/rerun/issues/4027
135 RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
136 }
137
138 /// An optional floating point value that specifies the 2D drawing order.
139 ///
140 /// Objects with higher values are drawn on top of those with lower values.
142 draw_order = std::move(_draw_order);
143 // See: https://github.com/rerun-io/rerun/issues/4027
144 RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
145 }
146
147 /// Returns the number of primary instances of this archetype.
148 size_t num_instances() const {
149 return 1;
150 }
151 };
152
153} // namespace rerun::archetypes
154
155namespace rerun {
156 /// \private
157 template <typename T>
158 struct AsComponents;
159
160 /// \private
161 template <>
162 struct AsComponents<archetypes::DepthImage> {
163 /// Serialize all set component batches.
164 static Result<std::vector<DataCell>> serialize(const archetypes::DepthImage& archetype);
165 };
166} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:47
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:66
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:20
Archetype: A depth image.
Definition depth_image.hpp:68
rerun::components::TensorData data
The depth-image data. Should always be a rank-2 tensor.
Definition depth_image.hpp:70
std::optional< rerun::components::DrawOrder > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition depth_image.hpp:81
size_t num_instances() const
Returns the number of primary instances of this archetype.
Definition depth_image.hpp:148
DepthImage(Collection< datatypes::TensorDimension > shape, const TElement *data_)
New depth image from dimensions and pointer to depth image data.
Definition depth_image.hpp:121
DepthImage(Collection< datatypes::TensorDimension > shape, datatypes::TensorBuffer buffer)
New depth image from height/width and tensor buffer.
Definition depth_image.hpp:100
DepthImage(components::TensorData data_)
New depth image from tensor data.
DepthImage with_meter(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:132
std::optional< 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:76
DepthImage with_draw_order(rerun::components::DrawOrder _draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition depth_image.hpp:141
Component: A component indicating how long a meter is, expressed in native units.
Definition depth_meter.hpp:24
Component: Draw order used for the display order of 2D elements.
Definition draw_order.hpp:30
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:23
Component: A multi-dimensional Tensor with optionally named arguments.
Definition tensor_data.hpp:21
Datatype: The underlying storage for a Tensor.
Definition tensor_buffer.hpp:93
Datatype: A multi-dimensional Tensor of data.
Definition tensor_data.hpp:29