Skip to content

Commit 9fdbd69

Browse files
authored
New DepthImage archetype (#6915)
### What * Part of #6386 This changes `DepthImage` from a tensor to a byte-blob + resolution + data-type. It adds new code for hovering images and uploading images to GPU, both general enough to also work for color images and segmentation images. This means those PRs will be a lot smaller. Since we still need to support color and segmentation images encoded as tensors, the code is quite complex, with duplicated paths here and there. It will all get cleaned up in later PRs. I'm reusing a lot of stuff from tensors, like `TensorMeaning`, `TensorStats` `TensorElement`, but these will be renamed and improved before #6386 is done. ### TODO * [x] Update `depth_image_ext.cpp` * [x] Update `depth_image_ext.py` * [x] Fix hovering depth images in 3D view ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/6915?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/6915?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide * [x] Test a few local examples - [PR Build Summary](https://build.rerun.io/pr/6915) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`.
1 parent 7176015 commit 9fdbd69

93 files changed

Lines changed: 3963 additions & 693 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* `mesh_material: Material` has been renamed to `albedo_factor: AlbedoFactor` [#6841](https://github.com/rerun-io/rerun/pull/6841)
77
* 3D transform APIs: Previously, the transform component was represented as one of several variants (an Arrow union, `enum` in Rust) depending on how the transform was expressed. Instead, there are now several components for translation/scale/rotation/matrices that can live side-by-side in the 3D transform archetype.
88
* Python: `NV12/YUY2` are now logged with the new `ImageChromaDownsampled`
9-
* `ImageEncoded`:s `format` parameter has been replaced with `media_type` (MIME)
9+
* [`ImageEncoded`](https://rerun.io/docs/reference/types/archetypes/image_encoded?speculative-link):s `format` parameter has been replaced with `media_type` (MIME)
10+
* [`DepthImage`](https://rerun.io/docs/reference/types/archetypes/depth_image) is no longer encoded as a tensor, and expects its shape in `[width, height]` order
1011

1112
🧳 Migration guide: http://rerun.io/docs/reference/migration/migration-0-18?speculative-link
1213

CODE_STYLE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ Preprocessor directives/macros are usually prefixed with `RR_`
215215

216216
Include what you use: if you use `std::vector`, then include `<vector>` - don't depend on a transitive include.
217217

218+
We prefer the "data, length" parameter order, e.g. `void foo(const void* data, size_t len)` or `void image(const f32* data, Resolution resolution)`.
219+
218220

219221
## Naming
220222
We prefer `snake_case` to `kebab-case` for most things (e.g. crate names, crate features, …). `snake_case` is a valid identifier in almost any programming language, while `kebab-case` is not. This means one can use the same `snake_case` identifier everywhere, and not think about whether it needs to be written as `snake_case` in some circumstances.

crates/build/re_types_builder/src/codegen/cpp/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ impl CppCodeGenerator {
181181

182182
for &obj in &objects_of_kind {
183183
if let Err(err) = generate_object_files(
184+
reporter,
184185
objects,
185186
&folder_path_sdk,
186187
&folder_path_testing,
@@ -225,6 +226,7 @@ impl CppCodeGenerator {
225226
}
226227

227228
fn generate_object_files(
229+
reporter: &Reporter,
228230
objects: &Objects,
229231
folder_path_sdk: &Utf8PathBuf,
230232
folder_path_testing: &Utf8PathBuf,
@@ -242,7 +244,7 @@ fn generate_object_files(
242244
let (hpp_type_extensions, hpp_extension_string) =
243245
hpp_type_extensions(folder_path_sdk, &filename_stem, &mut hpp_includes);
244246

245-
let (hpp, cpp) = generate_hpp_cpp(objects, obj, hpp_includes, &hpp_type_extensions)?;
247+
let (hpp, cpp) = generate_hpp_cpp(reporter, objects, obj, hpp_includes, &hpp_type_extensions)?;
246248

247249
for (extension, tokens) in [("hpp", Some(hpp)), ("cpp", cpp)] {
248250
let Some(tokens) = tokens else {
@@ -351,13 +353,14 @@ fn hpp_type_extensions(
351353
}
352354

353355
fn generate_hpp_cpp(
356+
reporter: &Reporter,
354357
objects: &Objects,
355358
obj: &Object,
356359
hpp_includes: Includes,
357360
hpp_type_extensions: &TokenStream,
358361
) -> Result<(TokenStream, Option<TokenStream>)> {
359362
let QuotedObject { hpp, cpp } =
360-
QuotedObject::new(objects, obj, hpp_includes, hpp_type_extensions)?;
363+
QuotedObject::new(reporter, objects, obj, hpp_includes, hpp_type_extensions)?;
361364
let snake_case_name = obj.snake_case_name();
362365
let hash = quote! { # };
363366
let pragma_once = pragma_once();
@@ -392,6 +395,7 @@ struct QuotedObject {
392395
impl QuotedObject {
393396
#[allow(clippy::unnecessary_wraps)] // TODO(emilk): implement proper error handling instead of panicking
394397
pub fn new(
398+
reporter: &Reporter,
395399
objects: &Objects,
396400
obj: &Object,
397401
hpp_includes: Includes,
@@ -412,11 +416,16 @@ impl QuotedObject {
412416
hpp_type_extensions,
413417
)),
414418
ObjectKind::View => {
415-
// TODO(#5521): Implement view codegen for Rust.
419+
// TODO(#5521): Implement view codegen for C++.
416420
unimplemented!();
417421
}
418422
},
419-
ObjectClass::Enum => Ok(Self::from_enum(objects, obj, hpp_includes)),
423+
ObjectClass::Enum => {
424+
if !hpp_type_extensions.is_empty() {
425+
reporter.error(&obj.virtpath, &obj.fqname, "C++ enums cannot have type extensions, because C++ enums doesn't support member functions");
426+
}
427+
Ok(Self::from_enum(objects, obj, hpp_includes))
428+
}
420429
ObjectClass::Union => Ok(Self::from_union(
421430
objects,
422431
obj,

crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ table DepthImage (
2525
) {
2626
// --- Required ---
2727

28-
/// The depth-image data. Should always be a 2-dimensional tensor.
29-
data: rerun.components.TensorData ("attr.rerun.component_required", order: 1000);
28+
/// The raw depth image data.
29+
data: rerun.components.Blob ("attr.rerun.component_required", order: 1000);
30+
31+
/// The size of the image
32+
resolution: rerun.components.Resolution2D ("attr.rerun.component_required", order: 1500);
33+
34+
/// The data type of the depth image data (U16, F32, …).
35+
data_type: rerun.components.ChannelDataType ("attr.rerun.component_required", order: 2000);
3036

3137
// --- Optional ---
3238

crates/store/re_types/definitions/rerun/components.fbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ include "./components/albedo_factor.fbs";
33
include "./components/annotation_context.fbs";
44
include "./components/axis_length.fbs";
55
include "./components/blob.fbs";
6+
include "./components/channel_data_type.fbs";
67
include "./components/class_id.fbs";
78
include "./components/clear_is_recursive.fbs";
9+
include "./components/color_model.fbs";
810
include "./components/color.fbs";
911
include "./components/colormap.fbs";
1012
include "./components/depth_meter.fbs";
@@ -31,6 +33,7 @@ include "./components/position3d.fbs";
3133
include "./components/radius.fbs";
3234
include "./components/range1d.fbs";
3335
include "./components/resolution.fbs";
36+
include "./components/resolution2d.fbs";
3437
include "./components/rotation3d.fbs";
3538
include "./components/scalar.fbs";
3639
include "./components/scale3d.fbs";
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
include "arrow/attributes.fbs";
2+
include "python/attributes.fbs";
3+
include "rust/attributes.fbs";
4+
5+
include "rerun/datatypes.fbs";
6+
include "rerun/attributes.fbs";
7+
8+
namespace rerun.components;
9+
10+
/// The innermost datatype of an image.
11+
///
12+
/// How individual color channel components are encoded.
13+
enum ChannelDataType: byte {
14+
/// 8-bit unsigned integer.
15+
U8 (default),
16+
17+
/// 16-bit unsigned integer.
18+
U16,
19+
20+
/// 32-bit unsigned integer.
21+
U32,
22+
23+
/// 64-bit unsigned integer.
24+
U64,
25+
26+
/// 8-bit signed integer.
27+
I8,
28+
29+
/// 16-bit signed integer.
30+
I16,
31+
32+
/// 32-bit signed integer.
33+
I32,
34+
35+
/// 64-bit signed integer.
36+
I64,
37+
38+
/// 16-bit IEEE-754 floating point, also known as `half`.
39+
F16,
40+
41+
/// 32-bit IEEE-754 floating point, also known as `float` or `single`.
42+
F32,
43+
44+
/// 64-bit IEEE-754 floating point, also known as `double`.
45+
F64,
46+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include "rerun/attributes.fbs";
2+
3+
namespace rerun.components;
4+
5+
/// Specified what color components are present in an [archetypes.Image].
6+
///
7+
/// This combined with [components.ChannelDataType] determines the pixel format of an image.
8+
enum ColorModel: byte {
9+
/// Grayscale luminance intencity/brightness/value, sometimes called `Y`
10+
L (default),
11+
12+
/// Red, Green, Blue
13+
RGB,
14+
15+
/// Red, Green, Blue, Alpha
16+
RGBA,
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
include "arrow/attributes.fbs";
2+
include "python/attributes.fbs";
3+
include "rust/attributes.fbs";
4+
5+
include "rerun/datatypes.fbs";
6+
include "rerun/attributes.fbs";
7+
8+
namespace rerun.components;
9+
10+
// ---
11+
12+
/// The width and height of a 2D image.
13+
struct Resolution2D (
14+
"attr.python.aliases": "npt.NDArray[np.int], Sequence[int], Tuple[int, int]",
15+
"attr.python.array_aliases": "npt.NDArray[np.int], Sequence[int]",
16+
"attr.rust.derive": "Default, Copy, PartialEq, Eq, Hash, bytemuck::Pod, bytemuck::Zeroable",
17+
"attr.rust.repr": "transparent"
18+
) {
19+
wh: rerun.datatypes.UVec2D (order: 100);
20+
}

crates/store/re_types/src/archetypes/depth_image.rs

Lines changed: 71 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)