Skip to content

Commit 93798b0

Browse files
authored
Add 2D in 3D & 3D in 2D image comparison tests (#11462)
1 parent cb45d5f commit 93798b0

File tree

5 files changed

+147
-26
lines changed

5 files changed

+147
-26
lines changed

crates/viewer/re_view_spatial/tests/annotations.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn run_view_ui_and_save_snapshot(
122122
harness.try_run_realtime().ok();
123123
harness.snapshot_options(
124124
&name,
125-
&SnapshotOptions::new().failed_pixel_count_threshold(1),
125+
&SnapshotOptions::new().failed_pixel_count_threshold(2),
126126
);
127127
}
128128

@@ -135,7 +135,7 @@ fn run_view_ui_and_save_snapshot(
135135
harness.run();
136136
harness.snapshot_options(
137137
&name,
138-
&SnapshotOptions::new().failed_pixel_count_threshold(1),
138+
&SnapshotOptions::new().failed_pixel_count_threshold(2),
139139
);
140140
}
141141

@@ -148,7 +148,7 @@ fn run_view_ui_and_save_snapshot(
148148
harness.run();
149149
harness.snapshot_options(
150150
&name,
151-
&SnapshotOptions::new().failed_pixel_count_threshold(1),
151+
&SnapshotOptions::new().failed_pixel_count_threshold(2),
152152
);
153153
}
154154

@@ -162,7 +162,7 @@ fn run_view_ui_and_save_snapshot(
162162

163163
harness.snapshot_options(
164164
&name,
165-
&SnapshotOptions::new().failed_pixel_count_threshold(1),
165+
&SnapshotOptions::new().failed_pixel_count_threshold(2),
166166
);
167167
}
168168

@@ -175,7 +175,7 @@ fn run_view_ui_and_save_snapshot(
175175
harness.run();
176176
harness.snapshot_options(
177177
&name,
178-
&SnapshotOptions::new().failed_pixel_count_threshold(1),
178+
&SnapshotOptions::new().failed_pixel_count_threshold(2),
179179
);
180180
}
181181
}

crates/viewer/re_view_spatial/tests/pinhole_camera.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use re_test_context::{TestContext, external::egui_kittest::SnapshotOptions};
44
use re_test_viewport::TestContextExt as _;
55
use re_types::archetypes::Pinhole;
66
use re_types::components::{Color, Radius};
7-
use re_viewer_context::{RecommendedView, ViewClass as _, ViewId};
7+
use re_viewer_context::{ViewClass as _, ViewId};
88
use re_viewport_blueprint::ViewBlueprint;
99

1010
#[test]
@@ -21,27 +21,13 @@ pub fn test_pinhole_camera() {
2121
)
2222
});
2323

24-
let view_id = setup_blueprint(&mut test_context);
25-
run_view_ui_and_save_snapshot(&mut test_context, view_id, egui::vec2(300.0, 300.0));
26-
}
27-
28-
#[allow(clippy::unwrap_used)]
29-
fn setup_blueprint(test_context: &mut TestContext) -> ViewId {
30-
test_context.setup_viewport_blueprint(|_ctx, blueprint| {
31-
let view_blueprint = ViewBlueprint::new(
32-
re_view_spatial::SpatialView3D::identifier(),
33-
RecommendedView {
34-
origin: "/world".into(),
35-
query_filter: "+ $origin/**".parse().unwrap(),
36-
},
37-
);
38-
39-
let view_id = view_blueprint.id;
40-
41-
blueprint.add_views(std::iter::once(view_blueprint), None, None);
24+
let view_id = test_context.setup_viewport_blueprint(|_ctx, blueprint| {
25+
let view =
26+
ViewBlueprint::new_with_root_wildcard(re_view_spatial::SpatialView3D::identifier());
27+
blueprint.add_view_at_root(view)
28+
});
4229

43-
view_id
44-
})
30+
run_view_ui_and_save_snapshot(&mut test_context, view_id, egui::vec2(300.0, 300.0));
4531
}
4632

4733
fn run_view_ui_and_save_snapshot(
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//! Test that 2D content can be added to a 3D space and vice versa.
2+
3+
use re_log_types::{EntityPathFilter, TimePoint};
4+
use re_test_context::{TestContext, external::egui_kittest::SnapshotOptions};
5+
use re_test_viewport::TestContextExt as _;
6+
use re_types::{RowId, archetypes, components};
7+
use re_viewer_context::{RecommendedView, ViewClass as _};
8+
use re_viewport_blueprint::ViewBlueprint;
9+
10+
fn setup_scene(test_context: &mut TestContext) {
11+
use ndarray::{Array, ShapeBuilder as _};
12+
13+
test_context.log_entity("boxes", |builder| {
14+
builder.with_archetype(
15+
RowId::new(),
16+
TimePoint::default(),
17+
&archetypes::Boxes3D::from_centers_and_half_sizes(
18+
[(-1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (1.0, 1.0, 0.0)],
19+
[(0.2, 0.4, 0.2), (0.2, 0.2, 0.4), (0.4, 0.2, 0.2)],
20+
)
21+
.with_colors([0xFF0000FF, 0x00FF00FF, 0x0000FFFF])
22+
.with_fill_mode(components::FillMode::Solid),
23+
)
24+
});
25+
26+
let eye_position = glam::vec3(0.0, -1.0, 0.2);
27+
28+
test_context.log_entity("camera", |builder| {
29+
builder
30+
.with_archetype(
31+
RowId::new(),
32+
TimePoint::default(),
33+
&archetypes::Transform3D::from_mat3x3(
34+
// Look at the middle box.
35+
glam::Mat3::look_at_rh(eye_position, glam::vec3(0.0, 1.0, 0.0), glam::Vec3::Z),
36+
)
37+
.with_translation(eye_position),
38+
)
39+
.with_archetype(
40+
RowId::new(),
41+
TimePoint::default(),
42+
&archetypes::Pinhole::from_focal_length_and_resolution([2., 2.], [3., 2.])
43+
.with_image_plane_distance(1.0),
44+
)
45+
.with_archetype(
46+
RowId::new(),
47+
TimePoint::default(),
48+
&archetypes::Image::from_color_model_and_tensor(
49+
re_types::datatypes::ColorModel::RGB,
50+
Array::<u8, _>::zeros((2, 3, 3).f()),
51+
)
52+
.expect("failed to create image"),
53+
)
54+
});
55+
test_context.log_entity("camera/points", |builder| {
56+
builder.with_archetype(
57+
RowId::new(),
58+
TimePoint::default(),
59+
&archetypes::Points2D::new([
60+
[0.0, 0.0],
61+
[3.0, 0.0],
62+
[0.0, 2.0],
63+
[3.0, 2.0],
64+
[1.5, 1.0],
65+
])
66+
.with_radii([0.2]),
67+
)
68+
});
69+
}
70+
71+
#[test]
72+
pub fn test_2d_in_3d() {
73+
let mut test_context = TestContext::new_with_view_class::<re_view_spatial::SpatialView3D>();
74+
75+
setup_scene(&mut test_context);
76+
77+
let view_id = test_context.setup_viewport_blueprint(|_ctx, blueprint| {
78+
let view =
79+
ViewBlueprint::new_with_root_wildcard(re_view_spatial::SpatialView3D::identifier());
80+
blueprint.add_view_at_root(view)
81+
});
82+
83+
let mut harness = test_context
84+
.setup_kittest_for_rendering()
85+
.with_size(egui::vec2(400.0, 300.0))
86+
.build_ui(|ui| {
87+
test_context.run_ui(ui, |ctx, ui| {
88+
test_context.ui_for_single_view(ui, ctx, view_id);
89+
});
90+
});
91+
92+
harness.run();
93+
harness.snapshot_options(
94+
"2d_in_3d",
95+
&SnapshotOptions::new()
96+
.threshold(1.0)
97+
.failed_pixel_count_threshold(30),
98+
);
99+
}
100+
101+
#[test]
102+
pub fn test_3d_in_2d() {
103+
let mut test_context = TestContext::new_with_view_class::<re_view_spatial::SpatialView2D>();
104+
105+
setup_scene(&mut test_context);
106+
107+
let view_id = test_context.setup_viewport_blueprint(|_ctx, blueprint| {
108+
let view = ViewBlueprint::new(
109+
re_view_spatial::SpatialView2D::identifier(),
110+
RecommendedView {
111+
origin: "camera".into(),
112+
query_filter: EntityPathFilter::all(),
113+
},
114+
);
115+
blueprint.add_view_at_root(view)
116+
});
117+
118+
let mut harness = test_context
119+
.setup_kittest_for_rendering()
120+
.with_size(egui::vec2(400.0, 300.0))
121+
.build_ui(|ui| {
122+
test_context.run_ui(ui, |ctx, ui| {
123+
test_context.ui_for_single_view(ui, ctx, view_id);
124+
});
125+
});
126+
127+
harness.run();
128+
harness.snapshot("3d_in_2d");
129+
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)