Skip to content

Commit

Permalink
Add support for scene units in the map view (#8015)
Browse files Browse the repository at this point in the history
### What

- Fixes #7872 
- Limitation: #8013

Add support for scene units (aka meter)  in the map view.


https://github.com/user-attachments/assets/012c86d7-70cd-4144-9e54-414570ca286e


### 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 examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/8015?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/8015?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)!
* [x] If have noted any breaking changes to the log API in
`CHANGELOG.md` and the migration guide

- [PR Build Summary](https://build.rerun.io/pr/8015)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
abey79 authored Nov 7, 2024
1 parent aab0b4e commit d25133a
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ table GeoLineStrings (
// --- Recommended ---

/// Optional radii for the line strings.
///
/// *Note*: scene units radiii are interpreted as meters. Currently, the display scale only considers the latitude of
/// the first vertex of each line string (see [this issue](https://github.com/rerun-io/rerun/issues/8013)).
radii: [rerun.components.Radius] ("attr.rerun.component_recommended", nullable, order: 2000);

/// Optional colors for the line strings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ table GeoPoints (
// --- Recommended ---

/// Optional radii for the points, effectively turning them into circles.
///
/// *Note*: scene units radiii are interpreted as meters.
radii: [rerun.components.Radius] ("attr.rerun.component_recommended", nullable, order: 2000);

/// Optional colors for the points.
Expand Down
6 changes: 6 additions & 0 deletions crates/store/re_types/src/archetypes/geo_line_strings.rs

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

4 changes: 4 additions & 0 deletions crates/store/re_types/src/archetypes/geo_points.rs

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

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use re_viewer_context::{
#[derive(Debug, Default)]
struct GeoLineStringsBatch {
lines: Vec<Vec<walkers::Position>>,
//TODO(#7872): to be converted to scene vs. ui
radii: Vec<f32>,
radii: Vec<Radius>,
colors: Vec<re_renderer::Color32>,
instance_id: Vec<PickingLayerInstanceId>,
}
Expand Down Expand Up @@ -93,7 +92,7 @@ impl VisualizerSystem for GeoLineStringsVisualizer {
.map(|pos| walkers::Position::from_lat_lon(pos.x(), pos.y()))
.collect(),
);
batch_data.radii.push(radius.0.abs());
batch_data.radii.push(*radius);
batch_data.colors.push(color.0.into());
batch_data
.instance_id
Expand Down Expand Up @@ -159,7 +158,15 @@ impl GeoLineStringsVisualizer {
let ui_position = projector.project(*pos);
glam::vec2(ui_position.x, ui_position.y)
}))
.radius(re_renderer::Size(*radius))
//TODO(#8013): we use the first vertex's latitude because `re_renderer` doesn't support per-vertex radii
.radius(super::radius_to_size(
*radius,
projector,
strip
.first()
.copied()
.unwrap_or(walkers::Position::from_lat_lon(0.0, 0.0)),
))
.color(*color)
.picking_instance_id(*instance)
.outline_mask_ids(
Expand Down
23 changes: 9 additions & 14 deletions crates/viewer/re_space_view_map/src/visualizers/geo_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use re_viewer_context::{
#[derive(Debug, Default)]
pub struct GeoPointBatch {
pub positions: Vec<walkers::Position>,
//TODO(#7872): to be converted to scene vs. ui
pub radii: Vec<f32>,
pub radii: Vec<Radius>,
pub colors: Vec<re_renderer::Color32>,
pub instance_id: Vec<PickingLayerInstanceId>,
}
Expand Down Expand Up @@ -90,7 +89,7 @@ impl VisualizerSystem for GeoPointsVisualizer {
position.latitude(),
position.longitude(),
));
batch_data.radii.push(radius.0.abs());
batch_data.radii.push(*radius);
batch_data.colors.push(color.0.into());
batch_data
.instance_id
Expand Down Expand Up @@ -138,20 +137,16 @@ impl GeoPointsVisualizer {
);

for (entity_path, batch) in &self.batches {
let positions = batch
let (positions, radii): (Vec<_>, Vec<_>) = batch
.positions
.iter()
.map(|pos| {
.zip(&batch.radii)
.map(|(pos, radius)| {
let size = super::radius_to_size(*radius, projector, *pos);
let ui_position = projector.project(*pos);
glam::vec3(ui_position.x, ui_position.y, 0.0)
(glam::vec3(ui_position.x, ui_position.y, 0.0), size)
})
.collect::<Vec<_>>();

let radii = batch
.radii
.iter()
.map(|radius| re_renderer::Size(*radius))
.collect::<Vec<_>>();
.unzip();

let outline = highlight.entity_outline_mask(entity_path.hash());

Expand Down Expand Up @@ -190,7 +185,7 @@ impl TypedComponentFallbackProvider<Color> for GeoPointsVisualizer {

impl TypedComponentFallbackProvider<Radius> for GeoPointsVisualizer {
fn fallback_for(&self, _ctx: &QueryContext<'_>) -> Radius {
Radius::from(5.0)
Radius::new_ui_points(5.0)
}
}

Expand Down
17 changes: 17 additions & 0 deletions crates/viewer/re_space_view_map/src/visualizers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ pub fn update_span(span: &mut Option<GeoSpan>, other: Option<GeoSpan>) {
}
}

/// Convert a [`re_types::components::Radius`] to a [`re_renderer::Size`], considering scene units
/// as meters.
#[inline]
pub fn radius_to_size(
radius: re_types::components::Radius,
projector: &walkers::Projector,
position: walkers::Position,
) -> re_renderer::Size {
re_renderer::Size(
radius
.scene_units()
.map(|radius_meter| projector.scale_pixel_per_meter(position) * radius_meter)
.or(radius.ui_points())
.unwrap_or_default(),
)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 4 additions & 3 deletions crates/viewer/re_viewer/src/reflection/mod.rs

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

6 changes: 6 additions & 0 deletions rerun_cpp/src/rerun/archetypes/geo_line_strings.hpp

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

4 changes: 4 additions & 0 deletions rerun_cpp/src/rerun/archetypes/geo_points.hpp

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

3 changes: 3 additions & 0 deletions rerun_py/rerun_sdk/rerun/archetypes/geo_line_strings.py

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

2 changes: 2 additions & 0 deletions rerun_py/rerun_sdk/rerun/archetypes/geo_points.py

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

0 comments on commit d25133a

Please sign in to comment.