use crate::{PointCloud, Vec3, with_context_mut};
pub fn register_point_cloud(name: impl Into<String>, points: Vec<Vec3>) -> PointCloudHandle {
let name = name.into();
let point_cloud = PointCloud::new(name.clone(), points);
with_context_mut(|ctx| {
ctx.registry
.register(Box::new(point_cloud))
.expect("failed to register point cloud");
ctx.update_extents();
});
PointCloudHandle { name }
}
impl_structure_accessors! {
get_fn = get_point_cloud,
with_fn = with_point_cloud,
with_ref_fn = with_point_cloud_ref,
handle = PointCloudHandle,
type_name = "PointCloud",
rust_type = PointCloud,
doc_name = "point cloud"
}
#[derive(Clone)]
pub struct PointCloudHandle {
name: String,
}
impl PointCloudHandle {
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
pub fn add_scalar_quantity(&self, name: &str, values: Vec<f32>) -> &Self {
with_context_mut(|ctx| {
if let Some(pc) = ctx.registry.get_mut("PointCloud", &self.name) {
if let Some(pc) = (pc as &mut dyn std::any::Any).downcast_mut::<PointCloud>() {
pc.add_scalar_quantity(name, values);
}
}
});
self
}
pub fn add_vector_quantity(&self, name: &str, vectors: Vec<Vec3>) -> &Self {
with_context_mut(|ctx| {
if let Some(pc) = ctx.registry.get_mut("PointCloud", &self.name) {
if let Some(pc) = (pc as &mut dyn std::any::Any).downcast_mut::<PointCloud>() {
pc.add_vector_quantity(name, vectors);
}
}
});
self
}
pub fn add_color_quantity(&self, name: &str, colors: Vec<Vec3>) -> &Self {
with_context_mut(|ctx| {
if let Some(pc) = ctx.registry.get_mut("PointCloud", &self.name) {
if let Some(pc) = (pc as &mut dyn std::any::Any).downcast_mut::<PointCloud>() {
pc.add_color_quantity(name, colors);
}
}
});
self
}
}