Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into release-0.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Aug 12, 2024
2 parents 7ec2e6e + 0315547 commit 8a761ef
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 162 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/reusable_test_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ jobs:
pixi run -e wheel-test-min which rerun
pixi run -e wheel-test-min rerun-from-path --version
- name: Run unit tests (with linux arm64 opencv workaround)
if: ${{ inputs.PLATFORM == 'linux-arm64' }}
# Workaround for OpenCV TLS issue, see https://github.com/opencv/opencv/issues/14884#issuecomment-815632861
run: cd rerun_py/tests && LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1 pixi run -e wheel-test-min pytest -c ../pyproject.toml

- name: Run unit tests
if: ${{ inputs.PLATFORM != 'linux-arm64' }}
run: cd rerun_py/tests && pixi run -e wheel-test-min pytest -c ../pyproject.toml

- name: Run e2e test
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4447,6 +4447,7 @@ dependencies = [
"egui_plot",
"image",
"itertools 0.13.0",
"nohash-hasher",
"re_chunk_store",
"re_entity_db",
"re_error",
Expand Down
2 changes: 1 addition & 1 deletion crates/store/re_types/definitions/rerun/archetypes.fbs

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

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace rerun.archetypes;
/// Some of its component are repeated here for convenience.
/// If there's more instance poses than half sizes, the last half size will be repeated for the remaining poses.
///
/// \example archetypes/ellipsoid_batch !api title="Batch of ellipsoids"
/// \example archetypes/ellipsoid3d_batch !api title="Batch of ellipsoids"
table Ellipsoids3D (
"attr.rust.derive": "PartialEq",
"attr.rust.new_pub_crate",
Expand Down
2 changes: 1 addition & 1 deletion crates/store/re_types/src/archetypes/ellipsoids3d.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/viewer/re_data_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ egui_plot.workspace = true
egui.workspace = true
image.workspace = true
itertools.workspace = true
nohash-hasher.workspace = true
rfd.workspace = true
unindent.workspace = true

Expand Down
46 changes: 3 additions & 43 deletions crates/viewer/re_data_ui/src/blob.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use egui::{NumExt, Vec2};

use re_log::ResultExt;
use re_renderer::renderer::ColormappedTexture;
use re_types::components::{Blob, MediaType};
use re_ui::{list_item::PropertyContent, UiExt as _};
use re_viewer_context::{gpu_bridge::image_to_gpu, UiLayout};

use crate::{image::show_image_preview, EntityDataUi};
use crate::{image::texture_preview_ui, EntityDataUi};

impl EntityDataUi for Blob {
fn entity_data_ui(
Expand Down Expand Up @@ -41,11 +39,7 @@ impl EntityDataUi for Blob {
}

if let (Some(render_ctx), Some(texture)) = (ctx.render_ctx, texture) {
// We want all preview images to take up the same amount of space,
// no matter what the actual aspect ratio of the images are.
let preview_size = Vec2::splat(ui.available_height());
let debug_name = entity_path.to_string();
show_mini_image_on_same_row(render_ctx, ui, preview_size, texture, &debug_name);
texture_preview_ui(render_ctx, ui, ui_layout, entity_path, texture);
}
});
} else {
Expand All @@ -71,16 +65,7 @@ impl EntityDataUi for Blob {
}

if let (Some(render_ctx), Some(texture)) = (ctx.render_ctx, texture) {
// We want all preview images to take up the same amount of space,
// no matter what the actual aspect ratio of the images are.
let preview_size =
Vec2::splat(ui.available_width().at_least(240.0)).at_most(Vec2::splat(640.0));
let debug_name = entity_path.to_string();
show_image_preview(render_ctx, ui, texture.clone(), &debug_name, preview_size)
.unwrap_or_else(|(response, err)| {
re_log::warn_once!("Failed to show texture {entity_path}: {err}");
response
});
texture_preview_ui(render_ctx, ui, ui_layout, entity_path, texture);
}

if ui_layout != UiLayout::Tooltip {
Expand Down Expand Up @@ -110,31 +95,6 @@ impl EntityDataUi for Blob {
}
}

fn show_mini_image_on_same_row(
render_ctx: &re_renderer::RenderContext,
ui: &mut egui::Ui,
preview_size: Vec2,
texture: ColormappedTexture,
debug_name: &str,
) {
ui.allocate_ui_with_layout(
preview_size,
egui::Layout::centered_and_justified(egui::Direction::TopDown),
|ui| {
ui.set_min_size(preview_size);

match show_image_preview(render_ctx, ui, texture.clone(), debug_name, preview_size) {
Ok(response) => response.on_hover_ui(|ui| {
// Show larger image on hover.
let hover_size = Vec2::splat(400.0);
show_image_preview(render_ctx, ui, texture, debug_name, hover_size).ok();
}),
Err((response, err)) => response.on_hover_text(err.to_string()),
}
},
);
}

fn blob_as_texture(
ctx: &re_viewer_context::ViewerContext<'_>,
query: &re_chunk_store::LatestAtQuery,
Expand Down
61 changes: 57 additions & 4 deletions crates/viewer/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
use egui::{Color32, Vec2};
use egui::{Color32, NumExt as _, Vec2};
use itertools::Itertools as _;

use re_renderer::renderer::ColormappedTexture;
use re_types::{
components::ClassId, datatypes::ColorModel, image::ImageKind, tensor_data::TensorElement,
};
use re_viewer_context::{gpu_bridge, Annotations, ImageInfo, ImageStats};
use re_viewer_context::{gpu_bridge, Annotations, ImageInfo, ImageStats, UiLayout};

/// Show the given texture with an appropriate size.
pub fn texture_preview_ui(
render_ctx: &re_renderer::RenderContext,
ui: &mut egui::Ui,
ui_layout: UiLayout,
entity_path: &re_log_types::EntityPath,
texture: ColormappedTexture,
) {
if ui_layout.is_single_line() {
let preview_size = Vec2::splat(ui.available_height());
let debug_name = entity_path.to_string();
ui.allocate_ui_with_layout(
preview_size,
egui::Layout::centered_and_justified(egui::Direction::TopDown),
|ui| {
ui.set_min_size(preview_size);

match show_image_preview(render_ctx, ui, texture.clone(), &debug_name, preview_size)
{
Ok(response) => response.on_hover_ui(|ui| {
// Show larger image on hover.
let hover_size = Vec2::splat(400.0);
show_image_preview(render_ctx, ui, texture, &debug_name, hover_size).ok();
}),
Err((response, err)) => response.on_hover_text(err.to_string()),
}
},
);
} else {
let size_range = if ui_layout == UiLayout::Tooltip {
egui::Rangef::new(64.0, 128.0)
} else {
egui::Rangef::new(240.0, 640.0)
};
let preview_size = Vec2::splat(
size_range
.clamp(ui.available_width())
.at_most(16.0 * texture.texture.width().max(texture.texture.height()) as f32),
);
let debug_name = entity_path.to_string();
show_image_preview(render_ctx, ui, texture, &debug_name, preview_size).unwrap_or_else(
|(response, err)| {
re_log::warn_once!("Failed to show texture {entity_path}: {err}");
response
},
);
}
}

/// Shows preview of an image.
///
Expand All @@ -15,7 +64,7 @@ use re_viewer_context::{gpu_bridge, Annotations, ImageInfo, ImageStats};
/// This does not preserve aspect ratio, but we only stretch it to a very thin size, so it is fine.
///
/// Returns error if the image could not be rendered.
pub fn show_image_preview(
fn show_image_preview(
render_ctx: &re_renderer::RenderContext,
ui: &mut egui::Ui,
colormapped_texture: ColormappedTexture,
Expand Down Expand Up @@ -46,7 +95,11 @@ pub fn show_image_preview(
&painter,
texture_rect_on_screen,
colormapped_texture,
egui::TextureOptions::LINEAR,
egui::TextureOptions {
magnification: egui::TextureFilter::Nearest,
minification: egui::TextureFilter::Linear,
..Default::default()
},
debug_name,
) {
let color = ui.visuals().error_fg_color;
Expand Down
Loading

0 comments on commit 8a761ef

Please sign in to comment.