Skip to content

Commit

Permalink
Remove legacy Transform3D (#2846)
Browse files Browse the repository at this point in the history
This PR annihilates the legacy `Transform3D` family of component and
data types, and deprecates the legacy `VecND` & `MatNxN` types as much
as possible (there are still many other components that we have to
migrate first).

The legacy `log_transform3d` API still exists, but now simply delegates
to the new `Transform3D` archetype.

---

This PR also includes some improved error reporting on the
deserialization path, as well as a workaround for `pa.nulls` misbehaving
in some cases, see #2871 for the full story.

---

This PR also removes any traces of datatypes being registered as UI
components, as it historically did not make sense and was never used,
and is simply impossible to do anymore since `Datatype` and `Component`
are now different traits.

Part of #2791

### What

### 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 [demo.rerun.io](https://demo.rerun.io/pr/2846) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2846)
- [Docs
preview](https://rerun.io/preview/pr%3Acmc%2Fgoodbye_old_transform/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Acmc%2Fgoodbye_old_transform/examples)
  • Loading branch information
teh-cmc authored Jul 31, 2023
1 parent bf27efd commit 44b1626
Show file tree
Hide file tree
Showing 75 changed files with 652 additions and 1,262 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/re_arrow_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ core_benchmarks_only = []

[dependencies]
# Rerun dependencies:
re_error.workspace = true
re_format.workspace = true
re_log_types.workspace = true
re_log.workspace = true
Expand Down
8 changes: 7 additions & 1 deletion crates/re_arrow_store/src/arrow_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,17 @@ fn test_clean_for_polars_nomodify() {
mod tests {
use arrow2::datatypes::{DataType, Field, UnionMode};
use arrow2_convert::{ArrowDeserialize, ArrowField, ArrowSerialize};
use re_components::Vec3D;
use re_components::FixedSizeArrayField;
use re_log_types::DataCell;

use crate::ArrayExt;

#[derive(
Copy, Clone, Debug, Default, PartialEq, ArrowField, ArrowSerialize, ArrowDeserialize,
)]
#[arrow_field(transparent)]
pub struct Vec3D(#[arrow_field(type = "FixedSizeArrayField<f32,3>")] pub [f32; 3]);

#[derive(Clone, Copy, Debug, PartialEq, ArrowField, ArrowSerialize, ArrowDeserialize)]
#[arrow_field(type = "dense")]
enum TestComponentWithUnionAndFixedSizeList {
Expand Down
32 changes: 30 additions & 2 deletions crates/re_arrow_store/src/store_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,38 @@ impl DataStore {

cell.try_to_native_mono::<C>()
.map_err(|err| {
if let re_log_types::DataCellError::LoggableDeserialize(err) = err {
let bt = err.backtrace().map(|mut bt| {
bt.resolve();
bt
});

let err = Box::new(err) as Box<dyn std::error::Error>;
if let Some(bt) = bt {
re_log::error_once!(
"Couldn't deserialize component at {entity_path}#{}: {}\n{:#?}",
C::name(),
re_error::format(&err),
bt,
);
} else {
re_log::error_once!(
"Couldn't deserialize component at {entity_path}#{}: {}",
C::name(),
re_error::format(&err)
);
}
return err;
}

let err = Box::new(err) as Box<dyn std::error::Error>;
re_log::error_once!(
"Couldn't deserialize component at {entity_path}.{}: {err}",
C::name()
"Couldn't deserialize component at {entity_path}#{}: {}",
C::name(),
re_error::format(&err)
);

err
})
.ok()?
}
Expand Down
6 changes: 3 additions & 3 deletions crates/re_components/src/arrow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::Vec3D;
use super::LegacyVec3D;
use arrow2_convert::{ArrowDeserialize, ArrowField, ArrowSerialize};

/// A 3D Arrow
Expand Down Expand Up @@ -31,8 +31,8 @@ use arrow2_convert::{ArrowDeserialize, ArrowField, ArrowSerialize};
#[derive(Copy, Clone, Debug, ArrowField, ArrowSerialize, ArrowDeserialize, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Arrow3D {
pub origin: Vec3D,
pub vector: Vec3D,
pub origin: LegacyVec3D,
pub vector: LegacyVec3D,
}

impl re_log_types::LegacyComponent for Arrow3D {
Expand Down
4 changes: 2 additions & 2 deletions crates/re_components/src/datagen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ pub fn build_some_point2d(len: usize) -> Vec<crate::Point2D> {
}

/// Create `len` dummy `Vec3D`
pub fn build_some_vec3d(len: usize) -> Vec<crate::Vec3D> {
pub fn build_some_vec3d(len: usize) -> Vec<crate::LegacyVec3D> {
use rand::Rng as _;
let mut rng = rand::thread_rng();

(0..len)
.map(|_| {
crate::Vec3D::new(
crate::LegacyVec3D::new(
rng.gen_range(0.0..10.0),
rng.gen_range(0.0..10.0),
rng.gen_range(0.0..10.0),
Expand Down
20 changes: 8 additions & 12 deletions crates/re_components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ mod tensor;
mod tensor_data;
mod text_box;
mod text_entry;
mod transform3d;
mod vec;

#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -57,13 +56,16 @@ pub(crate) use self::{
class_id::LegacyClassId, color::LegacyColor, keypoint_id::LegacyKeypointId, label::LegacyLabel,
};

// TODO(cmc): get rid of this once every single archetypes depending on those have been migrated.
pub use vec::{LegacyVec2D, LegacyVec3D, LegacyVec4D};

pub use self::{
arrow::Arrow3D,
bbox::Box3D,
context::{AnnotationContext, AnnotationInfo, ClassDescription},
coordinates::ViewCoordinates,
linestrip::{LineStrip2D, LineStrip3D},
mat::Mat3x3,
mat::LegacyMat3x3,
mesh3d::{EncodedMesh3D, Mesh3D, MeshFormat, MeshId, RawMesh3D},
pinhole::Pinhole,
quaternion::Quaternion,
Expand All @@ -76,11 +78,6 @@ pub use self::{
tensor_data::{TensorDataType, TensorDataTypeTrait, TensorElement},
text_box::TextBox,
text_entry::TextEntry,
transform3d::{
Angle, Rotation3D, RotationAxisAngle, Scale3D, Transform3D, Transform3DRepr,
TranslationAndMat3, TranslationRotationScale3D,
},
vec::{Vec2D, Vec3D, Vec4D},
};

#[cfg(feature = "image")]
Expand All @@ -104,12 +101,12 @@ pub mod external {

use re_types::components::{
ClassId, Color, DisconnectedSpace, DrawOrder, InstanceKey, KeypointId, Label, Point2D, Point3D,
Radius,
Radius, Transform3D,
};

lazy_static! {
//TODO(john): use a run-time type registry
static ref FIELDS: [Field; 28] = [
static ref FIELDS: [Field; 27] = [
<AnnotationContext as LegacyComponent>::field(),
<Arrow3D as LegacyComponent>::field(),
<Box3D as LegacyComponent>::field(),
Expand All @@ -124,9 +121,7 @@ lazy_static! {
<Tensor as LegacyComponent>::field(),
<TextBox as LegacyComponent>::field(),
<TextEntry as LegacyComponent>::field(),
<Transform3D as LegacyComponent>::field(),
<Vec2D as LegacyComponent>::field(),
<Vec3D as LegacyComponent>::field(),
<LegacyVec3D as LegacyComponent>::field(),
<ViewCoordinates as LegacyComponent>::field(),
Field::new(ClassId::name().as_str(), ClassId::to_arrow_datatype(), false),
Field::new(Color::name().as_str(), Color::to_arrow_datatype(), false),
Expand All @@ -138,6 +133,7 @@ lazy_static! {
Field::new(Point2D::name().as_str(), Point2D::to_arrow_datatype(), false),
Field::new(Point3D::name().as_str(), Point3D::to_arrow_datatype(), false),
Field::new(Radius::name().as_str(), Radius::to_arrow_datatype(), false),
Field::new(Transform3D::name().as_str(), Transform3D::to_arrow_datatype(), false),
];
}

Expand Down
24 changes: 12 additions & 12 deletions crates/re_components/src/linestrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use arrow2_convert::{
serialize::ArrowSerialize,
};

use super::Vec2D;
use super::Vec3D;
use super::LegacyVec2D;
use super::LegacyVec3D;

/// A Line Strip of 2D points
///
Expand All @@ -28,12 +28,12 @@ use super::Vec3D;
/// ```
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct LineStrip2D(pub Vec<Vec2D>);
pub struct LineStrip2D(pub Vec<LegacyVec2D>);

impl From<Vec<[f32; 2]>> for LineStrip2D {
#[inline]
fn from(v: Vec<[f32; 2]>) -> Self {
Self(v.into_iter().map(Vec2D).collect())
Self(v.into_iter().map(LegacyVec2D).collect())
}
}

Expand All @@ -51,7 +51,7 @@ impl ArrowField for LineStrip2D {

#[inline]
fn data_type() -> DataType {
<Vec<Vec2D> as ArrowField>::data_type()
<Vec<LegacyVec2D> as ArrowField>::data_type()
}
}

Expand Down Expand Up @@ -86,13 +86,13 @@ impl ArrowSerialize for LineStrip2D {
}

impl ArrowDeserialize for LineStrip2D {
type ArrayType = <Vec<Vec2D> as ArrowDeserialize>::ArrayType;
type ArrayType = <Vec<LegacyVec2D> as ArrowDeserialize>::ArrayType;

#[inline]
fn arrow_deserialize(
v: <&Self::ArrayType as IntoIterator>::Item,
) -> Option<<Self as ArrowField>::Type> {
<Vec<Vec2D> as ArrowDeserialize>::arrow_deserialize(v).map(Self)
<Vec<LegacyVec2D> as ArrowDeserialize>::arrow_deserialize(v).map(Self)
}
}

Expand All @@ -116,12 +116,12 @@ re_log_types::component_legacy_shim!(LineStrip2D);
/// ```
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct LineStrip3D(pub Vec<Vec3D>);
pub struct LineStrip3D(pub Vec<LegacyVec3D>);

impl From<Vec<[f32; 3]>> for LineStrip3D {
#[inline]
fn from(v: Vec<[f32; 3]>) -> Self {
Self(v.into_iter().map(Vec3D).collect())
Self(v.into_iter().map(LegacyVec3D).collect())
}
}

Expand All @@ -139,7 +139,7 @@ impl ArrowField for LineStrip3D {

#[inline]
fn data_type() -> DataType {
<Vec<Vec3D> as ArrowField>::data_type()
<Vec<LegacyVec3D> as ArrowField>::data_type()
}
}

Expand Down Expand Up @@ -174,13 +174,13 @@ impl ArrowSerialize for LineStrip3D {
}

impl ArrowDeserialize for LineStrip3D {
type ArrayType = <Vec<Vec3D> as ArrowDeserialize>::ArrayType;
type ArrayType = <Vec<LegacyVec3D> as ArrowDeserialize>::ArrayType;

#[inline]
fn arrow_deserialize(
v: <&Self::ArrayType as IntoIterator>::Item,
) -> Option<<Self as ArrowField>::Type> {
<Vec<Vec3D> as ArrowDeserialize>::arrow_deserialize(v).map(Self)
<Vec<LegacyVec3D> as ArrowDeserialize>::arrow_deserialize(v).map(Self)
}
}

Expand Down
Loading

0 comments on commit 44b1626

Please sign in to comment.