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 Point Cloud visualizers #7011

Merged
merged 8 commits into from
Jul 30, 2024

Conversation

teh-cmc
Copy link
Member

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

Title!

Because this is the first spatial view we've ever chunkified, this includes a new entity_iterator etc.
The old ones will be removed once everything has been ported.


super::entity_iterator::process_archetype2::<Self, Points3D, _>(
ctx,
view_query,
context_systems,
|ctx, spatial_ctx, results| {
use re_space_view::RangeResultsExt2 as _;
let Some(all_position_chunks) = results.get_required_chunks(&Position3D::name())
else {
return Ok(());
};
let num_positions = all_position_chunks
.iter()
.flat_map(|chunk| chunk.iter_primitive_array::<3, f32>(&Position3D::name()))
.map(|points| points.len())
.sum();
if num_positions == 0 {
return Ok(());
}
point_builder.reserve(num_positions)?;
let timeline = ctx.query.timeline();
let all_positions_indexed = all_position_chunks.iter().flat_map(|chunk| {
itertools::izip!(
chunk.iter_component_indices(&timeline, &Position3D::name()),
chunk.iter_primitive_array::<3, f32>(&Position3D::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_positions_indexed,
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_keypoint_ids.primitive::<u16>(),
)
.map(
|(_index, positions, colors, radii, labels, class_ids, keypoint_ids)| {
Points3DComponentData {
positions: bytemuck::cast_slice(positions),
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 point_builder,
&mut line_builder,
view_query,
spatial_ctx,
data,
)
},
)?;

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 the do-not-merge Do not merge this PR label Jul 29, 2024
@teh-cmc teh-cmc force-pushed the cmc/chunkified_queries_9_store_configs_in_my_stash branch from af25ad5 to ee0abec Compare July 29, 2024 16:10
Base automatically changed from cmc/chunkified_queries_9_store_configs_in_my_stash to main July 29, 2024 16:10
@teh-cmc teh-cmc force-pushed the cmc/chunkified_queries_10_spatial branch 3 times, most recently from 97bf8e9 to 35b5990 Compare July 30, 2024 09:07
@teh-cmc teh-cmc added 📺 re_viewer affects re_viewer itself 🔍 re_query affects re_query itself 🍏 primitives Relating to Rerun primitives include in changelog 🚀 performance Optimization, memory use, etc and removed do-not-merge Do not merge this PR labels Jul 30, 2024
@teh-cmc teh-cmc marked this pull request as ready for review July 30, 2024 09:13
@Wumpf Wumpf self-requested a review July 30, 2024 12:47
@teh-cmc teh-cmc force-pushed the cmc/chunkified_queries_10_spatial branch from a52cea0 to afdb95c Compare July 30, 2024 13:03
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.

some concerns on usability/how easy it is to mess up. Otherwise looking great.

iter_primitive_arrays <3. Ages ago I whined "why aren't we just reinterpret casting our float arrays T_T" and now we finally have it. What a time to be alive!

Either::Right(
self.iter_component_offsets(component_name)
.map(move |(idx, len)| {
bytemuck::cast_slice(&values[idx * size..idx * size + len * size])
Copy link
Member

Choose a reason for hiding this comment

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

oh, the doc wasn't joking, we're talking ptr cast fast here :O

Copy link
Member

Choose a reason for hiding this comment

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

should we be nervous though about alignment issues?
I figure right now we don't have any special alignment requirements on any of our types and I'm not sure its possible to have that and still implement arrow2::types::NativeType 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

should we be nervous though about alignment issues?

I wouldn't be: bytemuck::cast_slice panics on misalignment, which can only happen if someone has just modified this view's code and/or the arrow representation of points, at which point I sure hope said someone will try the view to see if it still works (and would insta panic).

Comment on lines +286 to +295
let world_from_entity =
if view_ctx.space_view_class_identifier() == SpatialSpaceView3D::identifier() {
transforms.reference_from_entity(&data_result.entity_path)
} else {
transforms.reference_from_entity_ignoring_pinhole(
&data_result.entity_path,
ctx.recording(),
&latest_at,
)
};
Copy link
Member

Choose a reason for hiding this comment

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

(fyi I'm break this on another PR, merge should be trivial thougyh)

.sum::<usize>();
let num_positions = all_position_chunks
.iter()
.flat_map(|chunk| chunk.iter_primitive_array::<2, f32>(&Position2D::name()))
Copy link
Member

Choose a reason for hiding this comment

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

it's a bit unfortunate how easy it is to get this wrong here: We first specify Position2D's name, then have to know this is two floats and then cast it to Position2D. If any of these steps are wrong, we get into a weird state.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same remark as above: you don't really get into a weird state most of the time, you just insta panic. And again you have to be actively modifying this code etc.

Comment on lines 239 to 244
let all_positions_indexed = all_position_chunks.iter().flat_map(|chunk| {
itertools::izip!(
chunk.iter_component_indices(&timeline, &Position2D::name()),
chunk.iter_primitive_array::<2, f32>(&Position2D::name())
)
});
Copy link
Member

Choose a reason for hiding this comment

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

it would be nice to have a similar utility like iter_as here to make this shorter

Copy link
Member Author

Choose a reason for hiding this comment

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

😭 I used to have them, but it seemed really over the top to maintain yet another set of helpers just for this part.

I'll try it once again and see how it feels.

Copy link
Member Author

Choose a reason for hiding this comment

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

Brought them back! 🙇

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