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

Add support for scene units in the map view #8015

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading