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

Improve heuristics around 2D vs 3D space-view creation #3822

Merged
merged 7 commits into from
Oct 12, 2023

Conversation

jleibs
Copy link
Member

@jleibs jleibs commented Oct 11, 2023

What

Resolves:

Against my better judgement I ended up with one more pile of compelling hacks.
I believe it addresses many of the existing annoyances with awkwardly mixed 2d/3d views without (to my knowledge) causing regressions on the existing examples, though I haven't thoroughly tested everything yet, SFM, Human Motion, Arkit, etc. all look good.

The very high level idea is to prevent including 2D data in 3D views when it can't be projected via a pinhole, and then in a few other common edge-cases, more aggressively force 3D views.

This is done through 3 heuristic changes:

  • In order for a 2D part to ever be part of a 3D view, there must be a Pinhole above it in the hierarchy. Because this is something that can be inspected within the context of the tree without regard to any given space, we can evaluate this for each entity path as part of identify_entities_per_system_per_class.
    • To make the information available to the filter, we introduce a new HeuristicFilterContext that allows the heuristic filter to observe which class it is being evaluated for as well as other information about the tree.
  • In the event that a 2d-space-view has a score of 0, we no longer spawn it. This should logically use 3d instead.
  • In the event that a 2d-space-view at the root has any entities that would rather be 3D don't spawn it. Logically this follows from the fact that the only applicable pinhole in such a space would be at the root itself, and 3d data would need to transform past the root to be projected.

Some examples of the improved behavior:

As reported in #3712

rr.init("test", spawn=True)
rr.log("image/box", rr.Boxes2D(array=[10, 10, 50, 50], array_format=rr.Box2DFormat.XYXY))
rr.log("image", rr.Image(np.random.rand(100, 100, 3)))
rr.log("points", rr.Points3D(np.random.rand(100, 3)))

Before:
image

After:
image

And another particularly bad case I found while exploring:

rr.init("test", spawn=True)
rr.log("box", rr.Boxes3D(half_sizes=[1, 1, 1]))
rr.log("image", rr.Image(np.random.rand(100, 100, 3)))
rr.log("points", rr.Points3D(np.random.rand(100, 3)))

Before:
image

After:
image

Checklist

  • I have read and agree to Contributor Guide and the Code of Conduct
  • I've included a screenshot or gif (if applicable)
  • I have tested demo.rerun.io (if applicable)
  • The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG

@jleibs jleibs added the 😤 annoying Something in the UI / SDK is annoying to use label Oct 11, 2023
@jleibs jleibs added this to the 0.9.1 milestone Oct 11, 2023
@jleibs jleibs changed the title More heuristic handling of edge-cases related to pinholes and 2D/3D view preferences Improve heuristics around 2D vs 3D space-view creation Oct 11, 2023
@jleibs jleibs added include in changelog 📺 re_viewer affects re_viewer itself labels Oct 11, 2023
@jleibs jleibs marked this pull request as ready for review October 11, 2023 23:40
@teh-cmc teh-cmc self-requested a review October 12, 2023 07:14
Copy link
Member

@teh-cmc teh-cmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no expert in this whole space-view-heuristic business (yet!) but this makes perfect sense to me.

crates/re_space_view_spatial/src/space_view_2d.rs Outdated Show resolved Hide resolved
crates/re_viewport/src/space_view_heuristics.rs Outdated Show resolved Hide resolved
Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing rationals for why we do things. That will be pretty important when we return to this code.

Let's not let that block the merging of this PR, but @jleibs please go back and add that later.

Comment on lines +692 to +695
// If this is a 3D view and there's no parent pinhole, do not include this part.
if ctx.class == "3D" && !ctx.has_ancestor_pinhole {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can already read the Rust code and see what it does, I want to know why it does it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +193 to +196
// If this is a 3D view and there's no parent pinhole, do not include this part.
if ctx.class == "3D" && !ctx.has_ancestor_pinhole {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again - why?

Comment on lines +215 to +218
// If this is a 3D view and there's no parent pinhole, do not include this part.
if ctx.class == "3D" && !ctx.has_ancestor_pinhole {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read this many times now

Comment on lines +84 to +85
// possible to correctly project 3d objects to a root 2d view since the
// the pinhole would go past the root.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow this. "go past the root"?

@teh-cmc
Copy link
Member

teh-cmc commented Oct 12, 2023

Couldn't find a single heuristic issue with run_all.py.

@teh-cmc teh-cmc merged commit 541f34d into main Oct 12, 2023
30 checks passed
@teh-cmc teh-cmc deleted the jleibs/ignore_2d_in_3d_without_pinhole branch October 12, 2023 09:58
jleibs added a commit that referenced this pull request Oct 12, 2023
@jleibs jleibs mentioned this pull request Oct 12, 2023
4 tasks
Wumpf pushed a commit that referenced this pull request Oct 12, 2023
### What
Address some PR concerns from:
 -  #3822

### 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 [demo.rerun.io](https://demo.rerun.io/pr/3836) (if
applicable)
* [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/3836)
- [Docs
preview](https://rerun.io/preview/9926b13d4f8bc925e37b506f46540058df211249/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/9926b13d4f8bc925e37b506f46540058df211249/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😤 annoying Something in the UI / SDK is annoying to use include in changelog 📺 re_viewer affects re_viewer itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants