Skip to content
Open
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 @@ -4,6 +4,11 @@ namespace rerun.blueprint.archetypes;
table SpatialInformation (
"attr.rerun.scope": "blueprint"
) {
/// The target reference frame for all transformations.
///
/// Defaults to the coordinate frame used by the space origin entity.
target_frame: rerun.components.TransformFrameId ("attr.rerun.component_optional", order: 50);

/// Whether axes should be shown at the origin.
show_axes: rerun.blueprint.components.Enabled ("attr.rerun.component_optional", nullable, order: 100);

Expand Down

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

7 changes: 7 additions & 0 deletions crates/store/re_types/src/reflection/mod.rs

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

5 changes: 3 additions & 2 deletions crates/viewer/re_component_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ use re_types::{
AggregationPolicy, AlbedoFactor, AxisLength, Color, DepthMeter, DrawOrder, FillMode,
FillRatio, GammaCorrection, GraphType, ImagePlaneDistance, LinearSpeed,
MagnificationFilter, MarkerSize, Name, Opacity, Position2D, Position3D, Range1D, Scale3D,
SeriesVisible, ShowLabels, StrokeWidth, Text, Timestamp, TransformRelation, Translation3D,
ValueRange, Vector3D, VideoCodec, Visible,
SeriesVisible, ShowLabels, StrokeWidth, Text, Timestamp, TransformFrameId,
TransformRelation, Translation3D, ValueRange, Vector3D, VideoCodec, Visible,
},
};
use re_viewer_context::gpu_bridge::colormap_edit_or_view_ui;
Expand Down Expand Up @@ -121,6 +121,7 @@ pub fn create_component_ui_registry() -> re_viewer_context::ComponentUiRegistry
registry.add_multiline_edit_or_view::<Text>(edit_multiline_string);
registry.add_singleline_edit_or_view::<Name>(edit_singleline_string);
registry.add_multiline_edit_or_view::<Name>(edit_multiline_string);
registry.add_singleline_edit_or_view::<TransformFrameId>(edit_singleline_string);

// Enums:
// TODO(#6974): Enums editors trivial and always the same, provide them automatically!
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_view_spatial/src/contexts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use re_tf::TransformInfo;
use re_types::ViewClassIdentifier;
use re_view::AnnotationSceneContext;

pub use transform_tree_context::TransformTreeContext;
pub use transform_tree_context::{TransformTreeContext, UNKNOWN_SPACE_ORIGIN};

// -----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ use nohash_hasher::IntMap;
use re_chunk_store::LatestAtQuery;
use re_log_types::EntityPathHash;
use re_tf::{TransformFrameId, TransformFrameIdHash};
use re_types::{archetypes, components::ImagePlaneDistance};
use re_types::{archetypes, blueprint, components::ImagePlaneDistance};
use re_view::{DataResultQuery as _, latest_at_with_blueprint_resolved_data};
use re_viewer_context::{
DataResult, IdentifiedViewSystem, TransformDatabaseStoreCache, ViewContext, ViewContextSystem,
ViewContextSystemOncePerFrameResult, typed_fallback_for,
};
use re_viewport_blueprint::ViewProperty;
use vec1::smallvec_v1::SmallVec1;

type FrameIdMapping = IntMap<TransformFrameIdHash, TransformFrameId>;

/// Currently, there is no straightforward way to retrieve the space origin
/// when registering fallbacks. So, if unknown we set the target frame to a
/// dummy string and rely on the view to supply that information after the
/// first frame.
pub const UNKNOWN_SPACE_ORIGIN: &str = "<unknown space origin>";

