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 "../compiler_utils.hpp"
8#include "../component_batch.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.
80
81 /// The format of the image.
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<rerun::components::DepthMeter> 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<rerun::components::Colormap> 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<rerun::components::ValueRange> 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<rerun::components::FillRatio> 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<rerun::components::DrawOrder> 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
132 public: // START of extensions from depth_image_ext.cpp:
133 /// Constructs image from pointer + resolution, inferring the datatype from the pointer type.
134 ///
135 /// @param pixels The raw image data.
136 /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image.
137 /// The number of elements is assumed to be `W * H`.
138 /// @param resolution The resolution of the image as {width, height}.
139 template <typename TElement>
140 DepthImage(const TElement* pixels, WidthHeight resolution)
141 : DepthImage{
142 reinterpret_cast<const uint8_t*>(pixels), resolution, get_datatype(pixels)} {}
143
144 /// Constructs image from pixel data + resolution with datatype inferred from the passed collection.
145 ///
146 /// @param pixels The raw image data.
147 /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection`
148 /// explicitly ahead of time with `rerun::Collection::take_ownership`.
149 /// The length of the data should be `W * H`.
150 /// @param resolution The resolution of the image as {width, height}.
151 template <typename TElement>
153 : DepthImage{pixels.to_uint8(), resolution, get_datatype(pixels.data())} {}
154
155 /// Constructs image from pixel data + resolution with explicit datatype. Borrows data from a pointer (i.e. data must outlive the image!).
156 ///
157 /// @param bytes The raw image data.
158 /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image.
159 /// The byte size of the data is assumed to be `W * H * datatype.size`
160 /// @param resolution The resolution of the image as {width, height}.
161 /// @param datatype How the data should be interpreted.
162 DepthImage(const void* bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
163 : DepthImage{
164 Collection<uint8_t>::borrow(bytes, num_bytes(resolution, datatype)),
165 resolution,
166 datatype} {}
167
168 /// Constructs image from pixel data + resolution + datatype.
169 ///
170 /// @param bytes The raw image data as bytes.
171 /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection`
172 /// explicitly ahead of time with `rerun::Collection::take_ownership`.
173 /// The length of the data should be `W * H`.
174 /// @param resolution The resolution of the image as {width, height}.
175 /// @param datatype How the data should be interpreted.
178 )
179 : buffer{bytes}, format{datatypes::ImageFormat{resolution, datatype}} {
180 if (buffer.size() != format.image_format.num_bytes()) {
181 Error(
182 ErrorCode::InvalidTensorDimension,
183 "DepthnImage buffer has the wrong size. Got " + std::to_string(buffer.size()) +
184 " bytes, expected " + std::to_string(format.image_format.num_bytes())
185 )
186 .handle();
187 }
188 }
189
190 // END of extensions from depth_image_ext.cpp, start of generated code:
191
192 public:
193 DepthImage() = default;
194 DepthImage(DepthImage&& other) = default;
195
196 /// An optional floating point value that specifies how long a meter is in the native depth units.
197 ///
198 /// For instance: with uint16, perhaps meter=1000 which would mean you have millimeter precision
199 /// and a range of up to ~65 meters (2^16 / 1000).
200 ///
201 /// Note that the only effect on 2D views is the physical depth values shown when hovering the image.
202 /// In 3D views on the other hand, this affects where the points of the point cloud are placed.
204 meter = std::move(_meter);
205 // See: https://github.com/rerun-io/rerun/issues/4027
206 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
207 }
208
209 /// Colormap to use for rendering the depth image.
210 ///
211 /// If not set, the depth image will be rendered using the Turbo colormap.
213 colormap = std::move(_colormap);
214 // See: https://github.com/rerun-io/rerun/issues/4027
215 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
216 }
217
218 /// The expected range of depth values.
219 ///
220 /// This is typically the expected range of valid values.
221 /// Everything outside of the range is clamped to the range for the purpose of colormpaping.
222 /// Note that point clouds generated from this image will still display all points, regardless of this range.
223 ///
224 /// If not specified, the range will be automatically estimated from the data.
225 /// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
226 /// in the contents of the depth image.
227 /// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
228 /// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
230 depth_range = std::move(_depth_range);
231 // See: https://github.com/rerun-io/rerun/issues/4027
232 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
233 }
234
235 /// Scale the radii of the points in the point cloud generated from this image.
236 ///
237 /// A fill ratio of 1.0 (the default) means that each point is as big as to touch the center of its neighbor
238 /// if it is at the same depth, leaving no gaps.
239 /// A fill ratio of 0.5 means that each point touches the edge of its neighbor if it has the same depth.
240 ///
241 /// TODO(#6744): This applies only to 3D views!
243 point_fill_ratio = std::move(_point_fill_ratio);
244 // See: https://github.com/rerun-io/rerun/issues/4027
245 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
246 }
247
248 /// An optional floating point value that specifies the 2D drawing order, used only if the depth image is shown as a 2D image.
249 ///
250 /// Objects with higher values are drawn on top of those with lower values.
252 draw_order = std::move(_draw_order);
253 // See: https://github.com/rerun-io/rerun/issues/4027
254 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
255 }
256 };
257
258} // namespace rerun::archetypes
259
260namespace rerun {
261 /// \private
262 template <typename T>
263 struct AsComponents;
264
265 /// \private
266 template <>
267 struct AsComponents<archetypes::DepthImage> {
268 /// Serialize all set component batches.
269 static Result<std::vector<ComponentBatch>> serialize(const archetypes::DepthImage& archetype
270 );
271 };
272} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:95
void handle() const
Handle this error based on the set log handler.
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:22
Collection< TElement > borrow(const TElement *data, size_t num_instances=1)
Borrows binary data into a Collection from a pointer.
Definition collection.hpp:461
The width and height of an image.
Definition image_utils.hpp:13
Archetype: A depth image, i.e.
Definition depth_image.hpp:77
rerun::components::ImageFormat format
The format of the image.
Definition depth_image.hpp:82
std::optional< 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:123
rerun::components::ImageBuffer buffer
The raw depth image data.
Definition depth_image.hpp:79
std::optional< rerun::components::Colormap > colormap
Colormap to use for rendering the depth image.
Definition depth_image.hpp:96
DepthImage with_colormap(rerun::components::Colormap _colormap) &&
Colormap to use for rendering the depth image.
Definition depth_image.hpp:212
DepthImage(Collection< uint8_t > bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
Constructs image from pixel data + resolution + datatype.
Definition depth_image.hpp:176
DepthImage with_point_fill_ratio(rerun::components::FillRatio _point_fill_ratio) &&
Scale the radii of the points in the point cloud generated from this image.
Definition depth_image.hpp:242
std::optional< rerun::components::FillRatio > point_fill_ratio
Scale the radii of the points in the point cloud generated from this image.
Definition depth_image.hpp:118
DepthImage(Collection< TElement > pixels, WidthHeight resolution)
Constructs image from pixel data + resolution with datatype inferred from the passed collection.
Definition depth_image.hpp:152
std::optional< rerun::components::ValueRange > depth_range
The expected range of depth values.
Definition depth_image.hpp:109
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:203
DepthImage(const void *bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype)
Constructs image from pixel data + resolution with explicit datatype.
Definition depth_image.hpp:162
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:91
DepthImage with_depth_range(rerun::components::ValueRange _depth_range) &&
The expected range of depth values.
Definition depth_image.hpp:229
DepthImage(const TElement *pixels, WidthHeight resolution)
Constructs image from pointer + resolution, inferring the datatype from the pointer type.
Definition depth_image.hpp:140
DepthImage with_draw_order(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:251
Component: The world->depth map scaling factor.
Definition depth_meter.hpp:21
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
size_t size() const
Number of bytes.
Definition image_buffer.hpp:23
Component: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:14
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:30
Component: Range of expected or valid values, specifying a lower and upper bound.
Definition value_range.hpp:15
size_t num_bytes() const
How many bytes will this image occupy?
Definition image_format.hpp:65