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

Chunkified, deserialization-free LineStrip visualizers #7018

Merged
merged 3 commits into from
Aug 2, 2024

Conversation

teh-cmc
Copy link
Member

@teh-cmc teh-cmc commented Jul 30, 2024

Title!

This introduces a new neat zero-deser zero-copy helper for array list (which should be the last one, we've covered everything!).


LineStrips2D

super::entity_iterator::process_archetype2::<Self, LineStrips2D, _>(
ctx,
view_query,
context_systems,
|ctx, spatial_ctx, results| {
use re_space_view::RangeResultsExt2 as _;
let Some(all_strip_chunks) = results.get_required_chunks(&LineStrip2D::name())
else {
return Ok(());
};
let num_strips = all_strip_chunks
.iter()
.flat_map(|chunk| {
chunk.iter_primitive_array_list::<2, f32>(&LineStrip2D::name())
})
.map(|strips| strips.len())
.sum();
if num_strips == 0 {
return Ok(());
}
line_builder.reserve_strips(num_strips)?;
let num_vertices = all_strip_chunks
.iter()
.flat_map(|chunk| {
chunk.iter_primitive_array_list::<2, f32>(&LineStrip2D::name())
})
.map(|strips| strips.iter().map(|strip| strip.len()).sum::<usize>())
.sum::<usize>();
line_builder.reserve_vertices(num_vertices)?;
let timeline = ctx.query.timeline();
let all_strips_indexed = all_strip_chunks.iter().flat_map(|chunk| {
itertools::izip!(
chunk.iter_component_indices(&timeline, &LineStrip2D::name()),
chunk.iter_primitive_array_list::<2, f32>(&LineStrip2D::name())
)
});
let all_colors = results.iter_as(timeline, Color::name());
let all_radii = results.iter_as(timeline, Radius::name());
let all_labels = results.iter_as(timeline, Text::name());
let all_class_ids = results.iter_as(timeline, ClassId::name());
let all_keypoint_ids = results.iter_as(timeline, KeypointId::name());
let data = re_query2::range_zip_1x5(
all_strips_indexed,
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_keypoint_ids.primitive::<u16>(),
)
.map(
|(_index, strips, colors, radii, labels, class_ids, keypoint_ids)| {
Lines2DComponentData {
strips,
colors: colors.map_or(&[], |colors| bytemuck::cast_slice(colors)),
radii: radii.map_or(&[], |radii| bytemuck::cast_slice(radii)),
labels: labels.unwrap_or_default(),
class_ids: class_ids
.map_or(&[], |class_ids| bytemuck::cast_slice(class_ids)),
keypoint_ids: keypoint_ids
.map_or(&[], |keypoint_ids| bytemuck::cast_slice(keypoint_ids)),
}
},
);
self.process_data(ctx, &mut line_builder, view_query, spatial_ctx, data);
Ok(())
},
)?;

image

LineStrips3D

super::entity_iterator::process_archetype2::<Self, LineStrips3D, _>(
ctx,
view_query,
context_systems,
|ctx, spatial_ctx, results| {
use re_space_view::RangeResultsExt2 as _;
let Some(all_strip_chunks) = results.get_required_chunks(&LineStrip3D::name())
else {
return Ok(());
};
let num_strips = all_strip_chunks
.iter()
.flat_map(|chunk| {
chunk.iter_primitive_array_list::<3, f32>(&LineStrip3D::name())
})
.map(|strips| strips.len())
.sum();
if num_strips == 0 {
return Ok(());
}
line_builder.reserve_strips(num_strips)?;
let num_vertices = all_strip_chunks
.iter()
.flat_map(|chunk| {
chunk.iter_primitive_array_list::<3, f32>(&LineStrip3D::name())
})
.map(|strips| strips.iter().map(|strip| strip.len()).sum::<usize>())
.sum::<usize>();
line_builder.reserve_vertices(num_vertices)?;
let timeline = ctx.query.timeline();
let all_strips_indexed = all_strip_chunks.iter().flat_map(|chunk| {
itertools::izip!(
chunk.iter_component_indices(&timeline, &LineStrip3D::name()),
chunk.iter_primitive_array_list::<3, f32>(&LineStrip3D::name())
)
});
let all_colors = results.iter_as(timeline, Color::name());
let all_radii = results.iter_as(timeline, Radius::name());
let all_labels = results.iter_as(timeline, Text::name());
let all_class_ids = results.iter_as(timeline, ClassId::name());
let all_keypoint_ids = results.iter_as(timeline, KeypointId::name());
let data = re_query2::range_zip_1x5(
all_strips_indexed,
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_keypoint_ids.primitive::<u16>(),
)
.map(
|(_index, strips, colors, radii, labels, class_ids, keypoint_ids)| {
Lines3DComponentData {
strips,
colors: colors.map_or(&[], |colors| bytemuck::cast_slice(colors)),
radii: radii.map_or(&[], |radii| bytemuck::cast_slice(radii)),
labels: labels.unwrap_or_default(),
class_ids: class_ids
.map_or(&[], |class_ids| bytemuck::cast_slice(class_ids)),
keypoint_ids: keypoint_ids
.map_or(&[], |keypoint_ids| bytemuck::cast_slice(keypoint_ids)),
}
},
);
self.process_data(ctx, &mut line_builder, view_query, spatial_ctx, data);
Ok(())
},
)?;

image


Checklist

  • I have read and agree to Contributor Guide and the Code of Conduct
  • I've included a screenshot or gif (if applicable)
  • I have tested the web demo (if applicable):
  • The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG
  • If applicable, add a new check to the release checklist!
  • If have noted any breaking changes to the log API in CHANGELOG.md and the migration guide

To run all checks from main, comment on the PR with @rerun-bot full-check.

@teh-cmc teh-cmc added 📺 re_viewer affects re_viewer itself 🔍 re_query affects re_query itself 🚀 performance Optimization, memory use, etc do-not-merge Do not merge this PR 🍏 primitives Relating to Rerun primitives include in changelog labels Jul 30, 2024
@teh-cmc teh-cmc changed the base branch from main to cmc/chunkified_queries_11_meshes July 30, 2024 13:46
@teh-cmc teh-cmc force-pushed the cmc/chunkified_queries_11_meshes branch from ab850e9 to 80317d4 Compare July 30, 2024 14:51
Base automatically changed from cmc/chunkified_queries_11_meshes to main July 30, 2024 15:01
@teh-cmc teh-cmc force-pushed the cmc/chunkified_queries_12_shapes branch from beeb939 to 4fa4826 Compare July 30, 2024 15:04
@teh-cmc teh-cmc removed the do-not-merge Do not merge this PR label Jul 30, 2024
@teh-cmc teh-cmc mentioned this pull request Jul 30, 2024
6 tasks
@Wumpf Wumpf self-requested a review August 1, 2024 09:49
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

nice!

@@ -142,12 +141,12 @@ impl Lines2DVisualizer {

struct Lines2DComponentData<'a> {
// Point of views
strips: &'a [LineStrip2D],
strips: Vec<&'a [[f32; 2]]>,
Copy link
Member

Choose a reason for hiding this comment

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

ahhh the delight of primitive types 😁

@teh-cmc teh-cmc merged commit 19b7afd into main Aug 2, 2024
34 checks passed
@teh-cmc teh-cmc deleted the cmc/chunkified_queries_12_shapes branch August 2, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include in changelog 🚀 performance Optimization, memory use, etc 🍏 primitives Relating to Rerun primitives 🔍 re_query affects re_query itself 📺 re_viewer affects re_viewer itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants