Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize gathering of point cloud colors #3730

Merged
merged 16 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions crates/re_space_view_spatial/src/parts/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,7 @@ impl ImagesPart {
.annotations
.resolved_class_description(None)
.annotation_info()
.color(
color.map(|c| c.to_array()).as_ref(),
DefaultColor::OpaqueWhite,
);
.color(color.map(|c| c.to_array()), DefaultColor::OpaqueWhite);

if let Some(textured_rect) = to_textured_rect(
ctx,
Expand Down Expand Up @@ -379,10 +376,7 @@ impl ImagesPart {
.annotations
.resolved_class_description(None)
.annotation_info()
.color(
color.map(|c| c.to_array()).as_ref(),
DefaultColor::OpaqueWhite,
);
.color(color.map(|c| c.to_array()), DefaultColor::OpaqueWhite);

if let Some(textured_rect) = to_textured_rect(
ctx,
Expand Down Expand Up @@ -467,10 +461,7 @@ impl ImagesPart {
.annotations
.resolved_class_description(None)
.annotation_info()
.color(
color.map(|c| c.to_array()).as_ref(),
DefaultColor::OpaqueWhite,
);
.color(color.map(|c| c.to_array()), DefaultColor::OpaqueWhite);

if let Some(textured_rect) = to_textured_rect(
ctx,
Expand Down
6 changes: 2 additions & 4 deletions crates/re_space_view_spatial/src/parts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn process_colors<'a, A: Archetype>(
arch_view.iter_optional_component::<Color>()?,
)
.map(move |(annotation_info, color)| {
annotation_info.color(color.map(move |c| c.to_array()).as_ref(), default_color)
annotation_info.color(color.map(|c| c.to_array()), default_color)
}))
}

Expand All @@ -134,9 +134,7 @@ pub fn process_labels<'a, A: Archetype>(
annotation_infos.iter(),
arch_view.iter_optional_component::<Text>()?,
)
.map(move |(annotation_info, text)| {
annotation_info.label(text.as_ref().map(move |t| t.as_str()))
}))
.map(move |(annotation_info, text)| annotation_info.label(text.as_ref().map(|t| t.as_str()))))
}

/// Process [`re_types::components::Radius`] components to [`re_renderer::Size`] using auto size
Expand Down
3 changes: 1 addition & 2 deletions crates/re_space_view_time_series/src/view_part_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ impl TimeSeriesSystem {
arch_view.iter_optional_component::<Radius>()?,
arch_view.iter_optional_component::<Text>()?,
) {
let color =
annotation_info.color(color.map(|c| c.to_array()).as_ref(), default_color);
let color = annotation_info.color(color.map(|c| c.to_array()), default_color);
let label = annotation_info.label(label.as_ref().map(|l| l.as_str()));

const DEFAULT_RADIUS: f32 = 0.75;
Expand Down
11 changes: 9 additions & 2 deletions crates/re_viewer_context/src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ pub struct ResolvedAnnotationInfo {

impl ResolvedAnnotationInfo {
/// `rgba` should be unmultiplied
#[inline]
pub fn color(
&self,
rgba: Option<&[u8; 4]>,
rgba: Option<[u8; 4]>,
default_color: DefaultColor<'_>,
) -> re_renderer::Color32 {
if let Some([r, g, b, a]) = rgba {
re_renderer::Color32::from_rgba_unmultiplied(*r, *g, *b, *a)
if a == 255 {
// Common-case optimization
re_renderer::Color32::from_rgb(r, g, b)
} else {
re_renderer::Color32::from_rgba_unmultiplied(r, g, b, a)
}
Comment on lines +161 to +166
Copy link
Member

@Wumpf Wumpf Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that you marked all color methods inline emilk/egui@38b4234 and given that from_rgba_unmultiplied already has this short-circuit, this shouldn't actually be here, amiright? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on when we update to egui, and wether or not the compiler will actually inline it, and what effect that will have, yadda yadda

} else if let Some(color) = self.annotation_info.as_ref().and_then(|info| {
info.color
.map(|c| c.into())
Expand All @@ -168,6 +174,7 @@ impl ResolvedAnnotationInfo {
}
}

#[inline]
pub fn label(&self, label: Option<&str>) -> Option<String> {
if let Some(label) = label {
Some(label.to_owned())
Expand Down
Loading