-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support annotation context / classids for
GeoPoints
(#8124)
### What In order to do so... * moves annotation scene context system to re_space_view * move some utilities for resolving annotation contexts to re_space_view * doing so, I noticed that it always processes keypoints, so I added a variant without keypoints to it * doing so I noticed that _almost everything_ queries keypoints for no reason at all - keypoints are only supported on points 2d & 3d (check the fbs definitions! also the way we speced it it doesn't make sense otherwise) * -> rip out a lot of of keypoint queries * move color resolve utility to re_space_view * breathe This allows me to have automagically colored points on nuscenes! (separate pr for this update coming soon!) ![image](https://github.com/user-attachments/assets/bb807f2f-0704-413b-852f-6578c5e5d898) ### 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/8124?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/8124?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/8124) - [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`. To deploy documentation changes immediately after merging this PR, add the `deploy docs` label.
- Loading branch information
Showing
32 changed files
with
340 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
crates/viewer/re_space_view/src/annotation_context_utils.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
use ahash::HashMap; | ||
|
||
use re_types::components::Color; | ||
use re_viewer_context::{Annotations, QueryContext, ResolvedAnnotationInfos}; | ||
|
||
use crate::clamped_or_nothing; | ||
|
||
/// Process [`Color`] components using annotations and default colors. | ||
pub fn process_color_slice<'a>( | ||
ctx: &QueryContext<'_>, | ||
fallback_provider: &'a dyn re_viewer_context::TypedComponentFallbackProvider<Color>, | ||
num_instances: usize, | ||
annotation_infos: &'a ResolvedAnnotationInfos, | ||
colors: &'a [Color], | ||
) -> Vec<egui::Color32> { | ||
re_tracing::profile_function_if!(10_000 < num_instances); | ||
|
||
if let Some(last_color) = colors.last() { | ||
// If we have colors we can ignore the annotation infos/contexts. | ||
|
||
if colors.len() == num_instances { | ||
// Common happy path | ||
colors.iter().map(|c| egui::Color32::from(*c)).collect() | ||
} else if colors.len() == 1 { | ||
// Common happy path | ||
vec![egui::Color32::from(*last_color); num_instances] | ||
} else { | ||
let colors = clamped_or_nothing(colors, num_instances); | ||
colors.map(|c| egui::Color32::from(*c)).collect() | ||
} | ||
} else { | ||
match annotation_infos { | ||
ResolvedAnnotationInfos::Same(count, annotation_info) => { | ||
re_tracing::profile_scope!("no colors, same annotation"); | ||
let color = annotation_info | ||
.color() | ||
.unwrap_or_else(|| fallback_provider.fallback_for(ctx).into()); | ||
vec![color; *count] | ||
} | ||
ResolvedAnnotationInfos::Many(annotation_info) => { | ||
re_tracing::profile_scope!("no-colors, many annotations"); | ||
let fallback = fallback_provider.fallback_for(ctx).into(); | ||
annotation_info | ||
.iter() | ||
.map(|annotation_info| annotation_info.color().unwrap_or(fallback)) | ||
.collect() | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub type Keypoints = HashMap< | ||
(re_types::components::ClassId, i64), | ||
HashMap<re_types::datatypes::KeypointId, glam::Vec3>, | ||
>; | ||
|
||
/// Resolves all annotations and keypoints for the given entity view. | ||
pub fn process_annotation_and_keypoint_slices( | ||
latest_at: re_log_types::TimeInt, | ||
num_instances: usize, | ||
positions: impl Iterator<Item = glam::Vec3>, | ||
keypoint_ids: &[re_types::components::KeypointId], | ||
class_ids: &[re_types::components::ClassId], | ||
annotations: &Annotations, | ||
) -> (ResolvedAnnotationInfos, Keypoints) { | ||
re_tracing::profile_function!(); | ||
|
||
let mut keypoints: Keypoints = HashMap::default(); | ||
|
||
// No need to process annotations if we don't have class-ids | ||
if class_ids.is_empty() { | ||
let resolved_annotation = annotations | ||
.resolved_class_description(None) | ||
.annotation_info(); | ||
|
||
return ( | ||
ResolvedAnnotationInfos::Same(num_instances, resolved_annotation), | ||
keypoints, | ||
); | ||
}; | ||
|
||
let class_ids = clamped_or_nothing(class_ids, num_instances); | ||
|
||
if keypoint_ids.is_empty() { | ||
let annotation_info = class_ids | ||
.map(|&class_id| { | ||
let class_description = annotations.resolved_class_description(Some(class_id)); | ||
class_description.annotation_info() | ||
}) | ||
.collect(); | ||
|
||
( | ||
ResolvedAnnotationInfos::Many(annotation_info), | ||
Default::default(), | ||
) | ||
} else { | ||
let keypoint_ids = clamped_or_nothing(keypoint_ids, num_instances); | ||
let annotation_info = itertools::izip!(positions, keypoint_ids, class_ids) | ||
.map(|(position, keypoint_id, &class_id)| { | ||
let class_description = annotations.resolved_class_description(Some(class_id)); | ||
|
||
keypoints | ||
.entry((class_id, latest_at.as_i64())) | ||
.or_default() | ||
.insert(keypoint_id.0, position); | ||
class_description.annotation_info_with_keypoint(keypoint_id.0) | ||
}) | ||
.collect(); | ||
|
||
(ResolvedAnnotationInfos::Many(annotation_info), keypoints) | ||
} | ||
} | ||
|
||
/// Resolves all annotations for the given entity view. | ||
pub fn process_annotation_slices( | ||
latest_at: re_log_types::TimeInt, | ||
num_instances: usize, | ||
class_ids: &[re_types::components::ClassId], | ||
annotations: &Annotations, | ||
) -> ResolvedAnnotationInfos { | ||
let (annotations, _keypoints) = process_annotation_and_keypoint_slices( | ||
latest_at, | ||
num_instances, | ||
std::iter::empty(), // positions are only needed for keypoint lookup | ||
&[], | ||
class_ids, | ||
annotations, | ||
); | ||
|
||
annotations | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.