Skip to content

Commit

Permalink
move image ui to re_data_ui and re-enable data ui for tensors
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed May 5, 2023
1 parent 3799ee0 commit eb31208
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 51 deletions.
10 changes: 7 additions & 3 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,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
4 changes: 4 additions & 0 deletions crates/re_data_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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
Expand All @@ -27,10 +28,13 @@ 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
2 changes: 1 addition & 1 deletion crates/re_data_ui/src/component_ui_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn create_component_ui_registry() -> ComponentUiRegistry {
// add::<re_log_types::component_types::Scalar>(&mut registry);
// add::<re_log_types::component_types::ScalarPlotProps>(&mut registry);
// add::<re_log_types::component_types::Size3D>(&mut registry);
// add::<re_log_types::component_types::Tensor>(&mut registry); // TODO:
add::<re_log_types::component_types::Tensor>(&mut registry);
add::<re_log_types::component_types::TextEntry>(&mut registry);
add::<re_log_types::component_types::Transform>(&mut registry);
add::<re_log_types::component_types::Vec2D>(&mut registry);
Expand Down
48 changes: 24 additions & 24 deletions crates/re_viewer/src/ui/image.rs → crates/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use egui::{Color32, Vec2};
use itertools::Itertools as _;

use re_data_ui::EntityDataUi;
use re_log_types::{
component_types::{ClassId, Tensor, TensorDataMeaning},
DecodedTensor, TensorElement,
Expand All @@ -13,34 +12,35 @@ use re_viewer_context::{
TensorStatsCache, UiVerbosity, ViewerContext,
};

use super::EntityDataUi;

pub fn format_tensor_shape_single_line(
shape: &[re_log_types::component_types::TensorDimension],
) -> String {
format!("[{}]", shape.iter().join(", "))
}

// TODO:
// impl EntityDataUi for Tensor {
// fn entity_data_ui(
// &self,
// ctx: &mut ViewerContext<'_>,
// ui: &mut egui::Ui,
// verbosity: UiVerbosity,
// entity_path: &re_log_types::EntityPath,
// query: &re_arrow_store::LatestAtQuery,
// ) {
// crate::profile_function!();

// match ctx.cache.entry::<TensorDecodeCache>().entry(self.clone()) {
// Ok(decoded) => {
// tensor_ui(ctx, ui, verbosity, entity_path, query, self, &decoded);
// }
// Err(err) => {
// ui.label(ctx.re_ui.error_text(err.to_string()));
// }
// }
// }
// }
impl EntityDataUi for Tensor {
fn entity_data_ui(
&self,
ctx: &mut ViewerContext<'_>,
ui: &mut egui::Ui,
verbosity: UiVerbosity,
entity_path: &re_log_types::EntityPath,
query: &re_arrow_store::LatestAtQuery,
) {
crate::profile_function!();

match ctx.cache.entry::<TensorDecodeCache>().entry(self.clone()) {
Ok(decoded) => {
tensor_ui(ctx, ui, verbosity, entity_path, query, self, &decoded);
}
Err(err) => {
ui.label(ctx.re_ui.error_text(err.to_string()));
}
}
}
}

fn tensor_ui(
ctx: &mut ViewerContext<'_>,
Expand Down Expand Up @@ -670,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
5 changes: 5 additions & 0 deletions crates/re_data_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ mod component_path;
mod component_ui_registry;
mod data;
mod entity_path;
mod image;
mod instance_path;
mod item;
pub mod item_ui;
mod log_msg;

pub use crate::image::{
show_zoomed_image_region, show_zoomed_image_region_area_outline,
tensor_summary_ui_grid_contents,
};
pub use component_ui_registry::create_component_ui_registry;

/// Types implementing [`DataUi`] can display themselves in an [`egui::Ui`].
Expand Down
7 changes: 1 addition & 6 deletions crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ macaw = { workspace = true, features = ["with_serde"] }
ndarray = "0.15"
nohash-hasher = "0.2"
poll-promise = "0.2"
rfd = { version = "0.11.3", default_features = false, features = [
"xdg-portal",
] }
rfd.workspace = true
serde = { version = "1", features = ["derive"] }
slotmap.workspace = true
smallvec = { workspace = true, features = ["serde"] }
Expand All @@ -110,9 +108,6 @@ wgpu.workspace = true

# native dependencies:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
arboard = { version = "3.2", default-features = false, features = [
"image-data",
] }
puffin_http = "0.11"
puffin.workspace = true

Expand Down
6 changes: 0 additions & 6 deletions crates/re_viewer/src/misc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ mod transform_cache;

pub mod instance_hash_conversions;

#[cfg(not(target_arch = "wasm32"))]
pub(crate) use clipboard::Clipboard;

#[cfg(not(target_arch = "wasm32"))]
pub(crate) mod profiler;

#[cfg(not(target_arch = "wasm32"))]
pub mod clipboard;

pub use mesh_cache::MeshCache;
pub use time_control_ui::TimeControlUi;
pub use transform_cache::{TransformCache, UnreachableTransform};
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/misc/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn start_puffin_viewer() {

if let Err(err) = child {
let cmd = format!("cargo install puffin_viewer && puffin_viewer --url {url}",);
crate::misc::Clipboard::with(|cliboard| cliboard.set_text(cmd.clone()));
re_viewer_context::Clipboard::with(|clipboard| clipboard.set_text(cmd.clone()));
re_log::warn!("Failed to start puffin_viewer: {err}. Try connecting manually with: {cmd}");

rfd::MessageDialog::new()
Expand Down
1 change: 0 additions & 1 deletion crates/re_viewer/src/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod auto_layout;
mod blueprint;
mod data_blueprint;
mod image;
mod selection_history_ui;
mod space_view;
mod space_view_entity_picker;
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl SpaceView {
fn handle_pending_screenshots(&self, data: &[u8], extent: glam::UVec2, mode: ScreenshotMode) {
// Set to clipboard.
#[cfg(not(target_arch = "wasm32"))]
crate::misc::Clipboard::with(|clipboard| {
re_viewer_context::Clipboard::with(|clipboard| {
clipboard.set_image([extent.x as _, extent.y as _], data);
});
if mode == ScreenshotMode::CopyToClipboard {
Expand Down
1 change: 0 additions & 1 deletion crates/re_viewer/src/ui/view_spatial/scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::sync::Arc;
use ahash::HashMap;

use re_data_store::{EntityPath, InstancePathHash};
use re_data_ui::DataUi;
use re_log_types::{
component_types::{ClassId, InstanceKey, KeypointId},
DecodedTensor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use re_log_types::{
Component,
};
use re_query::{query_primary_with_history, EntityView, QueryError};
use re_viewer_context::{DefaultColor, ResolvedAnnotationInfo, SceneQuery, ViewerContext};
use re_viewer_context::{ResolvedAnnotationInfo, SceneQuery, ViewerContext};

use crate::{
misc::{SpaceViewHighlights, SpaceViewOutlineMasks, TransformCache},
Expand Down
6 changes: 2 additions & 4 deletions crates/re_viewer/src/ui/view_spatial/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use macaw::BoundingBox;

use re_data_store::{query_latest_single, EditableAutoValue, EntityPath, EntityPropertyMap};
use re_data_ui::{item_ui, DataUi};
use re_data_ui::{show_zoomed_image_region, show_zoomed_image_region_area_outline};
use re_format::format_f32;
use re_log_types::component_types::{Tensor, TensorDataMeaning};
use re_renderer::OutlineConfig;
Expand All @@ -15,10 +16,7 @@ use re_viewer_context::{
use crate::{
misc::{space_info::query_view_coordinates, SpaceViewHighlights},
ui::{
data_blueprint::DataBlueprintTree,
image::{show_zoomed_image_region, show_zoomed_image_region_area_outline},
space_view::ScreenshotMode,
view_spatial::UiLabelTarget,
data_blueprint::DataBlueprintTree, space_view::ScreenshotMode, view_spatial::UiLabelTarget,
},
};

Expand Down
3 changes: 1 addition & 2 deletions crates/re_viewer/src/ui/view_tensor/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use eframe::emath::Align2;
use egui::{epaint::TextShape, NumExt as _, Vec2};
use ndarray::Axis;

use re_data_ui::tensor_summary_ui_grid_contents;
use re_log_types::{
component_types::{self, Tensor},
DecodedTensor,
Expand All @@ -12,8 +13,6 @@ use re_renderer::Colormap;
use re_tensor_ops::dimension_mapping::{DimensionMapping, DimensionSelector};
use re_viewer_context::{gpu_bridge, TensorStatsCache, ViewerContext};

use crate::ui::image::tensor_summary_ui_grid_contents;

use super::dimension_mapping_ui;

// ---
Expand Down
4 changes: 4 additions & 0 deletions crates/re_viewer_context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ thiserror.workspace = true
uuid = { version = "1.1", features = ["serde", "v4", "js"] }
wgpu.workspace = true

# Native only dependencies.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
arboard = { version = "3.2", default-features = false, features = [
"image-data",
] }
puffin.workspace = true
File renamed without changes.
5 changes: 5 additions & 0 deletions crates/re_viewer_context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ pub use time_control::{Looping, PlayState, TimeControl, TimeView};
pub use utils::{auto_color, level_to_rich_text, DefaultColor};
pub use viewer_context::{RecordingConfig, ViewerContext};

#[cfg(not(target_arch = "wasm32"))]
mod clipboard;
#[cfg(not(target_arch = "wasm32"))]
pub use clipboard::Clipboard;

// ---------------------------------------------------------------------------

/// A unique id for each space view.
Expand Down

0 comments on commit eb31208

Please sign in to comment.