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

Support displaying 1D tensors #5837

Merged
merged 6 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Blueprints are currently only supported in the Python API, with C++ and Rust sup
- Entity path query now shows simple statistics and warns if nothing is displayed [#5693](https://github.com/rerun-io/rerun/pull/5693)
- Go back to example page with browser Back-button [#5750](https://github.com/rerun-io/rerun/pull/5750)
- On Web, implement navigating back/forward with mouse buttons [#5792](https://github.com/rerun-io/rerun/pull/5792)
- Support displaying 1D tensors [#5837](https://github.com/rerun-io/rerun/pull/5837)

#### 🧑‍🏫 Examples
- New `incremental_logging` example [#5462](https://github.com/rerun-io/rerun/pull/5462)
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_tensor/src/dimension_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ impl DimensionMapping {
},

1 => DimensionMapping {
selectors: vec![DimensionSelector::new(0)],
width: None,
selectors: Default::default(),
width: Some(0),
height: None,
invert_width: false,
invert_height: false,
Expand Down
35 changes: 27 additions & 8 deletions crates/re_space_view_tensor/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,37 @@ pub fn selected_tensor_slice<'a, T: Copy>(

assert!(dimension_mapping.is_valid(tensor.ndim()));

// TODO(andreas) - shouldn't just give up here
if dimension_mapping.width.is_none() || dimension_mapping.height.is_none() {
return tensor.view();
}
let (width, height) =
if let (Some(width), Some(height)) = (dimension_mapping.width, dimension_mapping.height) {
(width, height)
} else if let Some(width) = dimension_mapping.width {
// If height is missing, create a 1D row.
(width, 1)
} else if let Some(height) = dimension_mapping.height {
// If width is missing, create a 1D column.
(1, height)
} else {
// If both are missing, give up.
return tensor.view();
};

let view = if tensor.shape().len() == 1 {
// We want 2D slices, so for "pure" 1D tensors add a dimension.
// This is important for above width/height conversion to work since this assumes at least 2 dimensions.
tensor
.view()
.into_shape(ndarray::IxDyn(&[tensor.len(), 1]))
.unwrap()
} else {
tensor.view()
};

let axis = dimension_mapping
.height
#[allow(clippy::tuple_array_conversions)]
let axis = [height, width]
.into_iter()
.chain(dimension_mapping.width)
.chain(dimension_mapping.selectors.iter().map(|s| s.dim_idx))
.collect::<Vec<_>>();
let mut slice = tensor.view().permuted_axes(axis);
let mut slice = view.permuted_axes(axis);

for DimensionSelector { dim_idx, .. } in &dimension_mapping.selectors {
let selector_value = selector_values.get(dim_idx).copied().unwrap_or_default() as usize;
Expand Down
18 changes: 1 addition & 17 deletions crates/re_space_view_tensor/src/visualizer_system.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use re_data_store::{LatestAtQuery, VersionedComponent};
use re_entity_db::EntityPath;
use re_log_types::RowId;
use re_space_view::diff_component_filter;
use re_types::{archetypes::Tensor, components::TensorData, tensor_data::DecodedTensor};
use re_viewer_context::{
IdentifiedViewSystem, SpaceViewSystemExecutionError, TensorDecodeCache, ViewContextCollection,
ViewQuery, ViewerContext, VisualizerAdditionalApplicabilityFilter, VisualizerQueryInfo,
VisualizerSystem,
ViewQuery, ViewerContext, VisualizerQueryInfo, VisualizerSystem,
};

#[derive(Default)]
Expand All @@ -20,25 +18,11 @@ impl IdentifiedViewSystem for TensorSystem {
}
}

struct TensorVisualizerEntityFilter;

impl VisualizerAdditionalApplicabilityFilter for TensorVisualizerEntityFilter {
fn update_applicability(&mut self, event: &re_data_store::StoreEvent) -> bool {
diff_component_filter(event, |tensor: &re_types::components::TensorData| {
!tensor.is_vector()
})
}
}

impl VisualizerSystem for TensorSystem {
fn visualizer_query_info(&self) -> VisualizerQueryInfo {
VisualizerQueryInfo::from_archetype::<Tensor>()
}

fn applicability_filter(&self) -> Option<Box<dyn VisualizerAdditionalApplicabilityFilter>> {
Some(Box::new(TensorVisualizerEntityFilter))
}
Wumpf marked this conversation as resolved.
Show resolved Hide resolved

fn execute(
&mut self,
ctx: &ViewerContext<'_>,
Expand Down