Skip to content

Commit

Permalink
get rid of a whole bunch of component_slow
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Dec 19, 2024
1 parent 1449efb commit dfc69d4
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 33 deletions.
31 changes: 31 additions & 0 deletions crates/store/re_types/src/components/colormap_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use super::Colormap;

impl Colormap {
/// Instantiate a new [`Colormap`] from a u8 value.
///
/// Returns `None` if the value doesn't match any of the enum's arms.
pub fn from_u8(value: u8) -> Option<Self> {
// NOTE: This code will be optimized out, it's only here to make sure this method fails to
// compile if the enum is modified.
match Self::default() {
Self::Grayscale
| Self::Inferno
| Self::Magma
| Self::Plasma
| Self::Turbo
| Self::Viridis
| Self::CyanToYellow => {}
}

match value {
v if v == Self::Grayscale as u8 => Some(Self::Grayscale),
v if v == Self::Inferno as u8 => Some(Self::Inferno),
v if v == Self::Magma as u8 => Some(Self::Magma),
v if v == Self::Plasma as u8 => Some(Self::Plasma),
v if v == Self::Turbo as u8 => Some(Self::Turbo),
v if v == Self::Viridis as u8 => Some(Self::Viridis),
v if v == Self::CyanToYellow as u8 => Some(Self::CyanToYellow),
_ => None,
}
}
}
21 changes: 21 additions & 0 deletions crates/store/re_types/src/components/fill_mode_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use super::FillMode;

impl FillMode {
/// Instantiate a new [`FillMode`] from a u8 value.
///
/// Returns `None` if the value doesn't match any of the enum's arms.
pub fn from_u8(value: u8) -> Option<Self> {
// NOTE: This code will be optimized out, it's only here to make sure this method fails to
// compile if the enum is modified.
match Self::default() {
Self::MajorWireframe | Self::DenseWireframe | Self::Solid => {}
}

match value {
v if v == Self::MajorWireframe as u8 => Some(Self::MajorWireframe),
v if v == Self::DenseWireframe as u8 => Some(Self::DenseWireframe),
v if v == Self::Solid as u8 => Some(Self::Solid),
_ => None,
}
}
}
2 changes: 2 additions & 0 deletions crates/store/re_types/src/components/mod.rs

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

