Skip to content

Commit

Permalink
Chunkified, deserialization-free visualizers for all standard shapes (#…
Browse files Browse the repository at this point in the history
…7020)

Chunkified, (mostly)deserialization-free visualizers for all remaining
standard shapes.

Pretty straightforward now that we have all the iteration tools already
in place.

- DNM: requires #7019

---

#### Ellipsoids3D

![image](https://github.com/user-attachments/assets/7ca5765e-a5b9-431b-91db-85cd98cf5f56)

#### Boxes2D

![image](https://github.com/user-attachments/assets/83fadea0-9a9d-4c49-9ef4-3eb0607713ad)

#### Boxes3D

![image](https://github.com/user-attachments/assets/28414c83-0d54-4405-80ff-598f50373a9c)

#### Arrows2D

![image](https://github.com/user-attachments/assets/2a93f9e4-561d-4912-8925-a0a4e63c37b5)

#### Arrows3D

![image](https://github.com/user-attachments/assets/63d0de57-ef94-4551-bd15-bcf3d6c31c20)
  • Loading branch information
teh-cmc authored Aug 2, 2024
1 parent 8c95f1e commit 35de029
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace rerun.components;
/// The box extends both in negative and positive direction along each axis.
/// Negative sizes indicate that the box is flipped along the respective axis, but this has no effect on how it is displayed.
struct HalfSize2D (
"attr.rust.derive": "Copy, PartialEq"
"attr.rust.derive": "Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent"
) {
xy: rerun.datatypes.Vec2D (order: 100);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace rerun.components;
/// The box extends both in negative and positive direction along each axis.
/// Negative sizes indicate that the box is flipped along the respective axis, but this has no effect on how it is displayed.
struct HalfSize3D (
"attr.rust.derive": "Copy, PartialEq"
"attr.rust.derive": "Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent"
) {
xyz: rerun.datatypes.Vec3D (order: 100);
}
5 changes: 3 additions & 2 deletions crates/store/re_types/src/components/half_size2d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/store/re_types/src/components/half_size3d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 41 additions & 36 deletions crates/viewer/re_space_view_spatial/src/visualizers/arrows2d.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use re_log_types::Instance;
use re_query::range_zip_1x6;
use re_renderer::{renderer::LineStripFlags, LineDrawableBuilder, PickingLayerInstanceId};
use re_types::{
archetypes::Arrows2D,
components::{ClassId, Color, DrawOrder, KeypointId, Position2D, Radius, Text, Vector2D},
ArrowString, Loggable as _,
};
use re_viewer_context::{
auto_color_for_entity_path, ApplicableEntities, IdentifiedViewSystem, QueryContext,
Expand All @@ -19,7 +19,7 @@ use crate::{

use super::{
entity_iterator::clamped_or, process_annotation_and_keypoint_slices, process_color_slice,
process_labels_2d, process_radius_slice, SpatialViewVisualizerData,
process_radius_slice, utilities::process_labels_2d, SpatialViewVisualizerData,
SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES,
};

Expand Down Expand Up @@ -140,7 +140,7 @@ impl Arrows2DVisualizer {
self.data.ui_labels.extend(process_labels_2d(
entity_path,
label_positions,
data.labels,
&data.labels,
&colors,
&annotation_infos,
world_from_obj,
Expand All @@ -160,7 +160,7 @@ struct Arrows2DComponentData<'a> {
origins: &'a [Position2D],
colors: &'a [Color],
radii: &'a [Radius],
labels: &'a [Text],
labels: Vec<ArrowString>,
keypoint_ids: &'a [KeypointId],
class_ids: &'a [ClassId],
}
Expand Down Expand Up @@ -198,57 +198,62 @@ impl VisualizerSystem for Arrows2DVisualizer {
let mut line_builder = LineDrawableBuilder::new(render_ctx);
line_builder.radius_boost_in_ui_points_for_outlines(SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES);

super::entity_iterator::process_archetype::<Self, Arrows2D, _>(
use super::entity_iterator::{iter_primitive_array, process_archetype2};
process_archetype2::<Self, Arrows2D, _>(
ctx,
view_query,
context_systems,
|ctx, spatial_ctx, results| {
use re_space_view::RangeResultsExt as _;
use re_space_view::RangeResultsExt2 as _;

let resolver = ctx.recording().resolver();

let vectors = match results.get_required_component_dense::<Vector2D>(resolver) {
Some(vectors) => vectors?,
_ => return Ok(()),
let Some(all_vector_chunks) = results.get_required_chunks(&Vector2D::name()) else {
return Ok(());
};

let num_vectors = vectors
.range_indexed()
.map(|(_, vectors)| vectors.len())
.sum::<usize>();
let num_vectors = all_vector_chunks
.iter()
.flat_map(|chunk| chunk.iter_primitive_array::<2, f32>(&Vector2D::name()))
.map(|vectors| vectors.len())
.sum();

if num_vectors == 0 {
return Ok(());
}

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(),
let timeline = ctx.query.timeline();
let all_vectors_indexed =
iter_primitive_array::<2, f32>(&all_vector_chunks, timeline, Vector2D::name());
let all_origins = results.iter_as(timeline, Position2D::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_1x6(
all_vectors_indexed,
all_origins.primitive_array::<2, f32>(),
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_keypoint_ids.primitive::<u16>(),
)
.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(),
vectors: bytemuck::cast_slice(vectors),
origins: origins.map_or(&[], |origins| bytemuck::cast_slice(origins)),
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.unwrap_or_default(),
keypoint_ids: keypoint_ids.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)),
}
},
);
Expand Down
75 changes: 40 additions & 35 deletions crates/viewer/re_space_view_spatial/src/visualizers/arrows3d.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use re_log_types::Instance;
use re_query::range_zip_1x6;
use re_renderer::{renderer::LineStripFlags, LineDrawableBuilder, PickingLayerInstanceId};
use re_types::{
archetypes::Arrows3D,
components::{ClassId, Color, KeypointId, Position3D, Radius, Text, Vector3D},
ArrowString, Loggable as _,
};
use re_viewer_context::{
auto_color_for_entity_path, ApplicableEntities, IdentifiedViewSystem, QueryContext,
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Arrows3DVisualizer {
self.data.ui_labels.extend(process_labels_3d(
entity_path,
label_positions,
data.labels,
&data.labels,
&colors,
&annotation_infos,
world_from_obj,
Expand All @@ -160,7 +160,7 @@ struct Arrows3DComponentData<'a> {
origins: &'a [Position3D],
colors: &'a [Color],
radii: &'a [Radius],
labels: &'a [Text],
labels: Vec<ArrowString>,
keypoint_ids: &'a [KeypointId],
class_ids: &'a [ClassId],
}
Expand Down Expand Up @@ -198,57 +198,62 @@ impl VisualizerSystem for Arrows3DVisualizer {
let mut line_builder = LineDrawableBuilder::new(render_ctx);
line_builder.radius_boost_in_ui_points_for_outlines(SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES);

super::entity_iterator::process_archetype::<Self, Arrows3D, _>(
use super::entity_iterator::{iter_primitive_array, process_archetype2};
process_archetype2::<Self, Arrows3D, _>(
ctx,
view_query,
context_systems,
|ctx, spatial_ctx, results| {
use re_space_view::RangeResultsExt as _;
use re_space_view::RangeResultsExt2 as _;

let resolver = ctx.recording().resolver();

let vectors = match results.get_required_component_dense::<Vector3D>(resolver) {
Some(vectors) => vectors?,
_ => return Ok(()),
let Some(all_vector_chunks) = results.get_required_chunks(&Vector3D::name()) else {
return Ok(());
};

let num_vectors = vectors
.range_indexed()
.map(|(_, vectors)| vectors.len())
.sum::<usize>();
let num_vectors = all_vector_chunks
.iter()
.flat_map(|chunk| chunk.iter_primitive_array::<3, f32>(&Vector3D::name()))
.map(|vectors| vectors.len())
.sum();

if num_vectors == 0 {
return Ok(());
}

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(),
let timeline = ctx.query.timeline();
let all_vectors_indexed =
iter_primitive_array::<3, f32>(&all_vector_chunks, timeline, Vector3D::name());
let all_origins = results.iter_as(timeline, 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_1x6(
all_vectors_indexed,
all_origins.primitive_array::<3, f32>(),
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_keypoint_ids.primitive::<u16>(),
)
.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(),
vectors: bytemuck::cast_slice(vectors),
origins: origins.map_or(&[], |origins| bytemuck::cast_slice(origins)),
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.unwrap_or_default(),
keypoint_ids: keypoint_ids.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)),
}
},
);
Expand Down
Loading

0 comments on commit 35de029

Please sign in to comment.