diff --git a/node-hub/dora-rerun/src/lib.rs b/node-hub/dora-rerun/src/lib.rs index 3a7f0614..999f0f04 100644 --- a/node-hub/dora-rerun/src/lib.rs +++ b/node-hub/dora-rerun/src/lib.rs @@ -14,7 +14,9 @@ use eyre::{eyre, Context, ContextCompat, Result}; use rerun::{ components::ImageBuffer, external::re_types::ArrowBuffer, ImageFormat, SpawnOptions, Text, }; +pub mod series; pub mod urdf; +use series::update_series; use urdf::{init_urdf, update_visualization}; pub fn lib_main() -> Result<()> { @@ -227,10 +229,14 @@ pub fn lib_main() -> Result<()> { } } - update_visualization(chain, &rec, &id, &positions)?; + update_visualization(&rec, &chain, &id, &positions)?; } else { println!("Could not find chain for {}", id); } + } else if id.as_str().contains("series") { + update_series(&rec, id, data).context("could not plot series")?; + } else { + println!("Could not find handler for {}", id); } } } diff --git a/node-hub/dora-rerun/src/series.rs b/node-hub/dora-rerun/src/series.rs new file mode 100644 index 00000000..d2d36806 --- /dev/null +++ b/node-hub/dora-rerun/src/series.rs @@ -0,0 +1,71 @@ +use dora_node_api::{ + arrow::array::{Float32Array, Float64Array, Int32Array, Int64Array}, + dora_core::config::DataId, + ArrowData, +}; +use eyre::{Context, ContextCompat, Result}; +use rerun::RecordingStream; + +pub fn update_series(rec: &RecordingStream, id: DataId, data: ArrowData) -> Result<()> { + match data.data_type() { + dora_node_api::arrow::datatypes::DataType::Float32 => { + let buffer: &Float32Array = data + .as_any() + .downcast_ref() + .context("series is not float32")?; + let series: Vec<_> = buffer.values().to_vec(); + for (i, value) in series.iter().enumerate() { + rec.log( + format!("{}_{}", id.as_str(), i), + &rerun::Scalar::new(*value as f64), + ) + .wrap_err("could not log series")?; + } + } + dora_node_api::arrow::datatypes::DataType::Float64 => { + let buffer: &Float64Array = data + .as_any() + .downcast_ref() + .context("series is not float64")?; + let series: Vec<_> = buffer.values().to_vec(); + for (i, value) in series.iter().enumerate() { + rec.log( + format!("{}_{}", id.as_str(), i), + &rerun::Scalar::new(*value as f64), + ) + .wrap_err("could not log series")?; + } + } + dora_node_api::arrow::datatypes::DataType::Int32 => { + let buffer: &Int32Array = data + .as_any() + .downcast_ref() + .context("series is not Int32")?; + let series: Vec<_> = buffer.values().to_vec(); + for (i, value) in series.iter().enumerate() { + rec.log( + format!("{}_{}", id.as_str(), i), + &rerun::Scalar::new(*value as f64), + ) + .wrap_err("could not log series")?; + } + } + dora_node_api::arrow::datatypes::DataType::Int64 => { + let buffer: &Int64Array = data + .as_any() + .downcast_ref() + .context("series is not Int64")?; + let series: Vec<_> = buffer.values().to_vec(); + for (i, value) in series.iter().enumerate() { + rec.log( + format!("{}_{}", id.as_str(), i), + &rerun::Scalar::new(*value as f64), + ) + .wrap_err("could not log series")?; + } + } + + _ => unimplemented!("This has not yet implemented. Please contribute to dora-rerun :)"), + } + Ok(()) +} diff --git a/node-hub/dora-rerun/src/urdf.rs b/node-hub/dora-rerun/src/urdf.rs index 55203b3e..796a4a90 100644 --- a/node-hub/dora-rerun/src/urdf.rs +++ b/node-hub/dora-rerun/src/urdf.rs @@ -96,8 +96,8 @@ pub fn init_urdf(rec: &RecordingStream) -> Result>> { } pub fn update_visualization( - chain: &Chain, rec: &RecordingStream, + chain: &Chain, id: &str, positions: &[f32], ) -> Result<()> {