Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jun 29, 2023
1 parent d0c976a commit 9e7a0f4
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 43 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_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ re_log_types.workspace = true
re_log.workspace = true
re_memory.workspace = true
re_sdk_comms = { workspace = true, features = ["client"] }
re_types = { workspace = true, features = ["ecolor", "glam"] }

ahash.workspace = true
crossbeam.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions crates/re_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ pub mod components {
};
}

// TODO
pub mod experimental {
pub use re_types::{archetypes, components, datatypes, Archetype, Component, Datatype};
}

/// Transform helpers, for use with [`components::Transform3D`].
pub mod transform {
pub use re_components::{
Expand Down
24 changes: 23 additions & 1 deletion crates/re_sdk/src/msg_sender.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use re_log_types::{DataRow, DataTableError, InstanceKey, RowId, StoreId};
use re_log_types::{
external::arrow2::datatypes::DataType, DataRow, DataTableError, InstanceKey, RowId, StoreId,
};
use re_types::Archetype;

use crate::{
log::DataCell,
Expand Down Expand Up @@ -102,6 +105,22 @@ impl MsgSender {
}
}

pub fn from_archetype(ent_path: impl Into<EntityPath>, arch: impl Archetype) -> Self {
let mut this = Self::new(ent_path);
let serialized = arch.to_arrow();
for (field, array) in serialized {
let DataType::Extension(_, _, legacy_fqname) = field.data_type else { unreachable!() };
this = this
.with_cell(DataCell::from_arrow(
legacy_fqname.as_deref().unwrap().into(),
array,
))
.unwrap();
// eprintln!("{} = {array:#?}", field.name);
}
this
}

/// Read the file at the given path and log it.
///
/// Supported file extensions are:
Expand Down Expand Up @@ -299,6 +318,9 @@ impl MsgSender {
let timeless = self.timeless;
let [row_standard, row_splats] = self.into_rows();

// dbg!(&row_standard);
// dbg!(&row_splats);

if let Some(row_splats) = row_splats {
rec_stream.record_row(row_splats, !timeless);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
0aac404674f7f25e4fcbc07f0e241c00e4a8f0fe982d4e82963c0efd0180fb25
a093290cd855fbf83bf265a8f36e12981c76b8aa3500cff0cfb149ed32fd035c
168 changes: 140 additions & 28 deletions crates/re_types/src/archetypes/fuzzy.rs

Large diffs are not rendered by default.

48 changes: 40 additions & 8 deletions crates/re_types/src/archetypes/points2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ impl crate::Archetype for Points2D {
let array =
<crate::components::Point2D>::try_to_arrow(self.points.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.Point2D".into(),
Box::new(array.data_type().clone()),
Some("rerun.point2d".into()),
);
(
::arrow2::datatypes::Field::new("points", datatype, false),
array,
Expand All @@ -126,7 +130,11 @@ impl crate::Archetype for Points2D {
.map(|many| {
let array = <crate::components::Radius>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.Radius".into(),
Box::new(array.data_type().clone()),
Some("rerun.radius".into()),
);
(
::arrow2::datatypes::Field::new("radii", datatype, false),
array,
Expand All @@ -141,7 +149,11 @@ impl crate::Archetype for Points2D {
.map(|many| {
let array = <crate::components::Color>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.Color".into(),
Box::new(array.data_type().clone()),
Some("rerun.colorrgba".into()),
);
(
::arrow2::datatypes::Field::new("colors", datatype, false),
array,
Expand All @@ -156,7 +168,11 @@ impl crate::Archetype for Points2D {
.map(|many| {
let array = <crate::components::Label>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.Label".into(),
Box::new(array.data_type().clone()),
Some("rerun.label".into()),
);
(
::arrow2::datatypes::Field::new("labels", datatype, false),
array,
Expand All @@ -171,7 +187,11 @@ impl crate::Archetype for Points2D {
.map(|single| {
let array = <crate::components::DrawOrder>::try_to_arrow([single], None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.DrawOrder".into(),
Box::new(array.data_type().clone()),
Some("rerun.draw_order".into()),
);
(
::arrow2::datatypes::Field::new("draw_order", datatype, false),
array,
Expand All @@ -186,7 +206,11 @@ impl crate::Archetype for Points2D {
.map(|many| {
let array = <crate::components::ClassId>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.ClassId".into(),
Box::new(array.data_type().clone()),
Some("rerun.class_id".into()),
);
(
::arrow2::datatypes::Field::new("class_ids", datatype, false),
array,
Expand All @@ -202,7 +226,11 @@ impl crate::Archetype for Points2D {
let array =
<crate::components::KeypointId>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.KeypointId".into(),
Box::new(array.data_type().clone()),
Some("rerun.keypoint_id".into()),
);
(
::arrow2::datatypes::Field::new("keypoint_ids", datatype, false),
array,
Expand All @@ -218,7 +246,11 @@ impl crate::Archetype for Points2D {
let array =
<crate::components::InstanceKey>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.InstanceKey".into(),
Box::new(array.data_type().clone()),
Some("rerun.instance_key".into()),
);
(
::arrow2::datatypes::Field::new("instance_keys", datatype, false),
array,
Expand Down
12 changes: 11 additions & 1 deletion crates/re_types_builder/src/codegen/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,20 @@ fn quote_trait_impls_from_obj(
let component = obj_field.typ.fqname().unwrap();
let component = format_ident!("{}", component.rsplit_once('.').unwrap().1);
let component = quote!(crate::components::#component);

let fqname = obj_field.typ.fqname().unwrap();
let legacy_fqname = objects
.get(fqname)
.try_get_attr::<String>(crate::ATTR_RERUN_LEGACY_FQNAME)
.unwrap_or_else(|| obj_field.typ.fqname().unwrap().to_owned());

let extract_datatype_and_return = quote! {
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
#fqname.into(),
Box::new(array.data_type().clone()),
Some(#legacy_fqname.into()),
);
(::arrow2::datatypes::Field::new(#field_name_str, datatype, false), array)
})
};
Expand Down
28 changes: 24 additions & 4 deletions examples/rust/minimal/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
//! Demonstrates the most barebone usage of the Rerun SDK.
use rerun::{
components::{ColorRGBA, Point3D, Radius},
components::{ColorRGBA, Point2D, Point3D, Radius},
demo_util::grid,
experimental,
external::glam,
MsgSender, RecordingStreamBuilder,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let (rec_stream, storage) = RecordingStreamBuilder::new("minimal_rs").memory()?;

let points = grid(glam::Vec3::splat(-10.0), glam::Vec3::splat(10.0), 10)
.map(Point3D::from)
// ---

let points = grid(glam::Vec3::splat(-1.0), glam::Vec3::splat(1.0), 2)
.map(|xyz| Point2D::from([xyz.x, xyz.y]))
.collect::<Vec<_>>();
let colors = grid(glam::Vec3::ZERO, glam::Vec3::splat(255.0), 10)
let colors = grid(glam::Vec3::ZERO, glam::Vec3::splat(255.0), 2)
.map(|v| ColorRGBA::from_rgb(v.x as u8, v.y as u8, v.z as u8))
.collect::<Vec<_>>();

Expand All @@ -23,6 +26,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.with_splat(Radius(0.5))?
.send(&rec_stream)?;

// ---

let points = grid(glam::Vec3::splat(-1.0), glam::Vec3::splat(1.0), 2)
.map(|xyz| glam::Vec2::from([xyz.x, xyz.y]));
let colors = grid(glam::Vec3::ZERO, glam::Vec3::splat(255.0), 2)
.map(|v| [v.x as u8, v.y as u8, v.z as u8, 255]);

MsgSender::from_archetype(
"my_experimental_points",
experimental::archetypes::Points2D::new(points)
.with_radii([0.5])
.with_colors(colors),
)
.send(&rec_stream)?;

// ---

rec_stream.flush_blocking();

rerun::native_viewer::show(storage.take())?;
Expand Down

0 comments on commit 9e7a0f4

Please sign in to comment.