Skip to content

Commit

Permalink
Fix orphaned space views by constructing from tree rather than redund…
Browse files Browse the repository at this point in the history
…ant component (rerun-io#5744)

### What
- Resolves: rerun-io#5570

This was mostly just doing a code-cleanup I'd been meaning to do to
avoid a foot-gun that was documented and ignored.

### 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):
* Using newly built examples:
[rerun.io/viewer](https://rerun.io/viewer/pr/5744)
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/5744?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/5744?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5744)
- [Docs
preview](https://rerun.io/preview/560dab5eeedc7953b2fe092d0a024652d72fd053/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/560dab5eeedc7953b2fe092d0a024652d72fd053/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
jleibs authored Apr 2, 2024
1 parent a4d8be4 commit 779231b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ table ViewportBlueprint (
// --- Required ---

// --- Optional ---
/// All of the space-views that belong to the viewport.
space_views: [rerun.blueprint.components.IncludedSpaceView] ("attr.rerun.component_optional", nullable, order: 1000);

/// The layout of the space-views
root_container: rerun.blueprint.components.RootContainer ("attr.rerun.component_optional", nullable, order: 2500);

Expand Down
47 changes: 5 additions & 42 deletions crates/re_viewport/src/blueprint/archetypes/viewport_blueprint.rs

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

34 changes: 12 additions & 22 deletions crates/re_viewport/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ impl ViewportBlueprint {
re_tracing::profile_function!();

let crate::blueprint::archetypes::ViewportBlueprint {
space_views,
root_container,
maximized,
auto_layout,
Expand All @@ -98,13 +97,19 @@ impl ViewportBlueprint {
}
};

let space_view_ids: Vec<SpaceViewId> = space_views
.unwrap_or(vec![])
.iter()
.map(|id| id.0.into())
.collect();
let all_space_view_ids: Vec<SpaceViewId> = blueprint_db
.tree()
.children
.get(SpaceViewId::registry_part())
.map(|tree| {
tree.children
.values()
.map(|subtree| SpaceViewId::from_entity_path(&subtree.path))
.collect()
})
.unwrap_or_default();

let space_views: BTreeMap<SpaceViewId, SpaceViewBlueprint> = space_view_ids
let space_views: BTreeMap<SpaceViewId, SpaceViewBlueprint> = all_space_view_ids
.into_iter()
.filter_map(|space_view: SpaceViewId| {
SpaceViewBlueprint::try_from_db(space_view, blueprint_db, query)
Expand Down Expand Up @@ -393,13 +398,6 @@ impl ViewportBlueprint {
///
/// Note that this doesn't focus the corresponding tab. Use [`Self::focus_tab`] with the returned ID
/// if needed.
///
/// NOTE: Calling this more than once per frame will result in lost data.
/// Each call to `add_space_views` emits an updated list of [`IncludedSpaceView`]s
/// Built by taking the list of [`IncludedSpaceView`]s from the current frame
/// and adding the new space views to it. Since this the edit is not applied until
/// the end of frame the second call will see a stale version of the data.
// TODO(jleibs): Better safety check here.
pub fn add_space_views(
&self,
space_views: impl Iterator<Item = SpaceViewBlueprint>,
Expand Down Expand Up @@ -427,14 +425,6 @@ impl ViewportBlueprint {
position_in_parent,
));
}

let components = self
.space_views
.keys()
.chain(new_ids.iter())
.map(|id| IncludedSpaceView((*id).into()))
.collect::<Vec<_>>();
ctx.save_blueprint_component(&VIEWPORT_PATH.into(), &components);
}

new_ids
Expand Down

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

13 changes: 0 additions & 13 deletions rerun_cpp/src/rerun/blueprint/archetypes/viewport_blueprint.hpp

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

16 changes: 0 additions & 16 deletions rerun_py/rerun_sdk/rerun/blueprint/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import itertools
import uuid
from typing import Any, Iterable, Optional, Union

Expand Down Expand Up @@ -104,12 +103,6 @@ def _log_to_stream(self, stream: RecordingStream) -> None:

stream.log(self.blueprint_path(), arch, recording=stream) # type: ignore[attr-defined]

def _iter_space_views(self) -> Iterable[bytes]:
"""Internal method to iterate over all of the space views in the blueprint."""
# TODO(jleibs): This goes away when we get rid of `space_views` from the viewport and just use
# the entity-path lookup instead.
return [self.id.bytes]

def _repr_html_(self) -> Any:
"""IPython interface to conversion to html."""
return as_html(blueprint=self)
Expand Down Expand Up @@ -228,12 +221,6 @@ def _log_to_stream(self, stream: RecordingStream) -> None:

stream.log(self.blueprint_path(), arch) # type: ignore[attr-defined]

def _iter_space_views(self) -> Iterable[bytes]:
"""Internal method to iterate over all of the space views in the blueprint."""
# TODO(jleibs): This goes away when we get rid of `space_views` from the viewport and just use
# the entity-path lookup instead.
return itertools.chain.from_iterable(sub._iter_space_views() for sub in self.contents)

def _repr_html_(self) -> Any:
"""IPython interface to conversion to html."""
return as_html(blueprint=self)
Expand Down Expand Up @@ -439,13 +426,10 @@ def _log_to_stream(self, stream: RecordingStream) -> None:
self.root_container._log_to_stream(stream)

root_container_id = self.root_container.id.bytes
space_views = list(self.root_container._iter_space_views())
else:
root_container_id = None
space_views = []

viewport_arch = ViewportBlueprint(
space_views=space_views,
root_container=root_container_id,
auto_layout=self.auto_layout,
auto_space_views=self.auto_space_views,
Expand Down

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

Loading

0 comments on commit 779231b

Please sign in to comment.