Skip to content

Commit

Permalink
transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Apr 18, 2024
1 parent ffae6ed commit ef52f75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 50 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

53 changes: 16 additions & 37 deletions crates/re_space_view_spatial/src/contexts/transform_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use nohash_hasher::IntMap;
use re_data_store::LatestAtQuery;
use re_entity_db::{EntityDb, EntityPath, EntityPropertyMap, EntityTree};
use re_types::{
components::{DisconnectedSpace, PinholeProjection, Resolution, Transform3D, ViewCoordinates},
components::{DisconnectedSpace, PinholeProjection, Transform3D, ViewCoordinates},
ComponentNameSet, Loggable as _,
};
use re_viewer_context::{IdentifiedViewSystem, ViewContextSystem};
Expand Down Expand Up @@ -296,37 +296,26 @@ fn get_cached_transform(
entity_db: &EntityDb,
query: &LatestAtQuery,
) -> Option<Transform3D> {
let mut transform3d = None;
entity_db
.query_caches()
.query_archetype_latest_at_pov1_comp0::<re_types::archetypes::Transform3D, Transform3D, _>(
entity_db.store(),
query,
entity_path,
|(_, _, transforms)| transform3d = transforms.first().cloned(),
)
.ok();
transform3d
.latest_at_component::<Transform3D>(entity_path, query)
.map(|res| res.value)
}

fn get_cached_pinhole(
entity_path: &re_log_types::EntityPath,
entity_db: &EntityDb,
query: &re_data_store::LatestAtQuery,
) -> Option<(PinholeProjection, ViewCoordinates)> {
let mut result = None;
entity_db.query_caches()
.query_archetype_latest_at_pov1_comp2::<re_types::archetypes::Pinhole, PinholeProjection, Resolution, ViewCoordinates, _>(
entity_db.store(),
query,
entity_path,
|(_, _, image_from_camera, _resolution, camera_xyz)| {
result = image_from_camera.first().map(|image_from_camera|
(*image_from_camera, camera_xyz.and_then(|c| c.first()).cloned().flatten().unwrap_or(ViewCoordinates::RDF)));
}
)
.ok();
result
entity_db
.latest_at_archetype::<re_types::archetypes::Pinhole>(entity_path, query)
.ok()
.flatten()
.map(|arch| {
(
arch.image_from_camera,
arch.camera_xyz.unwrap_or(ViewCoordinates::RDF),
)
})
}

fn transform_at(
Expand Down Expand Up @@ -390,19 +379,9 @@ fn transform_at(
});

let is_disconnect_space = || {
let mut disconnected_space = false;
entity_db.query_caches()
.query_archetype_latest_at_pov1_comp0::<re_types::archetypes::DisconnectedSpace, DisconnectedSpace, _>(
entity_db.store(),
query,
entity_path,
|(_, _, disconnected_spaces)| {
disconnected_space = disconnected_spaces
.first() .map_or(false, |dp| dp.0);
},
)
.ok();
disconnected_space
entity_db
.latest_at_component::<DisconnectedSpace>(entity_path, query)
.map_or(false, |res| res.value.0)
};

// If there is any other transform, we ignore `DisconnectedSpace`.
Expand Down
17 changes: 4 additions & 13 deletions crates/re_space_view_spatial/src/visualizers/transform3d_arrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ impl VisualizerSystem for Transform3DArrowsVisualizer {
) -> Result<Vec<re_renderer::QueueableDrawData>, SpaceViewSystemExecutionError> {
let transforms = view_ctx.get::<TransformContext>()?;

let query_caches = ctx.recording().query_caches();
let store = ctx.recording_store();

let latest_at_query = re_data_store::LatestAtQuery::new(query.timeline, query.latest_at);

// Counting all transforms ahead of time is a bit wasteful, but we also don't expect a huge amount,
Expand All @@ -66,16 +63,10 @@ impl VisualizerSystem for Transform3DArrowsVisualizer {
continue;
}

if query_caches
.query_archetype_latest_at_pov1_comp0::<re_types::archetypes::Transform3D, Transform3D, _>(
store,
&latest_at_query,
&data_result.entity_path,
|_| {},
)
// NOTE: Can only fail if the primary component is missing, which is what we
// want to check here (i.e.: there's no transform for this entity!).
.is_err()
if ctx
.recording()
.latest_at_component::<Transform3D>(&data_result.entity_path, &latest_at_query)
.is_none()
{
continue;
}
Expand Down

0 comments on commit ef52f75

Please sign in to comment.