use re_chunk_store::RowId;
use re_log_types::TimePoint;
use re_test_context::TestContext;
use re_test_viewport::TestContextExt as _;
use re_viewer_context::{ViewClass as _, ViewId};
use re_viewport_blueprint::ViewBlueprint;
#[test]
pub fn test_annotations() {
let mut test_context = get_test_context();
{
use ndarray::{Array, ShapeBuilder as _, s};
test_context.log_entity("/", |builder| {
builder.with_archetype(
RowId::new(),
TimePoint::default(),
&re_sdk_types::archetypes::AnnotationContext::new([
(
0,
"black",
re_sdk_types::datatypes::Rgba32::from_rgb(0, 0, 0),
),
(
1,
"red",
re_sdk_types::datatypes::Rgba32::from_rgb(255, 0, 0),
),
(
2,
"green",
re_sdk_types::datatypes::Rgba32::from_rgb(0, 255, 0),
),
]),
)
});
test_context.log_entity("detections", |builder| {
builder.with_archetype(
RowId::new(),
TimePoint::default(),
&re_sdk_types::archetypes::Boxes2D::from_mins_and_sizes(
[(200.0, 50.0), (75.0, 150.0)],
[(30.0, 30.0), (20.0, 20.0)],
)
.with_class_ids([1, 2]),
)
});
test_context.log_entity("segmentation/image", |builder| {
let mut image = Array::<u8, _>::zeros((200, 300).f());
image.slice_mut(s![50..100, 50..120]).fill(1);
image.slice_mut(s![100..180, 130..280]).fill(2);
builder.with_archetype(
RowId::new(),
TimePoint::default(),
&re_sdk_types::archetypes::SegmentationImage::try_from(image)
.unwrap()
.with_draw_order(0.0),
)
});
}
let view_id = test_context.setup_viewport_blueprint(|_ctx, blueprint| {
blueprint.add_view_at_root(ViewBlueprint::new_with_root_wildcard(
re_view_spatial::SpatialView2D::identifier(),
))
});
run_view_ui_and_save_snapshot(
&test_context,
view_id,
"annotations",
egui::vec2(300.0, 300.0) * 2.0,
);
}
fn get_test_context() -> TestContext {
let mut test_context = TestContext::new_with_view_class::<re_view_spatial::SpatialView2D>();
test_context.component_ui_registry = re_component_ui::create_component_ui_registry();
re_data_ui::register_component_uis(&mut test_context.component_ui_registry);
test_context
}
fn run_view_ui_and_save_snapshot(
test_context: &TestContext,
view_id: ViewId,
name: &str,
size: egui::Vec2,
) {
let mut harness = test_context
.setup_kittest_for_rendering_3d(size)
.build_ui(|ui| {
test_context.run_with_single_view(ui, view_id);
});
{
let name = format!("{name}_overview");
harness.run();
harness.snapshot(&name);
}
{
{
let name = format!("{name}_hover_background");
let raw_input = harness.input_mut();
raw_input
.events
.push(egui::Event::PointerMoved((50.0, 200.0).into()));
harness.try_run_realtime().ok();
harness.snapshot(&name);
}
{
let name = format!("{name}_hover_rect_red");
let raw_input = harness.input_mut();
raw_input
.events
.push(egui::Event::PointerMoved((200.0, 250.0).into()));
harness.run();
harness.snapshot(&name);
}
{
let name = format!("{name}_hover_rect_green");
let raw_input = harness.input_mut();
raw_input
.events
.push(egui::Event::PointerMoved((300.0, 400.0).into()));
harness.run();
harness.snapshot(&name);
}
{
let name = format!("{name}_hover_region_green");
let raw_input = harness.input_mut();
raw_input
.events
.push(egui::Event::PointerMoved((175.0, 450.).into()));
harness.run();
harness.snapshot(&name);
}
{
let name = format!("{name}_hover_region_red");
let raw_input = harness.input_mut();
raw_input
.events
.push(egui::Event::PointerMoved((425., 275.0).into()));
harness.run();
harness.snapshot(&name);
}
}
}