Skip to content

Commit d35e3ab

Browse files
authored
Expose FillRatio component to configure DepthImage backprojection radius scaling (#6566)
### What Introduces `FillRatio` component. Example: ```python rr.log("world/camera/depth", rr.DepthImage(depth_image, meter=10_000.0, backproject_radius_scale=0.2)) ``` * Almost done with #5067 * This was the last legacy property to blueprintify! * Only the actual cleanup is missing. Some of it already creeped in here since clippy noticed the cascade of unused things, but I went only as far as I had to to make it happy to keep this PR sane Works as before: <img width="1167" alt="image" src="https://github.com/rerun-io/rerun/assets/1220815/b564944b-c4a3-459a-a9a0-9692caeb5110"> Based on #6558 to avoid conflicts ### 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) * [ ] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/6566?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/6566?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)! - [PR Build Summary](https://build.rerun.io/pr/6566) - [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 5e91a30 commit d35e3ab

File tree

42 files changed

+585
-211
lines changed

Some content is hidden

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

42 files changed

+585
-211
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,6 +5137,7 @@ version = "0.17.0-alpha.4"
51375137
dependencies = [
51385138
"anyhow",
51395139
"backtrace",
5140+
"bytemuck",
51405141
"criterion",
51415142
"document-features",
51425143
"itertools 0.13.0",

crates/re_edit_ui/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use datatype_editors::edit_enum;
1313
use re_types::{
1414
blueprint::components::{BackgroundKind, Corner2D, LockRangeDuringZoom, Visible},
1515
components::{
16-
AggregationPolicy, AxisLength, Color, Colormap, ImagePlaneDistance, MarkerSize, Name,
17-
Radius, StrokeWidth, Text,
16+
AggregationPolicy, AxisLength, Color, Colormap, FillRatio, ImagePlaneDistance, MarkerSize,
17+
Name, Radius, StrokeWidth, Text,
1818
},
1919
};
2020
use re_viewer_context::ViewerContext;
@@ -45,17 +45,18 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) {
4545
registry.add_singleline_editor_ui(marker_shape::edit_marker_shape_ui);
4646
registry.add_singleline_editor_ui(range1d::edit_range1d);
4747

48-
registry.add_singleline_editor_ui::<ImagePlaneDistance>(datatype_editors::edit_f32_zero_to_inf);
4948
registry.add_singleline_editor_ui::<AxisLength>(datatype_editors::edit_f32_zero_to_inf);
49+
registry.add_singleline_editor_ui::<FillRatio>(datatype_editors::edit_f32_zero_to_inf);
50+
registry.add_singleline_editor_ui::<ImagePlaneDistance>(datatype_editors::edit_f32_zero_to_inf);
5051

5152
registry.add_singleline_editor_ui::<Visible>(datatype_editors::edit_bool_raw);
5253
registry.add_singleline_editor_ui::<LockRangeDuringZoom>(datatype_editors::edit_bool);
5354

5455
registry.add_singleline_editor_ui::<Text>(datatype_editors::edit_singleline_string);
5556
registry.add_singleline_editor_ui::<Name>(datatype_editors::edit_singleline_string);
5657

57-
registry.add_singleline_editor_ui::<Radius>(datatype_editors::edit_f32_zero_to_inf_raw);
5858
registry.add_singleline_editor_ui::<MarkerSize>(datatype_editors::edit_f32_zero_to_inf_raw);
59+
registry.add_singleline_editor_ui::<Radius>(datatype_editors::edit_f32_zero_to_inf_raw);
5960
registry.add_singleline_editor_ui::<StrokeWidth>(datatype_editors::edit_f32_zero_to_inf_raw);
6061

6162
registry.add_singleline_editor_ui(|_ctx, ui, value| {

crates/re_entity_db/src/entity_properties.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#[cfg(feature = "serde")]
22
use re_log_types::EntityPath;
33

4-
#[cfg(feature = "serde")]
5-
use crate::EditableAutoValue;
6-
74
// ----------------------------------------------------------------------------
85

96
/// Properties for a collection of entities.
107
#[cfg(feature = "serde")]
11-
#[derive(Clone, Default, PartialEq)]
8+
#[derive(Clone, Default, PartialEq, Eq)]
129
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1310
pub struct EntityPropertyMap {
1411
props: nohash_hasher::IntMap<EntityPath, EntityProperties>,
@@ -88,23 +85,19 @@ impl FromIterator<(EntityPath, EntityProperties)> for EntityPropertyMap {
8885
// ----------------------------------------------------------------------------
8986

9087
#[cfg(feature = "serde")]
91-
#[derive(Clone, Debug, PartialEq)]
88+
#[derive(Clone, Debug, PartialEq, Eq)]
9289
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
9390
#[cfg_attr(feature = "serde", serde(default))]
9491
pub struct EntityProperties {
9592
// TODO(#5067): Test property used so we don't have to continuously adjust existing tests while we're dismantling `EntityProperties`.
9693
pub test_property: bool,
97-
98-
/// Used to scale the radii of the points in the resulting point cloud.
99-
pub backproject_radius_scale: EditableAutoValue<f32>, // TODO(andreas): should be a component on the DepthImage archetype.
10094
}
10195

10296
#[cfg(feature = "serde")]
10397
impl Default for EntityProperties {
10498
fn default() -> Self {
10599
Self {
106100
test_property: true,
107-
backproject_radius_scale: EditableAutoValue::Auto(1.0),
108101
}
109102
}
110103
}
@@ -115,11 +108,6 @@ impl EntityProperties {
115108
pub fn with_child(&self, child: &Self) -> Self {
116109
Self {
117110
test_property: self.test_property && child.test_property,
118-
119-
backproject_radius_scale: self
120-
.backproject_radius_scale
121-
.or(&child.backproject_radius_scale)
122-
.clone(),
123111
}
124112
}
125113

@@ -130,25 +118,17 @@ impl EntityProperties {
130118
///
131119
/// This is important to combine the base-layer of up-to-date auto-values with values
132120
/// loaded from the Blueprint store where the Auto values are not up-to-date.
121+
#[allow(clippy::unused_self)] // TODO(andreas): we're on the way out anyways :)
133122
pub fn merge_with(&self, other: &Self) -> Self {
134123
Self {
135124
test_property: other.test_property,
136-
137-
backproject_radius_scale: other
138-
.backproject_radius_scale
139-
.or(&self.backproject_radius_scale)
140-
.clone(),
141125
}
142126
}
143127

144128
/// Determine whether this `EntityProperty` has user-edits relative to another `EntityProperty`
145129
pub fn has_edits(&self, other: &Self) -> bool {
146-
let Self {
147-
test_property,
148-
backproject_radius_scale,
149-
} = self;
130+
let Self { test_property } = self;
150131

151132
test_property != &other.test_property
152-
|| backproject_radius_scale.has_edits(&other.backproject_radius_scale)
153133
}
154134
}

crates/re_entity_db/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#![doc = document_features::document_features!()]
55
//!
66
7-
#![allow(unused_imports)] // TODO(andreas): temporary until entity_properties is removed.
8-
97
pub mod entity_db;
108
pub mod entity_properties;
119
pub mod entity_tree;
@@ -20,9 +18,11 @@ pub mod blueprint;
2018
#[cfg(feature = "serde")]
2119
mod editable_auto_value;
2220

21+
#[cfg(feature = "serde")]
22+
pub use self::entity_properties::*;
23+
2324
pub use self::{
2425
entity_db::EntityDb,
25-
entity_properties::*,
2626
entity_tree::EntityTree,
2727
instance_path::{InstancePath, InstancePathHash},
2828
store_bundle::{StoreBundle, StoreLoadError},

crates/re_selection_panel/src/selection_panel.rs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ use re_data_ui::{
77
item_ui::{guess_instance_path_icon, guess_query_and_db_for_selected_entity},
88
DataUi,
99
};
10-
use re_entity_db::{EditableAutoValue, EntityPath, EntityProperties, InstancePath};
10+
use re_entity_db::{EntityPath, InstancePath};
1111
use re_log_types::EntityPathFilter;
12-
use re_space_view::DataResultQuery as _;
12+
use re_space_view::{DataResultQuery as _, HybridLatestAtResults};
1313
use re_space_view_time_series::TimeSeriesSpaceView;
1414
use re_types::{
1515
archetypes::{Axes3D, DepthImage, Pinhole},
1616
blueprint::components::Interactive,
1717
components::{
18-
AxisLength, Colormap, DepthMeter, ImagePlaneDistance, PinholeProjection, Transform3D,
19-
VisualizerOverrides,
18+
AxisLength, Colormap, DepthMeter, FillRatio, ImagePlaneDistance, PinholeProjection,
19+
Transform3D, VisualizerOverrides,
2020
},
2121
tensor_data::TensorDataMeaning,
2222
};
@@ -1162,22 +1162,12 @@ fn blueprint_ui_for_data_result(
11621162
.lookup_result_by_path(entity_path)
11631163
.cloned()
11641164
{
1165-
let mut accumulated_legacy_props = data_result.accumulated_properties().clone();
1166-
let accumulated_legacy_props_before = accumulated_legacy_props.clone();
1167-
11681165
entity_props_ui(
11691166
ctx,
11701167
ui,
11711168
ctx.lookup_query_result(space_view_id),
11721169
&data_result,
1173-
&mut accumulated_legacy_props,
11741170
);
1175-
if accumulated_legacy_props != accumulated_legacy_props_before {
1176-
data_result.save_individual_override_properties(
1177-
ctx.viewer_ctx,
1178-
Some(accumulated_legacy_props),
1179-
);
1180-
}
11811171
}
11821172
}
11831173
}
@@ -1187,7 +1177,6 @@ fn entity_props_ui(
11871177
ui: &mut egui::Ui,
11881178
query_result: &DataQueryResult,
11891179
data_result: &DataResult,
1190-
entity_props: &mut EntityProperties,
11911180
) {
11921181
use re_types::blueprint::components::Visible;
11931182
use re_types::Loggable as _;
@@ -1261,18 +1250,18 @@ fn entity_props_ui(
12611250
// TODO(wumpf): It would be nice to only show pinhole & depth properties in the context of a 3D view.
12621251
// if *view_state.state_spatial.nav_mode.get() == SpatialNavigationMode::ThreeD {
12631252
pinhole_props_ui(ctx, ui, data_result);
1264-
depth_props_ui(ctx, ui, data_result, entity_path, entity_props);
1253+
depth_props_ui(ctx, ui, data_result, entity_path);
12651254
transform3d_visualization_ui(ctx, ui, data_result);
12661255
});
12671256
}
12681257

1269-
fn colormap_props_ui(ctx: &ViewContext<'_>, ui: &mut egui::Ui, data_result: &DataResult) {
1270-
let (query, _store) =
1271-
guess_query_and_db_for_selected_entity(ctx.viewer_ctx, &data_result.entity_path);
1272-
1273-
// TODO(andreas): Queries the entire image archetype for no good reason, but all of this ui is a hack anyways.
1274-
let results = data_result.latest_at_with_overrides::<DepthImage>(ctx, &query);
1275-
let colormap = results.get_mono_with_fallback::<Colormap>();
1258+
fn colormap_props_ui(
1259+
ctx: &ViewContext<'_>,
1260+
ui: &mut egui::Ui,
1261+
data_result: &DataResult,
1262+
depth_image_results: &HybridLatestAtResults<'_>,
1263+
) {
1264+
let colormap = depth_image_results.get_mono_with_fallback::<Colormap>();
12761265
let mut new_colormap = colormap;
12771266

12781267
ui.label("Color map");
@@ -1401,7 +1390,6 @@ fn depth_props_ui(
14011390
ui: &mut egui::Ui,
14021391
data_result: &DataResult,
14031392
entity_path: &EntityPath,
1404-
entity_props: &mut EntityProperties,
14051393
) -> Option<()> {
14061394
re_tracing::profile_function!();
14071395

@@ -1428,20 +1416,24 @@ fn depth_props_ui(
14281416
.on_hover_text("The entity path of the pinhole transform being used to do the backprojection.");
14291417
ui.end_row();
14301418

1431-
depth_from_world_scale_ui(ctx, ui, data_result);
1432-
backproject_radius_scale_ui(ui, &mut entity_props.backproject_radius_scale);
1433-
colormap_props_ui(ctx, ui, data_result);
1419+
let (query, _store) =
1420+
guess_query_and_db_for_selected_entity(ctx.viewer_ctx, &data_result.entity_path);
1421+
let depth_image_results = data_result.latest_at_with_overrides::<DepthImage>(ctx, &query);
1422+
1423+
depth_from_world_scale_ui(ctx, ui, data_result, &depth_image_results);
1424+
backproject_radius_scale_ui(ctx, ui, data_result, &depth_image_results);
1425+
colormap_props_ui(ctx, ui, data_result, &depth_image_results);
14341426

14351427
Some(())
14361428
}
14371429

1438-
fn depth_from_world_scale_ui(ctx: &ViewContext<'_>, ui: &mut egui::Ui, data_result: &DataResult) {
1439-
let (query, _store) =
1440-
guess_query_and_db_for_selected_entity(ctx.viewer_ctx, &data_result.entity_path);
1441-
1442-
// TODO(andreas): Queries the entire image archetype for no good reason, but all of this ui is a hack anyways.
1443-
let results = data_result.latest_at_with_overrides::<DepthImage>(ctx, &query);
1444-
let depth_meter = results.get_mono_with_fallback::<DepthMeter>();
1430+
fn depth_from_world_scale_ui(
1431+
ctx: &ViewContext<'_>,
1432+
ui: &mut egui::Ui,
1433+
data_result: &DataResult,
1434+
depth_image_results: &HybridLatestAtResults<'_>,
1435+
) {
1436+
let depth_meter = depth_image_results.get_mono_with_fallback::<DepthMeter>();
14451437

14461438
ui.label("Backproject meter");
14471439
let mut value = *depth_meter;
@@ -1464,9 +1456,16 @@ fn depth_from_world_scale_ui(ctx: &ViewContext<'_>, ui: &mut egui::Ui, data_resu
14641456
ui.end_row();
14651457
}
14661458

1467-
fn backproject_radius_scale_ui(ui: &mut egui::Ui, property: &mut EditableAutoValue<f32>) {
1459+
fn backproject_radius_scale_ui(
1460+
ctx: &ViewContext<'_>,
1461+
ui: &mut egui::Ui,
1462+
data_result: &DataResult,
1463+
depth_image_results: &HybridLatestAtResults<'_>,
1464+
) {
1465+
let radius_scale = depth_image_results.get_mono_with_fallback::<FillRatio>();
1466+
14681467
ui.label("Backproject radius scale");
1469-
let mut value = *property.get();
1468+
let mut value = *radius_scale.0;
14701469
let speed = (value * 0.01).at_least(0.001);
14711470
let response = ui
14721471
.add(
@@ -1481,10 +1480,10 @@ fn backproject_radius_scale_ui(ui: &mut egui::Ui, property: &mut EditableAutoVal
14811480
Double-click to reset.",
14821481
);
14831482
if response.double_clicked() {
1484-
*property = EditableAutoValue::Auto(2.0);
1483+
data_result.clear_individual_override::<FillRatio>(ctx.viewer_ctx);
14851484
response.surrender_focus();
14861485
} else if response.changed() {
1487-
*property = EditableAutoValue::UserEdited(value);
1486+
data_result.save_individual_override(ctx.viewer_ctx, &FillRatio(value.into()));
14881487
}
14891488
ui.end_row();
14901489
}

crates/re_space_view/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use heuristics::suggest_space_view_for_each_entity;
1414
pub use query::{
1515
latest_at_with_blueprint_resolved_data, range_with_blueprint_resolved_data, DataResultQuery,
1616
};
17-
pub use results_ext::{HybridResults, RangeResultsExt};
17+
pub use results_ext::{HybridLatestAtResults, HybridResults, RangeResultsExt};
1818
pub use screenshot::ScreenshotMode;
1919
pub use view_property_ui::view_property_ui;
2020

crates/re_space_view_spatial/src/heuristics.rs

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
1-
use std::collections::BTreeSet;
2-
31
use egui::NumExt as _;
42
use nohash_hasher::IntSet;
53

6-
use re_data_ui::image_meaning_for_entity;
7-
use re_entity_db::EditableAutoValue;
84
use re_log_types::EntityPath;
9-
use re_types::{tensor_data::TensorDataMeaning, SpaceViewClassIdentifier};
10-
use re_viewer_context::{IdentifiedViewSystem, PerSystemEntities, ViewerContext};
11-
12-
use crate::{
13-
view_kind::SpatialSpaceViewKind,
14-
visualizers::{ImageVisualizer, SpatialViewVisualizerData},
15-
};
16-
17-
pub fn generate_auto_legacy_properties(
18-
ctx: &ViewerContext<'_>,
19-
per_system_entities: &PerSystemEntities,
20-
) -> re_entity_db::EntityPropertyMap {
21-
re_tracing::profile_function!();
22-
23-
let mut auto_properties = re_entity_db::EntityPropertyMap::default();
5+
use re_types::SpaceViewClassIdentifier;
6+
use re_viewer_context::ViewerContext;
247

25-
// Do pinhole properties before, since they may be used in transform3d heuristics.
26-
update_depth_cloud_property_heuristics(ctx, per_system_entities, &mut auto_properties);
27-
28-
auto_properties
29-
}
8+
use crate::{view_kind::SpatialSpaceViewKind, visualizers::SpatialViewVisualizerData};
309

3110
pub fn auto_size_world_heuristic(
3211
scene_bbox_accum: &macaw::BoundingBox,
@@ -53,29 +32,6 @@ pub fn auto_size_world_heuristic(
5332
heuristic0.min(heuristic1)
5433
}
5534

56-
fn update_depth_cloud_property_heuristics(
57-
ctx: &ViewerContext<'_>,
58-
per_system_entities: &PerSystemEntities,
59-
auto_properties: &mut re_entity_db::EntityPropertyMap,
60-
) {
61-
// TODO(andreas): There should be a depth cloud system
62-
for ent_path in per_system_entities
63-
.get(&ImageVisualizer::identifier())
64-
.unwrap_or(&BTreeSet::new())
65-
{
66-
let meaning =
67-
image_meaning_for_entity(ent_path, &ctx.current_query(), ctx.recording().store());
68-
69-
let mut properties = auto_properties.get(ent_path);
70-
71-
if meaning == TensorDataMeaning::Depth {
72-
properties.backproject_radius_scale = EditableAutoValue::Auto(1.0);
73-
74-
auto_properties.overwrite_properties(ent_path.clone(), properties);
75-
}
76-
}
77-
}
78-
7935
/// Returns all entities for which a visualizer of the given kind would be picked.
8036
///
8137
/// I.e. all entities for which at least one visualizer of the specified kind is applicable

0 commit comments

Comments
 (0)