Skip to content

Commit

Permalink
Expose image opacity component (#6635)
Browse files Browse the repository at this point in the history
### What

Image opacity (for layering images) is now an exposed component that can
be set from blueprint & data store.

Heuristic for opacity is a lot simplified:
* stacked images will no longer be made transparent in general
* only segmentation image will use 0.5 opacity as a fallback if there is
any other image in the scene
Demonstrated here:


https://github.com/rerun-io/rerun/assets/1220815/8b133062-01cf-4bca-bfdc-1cec8c1457ae



---

* prerequisite for #6548 
* almost solves #2192


### 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/6635?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/6635?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/6635)
- [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 Jun 25, 2024
1 parent 39e393c commit e33ac30
Show file tree
Hide file tree
Showing 41 changed files with 734 additions and 88 deletions.
28 changes: 25 additions & 3 deletions crates/re_edit_ui/src/datatype_editors/float_drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use egui::NumExt as _;
use re_types::datatypes;

/// Generic editor for a [`re_types::datatypes::Float32`] value from zero to max float.
pub fn edit_f32_zero_to_max_float(
pub fn edit_f32_zero_to_max(
_ctx: &re_viewer_context::ViewerContext<'_>,
ui: &mut egui::Ui,
value: &mut impl std::ops::DerefMut<Target = datatypes::Float32>,
Expand All @@ -19,12 +19,34 @@ pub fn edit_f32_zero_to_max_float_raw(
edit_f32_zero_to_max_float_raw_impl(ui, value)
}

/// Non monomorphized implementation of [`edit_f32_zero_to_max_float`].
/// Non monomorphized implementation of [`edit_f32_zero_to_max_float_raw`].
fn edit_f32_zero_to_max_float_raw_impl(ui: &mut egui::Ui, value: &mut f32) -> egui::Response {
let speed = (*value * 0.01).at_least(0.001);
ui.add(
egui::DragValue::new(value)
.clamp_range(0.0..=f32::MAX)
.clamp_range(0.0..=f32::MAX) // TODO(#6633): Don't change incoming values
.speed(speed),
)
}

/// Generic editor for a [`re_types::datatypes::Float32`] value from zero to one float.
pub fn edit_f32_zero_to_one(
_ctx: &re_viewer_context::ViewerContext<'_>,
ui: &mut egui::Ui,
value: &mut impl std::ops::DerefMut<Target = datatypes::Float32>,
) -> egui::Response {
edit_f32_zero_to_one_raw(ui, &mut value.deref_mut().0)
}

/// Non monomorphized implementation of [`edit_f32_zero_to_one`].
fn edit_f32_zero_to_one_raw(ui: &mut egui::Ui, value: &mut f32) -> egui::Response {
// TODO(#6633): Pre-clamp the value, so the ui won't change the value if there's no interaction.
// This means we won't see the real value in the ui if it's outside the range.
*value = value.clamp(0.0, 1.0);
ui.add(
egui::DragValue::new(value)
.clamp_range(0.0..=1.0)
.speed(0.005)
.fixed_decimals(2),
)
}
2 changes: 1 addition & 1 deletion crates/re_edit_ui/src/datatype_editors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod singleline_string;

pub use bool_toggle::{edit_bool, edit_bool_raw};
pub use enum_combobox::edit_enum;
pub use float_drag::{edit_f32_zero_to_max_float, edit_f32_zero_to_max_float_raw};
pub use float_drag::{edit_f32_zero_to_max, edit_f32_zero_to_max_float_raw, edit_f32_zero_to_one};
pub use singleline_string::edit_singleline_string;
27 changes: 15 additions & 12 deletions crates/re_edit_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ mod response_utils;
mod visual_bounds2d;

use datatype_editors::{
edit_bool, edit_bool_raw, edit_enum, edit_f32_zero_to_max_float,
edit_f32_zero_to_max_float_raw, edit_singleline_string,
edit_bool, edit_bool_raw, edit_enum, edit_f32_zero_to_max, edit_f32_zero_to_max_float_raw,
edit_f32_zero_to_one, edit_singleline_string,
};
use re_types::{
blueprint::components::{BackgroundKind, Corner2D, LockRangeDuringZoom, ViewFit, Visible},
components::{
AggregationPolicy, AxisLength, Color, Colormap, DepthMeter, FillRatio, GammaCorrection,
ImagePlaneDistance, MagnificationFilter, MarkerSize, Name, Radius, StrokeWidth, Text,
ImagePlaneDistance, MagnificationFilter, MarkerSize, Name, Opacity, Radius, StrokeWidth,
Text,
},
};
use re_viewer_context::ViewerContext;
Expand Down Expand Up @@ -48,22 +49,24 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) {
registry.add_singleline_editor_ui(marker_shape::edit_marker_shape_ui);
registry.add_singleline_editor_ui(range1d::edit_range1d);

registry.add_singleline_editor_ui::<AxisLength>(edit_f32_zero_to_max_float);
registry.add_singleline_editor_ui::<FillRatio>(edit_f32_zero_to_max_float);
registry.add_singleline_editor_ui::<ImagePlaneDistance>(edit_f32_zero_to_max_float);
registry.add_singleline_editor_ui::<GammaCorrection>(edit_f32_zero_to_max_float);
registry.add_singleline_editor_ui::<AxisLength>(edit_f32_zero_to_max);
registry.add_singleline_editor_ui::<FillRatio>(edit_f32_zero_to_max);
registry.add_singleline_editor_ui::<ImagePlaneDistance>(edit_f32_zero_to_max);
registry.add_singleline_editor_ui::<GammaCorrection>(edit_f32_zero_to_max);

registry.add_singleline_editor_ui::<DepthMeter>(edit_f32_zero_to_max_float_raw);
registry.add_singleline_editor_ui::<MarkerSize>(edit_f32_zero_to_max_float_raw);
registry.add_singleline_editor_ui::<Radius>(edit_f32_zero_to_max_float_raw);
registry.add_singleline_editor_ui::<StrokeWidth>(edit_f32_zero_to_max_float_raw);

registry.add_singleline_editor_ui::<Opacity>(edit_f32_zero_to_one);

registry.add_singleline_editor_ui::<Visible>(edit_bool_raw);
registry.add_singleline_editor_ui::<LockRangeDuringZoom>(edit_bool);

registry.add_singleline_editor_ui::<Text>(edit_singleline_string);
registry.add_singleline_editor_ui::<Name>(edit_singleline_string);

registry.add_singleline_editor_ui::<DepthMeter>(edit_f32_zero_to_max_float_raw);
registry.add_singleline_editor_ui::<MarkerSize>(edit_f32_zero_to_max_float_raw);
registry.add_singleline_editor_ui::<Radius>(edit_f32_zero_to_max_float_raw);
registry.add_singleline_editor_ui::<StrokeWidth>(edit_f32_zero_to_max_float_raw);

registry.add_singleline_editor_ui(|_ctx, ui, value| edit_enum::<BackgroundKind>(ui, value));
registry.add_singleline_editor_ui(|_ctx, ui, value| edit_enum::<Colormap>(ui, value));
registry.add_singleline_editor_ui(|_ctx, ui, value| edit_enum::<Corner2D>(ui, value));
Expand Down
31 changes: 30 additions & 1 deletion crates/re_space_view_spatial/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ use re_viewer_context::{
};
use re_viewport_blueprint::SpaceViewBlueprint;

use crate::scene_bounding_boxes::SceneBoundingBoxes;
use crate::{
contexts::AnnotationSceneContext,
picking::{PickableUiRect, PickingContext, PickingHitType, PickingResult},
view_kind::SpatialSpaceViewKind,
visualizers::{CamerasVisualizer, ImageVisualizer, UiLabel, UiLabelTarget},
};
use crate::{contexts::PrimitiveCounter, scene_bounding_boxes::SceneBoundingBoxes};
use crate::{eye::EyeMode, heuristics::auto_size_world_heuristic};

use super::{eye::Eye, ui_3d::View3DState};
Expand Down Expand Up @@ -67,6 +67,9 @@ pub struct SpatialSpaceViewState {
/// Estimated number of primitives last frame. Used to inform some heuristics.
pub scene_num_primitives: usize,

/// Number of images & depth images processed last frame.
pub num_non_segmentation_images_last_frame: usize,

/// Last frame's picking result.
pub previous_picking_result: Option<PickingResult>,

Expand All @@ -90,6 +93,32 @@ impl SpaceViewState for SpatialSpaceViewState {
}

impl SpatialSpaceViewState {
/// Updates the state with statistics from the latest system outputs.
pub fn update_frame_statistics(
&mut self,
system_output: &re_viewer_context::SystemExecutionOutput,
) -> Result<(), SpaceViewSystemExecutionError> {
re_tracing::profile_function!();

self.bounding_boxes.update(&system_output.view_systems);

self.scene_num_primitives = system_output
.context_systems
.get::<PrimitiveCounter>()?
.num_primitives
.load(std::sync::atomic::Ordering::Relaxed);

self.num_non_segmentation_images_last_frame = system_output
.view_systems
.get::<ImageVisualizer>()?
.images
.iter()
.filter(|i| i.meaning != TensorDataMeaning::ClassId)
.count();

Ok(())
}

pub fn auto_size_config(&self) -> re_renderer::AutoSizeConfig {
let mut config = self.auto_size_config;
if config.point_radius.is_auto() {
Expand Down
9 changes: 2 additions & 7 deletions crates/re_space_view_spatial/src/view_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use re_viewer_context::{
};

use crate::{
contexts::{register_spatial_contexts, PrimitiveCounter},
contexts::register_spatial_contexts,
heuristics::default_visualized_entities_for_visualizer_kind,
max_image_dimension_subscriber::{ImageDimensions, MaxImageDimensions},
spatial_topology::{SpatialTopology, SubSpaceConnectionFlags},
Expand Down Expand Up @@ -249,12 +249,7 @@ impl SpaceViewClass for SpatialSpaceView2D {
re_tracing::profile_function!();

let state = state.downcast_mut::<SpatialSpaceViewState>()?;
state.bounding_boxes.update(&system_output.view_systems);
state.scene_num_primitives = system_output
.context_systems
.get::<PrimitiveCounter>()?
.num_primitives
.load(std::sync::atomic::Ordering::Relaxed);
state.update_frame_statistics(&system_output)?;

self.view_2d(ctx, ui, state, query, system_output)
}
Expand Down
10 changes: 2 additions & 8 deletions crates/re_space_view_spatial/src/view_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use re_viewer_context::{

use crate::visualizers::{CamerasVisualizer, Transform3DArrowsVisualizer, Transform3DDetector};
use crate::{
contexts::{register_spatial_contexts, PrimitiveCounter},
contexts::register_spatial_contexts,
heuristics::default_visualized_entities_for_visualizer_kind,
spatial_topology::{HeuristicHints, SpatialTopology, SubSpaceConnectionFlags},
ui::{format_vector, SpatialSpaceViewState},
Expand Down Expand Up @@ -429,13 +429,7 @@ impl SpaceViewClass for SpatialSpaceView3D {
re_tracing::profile_function!();

let state = state.downcast_mut::<SpatialSpaceViewState>()?;

state.bounding_boxes.update(&system_output.view_systems);
state.scene_num_primitives = system_output
.context_systems
.get::<PrimitiveCounter>()?
.num_primitives
.load(std::sync::atomic::Ordering::Relaxed);
state.update_frame_statistics(&system_output)?;

self.view_3d(ctx, ui, state, query, system_output)
}
Expand Down
Loading

0 comments on commit e33ac30

Please sign in to comment.