Skip to content

Commit

Permalink
Add series to dora-rerun
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed Nov 15, 2024
1 parent 22b0bd9 commit ba95c01
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
8 changes: 7 additions & 1 deletion node-hub/dora-rerun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
71 changes: 71 additions & 0 deletions node-hub/dora-rerun/src/series.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
2 changes: 1 addition & 1 deletion node-hub/dora-rerun/src/urdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ pub fn init_urdf(rec: &RecordingStream) -> Result<HashMap<String, Chain<f32>>> {
}

pub fn update_visualization(
chain: &Chain<f32>,
rec: &RecordingStream,
chain: &Chain<f32>,
id: &str,
positions: &[f32],
) -> Result<()> {
Expand Down

0 comments on commit ba95c01

Please sign in to comment.