Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

new color/keypoint/classid/label datatypes

# This is the commit message #2:

fixups
  • Loading branch information
Wumpf committed Aug 10, 2023
1 parent cdca754 commit a18093f
Show file tree
Hide file tree
Showing 47 changed files with 591 additions and 110 deletions.
25 changes: 15 additions & 10 deletions crates/re_data_ui/src/annotation_context.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use egui::{color_picker, Vec2};
use itertools::Itertools;

use re_types::components::{AnnotationContext, ClassId, KeypointId};
use re_types::components::AnnotationContext;
use re_types::datatypes::{
AnnotationInfo, ClassDescription, ClassDescriptionMapElem, KeypointPair,
AnnotationInfo, ClassDescription, ClassDescriptionMapElem, KeypointId, KeypointPair,
};
use re_viewer_context::{auto_color, UiVerbosity, ViewerContext};

use super::DataUi;

const TABLE_SCROLL_AREA_HEIGHT: f32 = 500.0; // add scroll-bars when we get to this height

impl crate::EntityDataUi for ClassId {
impl crate::EntityDataUi for re_types::components::ClassId {
fn entity_data_ui(
&self,
ctx: &mut re_viewer_context::ViewerContext<'_>,
Expand All @@ -34,18 +34,19 @@ impl crate::EntityDataUi for ClassId {
}
});

let id = self.0.into();
match verbosity {
UiVerbosity::Small => {
if !class.keypoint_connections.is_empty()
|| !class.keypoint_annotations.is_empty()
{
response.response.on_hover_ui(|ui| {
class_description_ui(ui, class, *self);
class_description_ui(ui, class, id);
});
}
}
UiVerbosity::Reduced | UiVerbosity::All => {
class_description_ui(ui, class, *self);
class_description_ui(ui, class, id);
}
}
} else {
Expand All @@ -63,7 +64,7 @@ impl crate::EntityDataUi for re_types::components::KeypointId {
entity_path: &re_log_types::EntityPath,
query: &re_arrow_store::LatestAtQuery,
) {
if let Some(info) = annotation_info(ctx, entity_path, query, self) {
if let Some(info) = annotation_info(ctx, entity_path, query, (*self).into()) {
ui.horizontal(|ui| {
// Color first, to keep subsequent rows of the same things aligned
small_color_ui(ui, &info);
Expand All @@ -82,16 +83,16 @@ fn annotation_info(
ctx: &mut re_viewer_context::ViewerContext<'_>,
entity_path: &re_log_types::EntityPath,
query: &re_arrow_store::LatestAtQuery,
keypoint_id: &re_types::components::KeypointId,
keypoint_id: KeypointId,
) -> Option<AnnotationInfo> {
let class_id = ctx
.store_db
.entity_db
.data_store
.query_latest_component::<ClassId>(entity_path, query)?;
.query_latest_component::<re_types::components::ClassId>(entity_path, query)?;
let annotations = crate::annotations(ctx, query, entity_path);
let class = annotations.resolved_class_description(Some(class_id));
class.keypoint_map?.get(keypoint_id).cloned()
class.keypoint_map?.get(&keypoint_id).cloned()
}

impl DataUi for AnnotationContext {
Expand Down Expand Up @@ -129,7 +130,11 @@ impl DataUi for AnnotationContext {
}
}

fn class_description_ui(ui: &mut egui::Ui, class: &ClassDescription, id: ClassId) {
fn class_description_ui(
ui: &mut egui::Ui,
class: &ClassDescription,
id: re_types::datatypes::ClassId,
) {
if class.keypoint_connections.is_empty() && class.keypoint_annotations.is_empty() {
return;
}
Expand Down
3 changes: 1 addition & 2 deletions crates/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use itertools::Itertools as _;

use re_components::{DecodedTensor, Tensor, TensorDataMeaning, TensorElement};
use re_renderer::renderer::ColormappedTexture;
use re_types::components::ClassId;
use re_ui::ReUi;
use re_viewer_context::{
gpu_bridge, Annotations, TensorDecodeCache, TensorStats, TensorStatsCache, UiVerbosity,
Expand Down Expand Up @@ -541,7 +540,7 @@ fn tensor_pixel_value_ui(
ui.label("Label:");
ui.label(
annotations
.resolved_class_description(Some(ClassId(u16_val)))
.resolved_class_description(Some(u16_val.into()))
.annotation_info()
.label(None)
.unwrap_or_else(|| u16_val.to_string()),
Expand Down
14 changes: 6 additions & 8 deletions crates/re_space_view_spatial/src/parts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ mod transform3d_arrows;
pub use cameras::CamerasPart;
pub use images::Image;
pub use images::ImagesPart;
use re_types::components::Color;
use re_types::components::InstanceKey;
use re_types::datatypes::KeypointPair;
use re_types::Archetype;
pub use spatial_view_part::SpatialViewPartData;
pub use transform3d_arrows::add_axis_arrows;

use ahash::HashMap;
use std::sync::Arc;

use re_data_store::{EntityPath, InstancePathHash};
use re_types::components::{ClassId, KeypointId};
use re_types::components::{Color, InstanceKey};
use re_types::datatypes::{KeypointId, KeypointPair};
use re_types::Archetype;
use re_viewer_context::SpaceViewClassRegistryError;
use re_viewer_context::{
auto_color, Annotations, DefaultColor, ResolvedAnnotationInfo, SpaceViewSystemRegistry,
Expand All @@ -38,7 +36,7 @@ use re_viewer_context::{
use super::contexts::SpatialSceneEntityContext;

/// Collection of keypoints for annotation context.
pub type Keypoints = HashMap<(ClassId, i64), HashMap<KeypointId, glam::Vec3>>;
pub type Keypoints = HashMap<(re_types::components::ClassId, i64), HashMap<KeypointId, glam::Vec3>>;

pub const SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES: f32 = 1.5;
pub const SIZE_BOOST_IN_POINTS_FOR_POINT_OUTLINES: f32 = 2.5;
Expand Down Expand Up @@ -188,8 +186,8 @@ where
keypoints
.entry((class_id, query.latest_at.as_i64()))
.or_insert_with(Default::default)
.insert(keypoint_id, primary_into_position(&primary));
class_description.annotation_info_with_keypoint(keypoint_id)
.insert(keypoint_id.into(), primary_into_position(&primary));
class_description.annotation_info_with_keypoint(keypoint_id.into())
} else {
class_description.annotation_info()
}
Expand Down
9 changes: 5 additions & 4 deletions crates/re_types/definitions/rerun/components/class_id.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ namespace rerun.components;

/// A 16-bit ID representing a type of semantic class.
///
/// \rs Used to look up a `crate::components::ClassDescription` within the `crate::components::AnnotationContext`.
struct ClassId (
/// \rs Used to look up a [`crate::datatypes::ClassDescription`] within the [`crate::components::AnnotationContext`].
table ClassId (
"attr.arrow.transparent",
"attr.python.aliases": "int",
"attr.python.array_aliases": "int, npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32], npt.NDArray[np.uint64]",
"attr.rerun.legacy_fqname": "rerun.class_id",
"attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.repr": "transparent",
"attr.rust.custom_clause":
'cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))',
order: 100
) {
id: ushort (order: 100);
id: rerun.datatypes.ClassId (order: 100, transparent);
}
7 changes: 4 additions & 3 deletions crates/re_types/definitions/rerun/components/color.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ namespace rerun.components;
/// \py Float colors are assumed to be in 0-1 gamma sRGB space.
/// \py All other colors are assumed to be in 0-255 gamma sRGB space.
/// \py If there is an alpha, we assume it is in linear space, and separate (NOT pre-multiplied).
struct Color (
table Color (
"attr.arrow.transparent",
"attr.rerun.legacy_fqname": "rerun.colorrgba",
"attr.python.aliases": "int, Sequence[int], npt.NDArray[Union[np.uint8, np.float32, np.float64]]",
"attr.python.array_aliases": "int, Sequence[Sequence[int]], npt.NDArray[Union[np.uint8, np.uint32, np.float32, np.float64]]",
"attr.rerun.legacy_fqname": "rerun.colorrgba",
"attr.rust.derive": "Default, Copy, PartialEq, Eq, PartialOrd, Ord, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent",
order: 100
) {
rgba: uint (order: 100);
rgba: rerun.datatypes.Color (order: 100, transparent);
}
7 changes: 4 additions & 3 deletions crates/re_types/definitions/rerun/components/keypoint_id.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ namespace rerun.components;
/// \rs
/// \rs Used to look up an `crate::components::AnnotationInfo` for a Keypoint within the `crate::components::AnnotationContext`.
struct KeypointId (
"attr.python.aliases": "float",
"attr.python.array_aliases": "float, npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32]",
"attr.arrow.transparent",
"attr.rerun.legacy_fqname": "rerun.keypoint_id",
"attr.python.aliases": "int",
"attr.python.array_aliases": "int, npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32], npt.NDArray[np.uint64]",
"attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.custom_clause":
'cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))',
order: 200
) {
id: ushort (order: 100);
id: rerun.datatypes.KeypointId (order: 100, transparent);
}
3 changes: 2 additions & 1 deletion crates/re_types/definitions/rerun/components/label.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ namespace rerun.components;

/// A String label component.
table Label (
"attr.arrow.transparent",
"attr.python.aliases": "str",
"attr.python.array_aliases": "str, Sequence[str]",
"attr.rerun.legacy_fqname": "rerun.label",
"attr.rust.derive": "PartialEq, Eq, PartialOrd, Ord",
"attr.rust.repr": "transparent",
order: 100
) {
value: string (order: 100);
value: rerun.datatypes.Label (order: 100, transparent);
}
12 changes: 8 additions & 4 deletions crates/re_types/definitions/rerun/datatypes.fbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
include "./datatypes/angle.fbs";
include "./datatypes/mat3x3.fbs";
include "./datatypes/mat4x4.fbs";
include "./datatypes/annotation_info.fbs";
include "./datatypes/class_description.fbs";
include "./datatypes/class_description_map_elem.fbs";
include "./datatypes/class_description.fbs";
include "./datatypes/class_id.fbs";
include "./datatypes/color.fbs";
include "./datatypes/keypoint_id.fbs";
include "./datatypes/keypoint_pair.fbs";
include "./datatypes/label.fbs";
include "./datatypes/mat3x3.fbs";
include "./datatypes/mat4x4.fbs";
include "./datatypes/quaternion.fbs";
include "./datatypes/rotation3d.fbs";
include "./datatypes/rotation_axis_angle.fbs";
include "./datatypes/rotation3d.fbs";
include "./datatypes/scalars.fbs";
include "./datatypes/scale3d.fbs";
include "./datatypes/transform3d.fbs";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
include "arrow/attributes.fbs";
include "fbs/attributes.fbs";

// Include components directly to avoid circular dependencies.
include "rerun/components/label.fbs";
include "rerun/components/color.fbs";
include "rerun/datatypes.fbs";

namespace rerun.datatypes;

Expand All @@ -22,7 +20,7 @@ table AnnotationInfo (
// TODO(jleibs): make this typed
id: ushort (order: 100);
/// The label that will be shown in the UI.
label: rerun.components.Label (nullable, order: 200);
label: rerun.datatypes.Label (nullable, order: 200);
/// The color that will be applied to the annotated entity.
color: rerun.components.Color (nullable, order: 300);
color: rerun.datatypes.Color (nullable, order: 300);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ include "arrow/attributes.fbs";
include "fbs/attributes.fbs";

include "rerun/datatypes.fbs";
include "rerun/components/class_id.fbs";

namespace rerun.datatypes;

Expand All @@ -16,6 +15,6 @@ table ClassDescriptionMapElem (
"attr.rust.derive": "Default, Eq, PartialEq",
order: 100
) {
class_id: rerun.components.ClassId (order: 100);
class_id: rerun.datatypes.ClassId (order: 100);
class_description: rerun.datatypes.ClassDescription (order: 200);
}
26 changes: 26 additions & 0 deletions crates/re_types/definitions/rerun/datatypes/class_id.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include "arrow/attributes.fbs";
include "python/attributes.fbs";
include "rust/attributes.fbs";

include "rerun/attributes.fbs";

namespace rerun.datatypes;

// ---

/// A 16-bit ID representing a type of semantic class.
///
/// \rs Used to look up a [`crate::datatypes::ClassDescription`] within the [`crate::components::AnnotationContext`].
struct ClassId (
"attr.arrow.transparent",
"attr.python.aliases": "int",
"attr.python.array_aliases": "int, npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32], npt.NDArray[np.uint64]",
"attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct",
"attr.rust.custom_clause":
'cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))',
order: 100
) {
id: ushort (order: 100);
}
26 changes: 26 additions & 0 deletions crates/re_types/definitions/rerun/datatypes/color.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include "arrow/attributes.fbs";
include "python/attributes.fbs";
include "rust/attributes.fbs";

include "rerun/attributes.fbs";

namespace rerun.datatypes;

// ---

/// An RGBA color tuple with unmultiplied/separate alpha, in sRGB gamma space with linear alpha.
///
/// \py Float colors are assumed to be in 0-1 gamma sRGB space.
/// \py All other colors are assumed to be in 0-255 gamma sRGB space.
/// \py If there is an alpha, we assume it is in linear space, and separate (NOT pre-multiplied).
struct Color (
"attr.arrow.transparent",
"attr.python.aliases": "int, Sequence[int], npt.NDArray[Union[np.uint8, np.float32, np.float64]]",
"attr.python.array_aliases": "int, Sequence[Sequence[int]], npt.NDArray[Union[np.uint8, np.uint32, np.float32, np.float64]]",
"attr.rust.derive": "Default, Copy, PartialEq, Eq, PartialOrd, Ord, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct",
order: 100
) {
rgba: uint (order: 100);
}
33 changes: 33 additions & 0 deletions crates/re_types/definitions/rerun/datatypes/keypoint_id.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include "arrow/attributes.fbs";
include "python/attributes.fbs";
include "rust/attributes.fbs";

include "rerun/attributes.fbs";

namespace rerun.datatypes;

// ---

/// A 16-bit ID representing a type of semantic keypoint within a class.
///
/// \py `KeypointId`s are only meaningful within the context of a [`rerun.components.ClassDescription`][].
/// \py
/// \py Used to look up an [`rerun.components.AnnotationInfo`][] for a Keypoint within the
/// \py [`rerun.components.AnnotationContext`].
///
/// \rs `KeypointId`s are only meaningful within the context of a `crate::components::ClassDescription`.
/// \rs
/// \rs Used to look up an `crate::components::AnnotationInfo` for a Keypoint within the `crate::components::AnnotationContext`.
struct KeypointId (
"attr.arrow.transparent",
"attr.python.aliases": "int",
"attr.python.array_aliases": "int, npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32], npt.NDArray[np.uint64]",
"attr.rust.derive": "Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct",
"attr.rust.custom_clause":
'cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))',
order: 200
) {
id: ushort (order: 100);
}
9 changes: 4 additions & 5 deletions crates/re_types/definitions/rerun/datatypes/keypoint_pair.fbs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
include "arrow/attributes.fbs";
include "fbs/attributes.fbs";

// Include components directly to avoid circular dependencies.
include "rerun/components/keypoint_id.fbs";
include "rerun/datatypes.fbs";

namespace rerun.datatypes;

// ---

/// A connection between two `Keypoints`.
table KeypointPair (
"attr.python.aliases": "Sequence[components.KeypointIdLike]",
"attr.python.aliases": "Sequence[datatypes.KeypointIdLike]",
"attr.rust.derive": "Default, Eq, PartialEq",
order: 100
) {
keypoint0: rerun.components.KeypointId (order: 100);
keypoint1: rerun.components.KeypointId (order: 200);
keypoint0: rerun.datatypes.KeypointId (order: 100);
keypoint1: rerun.datatypes.KeypointId (order: 200);
}
Loading

0 comments on commit a18093f

Please sign in to comment.