Skip to content

Commit

Permalink
[pure refactor] move data ui to new re_data_ui crate (#2048)
Browse files Browse the repository at this point in the history
* re_data_ui crate setup

* move all data_ui except tensor to re_data_ui

* move annotations to re_viewer_context

* move tensor stats & decode cache to re_viewer_context

* move gpu bridge to re_viewer_context for the time being

* move image ui to re_data_ui and re-enable data ui for tensors

* fix links in readme

* deduplicate select_hovered_on_click logic again, leaving a comment that it is misplaced

* minor crate cleanup via cargo machete
  • Loading branch information
Wumpf authored May 5, 2023
1 parent 364b40b commit 6c14940
Show file tree
Hide file tree
Showing 70 changed files with 412 additions and 325 deletions.
44 changes: 39 additions & 5 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ re_build_build_info = { path = "crates/re_build_build_info", version = "=0.6.0-a
re_build_info = { path = "crates/re_build_info", version = "=0.6.0-alpha.0", default-features = false }
re_build_web_viewer = { path = "crates/re_build_web_viewer", version = "=0.6.0-alpha.0", default-features = false }
re_data_store = { path = "crates/re_data_store", version = "=0.6.0-alpha.0", default-features = false }
re_data_ui = { path = "crates/re_data_ui", version = "=0.6.0-alpha.0", default-features = false }
re_error = { path = "crates/re_error", version = "=0.6.0-alpha.0", default-features = false }
re_format = { path = "crates/re_format", version = "=0.6.0-alpha.0", default-features = false }
re_int_histogram = { path = "crates/re_int_histogram", version = "=0.6.0-alpha.0", default-features = false }
Expand Down Expand Up @@ -85,6 +86,9 @@ polars-core = "0.27.1"
polars-lazy = "0.27.1"
polars-ops = "0.27.1"
puffin = "0.14"
rfd = { version = "0.11.3", default_features = false, features = [
"xdg-portal",
] }
slotmap = { version = "1.0.6", features = ["serde"] }
smallvec = { version = "1.0", features = ["const_generics", "union"] }
thiserror = "1.0"
Expand Down
40 changes: 40 additions & 0 deletions crates/re_data_ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
authors.workspace = true
description = "Provides ui elements for Rerun component data for the Rerun Viewer."
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "re_data_ui"
publish = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true
include = ["../../LICENSE-APACHE", "../../LICENSE-MIT", "**/*.rs", "Cargo.toml"]

[package.metadata.docs.rs]
all-features = true

[dependencies]
re_arrow_store.workspace = true
re_data_store.workspace = true
re_error.workspace = true
re_format.workspace = true
re_log_types.workspace = true
re_log.workspace = true
re_query.workspace = true
re_renderer.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true

anyhow.workspace = true
bytemuck.workspace = true
egui_extras.workspace = true
egui.workspace = true
image.workspace = true
itertools.workspace = true
nohash-hasher.workspace = true
rfd.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
puffin.workspace = true
10 changes: 10 additions & 0 deletions crates/re_data_ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# re_data_ui

Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.

[![Latest version](https://img.shields.io/crates/v/re_data_ui.svg)](https://crates.io/crates/re_data_ui)
[![Documentation](https://docs.rs/re_data_ui/badge.svg)](https://docs.rs/re_data_ui)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

Provides ui elements for Rerun component data for the Rerun Viewer.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use egui::{color_picker, Vec2};
use itertools::Itertools;
use re_log_types::{context::AnnotationInfo, AnnotationContext};
use re_viewer_context::{UiVerbosity, ViewerContext};
use re_viewer_context::{auto_color, UiVerbosity, ViewerContext};

use super::DataUi;
use crate::ui::annotations::auto_color;

const TABLE_SCROLL_AREA_HEIGHT: f32 = 500.0; // add scroll-bars when we get to this height

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use re_query::ComponentWithInstances;
use re_viewer_context::{UiVerbosity, ViewerContext};

use super::DataUi;
use crate::ui::item_ui;
use crate::item_ui;

// We do NOT implement `DataUi` for just `ComponentWithInstances`
// because we also want the context of what entity it is part of!
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl DataUi for re_log_types::component_types::TextEntry {
verbosity: UiVerbosity,
_query: &re_arrow_store::LatestAtQuery,
) {
use crate::ui::view_text::level_to_rich_text;
use re_viewer_context::level_to_rich_text;

let Self { body, level } = self;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use re_log_types::{
};
use re_renderer::renderer::ColormappedTexture;
use re_ui::ReUi;
use re_viewer_context::{UiVerbosity, ViewerContext};
use re_viewer_context::{
gpu_bridge, AnnotationMap, Annotations, SceneQuery, TensorDecodeCache, TensorStats,
TensorStatsCache, UiVerbosity, ViewerContext,
};

use super::EntityDataUi;
use crate::{
misc::caches::{TensorDecodeCache, TensorStats, TensorStatsCache},
ui::annotations::AnnotationMap,
};

pub fn format_tensor_shape_single_line(
shape: &[re_log_types::component_types::TensorDimension],
Expand Down Expand Up @@ -57,7 +56,7 @@ fn tensor_ui(
let tensor_stats = *ctx.cache.entry::<TensorStatsCache>().entry(tensor);
let annotations = annotations(ctx, query, entity_path);
let debug_name = entity_path.to_string();
let texture_result = crate::gpu_bridge::tensor_to_gpu(
let texture_result = gpu_bridge::tensor_to_gpu(
ctx.render_ctx,
&debug_name,
tensor,
Expand Down Expand Up @@ -166,11 +165,11 @@ fn annotations(
ctx: &mut ViewerContext<'_>,
query: &re_arrow_store::LatestAtQuery,
entity_path: &re_data_store::EntityPath,
) -> std::sync::Arc<crate::ui::Annotations> {
) -> std::sync::Arc<Annotations> {
let mut annotation_map = AnnotationMap::default();
let entity_paths: nohash_hasher::IntSet<_> = std::iter::once(entity_path.clone()).collect();
let entity_props_map = re_data_store::EntityPropertyMap::default();
let scene_query = crate::ui::scene::SceneQuery {
let scene_query = SceneQuery {
entity_paths: &entity_paths,
timeline: query.timeline,
latest_at: query.at,
Expand Down Expand Up @@ -201,7 +200,7 @@ fn show_image_at_max_size(
};

let (response, painter) = ui.allocate_painter(desired_size, egui::Sense::hover());
if let Err(err) = crate::gpu_bridge::render_image(
if let Err(err) = gpu_bridge::render_image(
render_ctx,
&painter,
response.rect,
Expand Down Expand Up @@ -326,7 +325,7 @@ fn show_zoomed_image_region_tooltip(
response: egui::Response,
tensor: &DecodedTensor,
tensor_stats: &TensorStats,
annotations: &crate::ui::Annotations,
annotations: &Annotations,
meter: Option<f32>,
debug_name: &str,
image_rect: egui::Rect,
Expand Down Expand Up @@ -406,7 +405,7 @@ pub fn show_zoomed_image_region(
ui: &mut egui::Ui,
tensor: &DecodedTensor,
tensor_stats: &TensorStats,
annotations: &crate::ui::Annotations,
annotations: &Annotations,
meter: Option<f32>,
debug_name: &str,
center_texel: [isize; 2],
Expand All @@ -432,18 +431,13 @@ fn try_show_zoomed_image_region(
ui: &mut egui::Ui,
tensor: &DecodedTensor,
tensor_stats: &TensorStats,
annotations: &crate::ui::Annotations,
annotations: &Annotations,
meter: Option<f32>,
debug_name: &str,
center_texel: [isize; 2],
) -> anyhow::Result<()> {
let texture = crate::gpu_bridge::tensor_to_gpu(
render_ctx,
debug_name,
tensor,
tensor_stats,
annotations,
)?;
let texture =
gpu_bridge::tensor_to_gpu(render_ctx, debug_name, tensor, tensor_stats, annotations)?;

let Some([height, width, _]) = tensor.image_height_width_channels() else { return Ok(()); };

Expand All @@ -463,7 +457,7 @@ fn try_show_zoomed_image_region(
POINTS_PER_TEXEL * egui::vec2(width as f32, height as f32),
);

crate::gpu_bridge::render_image(
gpu_bridge::render_image(
render_ctx,
&painter.with_clip_rect(zoom_rect),
image_rect_on_screen,
Expand Down Expand Up @@ -498,7 +492,7 @@ fn try_show_zoomed_image_region(
- zoom * egui::vec2(center_texel[0] as f32 + 0.5, center_texel[1] as f32 + 0.5),
zoom * egui::vec2(width as f32, height as f32),
);
crate::gpu_bridge::render_image(
gpu_bridge::render_image(
render_ctx,
&ui.painter().with_clip_rect(rect),
image_rect_on_screen,
Expand All @@ -515,7 +509,7 @@ fn try_show_zoomed_image_region(
fn tensor_pixel_value_ui(
ui: &mut egui::Ui,
tensor: &Tensor,
annotations: &crate::ui::Annotations,
annotations: &Annotations,
[x, y]: [u64; 2],
meter: Option<f32>,
) {
Expand Down Expand Up @@ -676,7 +670,7 @@ fn copy_and_save_image_ui(ui: &mut egui::Ui, tensor: &Tensor, _encoded_tensor: &
match tensor.to_dynamic_image() {
Ok(dynamic_image) => {
let rgba = dynamic_image.to_rgba8();
crate::misc::Clipboard::with(|clipboard| {
re_viewer_context::Clipboard::with(|clipboard| {
clipboard.set_image(
[rgba.width() as _, rgba.height() as _],
bytemuck::cast_slice(rgba.as_raw()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use re_query::{get_component_with_instances, QueryError};
use re_viewer_context::{UiVerbosity, ViewerContext};

use super::DataUi;
use crate::ui::item_ui;
use crate::item_ui;

const HIDDEN_COMPONENTS_FOR_ALL_VERBOSITY: &[&str] = &["rerun.instance_key"];
const HIDDEN_COMPONENTS_FOR_LOW_VERBOSITY: &[&str] = &[];
Expand Down
26 changes: 26 additions & 0 deletions crates/re_data_ui/src/item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use re_viewer_context::{Item, UiVerbosity, ViewerContext};

use crate::DataUi;

impl DataUi for Item {
fn data_ui(
&self,
ctx: &mut ViewerContext<'_>,
ui: &mut egui::Ui,
verbosity: UiVerbosity,
query: &re_arrow_store::LatestAtQuery,
) {
match self {
Item::SpaceView(_) | Item::DataBlueprintGroup(_, _) => {
// Shouldn't be reachable since SelectionPanel::contents doesn't show data ui for these.
// If you add something in here make sure to adjust SelectionPanel::contents accordingly.
}
Item::ComponentPath(component_path) => {
component_path.data_ui(ctx, ui, verbosity, query);
}
Item::InstancePath(_, instance_path) => {
instance_path.data_ui(ctx, ui, verbosity, query);
}
}
}
}
Loading

1 comment on commit 6c14940

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.25.

Benchmark suite Current: 6c14940 Previous: 364b40b Ratio
mono_points_arrow_batched/generate_message_bundles 27496592 ns/iter (± 1104270) 20723598 ns/iter (± 1445354) 1.33
mono_points_arrow_batched/generate_messages 5535137 ns/iter (± 500180) 4392746 ns/iter (± 259076) 1.26
mono_points_arrow_batched/decode_total 11975869 ns/iter (± 495779) 8101214 ns/iter (± 126551) 1.48

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.