From 734c6cbfb88c84eed89d1bb0abdf0891ad897f25 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Wed, 24 Apr 2024 10:42:24 +0200 Subject: [PATCH] abstract it all away --- .../src/visualizers/arrows2d.rs | 161 +++++---------- .../src/visualizers/arrows3d.rs | 161 +++++---------- .../src/visualizers/boxes2d.rs | 173 ++++++---------- .../src/visualizers/boxes3d.rs | 185 +++++++----------- .../src/visualizers/lines2d.rs | 166 ++++++---------- .../src/visualizers/lines3d.rs | 166 ++++++---------- .../src/visualizers/mod.rs | 2 +- .../src/visualizers/points2d.rs | 148 +++++--------- .../src/visualizers/points3d.rs | 148 +++++--------- 9 files changed, 464 insertions(+), 846 deletions(-) diff --git a/crates/re_space_view_spatial/src/visualizers/arrows2d.rs b/crates/re_space_view_spatial/src/visualizers/arrows2d.rs index a93b9e67ec825..a92603460a85a 100644 --- a/crates/re_space_view_spatial/src/visualizers/arrows2d.rs +++ b/crates/re_space_view_spatial/src/visualizers/arrows2d.rs @@ -1,5 +1,5 @@ use re_entity_db::{EntityPath, InstancePathHash}; -use re_query_cache2::{range_zip_1x6, CachedResults}; +use re_query_cache2::range_zip_1x6; use re_renderer::{renderer::LineStripFlags, LineDrawableBuilder, PickingLayerInstanceId}; use re_types::{ archetypes::Arrows2D, @@ -218,121 +218,66 @@ impl VisualizerSystem for Arrows2DVisualizer { view_ctx, view_ctx.get::()?.points, |ctx, entity_path, _entity_props, spatial_ctx, results| { - match results { - CachedResults::LatestAt(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); + re_tracing::profile_scope!(format!("{entity_path}")); - use crate::visualizers::CachedLatestAtResultsExt as _; + use crate::visualizers::CachedRangeResultsExt as _; - let resolver = ctx.recording().resolver(); + let resolver = ctx.recording().resolver(); - let vectors = match results.get_dense::(resolver) { - Some(Ok(vectors)) if !vectors.is_empty() => vectors, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; + let vectors = match results.get_dense::(resolver) { + Some(Ok(vectors)) => vectors, + Some(err @ Err(_)) => err?, + _ => return Ok(()), + }; - line_builder.reserve_strips(vectors.len())?; - line_builder.reserve_vertices(vectors.len() * 2)?; - - let origins = results.get_or_empty_dense(resolver)?; - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; + let num_vectors = vectors + .range_indexed() + .map(|(_, vectors)| vectors.len()) + .sum::(); + if num_vectors == 0 { + return Ok(()); + } - let data = Arrows2DComponentData { + line_builder.reserve_strips(num_vectors)?; + line_builder.reserve_vertices(num_vectors * 2)?; + + let origins = results.get_or_empty_dense(resolver)?; + let colors = results.get_or_empty_dense(resolver)?; + let radii = results.get_or_empty_dense(resolver)?; + let labels = results.get_or_empty_dense(resolver)?; + let class_ids = results.get_or_empty_dense(resolver)?; + let keypoint_ids = results.get_or_empty_dense(resolver)?; + + let data = range_zip_1x6( + vectors.range_indexed(), + origins.range_indexed(), + colors.range_indexed(), + radii.range_indexed(), + labels.range_indexed(), + class_ids.range_indexed(), + keypoint_ids.range_indexed(), + ) + .map( + |(_index, vectors, origins, colors, radii, labels, class_ids, keypoint_ids)| { + Arrows2DComponentData { vectors, - origins, - colors, - radii, - labels, - keypoint_ids, - class_ids, - }; - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - std::iter::once(data), - ); - } - - CachedResults::Range(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); - - use crate::visualizers::CachedRangeResultsExt as _; - - let resolver = ctx.recording().resolver(); - - let vectors = match results.get_dense::(resolver) { - Some(Ok(vectors)) => vectors, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; - - let num_vectors = vectors - .range_indexed() - .map(|(_, vectors)| vectors.len()) - .sum::(); - if num_vectors == 0 { - return Ok(()); + origins: origins.unwrap_or_default(), + colors: colors.unwrap_or_default(), + radii: radii.unwrap_or_default(), + labels: labels.unwrap_or_default(), + class_ids: class_ids.unwrap_or_default(), + keypoint_ids: keypoint_ids.unwrap_or_default(), } + }, + ); - line_builder.reserve_strips(num_vectors)?; - line_builder.reserve_vertices(num_vectors * 2)?; - - let origins = results.get_or_empty_dense(resolver)?; - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = range_zip_1x6( - vectors.range_indexed(), - origins.range_indexed(), - colors.range_indexed(), - radii.range_indexed(), - labels.range_indexed(), - class_ids.range_indexed(), - keypoint_ids.range_indexed(), - ) - .map( - |( - _index, - vectors, - origins, - colors, - radii, - labels, - class_ids, - keypoint_ids, - )| { - Arrows2DComponentData { - vectors, - origins: origins.unwrap_or_default(), - colors: colors.unwrap_or_default(), - radii: radii.unwrap_or_default(), - labels: labels.unwrap_or_default(), - class_ids: class_ids.unwrap_or_default(), - keypoint_ids: keypoint_ids.unwrap_or_default(), - } - }, - ); - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - data, - ); - } - } + self.process_data( + &mut line_builder, + view_query, + entity_path, + spatial_ctx, + data, + ); Ok(()) }, diff --git a/crates/re_space_view_spatial/src/visualizers/arrows3d.rs b/crates/re_space_view_spatial/src/visualizers/arrows3d.rs index e884f4afc9438..4c811226cfd2d 100644 --- a/crates/re_space_view_spatial/src/visualizers/arrows3d.rs +++ b/crates/re_space_view_spatial/src/visualizers/arrows3d.rs @@ -1,5 +1,5 @@ use re_entity_db::{EntityPath, InstancePathHash}; -use re_query_cache2::{range_zip_1x6, CachedResults}; +use re_query_cache2::range_zip_1x6; use re_renderer::{renderer::LineStripFlags, LineDrawableBuilder, PickingLayerInstanceId}; use re_types::{ archetypes::Arrows3D, @@ -221,121 +221,66 @@ impl VisualizerSystem for Arrows3DVisualizer { view_ctx, view_ctx.get::()?.points, |ctx, entity_path, _entity_props, spatial_ctx, results| { - match results { - CachedResults::LatestAt(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); + re_tracing::profile_scope!(format!("{entity_path}")); - use crate::visualizers::CachedLatestAtResultsExt as _; + use crate::visualizers::CachedRangeResultsExt as _; - let resolver = ctx.recording().resolver(); + let resolver = ctx.recording().resolver(); - let vectors = match results.get_dense::(resolver) { - Some(Ok(vectors)) if !vectors.is_empty() => vectors, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; + let vectors = match results.get_dense::(resolver) { + Some(Ok(vectors)) => vectors, + Some(err @ Err(_)) => err?, + _ => return Ok(()), + }; - line_builder.reserve_strips(vectors.len())?; - line_builder.reserve_vertices(vectors.len() * 2)?; - - let origins = results.get_or_empty_dense(resolver)?; - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; + let num_vectors = vectors + .range_indexed() + .map(|(_, vectors)| vectors.len()) + .sum::(); + if num_vectors == 0 { + return Ok(()); + } - let data = Arrows3DComponentData { + line_builder.reserve_strips(num_vectors)?; + line_builder.reserve_vertices(num_vectors * 2)?; + + let origins = results.get_or_empty_dense(resolver)?; + let colors = results.get_or_empty_dense(resolver)?; + let radii = results.get_or_empty_dense(resolver)?; + let labels = results.get_or_empty_dense(resolver)?; + let class_ids = results.get_or_empty_dense(resolver)?; + let keypoint_ids = results.get_or_empty_dense(resolver)?; + + let data = range_zip_1x6( + vectors.range_indexed(), + origins.range_indexed(), + colors.range_indexed(), + radii.range_indexed(), + labels.range_indexed(), + class_ids.range_indexed(), + keypoint_ids.range_indexed(), + ) + .map( + |(_index, vectors, origins, colors, radii, labels, class_ids, keypoint_ids)| { + Arrows3DComponentData { vectors, - origins, - colors, - radii, - labels, - keypoint_ids, - class_ids, - }; - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - std::iter::once(data), - ); - } - - CachedResults::Range(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); - - use crate::visualizers::CachedRangeResultsExt as _; - - let resolver = ctx.recording().resolver(); - - let vectors = match results.get_dense::(resolver) { - Some(Ok(vectors)) => vectors, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; - - let num_vectors = vectors - .range_indexed() - .map(|(_, vectors)| vectors.len()) - .sum::(); - if num_vectors == 0 { - return Ok(()); + origins: origins.unwrap_or_default(), + colors: colors.unwrap_or_default(), + radii: radii.unwrap_or_default(), + labels: labels.unwrap_or_default(), + class_ids: class_ids.unwrap_or_default(), + keypoint_ids: keypoint_ids.unwrap_or_default(), } + }, + ); - line_builder.reserve_strips(num_vectors)?; - line_builder.reserve_vertices(num_vectors * 2)?; - - let origins = results.get_or_empty_dense(resolver)?; - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = range_zip_1x6( - vectors.range_indexed(), - origins.range_indexed(), - colors.range_indexed(), - radii.range_indexed(), - labels.range_indexed(), - class_ids.range_indexed(), - keypoint_ids.range_indexed(), - ) - .map( - |( - _index, - vectors, - origins, - colors, - radii, - labels, - class_ids, - keypoint_ids, - )| { - Arrows3DComponentData { - vectors, - origins: origins.unwrap_or_default(), - colors: colors.unwrap_or_default(), - radii: radii.unwrap_or_default(), - labels: labels.unwrap_or_default(), - class_ids: class_ids.unwrap_or_default(), - keypoint_ids: keypoint_ids.unwrap_or_default(), - } - }, - ); - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - data, - ); - } - } + self.process_data( + &mut line_builder, + view_query, + entity_path, + spatial_ctx, + data, + ); Ok(()) }, diff --git a/crates/re_space_view_spatial/src/visualizers/boxes2d.rs b/crates/re_space_view_spatial/src/visualizers/boxes2d.rs index c34521f3ab1df..0af5c69c51693 100644 --- a/crates/re_space_view_spatial/src/visualizers/boxes2d.rs +++ b/crates/re_space_view_spatial/src/visualizers/boxes2d.rs @@ -1,5 +1,5 @@ use re_entity_db::{EntityPath, InstancePathHash}; -use re_query_cache2::{range_zip_1x6, CachedResults}; +use re_query_cache2::range_zip_1x6; use re_renderer::{LineDrawableBuilder, PickingLayerInstanceId}; use re_types::{ archetypes::Boxes2D, @@ -214,123 +214,76 @@ impl VisualizerSystem for Boxes2DVisualizer { view_ctx, view_ctx.get::()?.points, |ctx, entity_path, _entity_props, spatial_ctx, results| { - match results { - CachedResults::LatestAt(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); + re_tracing::profile_scope!(format!("{entity_path}")); - use crate::visualizers::CachedLatestAtResultsExt as _; + use crate::visualizers::CachedRangeResultsExt as _; - let resolver = ctx.recording().resolver(); + let resolver = ctx.recording().resolver(); - let half_sizes = match results.get_dense::(resolver) { - Some(Ok(vectors)) if !vectors.is_empty() => vectors, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; + let half_sizes = match results.get_dense::(resolver) { + Some(Ok(vectors)) => vectors, + Some(err @ Err(_)) => err?, + _ => return Ok(()), + }; - // Each box consists of 4 independent lines of 2 vertices each. - line_builder.reserve_strips(half_sizes.len() * 4)?; - line_builder.reserve_vertices(half_sizes.len() * 4 * 2)?; - - let centers = results.get_or_empty_dense(resolver)?; - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; + let num_boxes = half_sizes + .range_indexed() + .map(|(_, vectors)| vectors.len()) + .sum::(); + if num_boxes == 0 { + return Ok(()); + } - let data = Boxes2DComponentData { + // Each box consists of 4 independent lines of 2 vertices each. + line_builder.reserve_strips(num_boxes * 4)?; + line_builder.reserve_vertices(num_boxes * 4 * 2)?; + + let centers = results.get_or_empty_dense(resolver)?; + let colors = results.get_or_empty_dense(resolver)?; + let radii = results.get_or_empty_dense(resolver)?; + let labels = results.get_or_empty_dense(resolver)?; + let class_ids = results.get_or_empty_dense(resolver)?; + let keypoint_ids = results.get_or_empty_dense(resolver)?; + + let data = range_zip_1x6( + half_sizes.range_indexed(), + centers.range_indexed(), + colors.range_indexed(), + radii.range_indexed(), + labels.range_indexed(), + class_ids.range_indexed(), + keypoint_ids.range_indexed(), + ) + .map( + |( + _index, + half_sizes, + centers, + colors, + radii, + labels, + class_ids, + keypoint_ids, + )| { + Boxes2DComponentData { half_sizes, - centers, - colors, - radii, - labels, - keypoint_ids, - class_ids, - }; - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - std::iter::once(data), - ); - } - - CachedResults::Range(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); - - use crate::visualizers::CachedRangeResultsExt as _; - - let resolver = ctx.recording().resolver(); - - let half_sizes = match results.get_dense::(resolver) { - Some(Ok(vectors)) => vectors, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; - - let num_boxes = half_sizes - .range_indexed() - .map(|(_, vectors)| vectors.len()) - .sum::(); - if num_boxes == 0 { - return Ok(()); + centers: centers.unwrap_or_default(), + colors: colors.unwrap_or_default(), + radii: radii.unwrap_or_default(), + labels: labels.unwrap_or_default(), + class_ids: class_ids.unwrap_or_default(), + keypoint_ids: keypoint_ids.unwrap_or_default(), } + }, + ); - // Each box consists of 4 independent lines of 2 vertices each. - line_builder.reserve_strips(num_boxes * 4)?; - line_builder.reserve_vertices(num_boxes * 4 * 2)?; - - let centers = results.get_or_empty_dense(resolver)?; - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = range_zip_1x6( - half_sizes.range_indexed(), - centers.range_indexed(), - colors.range_indexed(), - radii.range_indexed(), - labels.range_indexed(), - class_ids.range_indexed(), - keypoint_ids.range_indexed(), - ) - .map( - |( - _index, - half_sizes, - centers, - colors, - radii, - labels, - class_ids, - keypoint_ids, - )| { - Boxes2DComponentData { - half_sizes, - centers: centers.unwrap_or_default(), - colors: colors.unwrap_or_default(), - radii: radii.unwrap_or_default(), - labels: labels.unwrap_or_default(), - class_ids: class_ids.unwrap_or_default(), - keypoint_ids: keypoint_ids.unwrap_or_default(), - } - }, - ); - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - data, - ); - } - } + self.process_data( + &mut line_builder, + view_query, + entity_path, + spatial_ctx, + data, + ); Ok(()) }, diff --git a/crates/re_space_view_spatial/src/visualizers/boxes3d.rs b/crates/re_space_view_spatial/src/visualizers/boxes3d.rs index 9162f8edc1a94..e9f441c7eefe4 100644 --- a/crates/re_space_view_spatial/src/visualizers/boxes3d.rs +++ b/crates/re_space_view_spatial/src/visualizers/boxes3d.rs @@ -1,5 +1,5 @@ use re_entity_db::{EntityPath, InstancePathHash}; -use re_query_cache2::{range_zip_1x7, CachedResults}; +use re_query_cache2::range_zip_1x7; use re_renderer::{LineDrawableBuilder, PickingLayerInstanceId}; use re_types::{ archetypes::Boxes3D, @@ -204,129 +204,80 @@ impl VisualizerSystem for Boxes3DVisualizer { view_ctx, view_ctx.get::()?.points, |ctx, entity_path, _entity_props, spatial_ctx, results| { - match results { - CachedResults::LatestAt(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); + re_tracing::profile_scope!(format!("{entity_path}")); - use crate::visualizers::CachedLatestAtResultsExt as _; + use crate::visualizers::CachedRangeResultsExt as _; - let resolver = ctx.recording().resolver(); + let resolver = ctx.recording().resolver(); - let half_sizes = match results.get_dense::(resolver) { - Some(Ok(vectors)) if !vectors.is_empty() => vectors, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; + let half_sizes = match results.get_dense::(resolver) { + Some(Ok(vectors)) => vectors, + Some(err @ Err(_)) => err?, + _ => return Ok(()), + }; - // Each box consists of 12 independent lines with 2 vertices each. - line_builder.reserve_strips(half_sizes.len() * 12)?; - line_builder.reserve_vertices(half_sizes.len() * 12 * 2)?; - - let centers = results.get_or_empty_dense(resolver)?; - let rotations = results.get_or_empty_dense(resolver)?; - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; + let num_boxes = half_sizes + .range_indexed() + .map(|(_, vectors)| vectors.len()) + .sum::(); + if num_boxes == 0 { + return Ok(()); + } - let data = Boxes3DComponentData { + // Each box consists of 12 independent lines with 2 vertices each. + line_builder.reserve_strips(num_boxes * 12)?; + line_builder.reserve_vertices(num_boxes * 12 * 2)?; + + let centers = results.get_or_empty_dense(resolver)?; + let rotations = results.get_or_empty_dense(resolver)?; + let colors = results.get_or_empty_dense(resolver)?; + let radii = results.get_or_empty_dense(resolver)?; + let labels = results.get_or_empty_dense(resolver)?; + let class_ids = results.get_or_empty_dense(resolver)?; + let keypoint_ids = results.get_or_empty_dense(resolver)?; + + let data = range_zip_1x7( + half_sizes.range_indexed(), + centers.range_indexed(), + rotations.range_indexed(), + colors.range_indexed(), + radii.range_indexed(), + labels.range_indexed(), + class_ids.range_indexed(), + keypoint_ids.range_indexed(), + ) + .map( + |( + _index, + half_sizes, + centers, + rotations, + colors, + radii, + labels, + class_ids, + keypoint_ids, + )| { + Boxes3DComponentData { half_sizes, - centers, - rotations, - colors, - radii, - labels, - keypoint_ids, - class_ids, - }; - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - std::iter::once(data), - ); - } - - CachedResults::Range(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); - - use crate::visualizers::CachedRangeResultsExt as _; - - let resolver = ctx.recording().resolver(); - - let half_sizes = match results.get_dense::(resolver) { - Some(Ok(vectors)) => vectors, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; - - let num_boxes = half_sizes - .range_indexed() - .map(|(_, vectors)| vectors.len()) - .sum::(); - if num_boxes == 0 { - return Ok(()); + centers: centers.unwrap_or_default(), + rotations: rotations.unwrap_or_default(), + colors: colors.unwrap_or_default(), + radii: radii.unwrap_or_default(), + labels: labels.unwrap_or_default(), + class_ids: class_ids.unwrap_or_default(), + keypoint_ids: keypoint_ids.unwrap_or_default(), } - - // Each box consists of 12 independent lines with 2 vertices each. - line_builder.reserve_strips(num_boxes * 12)?; - line_builder.reserve_vertices(num_boxes * 12 * 2)?; - - let centers = results.get_or_empty_dense(resolver)?; - let rotations = results.get_or_empty_dense(resolver)?; - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = range_zip_1x7( - half_sizes.range_indexed(), - centers.range_indexed(), - rotations.range_indexed(), - colors.range_indexed(), - radii.range_indexed(), - labels.range_indexed(), - class_ids.range_indexed(), - keypoint_ids.range_indexed(), - ) - .map( - |( - _index, - half_sizes, - centers, - rotations, - colors, - radii, - labels, - class_ids, - keypoint_ids, - )| { - Boxes3DComponentData { - half_sizes, - centers: centers.unwrap_or_default(), - rotations: rotations.unwrap_or_default(), - colors: colors.unwrap_or_default(), - radii: radii.unwrap_or_default(), - labels: labels.unwrap_or_default(), - class_ids: class_ids.unwrap_or_default(), - keypoint_ids: keypoint_ids.unwrap_or_default(), - } - }, - ); - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - data, - ); - } - } + }, + ); + + self.process_data( + &mut line_builder, + view_query, + entity_path, + spatial_ctx, + data, + ); Ok(()) }, diff --git a/crates/re_space_view_spatial/src/visualizers/lines2d.rs b/crates/re_space_view_spatial/src/visualizers/lines2d.rs index a0ced702e8a6f..539db0f26aa94 100644 --- a/crates/re_space_view_spatial/src/visualizers/lines2d.rs +++ b/crates/re_space_view_spatial/src/visualizers/lines2d.rs @@ -1,5 +1,5 @@ use re_entity_db::{EntityPath, InstancePathHash}; -use re_query_cache2::{range_zip_1x5, CachedResults}; +use re_query_cache2::range_zip_1x5; use re_renderer::{LineDrawableBuilder, PickingLayerInstanceId}; use re_types::{ archetypes::LineStrips2D, @@ -202,116 +202,70 @@ impl VisualizerSystem for Lines2DVisualizer { view_query, view_ctx, view_ctx.get::()?.points, - |ctx, entity_path, _entity_props, spatial_ctx, results| match results { - CachedResults::LatestAt(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); - - use crate::visualizers::CachedLatestAtResultsExt as _; - - let resolver = ctx.recording().resolver(); - - let strips = match results.get_dense::(resolver) { - Some(Ok(strips)) if !strips.is_empty() => strips, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; - - line_builder.reserve_strips(strips.len())?; - line_builder.reserve_vertices( - strips.iter().map(|strip| strip.0.len()).sum::(), - )?; - - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = Lines2DComponentData { - strips, - colors, - radii, - labels, - keypoint_ids, - class_ids, - }; - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - std::iter::once(data), - ); - - Ok(()) - } - - CachedResults::Range(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); + |ctx, entity_path, _entity_props, spatial_ctx, results| { + re_tracing::profile_scope!(format!("{entity_path}")); - use crate::visualizers::CachedRangeResultsExt as _; + use crate::visualizers::CachedRangeResultsExt as _; - let resolver = ctx.recording().resolver(); + let resolver = ctx.recording().resolver(); - let strips = match results.get_dense::(resolver) { - Some(Ok(strips)) => strips, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; + let strips = match results.get_dense::(resolver) { + Some(Ok(strips)) => strips, + Some(err @ Err(_)) => err?, + _ => return Ok(()), + }; - let num_strips = strips - .range_indexed() - .map(|(_, strips)| strips.len()) - .sum::(); - if num_strips == 0 { - return Ok(()); - } - line_builder.reserve_strips(num_strips)?; - - let num_vertices = strips - .range_indexed() - .map(|(_, strips)| strips.iter().map(|strip| strip.0.len()).sum::()) - .sum::(); - line_builder.reserve_vertices(num_vertices)?; - - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = range_zip_1x5( - strips.range_indexed(), - colors.range_indexed(), - radii.range_indexed(), - labels.range_indexed(), - class_ids.range_indexed(), - keypoint_ids.range_indexed(), - ) - .map( - |(_index, strips, colors, radii, labels, class_ids, keypoint_ids)| { - Lines2DComponentData { - strips, - colors: colors.unwrap_or_default(), - radii: radii.unwrap_or_default(), - labels: labels.unwrap_or_default(), - class_ids: class_ids.unwrap_or_default(), - keypoint_ids: keypoint_ids.unwrap_or_default(), - } - }, - ); - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - data, - ); - - Ok(()) + let num_strips = strips + .range_indexed() + .map(|(_, strips)| strips.len()) + .sum::(); + if num_strips == 0 { + return Ok(()); } + line_builder.reserve_strips(num_strips)?; + + let num_vertices = strips + .range_indexed() + .map(|(_, strips)| strips.iter().map(|strip| strip.0.len()).sum::()) + .sum::(); + line_builder.reserve_vertices(num_vertices)?; + + let colors = results.get_or_empty_dense(resolver)?; + let radii = results.get_or_empty_dense(resolver)?; + let labels = results.get_or_empty_dense(resolver)?; + let class_ids = results.get_or_empty_dense(resolver)?; + let keypoint_ids = results.get_or_empty_dense(resolver)?; + + let data = range_zip_1x5( + strips.range_indexed(), + colors.range_indexed(), + radii.range_indexed(), + labels.range_indexed(), + class_ids.range_indexed(), + keypoint_ids.range_indexed(), + ) + .map( + |(_index, strips, colors, radii, labels, class_ids, keypoint_ids)| { + Lines2DComponentData { + strips, + colors: colors.unwrap_or_default(), + radii: radii.unwrap_or_default(), + labels: labels.unwrap_or_default(), + class_ids: class_ids.unwrap_or_default(), + keypoint_ids: keypoint_ids.unwrap_or_default(), + } + }, + ); + + self.process_data( + &mut line_builder, + view_query, + entity_path, + spatial_ctx, + data, + ); + + Ok(()) }, )?; diff --git a/crates/re_space_view_spatial/src/visualizers/lines3d.rs b/crates/re_space_view_spatial/src/visualizers/lines3d.rs index 877e80ce1509c..ec633399584e9 100644 --- a/crates/re_space_view_spatial/src/visualizers/lines3d.rs +++ b/crates/re_space_view_spatial/src/visualizers/lines3d.rs @@ -1,5 +1,5 @@ use re_entity_db::{EntityPath, InstancePathHash}; -use re_query_cache2::{range_zip_1x5, CachedResults}; +use re_query_cache2::range_zip_1x5; use re_renderer::PickingLayerInstanceId; use re_types::{ archetypes::LineStrips3D, @@ -211,116 +211,70 @@ impl VisualizerSystem for Lines3DVisualizer { view_query, view_ctx, view_ctx.get::()?.points, - |ctx, entity_path, _entity_props, spatial_ctx, results| match results { - CachedResults::LatestAt(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); - - use crate::visualizers::CachedLatestAtResultsExt as _; - - let resolver = ctx.recording().resolver(); - - let strips = match results.get_dense::(resolver) { - Some(Ok(strips)) if !strips.is_empty() => strips, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; - - line_builder.reserve_strips(strips.len())?; - line_builder.reserve_vertices( - strips.iter().map(|strip| strip.0.len()).sum::(), - )?; - - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = Lines3DComponentData { - strips, - colors, - radii, - labels, - keypoint_ids, - class_ids, - }; - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - std::iter::once(data), - ); - - Ok(()) - } - - CachedResults::Range(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); + |ctx, entity_path, _entity_props, spatial_ctx, results| { + re_tracing::profile_scope!(format!("{entity_path}")); - use crate::visualizers::CachedRangeResultsExt as _; + use crate::visualizers::CachedRangeResultsExt as _; - let resolver = ctx.recording().resolver(); + let resolver = ctx.recording().resolver(); - let strips = match results.get_dense::(resolver) { - Some(Ok(strips)) => strips, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; + let strips = match results.get_dense::(resolver) { + Some(Ok(strips)) => strips, + Some(err @ Err(_)) => err?, + _ => return Ok(()), + }; - let num_strips = strips - .range_indexed() - .map(|(_, strips)| strips.len()) - .sum::(); - if num_strips == 0 { - return Ok(()); - } - line_builder.reserve_strips(num_strips)?; - - let num_vertices = strips - .range_indexed() - .map(|(_, strips)| strips.iter().map(|strip| strip.0.len()).sum::()) - .sum::(); - line_builder.reserve_vertices(num_vertices)?; - - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = range_zip_1x5( - strips.range_indexed(), - colors.range_indexed(), - radii.range_indexed(), - labels.range_indexed(), - class_ids.range_indexed(), - keypoint_ids.range_indexed(), - ) - .map( - |(_index, strips, colors, radii, labels, class_ids, keypoint_ids)| { - Lines3DComponentData { - strips, - colors: colors.unwrap_or_default(), - radii: radii.unwrap_or_default(), - labels: labels.unwrap_or_default(), - class_ids: class_ids.unwrap_or_default(), - keypoint_ids: keypoint_ids.unwrap_or_default(), - } - }, - ); - - self.process_data( - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - data, - ); - - Ok(()) + let num_strips = strips + .range_indexed() + .map(|(_, strips)| strips.len()) + .sum::(); + if num_strips == 0 { + return Ok(()); } + line_builder.reserve_strips(num_strips)?; + + let num_vertices = strips + .range_indexed() + .map(|(_, strips)| strips.iter().map(|strip| strip.0.len()).sum::()) + .sum::(); + line_builder.reserve_vertices(num_vertices)?; + + let colors = results.get_or_empty_dense(resolver)?; + let radii = results.get_or_empty_dense(resolver)?; + let labels = results.get_or_empty_dense(resolver)?; + let class_ids = results.get_or_empty_dense(resolver)?; + let keypoint_ids = results.get_or_empty_dense(resolver)?; + + let data = range_zip_1x5( + strips.range_indexed(), + colors.range_indexed(), + radii.range_indexed(), + labels.range_indexed(), + class_ids.range_indexed(), + keypoint_ids.range_indexed(), + ) + .map( + |(_index, strips, colors, radii, labels, class_ids, keypoint_ids)| { + Lines3DComponentData { + strips, + colors: colors.unwrap_or_default(), + radii: radii.unwrap_or_default(), + labels: labels.unwrap_or_default(), + class_ids: class_ids.unwrap_or_default(), + keypoint_ids: keypoint_ids.unwrap_or_default(), + } + }, + ); + + self.process_data( + &mut line_builder, + view_query, + entity_path, + spatial_ctx, + data, + ); + + Ok(()) }, )?; diff --git a/crates/re_space_view_spatial/src/visualizers/mod.rs b/crates/re_space_view_spatial/src/visualizers/mod.rs index 39da3eec59b46..5ad319d268660 100644 --- a/crates/re_space_view_spatial/src/visualizers/mod.rs +++ b/crates/re_space_view_spatial/src/visualizers/mod.rs @@ -22,7 +22,7 @@ pub use images::{ImageVisualizer, ViewerImage}; pub use spatial_view_visualizer::SpatialViewVisualizerData; pub use transform3d_arrows::{add_axis_arrows, Transform3DArrowsVisualizer}; -pub(crate) use self::results_ext::{CachedLatestAtResultsExt, CachedRangeResultsExt}; +pub(crate) use self::results_ext::CachedRangeResultsExt; // --- diff --git a/crates/re_space_view_spatial/src/visualizers/points2d.rs b/crates/re_space_view_spatial/src/visualizers/points2d.rs index c1b47970c3646..2f1923e4189c0 100644 --- a/crates/re_space_view_spatial/src/visualizers/points2d.rs +++ b/crates/re_space_view_spatial/src/visualizers/points2d.rs @@ -1,7 +1,7 @@ use itertools::Itertools as _; use re_entity_db::{EntityPath, InstancePathHash}; -use re_query_cache2::{range_zip_1x5, CachedResults}; +use re_query_cache2::range_zip_1x5; use re_renderer::{LineDrawableBuilder, PickingLayerInstanceId, PointCloudBuilder}; use re_types::{ archetypes::Points2D, @@ -221,106 +221,64 @@ impl VisualizerSystem for Points2DVisualizer { view_query, view_ctx, view_ctx.get::()?.points, - |ctx, entity_path, _entity_props, spatial_ctx, results| match results { - CachedResults::LatestAt(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); - - use crate::visualizers::CachedLatestAtResultsExt as _; - - let resolver = ctx.recording().resolver(); - - let positions = match results.get_dense::(resolver) { - Some(Ok(positions)) if !positions.is_empty() => positions, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; - - point_builder.reserve(positions.len())?; - - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = Points2DComponentData { - positions, - colors, - radii, - labels, - keypoint_ids, - class_ids, - }; - - self.process_data( - &mut point_builder, - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - std::iter::once(data), - ) - } + |ctx, entity_path, _entity_props, spatial_ctx, results| { + re_tracing::profile_scope!(format!("{entity_path}")); - CachedResults::Range(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); + use crate::visualizers::CachedRangeResultsExt as _; - use crate::visualizers::CachedRangeResultsExt as _; + let resolver = ctx.recording().resolver(); - let resolver = ctx.recording().resolver(); + let positions = match results.get_dense::(resolver) { + Some(Ok(positions)) => positions, + Some(err @ Err(_)) => err?, + _ => return Ok(()), + }; - let positions = match results.get_dense::(resolver) { - Some(Ok(positions)) => positions, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; + let num_positions = positions + .range_indexed() + .map(|(_, positions)| positions.len()) + .sum::(); + if num_positions == 0 { + return Ok(()); + } - let num_positions = positions - .range_indexed() - .map(|(_, positions)| positions.len()) - .sum::(); - if num_positions == 0 { - return Ok(()); - } + point_builder.reserve(num_positions)?; + + let colors = results.get_or_empty_dense(resolver)?; + let radii = results.get_or_empty_dense(resolver)?; + let labels = results.get_or_empty_dense(resolver)?; + let class_ids = results.get_or_empty_dense(resolver)?; + let keypoint_ids = results.get_or_empty_dense(resolver)?; + + let data = range_zip_1x5( + positions.range_indexed(), + colors.range_indexed(), + radii.range_indexed(), + labels.range_indexed(), + class_ids.range_indexed(), + keypoint_ids.range_indexed(), + ) + .map( + |(_index, positions, colors, radii, labels, class_ids, keypoint_ids)| { + Points2DComponentData { + positions, + colors: colors.unwrap_or_default(), + radii: radii.unwrap_or_default(), + labels: labels.unwrap_or_default(), + class_ids: class_ids.unwrap_or_default(), + keypoint_ids: keypoint_ids.unwrap_or_default(), + } + }, + ); - point_builder.reserve(num_positions)?; - - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = range_zip_1x5( - positions.range_indexed(), - colors.range_indexed(), - radii.range_indexed(), - labels.range_indexed(), - class_ids.range_indexed(), - keypoint_ids.range_indexed(), - ) - .map( - |(_index, positions, colors, radii, labels, class_ids, keypoint_ids)| { - Points2DComponentData { - positions, - colors: colors.unwrap_or_default(), - radii: radii.unwrap_or_default(), - labels: labels.unwrap_or_default(), - class_ids: class_ids.unwrap_or_default(), - keypoint_ids: keypoint_ids.unwrap_or_default(), - } - }, - ); - - self.process_data( - &mut point_builder, - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - data, - ) - } + self.process_data( + &mut point_builder, + &mut line_builder, + view_query, + entity_path, + spatial_ctx, + data, + ) }, )?; diff --git a/crates/re_space_view_spatial/src/visualizers/points3d.rs b/crates/re_space_view_spatial/src/visualizers/points3d.rs index 7c701bc60f6a9..fa40239a27812 100644 --- a/crates/re_space_view_spatial/src/visualizers/points3d.rs +++ b/crates/re_space_view_spatial/src/visualizers/points3d.rs @@ -1,7 +1,7 @@ use itertools::Itertools as _; use re_entity_db::{EntityPath, InstancePathHash}; -use re_query_cache2::{range_zip_1x5, CachedResults}; +use re_query_cache2::range_zip_1x5; use re_renderer::{LineDrawableBuilder, PickingLayerInstanceId, PointCloudBuilder}; use re_types::{ archetypes::Points3D, @@ -212,106 +212,64 @@ impl VisualizerSystem for Points3DVisualizer { view_query, view_ctx, view_ctx.get::()?.points, - |ctx, entity_path, _entity_props, spatial_ctx, results| match results { - CachedResults::LatestAt(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); - - use crate::visualizers::CachedLatestAtResultsExt as _; - - let resolver = ctx.recording().resolver(); - - let positions = match results.get_dense::(resolver) { - Some(Ok(positions)) if !positions.is_empty() => positions, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; - - point_builder.reserve(positions.len())?; - - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = Points3DComponentData { - positions, - colors, - radii, - labels, - keypoint_ids, - class_ids, - }; - - self.process_data( - &mut point_builder, - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - std::iter::once(data), - ) - } + |ctx, entity_path, _entity_props, spatial_ctx, results| { + re_tracing::profile_scope!(format!("{entity_path}")); - CachedResults::Range(_query, results) => { - re_tracing::profile_scope!(format!("{entity_path} @ {_query:?}")); + use crate::visualizers::CachedRangeResultsExt as _; - use crate::visualizers::CachedRangeResultsExt as _; + let resolver = ctx.recording().resolver(); - let resolver = ctx.recording().resolver(); + let positions = match results.get_dense::(resolver) { + Some(Ok(positions)) => positions, + Some(err @ Err(_)) => err?, + _ => return Ok(()), + }; - let positions = match results.get_dense::(resolver) { - Some(Ok(positions)) => positions, - Some(err @ Err(_)) => err?, - _ => return Ok(()), - }; + let num_positions = positions + .range_indexed() + .map(|(_, positions)| positions.len()) + .sum::(); + if num_positions == 0 { + return Ok(()); + } - let num_positions = positions - .range_indexed() - .map(|(_, positions)| positions.len()) - .sum::(); - if num_positions == 0 { - return Ok(()); - } + point_builder.reserve(num_positions)?; + + let colors = results.get_or_empty_dense(resolver)?; + let radii = results.get_or_empty_dense(resolver)?; + let labels = results.get_or_empty_dense(resolver)?; + let class_ids = results.get_or_empty_dense(resolver)?; + let keypoint_ids = results.get_or_empty_dense(resolver)?; + + let data = range_zip_1x5( + positions.range_indexed(), + colors.range_indexed(), + radii.range_indexed(), + labels.range_indexed(), + class_ids.range_indexed(), + keypoint_ids.range_indexed(), + ) + .map( + |(_index, positions, colors, radii, labels, class_ids, keypoint_ids)| { + Points3DComponentData { + positions, + colors: colors.unwrap_or_default(), + radii: radii.unwrap_or_default(), + labels: labels.unwrap_or_default(), + class_ids: class_ids.unwrap_or_default(), + keypoint_ids: keypoint_ids.unwrap_or_default(), + } + }, + ); - point_builder.reserve(num_positions)?; - - let colors = results.get_or_empty_dense(resolver)?; - let radii = results.get_or_empty_dense(resolver)?; - let labels = results.get_or_empty_dense(resolver)?; - let class_ids = results.get_or_empty_dense(resolver)?; - let keypoint_ids = results.get_or_empty_dense(resolver)?; - - let data = range_zip_1x5( - positions.range_indexed(), - colors.range_indexed(), - radii.range_indexed(), - labels.range_indexed(), - class_ids.range_indexed(), - keypoint_ids.range_indexed(), - ) - .map( - |(_index, positions, colors, radii, labels, class_ids, keypoint_ids)| { - Points3DComponentData { - positions, - colors: colors.unwrap_or_default(), - radii: radii.unwrap_or_default(), - labels: labels.unwrap_or_default(), - class_ids: class_ids.unwrap_or_default(), - keypoint_ids: keypoint_ids.unwrap_or_default(), - } - }, - ); - - self.process_data( - &mut point_builder, - &mut line_builder, - view_query, - entity_path, - spatial_ctx, - data, - ) - } + self.process_data( + &mut point_builder, + &mut line_builder, + view_query, + entity_path, + spatial_ctx, + data, + ) }, )?;