Skip to content

Commit

Permalink
annihilate legacy Label (as much as humanly possible)
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jul 24, 2023
1 parent 090868f commit f2523a7
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 74 deletions.
13 changes: 13 additions & 0 deletions crates/re_components/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ impl From<LegacyLabel> for re_types::components::Label {
}
}

impl From<re_types::components::Label> for LegacyLabel {
fn from(value: re_types::components::Label) -> Self {
Self(value.0)
}
}

impl LegacyLabel {
#[inline]
pub fn as_str(&self) -> &str {
Expand All @@ -36,6 +42,13 @@ impl re_log_types::LegacyComponent for LegacyLabel {
}
}

impl From<&str> for LegacyLabel {
#[inline]
fn from(value: &str) -> Self {
Self(value.into())
}
}

impl From<String> for LegacyLabel {
#[inline]
fn from(value: String) -> Self {
Expand Down
3 changes: 1 addition & 2 deletions crates/re_components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub mod datagen;
// TODO(emilk): split into modules, like we do in re_sdk/src/lib.rs

// TODO: stuff we keep for annotation context
pub(crate) use self::{class_id::LegacyClassId, keypoint_id::LegacyKeypointId};
pub(crate) use self::{class_id::LegacyClassId, keypoint_id::LegacyKeypointId, label::LegacyLabel};

pub use self::{
arrow::Arrow3D,
Expand All @@ -62,7 +62,6 @@ pub use self::{
context::{AnnotationContext, AnnotationInfo, ClassDescription},
coordinates::ViewCoordinates,
disconnected_space::DisconnectedSpace,
label::LegacyLabel,
linestrip::{LineStrip2D, LineStrip3D},
mat::Mat3x3,
mesh3d::{EncodedMesh3D, Mesh3D, MeshFormat, MeshId, RawMesh3D},
Expand Down
9 changes: 6 additions & 3 deletions crates/re_components/tests/data_row.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use re_components::{LegacyColor, LegacyLabel};
use re_components::LegacyColor;
use re_log_types::{DataRow, DataRowError, EntityPath, RowId, TimePoint};
use re_types::{components::Point2D, Loggable as _};
use re_types::{
components::{Label, Point2D},
Loggable as _,
};

#[test]
fn data_row_error_num_instances() {
Expand All @@ -10,7 +13,7 @@ fn data_row_error_num_instances() {
let num_instances = 2;
let points: &[Point2D] = &[[10.0, 10.0].into(), [20.0, 20.0].into()];
let colors: &[_] = &[LegacyColor::from_rgb(128, 128, 128)];
let labels: &[LegacyLabel] = &[];
let labels: &[Label] = &[];

// 0 = clear: legal
DataRow::try_from_cells1(row_id, "a/b/c", timepoint.clone(), num_instances, labels).unwrap();
Expand Down
8 changes: 4 additions & 4 deletions crates/re_components/tests/data_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ fn data_table_sizes_basics() {
// utf8 (and more generally: dyn_binary)
let mut cell = DataCell::from_native(
[
re_components::LegacyLabel("hey".into()),
re_components::LegacyLabel("hey".into()),
re_components::LegacyLabel("hey".into()),
re_types::components::Label("hey".into()),
re_types::components::Label("hey".into()),
re_types::components::Label("hey".into()),
]
.as_slice(),
);
Expand All @@ -79,7 +79,7 @@ fn data_table_sizes_basics() {
);
expect(
DataCell::from_arrow(
re_components::LegacyLabel::name(),
re_types::components::Label::name(),
cell.to_arrow().sliced(1, 1),
),
10_000, // num_rows
Expand Down
8 changes: 4 additions & 4 deletions crates/re_components/tests/data_table_batcher.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crossbeam::{channel::TryRecvError, select};
use itertools::Itertools as _;

use re_components::{LegacyColor, LegacyLabel};
use re_components::LegacyColor;
use re_log_types::{
DataRow, DataTableBatcher, DataTableBatcherConfig, RowId, SizeBytes, TimePoint, Timeline,
};
use re_log_types::{DataTable, TableId, Time};
use re_types::components::Point2D;
use re_types::components::{Label, Point2D};

#[test]
fn manual_trigger() {
Expand Down Expand Up @@ -284,7 +284,7 @@ fn create_table() -> DataTable {
let num_instances = 2;
let points: &[Point2D] = &[[10.0, 10.0].into(), [20.0, 20.0].into()];
let colors: &[_] = &[LegacyColor::from_rgb(128, 128, 128)];
let labels: &[LegacyLabel] = &[];
let labels: &[Label] = &[];

DataRow::from_cells3(
RowId::random(),
Expand All @@ -305,7 +305,7 @@ fn create_table() -> DataTable {
let row2 = {
let num_instances = 1;
let colors: &[_] = &[LegacyColor::from_rgb(255, 255, 255)];
let labels: &[_] = &[LegacyLabel("hey".into())];
let labels: &[_] = &[Label("hey".into())];

DataRow::from_cells2(
RowId::random(),
Expand Down
8 changes: 4 additions & 4 deletions crates/re_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ pub mod time {
pub mod components {
pub use re_components::{
AnnotationContext, AnnotationInfo, Arrow3D, Box3D, ClassDescription, DisconnectedSpace,
EncodedMesh3D, LegacyColor, LegacyLabel, LineStrip2D, LineStrip3D, Mat3x3, Mesh3D,
MeshFormat, MeshId, Pinhole, Quaternion, RawMesh3D, Rect2D, Scalar, ScalarPlotProps,
Size3D, Tensor, TensorData, TensorDataMeaning, TensorDimension, TensorId, TextEntry,
Transform3D, Vec2D, Vec3D, Vec4D, ViewCoordinates,
EncodedMesh3D, LegacyColor, LineStrip2D, LineStrip3D, Mat3x3, Mesh3D, MeshFormat, MeshId,
Pinhole, Quaternion, RawMesh3D, Rect2D, Scalar, ScalarPlotProps, Size3D, Tensor,
TensorData, TensorDataMeaning, TensorDimension, TensorId, TextEntry, Transform3D, Vec2D,
Vec3D, Vec4D, ViewCoordinates,
};
pub use re_types::components::{
ClassId, Color, DrawOrder, InstanceKey, KeypointId, Label, Point2D, Point3D, Radius,
Expand Down
26 changes: 13 additions & 13 deletions crates/re_sdk/src/msg_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ mod tests {
#[test]
fn full() -> Result<(), MsgSenderError> {
let labels = vec![
components::LegacyLabel("label1".into()),
components::LegacyLabel("label2".into()),
re_types::components::Label("label1".into()),
re_types::components::Label("label2".into()),
];
let transform = vec![components::Transform3D::IDENTITY];
let color = components::LegacyColor::from_rgb(255, 0, 255);
Expand All @@ -435,7 +435,7 @@ mod tests {
{
let standard = standard.unwrap();
let idx = standard
.find_cell(&components::LegacyLabel::name())
.find_cell(&re_types::components::Label::name())
.unwrap();
let cell = &standard.cells[idx];
assert!(cell.num_instances() == 2);
Expand Down Expand Up @@ -475,7 +475,7 @@ mod tests {

let sender = MsgSender::new("some/path")
.with_timeless(true)
.with_component([components::LegacyLabel("label1".into())].as_slice())?
.with_component([re_types::components::Label("label1".into())].as_slice())?
.with_time(my_timeline, 2);
assert!(!sender.timepoint.is_empty()); // not yet

Expand All @@ -488,7 +488,7 @@ mod tests {
#[test]
fn illegal_instance_key() -> Result<(), MsgSenderError> {
let _ = MsgSender::new("some/path")
.with_component([components::LegacyLabel("label1".into())].as_slice())?
.with_component([re_types::components::Label("label1".into())].as_slice())?
.with_component([components::InstanceKey(u64::MAX)].as_slice())?
.into_rows();

Expand All @@ -500,7 +500,7 @@ mod tests {
#[test]
fn splatted_instance_key() -> Result<(), MsgSenderError> {
let res = MsgSender::new("some/path")
.with_component([components::LegacyLabel("label1".into())].as_slice())?
.with_component([re_types::components::Label("label1".into())].as_slice())?
.with_splat(components::InstanceKey(42));

assert!(matches!(res, Err(MsgSenderError::SplattedInstanceKeys)));
Expand All @@ -513,7 +513,7 @@ mod tests {
// 1 for 1 -- fine
{
MsgSender::new("some/path")
.with_component([components::LegacyLabel("label1".into())].as_slice())?
.with_component([re_types::components::Label("label1".into())].as_slice())?
.with_component([components::LegacyColor::from_rgb(1, 1, 1)].as_slice())?;
}

Expand All @@ -522,9 +522,9 @@ mod tests {
MsgSender::new("some/path")
.with_component(
[
components::LegacyLabel("label1".into()),
components::LegacyLabel("label2".into()),
components::LegacyLabel("label3".into()),
re_types::components::Label("label1".into()),
re_types::components::Label("label2".into()),
re_types::components::Label("label3".into()),
]
.as_slice(),
)?
Expand All @@ -536,9 +536,9 @@ mod tests {
let res = MsgSender::new("some/path")
.with_component(
[
components::LegacyLabel("label1".into()),
components::LegacyLabel("label2".into()),
components::LegacyLabel("label3".into()),
re_types::components::Label("label1".into()),
re_types::components::Label("label2".into()),
re_types::components::Label("label3".into()),
]
.as_slice(),
)?
Expand Down
8 changes: 4 additions & 4 deletions crates/re_space_view_spatial/src/parts/arrows3d.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use re_components::{Arrow3D, LegacyColor, LegacyLabel};
use re_components::{Arrow3D, LegacyColor};
use re_data_store::EntityPath;
use re_query::{EntityView, QueryError};
use re_renderer::{renderer::LineStripFlags, Size};
use re_types::{
components::{InstanceKey, Radius},
components::{InstanceKey, Label, Radius},
Loggable as _,
};
use re_viewer_context::{
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Arrows3DPart {
arrow: Arrow3D,
color: Option<LegacyColor>,
radius: Option<Radius>,
_label: Option<LegacyLabel>| {
_label: Option<Label>| {
// TODO(andreas): support labels
// TODO(andreas): support class ids for arrows
let annotation_info = ent_context
Expand Down Expand Up @@ -104,7 +104,7 @@ impl ViewPartSystem for Arrows3DPart {
InstanceKey::name(),
LegacyColor::name(),
Radius::name(),
LegacyLabel::name(),
Label::name(),
]
}

Expand Down
8 changes: 4 additions & 4 deletions crates/re_space_view_spatial/src/parts/boxes2d.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use re_components::{LegacyColor, LegacyLabel, Rect2D};
use re_components::{LegacyColor, Rect2D};
use re_data_store::EntityPath;
use re_query::{EntityView, QueryError};
use re_renderer::Size;
use re_types::{
components::{ClassId, InstanceKey, Radius},
components::{ClassId, InstanceKey, Label, Radius},
Loggable as _,
};
use re_viewer_context::{
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Boxes2DPart {
rect,
color: Option<LegacyColor>,
radius: Option<Radius>,
label: Option<LegacyLabel>,
label: Option<Label>,
class_id: Option<ClassId>| {
let instance_hash =
re_data_store::InstancePathHash::instance(ent_path, instance_key);
Expand Down Expand Up @@ -115,7 +115,7 @@ impl ViewPartSystem for Boxes2DPart {
InstanceKey::name(),
LegacyColor::name(),
Radius::name(),
LegacyLabel::name(),
Label::name(),
ClassId::name(),
]
}
Expand Down
8 changes: 4 additions & 4 deletions crates/re_space_view_spatial/src/parts/boxes3d.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use re_components::{Box3D, LegacyColor, LegacyLabel, Quaternion, Vec3D};
use re_components::{Box3D, LegacyColor, Quaternion, Vec3D};
use re_data_store::EntityPath;
use re_query::{EntityView, QueryError};
use re_renderer::Size;
use re_types::{
components::{ClassId, InstanceKey, Radius},
components::{ClassId, InstanceKey, Label, Radius},
Loggable as _,
};
use re_viewer_context::{
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Boxes3DPart {
rotation: Option<Quaternion>,
color: Option<LegacyColor>,
radius: Option<Radius>,
label: Option<LegacyLabel>,
label: Option<Label>,
class_id: Option<ClassId>| {
let class_description = ent_context.annotations.class_description(class_id);
let annotation_info = class_description.annotation_info();
Expand Down Expand Up @@ -112,7 +112,7 @@ impl ViewPartSystem for Boxes3DPart {
Quaternion::name(), // obb.rotation
LegacyColor::name(),
Radius::name(), // stroke_width
LegacyLabel::name(),
Label::name(),
ClassId::name(),
]
}
Expand Down
9 changes: 6 additions & 3 deletions crates/re_space_view_spatial/src/parts/points3d.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use re_components::LegacyLabel;
use re_data_store::{EntityPath, InstancePathHash};
use re_query::{ArchetypeView, QueryError};
use re_types::{archetypes::Points3D, components::Point3D, Archetype as _};
use re_types::{
archetypes::Points3D,
components::{Label, Point3D},
Archetype as _,
};
use re_viewer_context::{
ArchetypeDefinition, ResolvedAnnotationInfo, SpaceViewSystemExecutionError,
ViewContextCollection, ViewPartSystem, ViewQuery, ViewerContext,
Expand Down Expand Up @@ -45,7 +48,7 @@ impl Points3DPart {
let labels = itertools::izip!(
annotation_infos.iter(),
arch_view.iter_required_component::<Point3D>()?,
arch_view.iter_optional_component::<LegacyLabel>()?,
arch_view.iter_optional_component::<Label>()?,
colors,
instance_path_hashes,
)
Expand Down
4 changes: 2 additions & 2 deletions crates/re_space_view_time_series/src/view_part_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl TimeSeriesSystem {
re_components::ScalarPlotProps::name(),
re_components::LegacyColor::name(),
re_types::components::Radius::name(),
re_components::LegacyLabel::name(),
re_types::components::Label::name(),
]
}

Expand Down Expand Up @@ -138,7 +138,7 @@ impl TimeSeriesSystem {
props: Option<re_components::ScalarPlotProps>,
color: Option<re_components::LegacyColor>,
radius: Option<re_types::components::Radius>,
label: Option<re_components::LegacyLabel>| {
label: Option<re_types::components::Label>| {
// TODO(andreas): Support entity path
let color = annotation_info
.color(color.map(|c| c.to_array()).as_ref(), default_color);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt

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

12 changes: 6 additions & 6 deletions docs/code-examples/annotation_context_connections.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Log some very simple points.
use rerun::components::{
AnnotationContext, AnnotationInfo, ClassDescription, ClassId, KeypointId, LegacyColor,
LegacyLabel, Point3D,
AnnotationContext, AnnotationInfo, ClassDescription, ClassId, KeypointId, Label, LegacyColor,
Point3D,
};
use rerun::{MsgSender, RecordingStreamBuilder};

Expand All @@ -17,31 +17,31 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
KeypointId(0),
AnnotationInfo {
id: 0,
label: Some(LegacyLabel("zero".to_owned())),
label: Some(Label("zero".into()).into()),
color: Some(LegacyColor::from_rgb(255, 0, 0)),
},
);
class_desc.keypoint_map.insert(
KeypointId(1),
AnnotationInfo {
id: 1,
label: Some(LegacyLabel("one".to_owned())),
label: Some(Label("one".into()).into()),
color: Some(LegacyColor::from_rgb(0, 255, 0)),
},
);
class_desc.keypoint_map.insert(
KeypointId(2),
AnnotationInfo {
id: 2,
label: Some(LegacyLabel("two".to_owned())),
label: Some(Label("two".into()).into()),
color: Some(LegacyColor::from_rgb(0, 0, 255)),
},
);
class_desc.keypoint_map.insert(
KeypointId(3),
AnnotationInfo {
id: 3,
label: Some(LegacyLabel("three".to_owned())),
label: Some(Label("three".into()).into()),
color: Some(LegacyColor::from_rgb(255, 255, 0)),
},
);
Expand Down
Loading

0 comments on commit f2523a7

Please sign in to comment.