Skip to content

Commit

Permalink
patch all the visualizers to use the APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Dec 20, 2024
1 parent 81cbd4f commit 92a0bce
Show file tree
Hide file tree
Showing 27 changed files with 165 additions and 182 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6648,6 +6648,7 @@ dependencies = [
"ahash",
"egui",
"fjadra",
"itertools 0.13.0",
"nohash-hasher",
"re_chunk",
"re_data_ui",
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_view_graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ re_viewport_blueprint.workspace = true
ahash.workspace = true
egui.workspace = true
fjadra.workspace = true
itertools.workspace = true
nohash-hasher.workspace = true
16 changes: 8 additions & 8 deletions crates/viewer/re_view_graph/src/visualizers/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl VisualizerSystem for NodeVisualizer {
&timeline_query,
);

let all_indexed_nodes = results.iter_as(query.timeline, components::GraphNode::name());
let all_nodes = results.iter_as(query.timeline, components::GraphNode::name());
let all_colors = results.iter_as(query.timeline, components::Color::name());
let all_positions = results.iter_as(query.timeline, components::Position2D::name());
let all_labels = results.iter_as(query.timeline, components::Text::name());
Expand All @@ -88,12 +88,11 @@ impl VisualizerSystem for NodeVisualizer {
.map_or(true, bool::from);

let data = range_zip_1x4(
// TODO(cmc): Provide a `iter_struct`.
all_indexed_nodes.component_slow::<components::GraphNode>(),
all_colors.primitive::<u32>(),
all_positions.primitive_array::<2, f32>(),
all_labels.string(),
all_radii.primitive::<f32>(),
all_nodes.slice::<String>(),
all_colors.slice::<u32>(),
all_positions.slice::<[f32; 2]>(),
all_labels.slice::<String>(),
all_radii.slice::<f32>(),
);

for (_index, nodes, colors, positions, labels, radii) in data {
Expand All @@ -114,6 +113,7 @@ impl VisualizerSystem for NodeVisualizer {
Option::<f32>::default,
)
.map(|(node, instance, color, position, label, radius)| {
let node = components::GraphNode(node.clone().into());
let color = color.map(|&c| egui::Color32::from(Color::new(c)));
let label = match (label, show_label) {
(Some(label), true) => Label::Text {
Expand All @@ -133,7 +133,7 @@ impl VisualizerSystem for NodeVisualizer {

NodeInstance {
instance_index: instance,
id: NodeId::from_entity_node(&data_result.entity_path, node),
id: NodeId::from_entity_node(&data_result.entity_path, &node),
position: position.map(|[x, y]| egui::Pos2::new(x, y)),
label,
}
Expand Down
6 changes: 3 additions & 3 deletions crates/viewer/re_view_map/src/visualizers/geo_line_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ impl VisualizerSystem for GeoLineStringsVisualizer {

// iterate over each chunk and find all relevant component slices
for (_index, lines, colors, radii) in re_query::range_zip_1x2(
all_lines.primitive_array_list::<2, f64>(),
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_lines.slice::<&[[f64; 2]]>(),
all_colors.slice::<u32>(),
all_radii.slice::<f32>(),
) {
// required component
let lines = lines.as_slice();
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_view_map/src/visualizers/geo_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ impl VisualizerSystem for GeoPointsVisualizer {

// iterate over each chunk and find all relevant component slices
for (_index, positions, colors, radii, class_ids) in re_query::range_zip_1x3(
all_positions.primitive_array::<2, f64>(),
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_class_ids.primitive::<u16>(),
all_positions.slice::<[f64; 2]>(),
all_colors.slice::<u32>(),
all_radii.slice::<f32>(),
all_class_ids.slice::<u16>(),
) {
// required component
let num_instances = positions.len();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl PerStoreChunkSubscriber for MaxImageDimensionsStoreSubscriber {
}

// Handle `ImageEncoded`, `AssetVideo`…
let blobs = event.diff.chunk.iter_buffer(&Blob::name());
let media_types = event.diff.chunk.iter_string(&MediaType::name());
let blobs = event.diff.chunk.iter_slices::<&[u8]>(Blob::name());
let media_types = event.diff.chunk.iter_slices::<String>(MediaType::name());
for (blob, media_type) in
itertools::izip!(blobs, media_types.map(Some).chain(std::iter::repeat(None)))
{
Expand Down
20 changes: 10 additions & 10 deletions crates/viewer/re_view_spatial/src/visualizers/arrows2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl VisualizerSystem for Arrows2DVisualizer {
re_view::SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES,
);

use super::entity_iterator::{iter_primitive_array, process_archetype};
use super::entity_iterator::{iter_slices, process_archetype};
process_archetype::<Self, Arrows2D, _>(
ctx,
view_query,
Expand All @@ -214,7 +214,7 @@ impl VisualizerSystem for Arrows2DVisualizer {

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

Expand All @@ -227,7 +227,7 @@ impl VisualizerSystem for Arrows2DVisualizer {

let timeline = ctx.query.timeline();
let all_vectors_indexed =
iter_primitive_array::<2, f32>(&all_vector_chunks, timeline, Vector2D::name());
iter_slices::<[f32; 2]>(&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());
Expand All @@ -238,13 +238,13 @@ impl VisualizerSystem for Arrows2DVisualizer {

let data = re_query::range_zip_1x7(
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>(),
all_show_labels.bool(),
all_origins.slice::<[f32; 2]>(),
all_colors.slice::<u32>(),
all_radii.slice::<f32>(),
all_labels.slice::<String>(),
all_class_ids.slice::<u16>(),
all_keypoint_ids.slice::<u16>(),
all_show_labels.slice::<bool>(),
)
.map(
|(
Expand Down
18 changes: 9 additions & 9 deletions crates/viewer/re_view_spatial/src/visualizers/arrows3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl VisualizerSystem for Arrows3DVisualizer {
re_view::SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES,
);

use super::entity_iterator::{iter_primitive_array, process_archetype};
use super::entity_iterator::{iter_slices, process_archetype};
process_archetype::<Self, Arrows3D, _>(
ctx,
view_query,
Expand All @@ -213,7 +213,7 @@ impl VisualizerSystem for Arrows3DVisualizer {

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

Expand All @@ -226,7 +226,7 @@ impl VisualizerSystem for Arrows3DVisualizer {

let timeline = ctx.query.timeline();
let all_vectors_indexed =
iter_primitive_array::<3, f32>(&all_vector_chunks, timeline, Vector3D::name());
iter_slices::<[f32; 3]>(&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());
Expand All @@ -236,12 +236,12 @@ impl VisualizerSystem for Arrows3DVisualizer {

let data = re_query::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_show_labels.bool(),
all_origins.slice::<[f32; 3]>(),
all_colors.slice::<u32>(),
all_radii.slice::<f32>(),
all_labels.slice::<String>(),
all_class_ids.slice::<u16>(),
all_show_labels.slice::<bool>(),
)
.map(
|(_index, vectors, origins, colors, radii, labels, class_ids, show_labels)| {
Expand Down
9 changes: 5 additions & 4 deletions crates/viewer/re_view_spatial/src/visualizers/assets3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl VisualizerSystem for Asset3DVisualizer {

let mut instances = Vec::new();

use super::entity_iterator::{iter_buffer, process_archetype};
use super::entity_iterator::{iter_slices, process_archetype};
process_archetype::<Self, Asset3D, _>(
ctx,
view_query,
Expand All @@ -155,16 +155,17 @@ impl VisualizerSystem for Asset3DVisualizer {
};

let timeline = ctx.query.timeline();
let all_blobs_indexed = iter_buffer::<u8>(&all_blob_chunks, timeline, Blob::name());
let all_blobs_indexed =
iter_slices::<&[u8]>(&all_blob_chunks, timeline, Blob::name());
let all_media_types = results.iter_as(timeline, MediaType::name());
let all_albedo_factors = results.iter_as(timeline, AlbedoFactor::name());

let query_result_hash = results.query_result_hash();

let data = re_query::range_zip_1x2(
all_blobs_indexed,
all_media_types.string(),
all_albedo_factors.primitive::<u32>(),
all_media_types.slice::<String>(),
all_albedo_factors.slice::<u32>(),
)
.filter_map(|(index, blobs, media_types, albedo_factors)| {
blobs.first().map(|blob| Asset3DComponentData {
Expand Down
23 changes: 10 additions & 13 deletions crates/viewer/re_view_spatial/src/visualizers/boxes2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl VisualizerSystem for Boxes2DVisualizer {
re_view::SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES,
);

use super::entity_iterator::{iter_primitive_array, process_archetype};
use super::entity_iterator::{iter_slices, process_archetype};
process_archetype::<Self, Boxes2D, _>(
ctx,
view_query,
Expand All @@ -214,7 +214,7 @@ impl VisualizerSystem for Boxes2DVisualizer {

let num_boxes: usize = all_half_size_chunks
.iter()
.flat_map(|chunk| chunk.iter_primitive_array::<2, f32>(&HalfSize2D::name()))
.flat_map(|chunk| chunk.iter_slices::<[f32; 2]>(HalfSize2D::name()))
.map(|vectors| vectors.len())
.sum();
if num_boxes == 0 {
Expand All @@ -226,11 +226,8 @@ impl VisualizerSystem for Boxes2DVisualizer {
line_builder.reserve_vertices(num_boxes * 5)?;

let timeline = ctx.query.timeline();
let all_half_sizes_indexed = iter_primitive_array::<2, f32>(
&all_half_size_chunks,
timeline,
HalfSize2D::name(),
);
let all_half_sizes_indexed =
iter_slices::<[f32; 2]>(&all_half_size_chunks, timeline, HalfSize2D::name());
let all_centers = results.iter_as(timeline, Position2D::name());
let all_colors = results.iter_as(timeline, Color::name());
let all_radii = results.iter_as(timeline, Radius::name());
Expand All @@ -240,12 +237,12 @@ impl VisualizerSystem for Boxes2DVisualizer {

let data = re_query::range_zip_1x6(
all_half_sizes_indexed,
all_centers.primitive_array::<2, f32>(),
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_show_labels.bool(),
all_centers.slice::<[f32; 2]>(),
all_colors.slice::<u32>(),
all_radii.slice::<f32>(),
all_labels.slice::<String>(),
all_class_ids.slice::<u16>(),
all_show_labels.slice::<bool>(),
)
.map(
|(
Expand Down
23 changes: 10 additions & 13 deletions crates/viewer/re_view_spatial/src/visualizers/boxes3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl VisualizerSystem for Boxes3DVisualizer {
let mut builder =
ProcMeshDrawableBuilder::new(&mut self.0, render_ctx, view_query, "boxes3d", &Fallback);

use super::entity_iterator::{iter_primitive_array, process_archetype};
use super::entity_iterator::{iter_slices, process_archetype};
process_archetype::<Self, Boxes3D, _>(
ctx,
view_query,
Expand All @@ -136,19 +136,16 @@ impl VisualizerSystem for Boxes3DVisualizer {

let num_boxes: usize = all_half_size_chunks
.iter()
.flat_map(|chunk| chunk.iter_primitive_array::<3, f32>(&HalfSize3D::name()))
.flat_map(|chunk| chunk.iter_slices::<[f32; 3]>(HalfSize3D::name()))
.map(|vectors| vectors.len())
.sum();
if num_boxes == 0 {
return Ok(());
}

let timeline = ctx.query.timeline();
let all_half_sizes_indexed = iter_primitive_array::<3, f32>(
&all_half_size_chunks,
timeline,
HalfSize3D::name(),
);
let all_half_sizes_indexed =
iter_slices::<[f32; 3]>(&all_half_size_chunks, timeline, HalfSize3D::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());
Expand All @@ -159,7 +156,7 @@ impl VisualizerSystem for Boxes3DVisualizer {
let all_fill_modes = results.iter_as(timeline, FillMode::name());
// fill mode is currently a non-repeated component
let fill_mode: FillMode = all_fill_modes
.primitive::<u8>()
.slice::<u8>()
.next()
.and_then(|(_, fill_modes)| {
fill_modes.first().copied().and_then(FillMode::from_u8)
Expand All @@ -179,11 +176,11 @@ impl VisualizerSystem for Boxes3DVisualizer {

let data = re_query::range_zip_1x5(
all_half_sizes_indexed,
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_show_labels.bool(),
all_colors.slice::<u32>(),
all_radii.slice::<f32>(),
all_labels.slice::<String>(),
all_class_ids.slice::<u16>(),
all_show_labels.slice::<bool>(),
)
.map(
|(_index, half_sizes, colors, radii, labels, class_ids, show_labels)| {
Expand Down
18 changes: 9 additions & 9 deletions crates/viewer/re_view_spatial/src/visualizers/capsules3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl VisualizerSystem for Capsules3DVisualizer {
&Fallback,
);

use super::entity_iterator::{iter_primitive, process_archetype};
use super::entity_iterator::{iter_slices, process_archetype};
process_archetype::<Self, Capsules3D, _>(
ctx,
view_query,
Expand All @@ -167,12 +167,12 @@ impl VisualizerSystem for Capsules3DVisualizer {

let num_lengths: usize = all_length_chunks
.iter()
.flat_map(|chunk| chunk.iter_primitive::<f32>(&Length::name()))
.flat_map(|chunk| chunk.iter_slices::<f32>(Length::name()))
.map(|lengths| lengths.len())
.sum();
let num_radii: usize = all_radius_chunks
.iter()
.flat_map(|chunk| chunk.iter_primitive::<f32>(&components::Radius::name()))
.flat_map(|chunk| chunk.iter_slices::<f32>(components::Radius::name()))
.map(|radii| radii.len())
.sum();
let num_instances = num_lengths.max(num_radii);
Expand All @@ -182,9 +182,9 @@ impl VisualizerSystem for Capsules3DVisualizer {

let timeline = ctx.query.timeline();
let all_lengths_indexed =
iter_primitive::<f32>(&all_length_chunks, timeline, Length::name());
iter_slices::<f32>(&all_length_chunks, timeline, Length::name());
let all_radii_indexed =
iter_primitive::<f32>(&all_radius_chunks, timeline, components::Radius::name());
iter_slices::<f32>(&all_radius_chunks, timeline, components::Radius::name());
let all_colors = results.iter_as(timeline, Color::name());
let all_labels = results.iter_as(timeline, Text::name());
let all_show_labels = results.iter_as(timeline, ShowLabels::name());
Expand All @@ -193,10 +193,10 @@ impl VisualizerSystem for Capsules3DVisualizer {
let data = re_query::range_zip_2x4(
all_lengths_indexed,
all_radii_indexed,
all_colors.primitive::<u32>(),
all_labels.string(),
all_show_labels.bool(),
all_class_ids.primitive::<u16>(),
all_colors.slice::<u32>(),
all_labels.slice::<String>(),
all_show_labels.slice::<bool>(),
all_class_ids.slice::<u16>(),
)
.map(
|(_index, lengths, radii, colors, labels, show_labels, class_ids)| {
Expand Down
Loading

0 comments on commit 92a0bce

Please sign in to comment.