/// Provides a transform tree for the view & time it operates on.
///
/// Will do the necessary bulk processing of transform information and make it available
Expand Down Expand Up @@ -106,8 +113,35 @@ impl ViewContextSystem for TransformTreeContext {
// Currently, we don't keep it around during the frame, but we may do so in the future.
self.entity_transform_id_mapping = EntityTransformIdMapping::new(ctx, query);

// Target frame is the coordinate frame of the space origin entity.
self.target_frame = self.transform_frame_id_for(query.space_origin.hash());
// Target frame - check for blueprint override first, otherwise use space origin's coordinate frame.
self.target_frame = {
let spatial_info_prop = ViewProperty::from_archetype::<
blueprint::archetypes::SpatialInformation,
>(
ctx.blueprint_db(), ctx.blueprint_query(), ctx.view_id
);

let target_frame_component = spatial_info_prop
.component_or_fallback::<TransformFrameId>(
ctx,
blueprint::archetypes::SpatialInformation::descriptor_target_frame().component,
);

match target_frame_component {
Ok(target_frame) => {
let target_frame_str = target_frame.as_str();
if target_frame_str == UNKNOWN_SPACE_ORIGIN {
self.transform_frame_id_for(query.space_origin.hash())
} else {
TransformFrameIdHash::from_str(target_frame.as_str())
}
}
Err(err) => {
re_log::error_once!("Failed to query target frame: {err}");
self.transform_frame_id_for(query.space_origin.hash())
}
}
};

let latest_at_query = query.latest_at_query();

Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_view_spatial/src/shared_fallbacks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use re_types::{archetypes, components, image::ImageKind};
use re_types::{archetypes, blueprint, components, image::ImageKind};
use re_view::DataResultQuery as _;
use re_viewer_context::{IdentifiedViewSystem as _, QueryContext, ViewStateExt as _};

Expand Down
4 changes: 4 additions & 0 deletions crates/viewer/re_view_spatial/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ pub struct SpatialViewState {
pub pinhole_at_origin: Option<Pinhole>,

pub visual_bounds_2d: Option<VisualBounds2D>,

/// The target frame, i.e., the coordinate frame that transforms are resolved to.
/// Computed from the space origin via the transform tree.
pub target_frame: Option<String>,
}

impl ViewState for SpatialViewState {
Expand Down
7 changes: 6 additions & 1 deletion crates/viewer/re_view_spatial/src/view_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use re_viewer_context::{
};

use crate::{
contexts::register_spatial_contexts,
contexts::{TransformTreeContext, register_spatial_contexts},
heuristics::default_visualized_entities_for_visualizer_kind,
max_image_dimension_subscriber::{ImageTypes, MaxDimensions},
shared_fallbacks,
Expand Down Expand Up @@ -259,6 +259,11 @@ impl ViewClass for SpatialView2D {
let state = state.downcast_mut::<SpatialViewState>()?;
state.update_frame_statistics(ui, &system_output, SpatialViewKind::TwoD);

// Store the target frame for display in the selection panel
if let Ok(transforms) = system_output.context_systems.get::<TransformTreeContext>() {
state.target_frame = Some(transforms.format_frame(transforms.target_frame()));
}

self.view_2d(ctx, ui, state, query, system_output)
}
}
Expand Down
29 changes: 26 additions & 3 deletions crates/viewer/re_view_spatial/src/view_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use re_types::{
archetypes::{Background, EyeControls3D, LineGrid3D, SpatialInformation},
components::Eye3DKind,
},
components::{LinearSpeed, Plane3D, Position3D, Vector3D},
components::{LinearSpeed, Plane3D, Position3D, TransformFrameId, Vector3D},
datatypes::Vec3D,
view_coordinates::SignedAxis3,
};
Expand All @@ -27,7 +27,7 @@ use re_viewer_context::{
use re_viewport_blueprint::ViewProperty;

use crate::{
contexts::register_spatial_contexts,
contexts::{TransformTreeContext, UNKNOWN_SPACE_ORIGIN, register_spatial_contexts},
heuristics::default_visualized_entities_for_visualizer_kind,
spatial_topology::{HeuristicHints, SpatialTopology, SubSpaceConnectionFlags},
ui::SpatialViewState,
Expand Down Expand Up @@ -251,6 +251,24 @@ impl ViewClass for SpatialView3D {
},
);

system_registry.register_fallback_provider(
SpatialInformation::descriptor_target_frame().component,
|ctx| {
let unknown_space_origin = || TransformFrameId(UNKNOWN_SPACE_ORIGIN.into());

let Ok(state) = ctx.view_state().downcast_ref::<SpatialViewState>() else {
return unknown_space_origin();
};

// Return the computed target frame from the view state
state
.target_frame
.as_ref()
.map(|frame_str| TransformFrameId(frame_str.clone().into()))
.unwrap_or_else(unknown_space_origin)
},
);

shared_fallbacks::register_fallbacks(system_registry);

// Ensure spatial topology is registered.
Expand Down Expand Up @@ -515,10 +533,10 @@ impl ViewClass for SpatialView3D {

re_ui::list_item::list_item_scope(ui, "spatial_view3d_selection_ui", |ui| {
let view_ctx = self.view_context(ctx, view_id, state);
view_property_ui::<SpatialInformation>(&view_ctx, ui);
view_property_ui::<EyeControls3D>(&view_ctx, ui);
view_property_ui::<Background>(&view_ctx, ui);
view_property_ui_grid3d(&view_ctx, ui);
view_property_ui::<SpatialInformation>(&view_ctx, ui);
});

Ok(())
Expand All @@ -538,6 +556,11 @@ impl ViewClass for SpatialView3D {
let state = state.downcast_mut::<SpatialViewState>()?;
state.update_frame_statistics(ui, &system_output, SpatialViewKind::ThreeD);

// Store the target frame for display in the selection panel
if let Ok(transforms) = system_output.context_systems.get::<TransformTreeContext>() {
state.target_frame = Some(transforms.format_frame(transforms.target_frame()));
}

self.view_3d(ctx, ui, state, query, system_output)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
source: crates/viewer/re_viewer/tests/all_component_fallbacks.rs
expression: arch_display
---
target_frame: []
show_axes: [false]
show_bounding_box: [false]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading