Skip to content

Commit

Permalink
fix sourcing labels from annotation contexts
Browse files Browse the repository at this point in the history
Fixes #6093
  • Loading branch information
Wumpf committed Jul 4, 2024
1 parent 9137e49 commit aec8620
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
46 changes: 23 additions & 23 deletions crates/re_space_view_spatial/src/visualizers/boxes2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,32 @@ impl Boxes2DVisualizer {
"Cannot add labels without colors"
);

let labels = clamped(labels, annotation_infos.len());
let labels = annotation_infos
.iter()
.zip(labels.iter().map(Some).chain(std::iter::repeat(None)))
.map(|(annotation_info, label)| annotation_info.label(label.map(|l| l.as_str())));
let colors = clamped(colors, annotation_infos.len());

itertools::izip!(annotation_infos.iter(), half_sizes, centers, labels, colors)
itertools::izip!(half_sizes, centers, labels, colors)
.enumerate()
.filter_map(
move |(i, (annotation_info, half_size, center, label, color))| {
let label = annotation_info.label(Some(label.as_str()));
label.map(|label| {
let min = half_size.box_min(*center);
let max = half_size.box_max(*center);
UiLabel {
text: label,
color: *color,
target: UiLabelTarget::Rect(egui::Rect::from_min_max(
egui::pos2(min.x, min.y),
egui::pos2(max.x, max.y),
)),
labeled_instance: InstancePathHash::instance(
entity_path,
Instance::from(i as u64),
),
}
})
},
)
.filter_map(move |(i, (half_size, center, label, color))| {
label.map(|label| {
let min = half_size.box_min(*center);
let max = half_size.box_max(*center);
UiLabel {
text: label,
color: *color,
target: UiLabelTarget::Rect(egui::Rect::from_min_max(
egui::pos2(min.x, min.y),
egui::pos2(max.x, max.y),
)),
labeled_instance: InstancePathHash::instance(
entity_path,
Instance::from(i as u64),
),
}
})
})
}

fn process_data<'a>(
Expand Down
20 changes: 12 additions & 8 deletions crates/re_space_view_spatial/src/visualizers/utilities/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ pub fn process_labels_3d<'a>(
"Cannot add labels without colors"
);

let labels = clamped(labels, annotation_infos.len());
let labels = annotation_infos
.iter()
.zip(labels.iter().map(Some).chain(std::iter::repeat(None)))
.map(|(annotation_info, label)| annotation_info.label(label.map(|l| l.as_str())));
let colors = clamped(colors, annotation_infos.len());

itertools::izip!(annotation_infos.iter(), positions, labels, colors)
itertools::izip!(positions, labels, colors)
.enumerate()
.filter_map(move |(i, (annotation_info, point, label, color))| {
let label = annotation_info.label(Some(label.as_str()));
.filter_map(move |(i, (point, label, color))| {
label.map(|label| UiLabel {
text: label,
color: *color,
Expand Down Expand Up @@ -85,13 +87,15 @@ pub fn process_labels_2d<'a>(
"Cannot add labels without colors"
);

let labels = clamped(labels, annotation_infos.len());
let labels = annotation_infos
.iter()
.zip(labels.iter().map(Some).chain(std::iter::repeat(None)))
.map(|(annotation_info, label)| annotation_info.label(label.map(|l| l.as_str())));
let colors = clamped(colors, annotation_infos.len());

itertools::izip!(annotation_infos.iter(), positions, labels, colors)
itertools::izip!(positions, labels, colors)
.enumerate()
.filter_map(move |(i, (annotation_info, point, label, color))| {
let label = annotation_info.label(Some(label.as_str()));
.filter_map(move |(i, (point, label, color))| {
label.map(|label| {
let point = world_from_obj.transform_point3(glam::Vec3::new(point.x, point.y, 0.0));
UiLabel {
Expand Down

0 comments on commit aec8620

Please sign in to comment.