Skip to content

Commit

Permalink
Tensor & depth image value ranges can now be configured (from ui & co…
Browse files Browse the repository at this point in the history
…de) (#7549)

### What

* Fixes #6106
* Fixes #2341
* NOT included here is image ranges, this PR is only about things
affecting colormaps (#4624)

Depth images (and their clouds):


https://github.com/user-attachments/assets/949ffb14-38e9-452d-a84f-695104f146c8

Tensors:


https://github.com/user-attachments/assets/eea3b38f-e4c7-4b97-9cc3-2fc6104ed6b7


Noteworth ripple effects & considerations in this PR:
* turns out depth image constructor on Python missed a lot of
parameters, fixed that
* went with a new `ValueRange` component rather than reusing `Range1D`
because the semantics (and names in the ui) of the later were just too
unclear
   * we need a tagged component mechanism really badly!
* decided against putting this on the tensor view as some notes
indicated was the plan
* ended up refactoring a few interesting things around image/tensor
handling:
* colormap is no longer part of `ImageInfo`, we already didn't use it
for hashing it. Having now a range made it even more clear that this
doesn't belong there
* `finite_range` on tensor & image is now always present, using the
datatypes' finite range as fallback. The `None` case handling was
awkward at best and non-existant (error out) usually

### 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/7549?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/7549?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

- [PR Build Summary](https://build.rerun.io/pr/7549)
- [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`.
  • Loading branch information
Wumpf authored Oct 1, 2024
1 parent 49fee63 commit c4eb805
Show file tree
Hide file tree
Showing 73 changed files with 1,175 additions and 295 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5572,6 +5572,7 @@ dependencies = [
"re_chunk_store",
"re_data_ui",
"re_log_types",
"re_query",
"re_renderer",
"re_space_view",
"re_tracing",
Expand Down
19 changes: 16 additions & 3 deletions crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace rerun.archetypes;
///
/// Each pixel corresponds to a depth value in units specified by [components.DepthMeter].
///
/// \cpp Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
/// \cpp Since the underlying `rerun::datatypes::ImageBuffer` uses `rerun::Collection` internally,
/// \cpp data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
/// \cpp If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
///
Expand Down Expand Up @@ -41,17 +41,30 @@ table DepthImage (
/// If not set, the depth image will be rendered using the Turbo colormap.
colormap: rerun.components.Colormap ("attr.rerun.component_optional", nullable, order: 3200);

/// The expected range of depth values.
///
/// This is typically the expected range of valid values.
/// Everything outside of the range is clamped to the range for the purpose of colormpaping.
/// Note that point clouds generated from this image will still display all points, regardless of this range.
///
/// If not specified, the range will be automatically estimated from the data.
/// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
/// in the contents of the depth image.
/// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
/// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
depth_range: rerun.components.ValueRange ("attr.rerun.component_optional", nullable, order: 3300);

/// Scale the radii of the points in the point cloud generated from this image.
///
/// A fill ratio of 1.0 (the default) means that each point is as big as to touch the center of its neighbor
/// if it is at the same depth, leaving no gaps.
/// A fill ratio of 0.5 means that each point touches the edge of its neighbor if it has the same depth.
///
/// TODO(#6744): This applies only to 3D views!
point_fill_ratio: rerun.components.FillRatio ("attr.rerun.component_optional", nullable, order: 3300);
point_fill_ratio: rerun.components.FillRatio ("attr.rerun.component_optional", nullable, order: 3400);

/// An optional floating point value that specifies the 2D drawing order, used only if the depth image is shown as a 2D image.
///
/// Objects with higher values are drawn on top of those with lower values.
draw_order: rerun.components.DrawOrder ("attr.rerun.component_optional", nullable, order: 3400);
draw_order: rerun.components.DrawOrder ("attr.rerun.component_optional", nullable, order: 3500);
}
15 changes: 15 additions & 0 deletions crates/store/re_types/definitions/rerun/archetypes/tensor.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@ table Tensor (
) {
/// The tensor data
data: rerun.components.TensorData ("attr.rerun.component_required", order: 1000);

// --- Optional ---

/// The expected range of values.
///
/// This is typically the expected range of valid values.
/// Everything outside of the range is clamped to the range for the purpose of colormpaping.
/// Any colormap applied for display, will map this range.
///
/// If not specified, the range will be automatically estimated from the data.
/// Note that the Viewer may try to guess a wider range than the minimum/maximum of values
/// in the contents of the tensor.
/// E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0,
/// the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.
value_range: rerun.components.ValueRange ("attr.rerun.component_optional", nullable, order: 2000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ table TensorScalarMapping (
///
/// Raises the normalized values to the power of this value before mapping to color.
/// Acts like an inverse brightness. Defaults to 1.0.
///
/// The final value for display is set as:
/// `colormap( ((value - data_display_range.min) / (data_display_range.max - data_display_range.min)) ** gamma )`
gamma: rerun.components.GammaCorrection ("attr.rerun.component_optional", nullable, order: 1200);

// TODO(andreas): explicit scalar ranges should go in here as well!
// Overall we should communicate scalar mapping to work like this here
// https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.PowerNorm.html#matplotlib.colors.PowerNorm
// (value - vmin) ** gamma / (vmax - vmin) ** gamma
}
1 change: 1 addition & 0 deletions crates/store/re_types/definitions/rerun/components.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions crates/store/re_types/definitions/rerun/components/value_range.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace rerun.components;

// ---

/// Range of expected or valid values, specifying a lower and upper bound.
struct ValueRange (
"attr.rust.derive": "Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent"
) {
range: rerun.datatypes.Range1D (order: 100);
}
59 changes: 55 additions & 4 deletions crates/store/re_types/src/archetypes/depth_image.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/store/re_types/src/archetypes/depth_image_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl DepthImage {
meter: None,
colormap: None,
point_fill_ratio: None,
depth_range: None,
})
}
}
66 changes: 58 additions & 8 deletions crates/store/re_types/src/archetypes/tensor.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c4eb805

Please sign in to comment.