1 change: 1 addition & 0 deletions crates/viewer/re_view_graph/src/visualizers/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl VisualizerSystem for EdgesVisualizer {
let all_indexed_edges = results.iter_as(query.timeline, components::GraphEdge::name());
let graph_type = results.get_mono_with_fallback::<components::GraphType>();

// TODO(cmc): Provide a `iter_struct`.
for (_index, edges) in all_indexed_edges.component_slow::<GraphEdge>() {
let edges = edges
.iter()
Expand Down
7 changes: 4 additions & 3 deletions crates/viewer/re_view_graph/src/visualizers/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ 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.component_slow::<components::Color>(),
all_colors.primitive::<u32>(),
all_positions.primitive_array::<2, f32>(),
all_labels.string(),
all_radii.primitive::<f32>(),
Expand All @@ -101,7 +102,7 @@ impl VisualizerSystem for NodeVisualizer {
nodes.iter(),
(0..).map(Instance::from),
colors.unwrap_or_default().iter().map(Option::Some),
Option::<&Color>::default,
Option::<&u32>::default,
positions
.unwrap_or_default()
.iter()
Expand All @@ -114,7 +115,7 @@ impl VisualizerSystem for NodeVisualizer {
Option::<f32>::default,
)
.map(|(node, instance, color, position, label, radius)| {
let color = color.map(|&c| egui::Color32::from(c));
let color = color.map(|&c| egui::Color32::from(Color::new(c)));
let label = match (label, show_label) {
(Some(label), true) => Label::Text {
text: label.clone(),
Expand Down
16 changes: 8 additions & 8 deletions crates/viewer/re_view_map/src/visualizers/geo_line_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ 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.component_slow::<GeoLineString>(),
all_colors.component_slow::<Color>(),
all_radii.component_slow::<Radius>(),
all_colors.primitive::<u32>(),
all_radii.primitive::<f32>(),
) {
// required component
let lines = lines.as_slice();

// optional components
let colors = colors.as_ref().map(|c| c.as_slice()).unwrap_or(&[]);
let radii = radii.as_ref().map(|r| r.as_slice()).unwrap_or(&[]);
let colors = colors.unwrap_or(&[]);
let radii = radii.unwrap_or(&[]);

// optional components values to be used for instance clamping semantics
let last_color = colors.last().copied().unwrap_or(fallback_color);
let last_radii = radii.last().copied().unwrap_or(fallback_radius);
let last_color = colors.last().copied().unwrap_or(fallback_color.0 .0);
let last_radii = radii.last().copied().unwrap_or(fallback_radius.0 .0);

// iterate over all instances
for (instance_index, (line, color, radius)) in itertools::izip!(
Expand All @@ -95,8 +95,8 @@ impl VisualizerSystem for GeoLineStringsVisualizer {
.map(|pos| walkers::Position::from_lat_lon(pos.x(), pos.y()))
.collect(),
);
batch_data.radii.push(*radius);
batch_data.colors.push(color.0.into());
batch_data.radii.push(Radius((*radius).into()));
batch_data.colors.push(Color::new(*color).into());
batch_data
.instance_id
.push(re_renderer::PickingLayerInstanceId(instance_index as _));
Expand Down
18 changes: 8 additions & 10 deletions crates/viewer/re_view_map/src/visualizers/geo_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ 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.component_slow::<LatLon>(),
all_positions.primitive_array::<2, f64>(),
all_colors.primitive::<u32>(),
all_radii.component_slow::<Radius>(),
all_radii.primitive::<f32>(),
all_class_ids.primitive::<u16>(),
) {
// required component
let positions = positions.as_slice();
let num_instances = positions.len();

// Resolve annotation info (if needed).
Expand All @@ -94,10 +93,10 @@ impl VisualizerSystem for GeoPointsVisualizer {
&annotation_infos,
colors.map_or(&[], |colors| bytemuck::cast_slice(colors)),
);
let radii = radii.as_ref().map(|r| r.as_slice()).unwrap_or(&[]);
let radii = radii.unwrap_or(&[]);

// optional components values to be used for instance clamping semantics
let last_radii = radii.last().copied().unwrap_or(fallback_radius);
let last_radii = radii.last().copied().unwrap_or(fallback_radius.0 .0);

// iterate over all instances
for (instance_index, (position, color, radius)) in itertools::izip!(
Expand All @@ -107,11 +106,10 @@ impl VisualizerSystem for GeoPointsVisualizer {
)
.enumerate()
{
batch_data.positions.push(walkers::Position::from_lat_lon(
position.latitude(),
position.longitude(),
));
batch_data.radii.push(*radius);
batch_data
.positions
.push(walkers::Position::from_lat_lon(position[0], position[1]));
batch_data.radii.push(Radius((*radius).into()));
batch_data.colors.push(*color);
batch_data
.instance_id
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_view_spatial/src/visualizers/arrows2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl VisualizerSystem for Arrows2DVisualizer {
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_keypoint_ids.primitive::<u16>(),
// TODO(cmc): provide a `iter_bool`.
all_show_labels.component_slow::<ShowLabels>(),
)
.map(
Expand Down
6 changes: 4 additions & 2 deletions crates/viewer/re_view_spatial/src/visualizers/boxes3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ 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
.component_slow::<FillMode>()
.primitive::<u8>()
.next()
.and_then(|(_, fill_modes)| fill_modes.as_slice().first().copied())
.and_then(|(_, fill_modes)| {
fill_modes.first().copied().and_then(FillMode::from_u8)
})
.unwrap_or_default();

match fill_mode {
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/re_view_spatial/src/visualizers/depth_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl VisualizerSystem for DepthImageVisualizer {
let mut data = re_query::range_zip_1x5(
all_buffers_indexed,
all_formats_indexed,
all_colormaps.component_slow::<components::Colormap>(),
all_colormaps.primitive::<u8>(),
all_value_ranges.primitive_array::<2, f64>(),
all_depth_meters.primitive::<f32>(),
all_fill_ratios.primitive::<f32>(),
Expand All @@ -310,7 +310,7 @@ impl VisualizerSystem for DepthImageVisualizer {
},
depth_meter: first_copied(depth_meter).map(Into::into),
fill_ratio: first_copied(fill_ratio).map(Into::into),
colormap: first_copied(colormap.as_deref()),
colormap: first_copied(colormap).and_then(Colormap::from_u8),
value_range: first_copied(value_range).map(Into::into),
})
},
Expand Down
3 changes: 2 additions & 1 deletion crates/viewer/re_view_spatial/src/visualizers/ellipsoids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl VisualizerSystem for Ellipsoids3DVisualizer {
all_half_sizes_indexed,
all_colors.primitive::<u32>(),
all_line_radii.primitive::<f32>(),
all_fill_modes.component_slow::<FillMode>(),
all_fill_modes.primitive::<u8>(),
all_labels.string(),
all_class_ids.primitive::<u16>(),
all_show_labels.component_slow::<ShowLabels>(),
Expand All @@ -204,6 +204,7 @@ impl VisualizerSystem for Ellipsoids3DVisualizer {
.unwrap_or_default()
.first()
.copied()
.and_then(FillMode::from_u8)
.unwrap_or_default(),
labels: labels.unwrap_or_default(),
class_ids: class_ids
Expand Down
2 changes: 2 additions & 0 deletions crates/viewer/re_view_spatial/src/visualizers/meshes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ impl VisualizerSystem for Mesh3DVisualizer {
all_vertex_texcoords.primitive_array::<2, f32>(),
all_triangle_indices.primitive_array::<3, u32>(),
all_albedo_factors.primitive::<u32>(),
// TODO(cmc): Provide a `iter_blob`.
all_albedo_buffers.component_slow::<ImageBuffer>(),
// Legit call to `component_slow`, `ImageFormat` is real complicated.
all_albedo_formats.component_slow::<ImageFormat>(),
all_class_ids.primitive::<u16>(),
)
Expand Down
14 changes: 9 additions & 5 deletions crates/viewer/re_view_tensor/src/visualizer_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ impl VisualizerSystem for TensorSystem {
});
let all_ranges = results.iter_as(timeline, ValueRange::name());

for ((_, tensor_row_id), tensors, data_ranges) in re_query::range_zip_1x1(
all_tensors_indexed,
all_ranges.component_slow::<ValueRange>(),
) {
for ((_, tensor_row_id), tensors, data_ranges) in
re_query::range_zip_1x1(all_tensors_indexed, all_ranges.primitive_array::<2, f64>())
{
let Some(tensor) = tensors.first() else {
continue;
};
let data_range = data_ranges
.and_then(|ranges| ranges.first().copied())
.and_then(|ranges| {
ranges
.first()
.copied()
.map(|range| ValueRange(range.into()))
})
.unwrap_or_else(|| {
let tensor_stats = ctx
.viewer_ctx
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/re_view_text_log/src/visualizer_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl TextLogSystem {

let all_frames = range_zip_1x2(
all_texts.string(),
all_levels.component_slow(),
all_levels.string(),
all_colors.primitive::<u32>(),
);

Expand Down Expand Up @@ -139,7 +139,7 @@ impl TextLogSystem {
timepoint: timepoint.clone(),
color,
body: text.clone().into(),
level,
level: level.clone().map(Into::into),
});
}
}
Expand Down

0 comments on commit dfc69d4

Please sign in to comment.