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 1 commit
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
3 changes: 3 additions & 0 deletions crates/re_space_view_spatial/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ mod ui_3d;
pub use space_view_2d::SpatialSpaceView2D;
pub use space_view_3d::SpatialSpaceView3D;

#[doc(hidden)] // Public for benchmarks
pub use parts::LoadedPoints;

// ---

mod view_kind {
Expand Down
3 changes: 3 additions & 0 deletions crates/re_space_view_spatial/src/parts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ use re_types::components::Text;
pub use spatial_view_part::SpatialViewPartData;
pub use transform3d_arrows::{add_axis_arrows, Transform3DArrowsPart};

#[doc(hidden)] // Public for benchmarks
pub use points3d::LoadedPoints;

use ahash::HashMap;

use re_data_store::{EntityPath, InstancePathHash};
Expand Down
88 changes: 49 additions & 39 deletions crates/re_space_view_spatial/src/parts/points3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ use re_renderer::PickingLayerInstanceId;
use re_types::{
archetypes::Points3D,
components::{Position3D, Text},
Archetype as _, ComponentNameSet,
Archetype as _, ComponentNameSet, DeserializationResult,
};
use re_viewer_context::{
Annotations, NamedViewSystem, ResolvedAnnotationInfos, SpaceViewSystemExecutionError,
ViewContextCollection, ViewPartSystem, ViewQuery, ViewerContext,
};

use itertools::Itertools as _;

use crate::{
contexts::{EntityDepthOffsets, SpatialSceneEntityContext},
parts::{
Expand Down Expand Up @@ -211,14 +209,14 @@ impl ViewPartSystem for Points3DPart {
}
}

// Public so we can write a benchmark for it!
#[doc(hidden)] // Public for benchmarks
pub struct LoadedPoints {
annotation_infos: ResolvedAnnotationInfos,
keypoints: Keypoints,
positions: Vec<glam::Vec3>,
radii: Vec<re_renderer::Size>,
colors: Vec<re_renderer::Color32>,
picking_instance_ids: Vec<PickingLayerInstanceId>,
pub annotation_infos: ResolvedAnnotationInfos,
pub keypoints: Keypoints,
pub positions: Vec<glam::Vec3>,
pub radii: Vec<re_renderer::Size>,
pub colors: Vec<re_renderer::Color32>,
pub picking_instance_ids: Vec<PickingLayerInstanceId>,
}

impl LoadedPoints {
emilk marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -237,44 +235,56 @@ impl LoadedPoints {
(*p).into()
})?;

let colors = process_colors(arch_view, ent_path, &annotation_infos)?;
let radii = process_radii(arch_view, ent_path)?;

let (positions, radii, colors, picking_instance_ids) = join4(
|| {
re_tracing::profile_scope!("positions");
arch_view
.iter_required_component::<Position3D>()
.map(|p| p.map(glam::Vec3::from).collect_vec())
},
|| {
re_tracing::profile_scope!("radii");
radii.collect_vec()
},
|| {
re_tracing::profile_scope!("colors");
colors.collect_vec()
},
|| {
re_tracing::profile_scope!("picking_ids");
arch_view
.iter_instance_keys()
.map(picking_id_from_instance_key)
.collect_vec()
},
|| Self::load_positions(arch_view),
|| Self::load_radii(arch_view, ent_path),
|| Self::load_colors(arch_view, ent_path, &annotation_infos),
|| Self::load_picking_ids(arch_view),
);

let positions = positions?;

Ok(Self {
annotation_infos,
keypoints,
positions,
radii,
colors,
positions: positions?,
radii: radii?,
colors: colors?,
picking_instance_ids,
})
}

pub fn load_positions(
arch_view: &ArchetypeView<Points3D>,
) -> DeserializationResult<Vec<glam::Vec3>> {
re_tracing::profile_function!();
arch_view
.iter_required_component::<Position3D>()
.map(|p| p.map(glam::Vec3::from).collect())
}

pub fn load_radii(
arch_view: &ArchetypeView<Points3D>,
ent_path: &EntityPath,
) -> Result<Vec<re_renderer::Size>, QueryError> {
re_tracing::profile_function!();
process_radii(arch_view, ent_path).map(|radii| radii.collect())
}

pub fn load_colors(
arch_view: &ArchetypeView<Points3D>,
ent_path: &EntityPath,
annotation_infos: &ResolvedAnnotationInfos,
) -> Result<Vec<re_renderer::Color32>, QueryError> {
re_tracing::profile_function!();
process_colors(arch_view, ent_path, annotation_infos).map(|colors| colors.collect())
}

pub fn load_picking_ids(arch_view: &ArchetypeView<Points3D>) -> Vec<PickingLayerInstanceId> {
re_tracing::profile_function!();
arch_view
.iter_instance_keys()
.map(picking_id_from_instance_key)
.collect()
}
}

/// Run 4 things in parallel
Expand Down
14 changes: 8 additions & 6 deletions crates/re_viewer_context/src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub struct Annotations {
}

impl Annotations {
pub fn missing() -> Self {
emilk marked this conversation as resolved.
Show resolved Hide resolved
Self {
row_id: MISSING_ROW_ID,
class_map: Default::default(),
}
}

pub fn try_from_view(view: &ArchetypeView<AnnotationContext>) -> Option<Self> {
re_tracing::profile_function!();

Expand Down Expand Up @@ -286,10 +293,5 @@ impl AnnotationMap {
const MISSING_ROW_ID: RowId = RowId::ZERO;

lazy_static! {
pub static ref MISSING_ANNOTATIONS: Arc<Annotations> = {
Arc::new(Annotations {
row_id: MISSING_ROW_ID,
class_map: Default::default(),
})
};
pub static ref MISSING_ANNOTATIONS: Arc<Annotations> = Arc::new(Annotations::missing());
}
Loading