From f44f779a987d31b2e3b55da14b438c3635bcd1c8 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Fri, 27 Sep 2024 14:24:26 +0200 Subject: [PATCH] Bump rerun version --- node-hub/dora-rerun/Cargo.toml | 4 +-- node-hub/dora-rerun/src/main.rs | 47 +++++++++++++++------------------ 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/node-hub/dora-rerun/Cargo.toml b/node-hub/dora-rerun/Cargo.toml index 6a9723881..61975e97a 100644 --- a/node-hub/dora-rerun/Cargo.toml +++ b/node-hub/dora-rerun/Cargo.toml @@ -12,6 +12,6 @@ repository.workspace = true [dependencies] dora-node-api = { workspace = true, features = ["tracing"] } eyre = "0.6.8" -tokio = { version = "1.36.0", features = ["rt"] } -rerun = { version = "0.15.1", features = ["web_viewer", "image"] } +tokio = { workspace = true, features = ["rt"] } +rerun = { version = "0.18.2", features = ["web_viewer", "image"] } ndarray = "0.15.6" diff --git a/node-hub/dora-rerun/src/main.rs b/node-hub/dora-rerun/src/main.rs index b16272d99..c92564c7c 100644 --- a/node-hub/dora-rerun/src/main.rs +++ b/node-hub/dora-rerun/src/main.rs @@ -11,12 +11,14 @@ use dora_node_api::{ }; use eyre::{eyre, Context, ContextCompat, Result}; use rerun::{ - external::re_types::ArrowBuffer, SpawnOptions, TensorBuffer, TensorData, TensorDimension, Text, + components::ImageBuffer, external::re_types::ArrowBuffer, ImageFormat, SpawnOptions, Text, }; fn main() -> Result<()> { // rerun `serve()` requires to have a running Tokio runtime in the current context. - let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime"); + let rt = tokio::runtime::Builder::new_current_thread() + .build() + .expect("Failed to create tokio runtime"); let _guard = rt.enter(); let (_node, mut events) = @@ -63,22 +65,6 @@ fn main() -> Result<()> { } else { "bgr8" }; - let channels = 3; - - let shape = vec![ - TensorDimension { - name: Some("height".into()), - size: *height as u64, - }, - TensorDimension { - name: Some("width".into()), - size: *width as u64, - }, - TensorDimension { - name: Some("depth".into()), - size: channels as u64, - }, - ]; let image = if encoding == "bgr8" { let buffer: &UInt8Array = data.as_any().downcast_ref().unwrap(); @@ -87,17 +73,26 @@ fn main() -> Result<()> { // Transpose values from BGR to RGB let buffer: Vec = buffer.chunks(3).flat_map(|x| [x[2], x[1], x[0]]).collect(); - let buffer = TensorBuffer::U8(ArrowBuffer::from(buffer)); - let tensordata = TensorData::new(shape.clone(), buffer); - - rerun::Image::new(tensordata) + let buffer = ArrowBuffer::from(buffer); + let image_buffer = ImageBuffer::try_from(buffer) + .context("Could not convert buffer to image buffer")?; + // let tensordata = ImageBuffer(buffer); + + rerun::Image::new( + image_buffer, + ImageFormat::rgb8([*width as u32, *height as u32]), + ) } else if encoding == "rgb8" { let buffer: &UInt8Array = data.as_any().downcast_ref().unwrap(); let buffer: &[u8] = buffer.values(); - let buffer = TensorBuffer::U8(ArrowBuffer::from(buffer)); - let tensordata = TensorData::new(shape.clone(), buffer); - - rerun::Image::new(tensordata) + let buffer = ArrowBuffer::from(buffer); + let image_buffer = ImageBuffer::try_from(buffer) + .context("Could not convert buffer to image buffer")?; + + rerun::Image::new( + image_buffer, + ImageFormat::rgb8([*width as u32, *height as u32]), + ) } else { unimplemented!("We haven't worked on additional encodings.") };