Skip to content

Commit

Permalink
Keep global registry of all visualizers & context systems instead of …
Browse files Browse the repository at this point in the history
…isolating per space view class (#4540)

### What

* Refactor towards #4490

This will allow us to store additional state with each registry entry:
This will be used to register a `VisualizerEntitySubscriber` and store a
handle to it for every visualizer.

All the "interesting" changes are in
`crates/re_viewer_context/src/space_view/space_view_class_registry.rs`,
everything else is just ripples.

Note that this pr sneakily starts the renaming of `ViewPart(System)` to
just `Visualizer`

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
  * Full build: [app.rerun.io](https://app.rerun.io/pr/4540/index.html)
* Partial build:
[app.rerun.io](https://app.rerun.io/pr/4540/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
- Useful for quick testing when changes do not affect examples in any
way
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4540)
- [Docs
preview](https://rerun.io/preview/13e2dbf32f0dd151e7ce18c2b98af9f1f929eb63/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/13e2dbf32f0dd151e7ce18c2b98af9f1f929eb63/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
Wumpf authored Dec 15, 2023
1 parent 5a93347 commit 490fc63
Show file tree
Hide file tree
Showing 23 changed files with 243 additions and 201 deletions.
4 changes: 2 additions & 2 deletions crates/re_space_view_bar_chart/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl SpaceViewClass for BarChartSpaceView {

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_part_system::<BarChartViewPartSystem>()
system_registry.register_visualizer::<BarChartViewPartSystem>()
}

fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> {
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_dataframe/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl SpaceViewClass for DataframeSpaceView {

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_part_system::<EmptySystem>()
system_registry.register_visualizer::<EmptySystem>()
}

fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/contexts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl ViewContextSystem for PrimitiveCounter {
}

pub fn register_spatial_contexts(
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_context_system::<TransformContext>()?;
system_registry.register_context_system::<EntityDepthOffsets>()?;
Expand Down
7 changes: 2 additions & 5 deletions crates/re_space_view_spatial/src/heuristics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
};

pub fn auto_spawn_heuristic(
class: &SpaceViewClassIdentifier,
class: SpaceViewClassIdentifier,
ctx: &ViewerContext<'_>,
per_system_entities: &PerSystemEntities,
view_kind: SpatialSpaceViewKind,
Expand All @@ -31,10 +31,7 @@ pub fn auto_spawn_heuristic(

let mut score = 0.0;

let parts = ctx
.space_view_class_registry
.get_system_registry_or_log_error(class)
.new_part_collection();
let parts = ctx.space_view_class_registry.new_part_collection(class);

// Gather all systems that advertise a "preferred view kind" matching the passed in kind.
let system_names_with_matching_view_kind = parts
Expand Down
52 changes: 26 additions & 26 deletions crates/re_space_view_spatial/src/parts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use re_types::datatypes::{KeypointId, KeypointPair};
use re_types::Archetype;
use re_viewer_context::SpaceViewClassRegistryError;
use re_viewer_context::{
auto_color, Annotations, DefaultColor, ResolvedAnnotationInfos, SpaceViewSystemRegistry,
auto_color, Annotations, DefaultColor, ResolvedAnnotationInfos, SpaceViewSystemRegistrator,
ViewPartCollection, ViewQuery,
};

Expand All @@ -46,39 +46,39 @@ pub const SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES: f32 = 1.5;
pub const SIZE_BOOST_IN_POINTS_FOR_POINT_OUTLINES: f32 = 2.5;

pub fn register_2d_spatial_parts(
system_registry: &mut SpaceViewSystemRegistry,
system_registry: &mut SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
// Note: 2D spatial systems don't include cameras as this
// part only shows a 2D projection WITHIN a 3D view.
system_registry.register_part_system::<arrows3d::Arrows3DPart>()?;
system_registry.register_part_system::<assets3d::Asset3DPart>()?;
system_registry.register_part_system::<boxes2d::Boxes2DPart>()?;
system_registry.register_part_system::<boxes3d::Boxes3DPart>()?;
system_registry.register_part_system::<images::ImagesPart>()?;
system_registry.register_part_system::<lines2d::Lines2DPart>()?;
system_registry.register_part_system::<lines3d::Lines3DPart>()?;
system_registry.register_part_system::<meshes::Mesh3DPart>()?;
system_registry.register_part_system::<points2d::Points2DPart>()?;
system_registry.register_part_system::<points3d::Points3DPart>()?;
system_registry.register_part_system::<transform3d_arrows::Transform3DArrowsPart>()?;
system_registry.register_visualizer::<arrows3d::Arrows3DPart>()?;
system_registry.register_visualizer::<assets3d::Asset3DPart>()?;
system_registry.register_visualizer::<boxes2d::Boxes2DPart>()?;
system_registry.register_visualizer::<boxes3d::Boxes3DPart>()?;
system_registry.register_visualizer::<images::ImagesPart>()?;
system_registry.register_visualizer::<lines2d::Lines2DPart>()?;
system_registry.register_visualizer::<lines3d::Lines3DPart>()?;
system_registry.register_visualizer::<meshes::Mesh3DPart>()?;
system_registry.register_visualizer::<points2d::Points2DPart>()?;
system_registry.register_visualizer::<points3d::Points3DPart>()?;
system_registry.register_visualizer::<transform3d_arrows::Transform3DArrowsPart>()?;
Ok(())
}

pub fn register_3d_spatial_parts(
system_registry: &mut SpaceViewSystemRegistry,
system_registry: &mut SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_part_system::<arrows3d::Arrows3DPart>()?;
system_registry.register_part_system::<assets3d::Asset3DPart>()?;
system_registry.register_part_system::<boxes2d::Boxes2DPart>()?;
system_registry.register_part_system::<boxes3d::Boxes3DPart>()?;
system_registry.register_part_system::<cameras::CamerasPart>()?;
system_registry.register_part_system::<images::ImagesPart>()?;
system_registry.register_part_system::<lines2d::Lines2DPart>()?;
system_registry.register_part_system::<lines3d::Lines3DPart>()?;
system_registry.register_part_system::<meshes::Mesh3DPart>()?;
system_registry.register_part_system::<points2d::Points2DPart>()?;
system_registry.register_part_system::<points3d::Points3DPart>()?;
system_registry.register_part_system::<transform3d_arrows::Transform3DArrowsPart>()?;
system_registry.register_visualizer::<arrows3d::Arrows3DPart>()?;
system_registry.register_visualizer::<assets3d::Asset3DPart>()?;
system_registry.register_visualizer::<boxes2d::Boxes2DPart>()?;
system_registry.register_visualizer::<boxes3d::Boxes3DPart>()?;
system_registry.register_visualizer::<cameras::CamerasPart>()?;
system_registry.register_visualizer::<images::ImagesPart>()?;
system_registry.register_visualizer::<lines2d::Lines2DPart>()?;
system_registry.register_visualizer::<lines3d::Lines3DPart>()?;
system_registry.register_visualizer::<meshes::Mesh3DPart>()?;
system_registry.register_visualizer::<points2d::Points2DPart>()?;
system_registry.register_visualizer::<points3d::Points3DPart>()?;
system_registry.register_visualizer::<transform3d_arrows::Transform3DArrowsPart>()?;
Ok(())
}

Expand Down
7 changes: 3 additions & 4 deletions crates/re_space_view_spatial/src/space_view_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl SpaceViewClass for SpatialSpaceView2D {

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
register_spatial_contexts(system_registry)?;
register_2d_spatial_parts(system_registry)?;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl SpaceViewClass for SpatialSpaceView2D {
per_system_entities: &PerSystemEntities,
) -> AutoSpawnHeuristic {
let mut score = auto_spawn_heuristic(
&self.identifier(),
self.identifier(),
ctx,
per_system_entities,
SpatialSpaceViewKind::TwoD,
Expand All @@ -92,8 +92,7 @@ impl SpaceViewClass for SpatialSpaceView2D {
if space_origin.is_root() {
let parts = ctx
.space_view_class_registry
.get_system_registry_or_log_error(&self.identifier())
.new_part_collection();
.new_part_collection(self.identifier());

for part in per_system_entities.keys() {
if let Ok(part) = parts.get_by_identifier(*part) {
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_spatial/src/space_view_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl SpaceViewClass for SpatialSpaceView3D {

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
register_spatial_contexts(system_registry)?;
register_3d_spatial_parts(system_registry)?;
Expand All @@ -56,7 +56,7 @@ impl SpaceViewClass for SpatialSpaceView3D {
per_system_entities: &PerSystemEntities,
) -> AutoSpawnHeuristic {
let score = auto_spawn_heuristic(
&self.identifier(),
self.identifier(),
ctx,
per_system_entities,
SpatialSpaceViewKind::ThreeD,
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_tensor/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ impl SpaceViewClass for TensorSpaceView {

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_part_system::<TensorSystem>()
system_registry.register_visualizer::<TensorSystem>()
}

fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> {
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_text_document/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ impl SpaceViewClass for TextDocumentSpaceView {

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_part_system::<TextDocumentSystem>()
system_registry.register_visualizer::<TextDocumentSystem>()
}

fn layout_priority(&self) -> re_viewer_context::SpaceViewClassLayoutPriority {
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_text_log/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ impl SpaceViewClass for TextSpaceView {

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_part_system::<TextLogSystem>()
system_registry.register_visualizer::<TextLogSystem>()
}

fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> {
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ impl SpaceViewClass for TimeSeriesSpaceView {

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_part_system::<TimeSeriesSystem>()
system_registry.register_visualizer::<TimeSeriesSystem>()
}

fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> {
Expand Down
6 changes: 3 additions & 3 deletions crates/re_viewer_context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub use space_view::{
HeuristicFilterContext, IdentifiedViewSystem, PerSystemDataResults, PerSystemEntities,
SpaceViewClass, SpaceViewClassIdentifier, SpaceViewClassLayoutPriority, SpaceViewClassRegistry,
SpaceViewClassRegistryError, SpaceViewEntityHighlight, SpaceViewHighlights,
SpaceViewOutlineMasks, SpaceViewState, SpaceViewSystemExecutionError, SpaceViewSystemRegistry,
SystemExecutionOutput, ViewContextCollection, ViewContextSystem, ViewPartCollection,
ViewPartSystem, ViewQuery, ViewSystemIdentifier,
SpaceViewOutlineMasks, SpaceViewState, SpaceViewSystemExecutionError,
SpaceViewSystemRegistrator, SystemExecutionOutput, ViewContextCollection, ViewContextSystem,
ViewPartCollection, ViewPartSystem, ViewQuery, ViewSystemIdentifier,
};
pub use store_context::StoreContext;
pub use tensor::{TensorDecodeCache, TensorStats, TensorStatsCache};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use re_types::ComponentName;

use crate::{
AutoSpawnHeuristic, PerSystemEntities, SpaceViewClassRegistryError, SpaceViewId,
SpaceViewSystemRegistry, SystemExecutionOutput, ViewQuery, ViewerContext,
SpaceViewSystemRegistrator, SystemExecutionOutput, ViewQuery, ViewerContext,
};

re_string_interner::declare_new_type!(
Expand Down Expand Up @@ -71,7 +71,7 @@ pub trait DynSpaceViewClass: Send + Sync {
/// This can be used to register all built-in [`crate::ViewContextSystem`] and [`crate::ViewPartSystem`].
fn on_register(
&self,
system_registry: &mut SpaceViewSystemRegistry,
system_registry: &mut SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError>;

/// Called once for every new space view instance of this class.
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer_context/src/space_view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use highlights::{SpaceViewEntityHighlight, SpaceViewHighlights, SpaceViewOut
pub use named_system::{IdentifiedViewSystem, PerSystemEntities, ViewSystemIdentifier};
pub use space_view_class::SpaceViewClass;
pub use space_view_class_registry::{
SpaceViewClassRegistry, SpaceViewClassRegistryError, SpaceViewSystemRegistry,
SpaceViewClassRegistry, SpaceViewClassRegistryError, SpaceViewSystemRegistrator,
};
pub use system_execution_output::SystemExecutionOutput;
pub use view_context_system::{ViewContextCollection, ViewContextSystem};
Expand Down
6 changes: 3 additions & 3 deletions crates/re_viewer_context/src/space_view/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use re_types::ComponentName;
use crate::{
AutoSpawnHeuristic, DynSpaceViewClass, PerSystemEntities, SpaceViewClassIdentifier,
SpaceViewClassRegistryError, SpaceViewId, SpaceViewState, SpaceViewSystemExecutionError,
SpaceViewSystemRegistry, SystemExecutionOutput, ViewQuery, ViewerContext,
SpaceViewSystemRegistrator, SystemExecutionOutput, ViewQuery, ViewerContext,
};

/// Defines a class of space view.
Expand Down Expand Up @@ -50,7 +50,7 @@ pub trait SpaceViewClass: std::marker::Sized + Send + Sync {
/// This can be used to register all built-in [`crate::ViewContextSystem`] and [`crate::ViewPartSystem`].
fn on_register(
&self,
system_registry: &mut SpaceViewSystemRegistry,
system_registry: &mut SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError>;

/// Preferred aspect ratio for the ui tiles of this space view.
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<T: SpaceViewClass + 'static> DynSpaceViewClass for T {

fn on_register(
&self,
system_registry: &mut SpaceViewSystemRegistry,
system_registry: &mut SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
self.on_register(system_registry)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
SpaceViewClass, SpaceViewClassRegistryError, SpaceViewSystemExecutionError,
SpaceViewSystemRegistry, SystemExecutionOutput, ViewQuery, ViewerContext,
SpaceViewSystemRegistrator, SystemExecutionOutput, ViewQuery, ViewerContext,
};
use re_data_store::EntityProperties;

Expand All @@ -24,7 +24,7 @@ impl SpaceViewClass for SpaceViewClassPlaceholder {

fn on_register(
&self,
_system_registry: &mut SpaceViewSystemRegistry,
_system_registry: &mut SpaceViewSystemRegistrator<'_>,
) -> Result<(), SpaceViewClassRegistryError> {
Ok(())
}
Expand Down
Loading

0 comments on commit 490fc63

Please sign in to comment.