pointrain_core/pc/
xyz.rs

1#[cfg(feature = "rerun")]
2use rerun::{EntityPath, MsgSender, MsgSenderError};
3
4use crate::{traits::PointCloud, types::Position};
5
6#[derive(Debug, Default, Clone, Copy, PartialEq)]
7pub struct PointXYZ {
8    pub pos: Position,
9}
10
11#[derive(Debug, Default, Clone)]
12pub struct PointCloudXYZ {
13    positions: Vec<Position>,
14}
15
16impl PointCloudXYZ {
17    pub fn new() -> Self {
18        Self::default()
19    }
20
21    #[cfg(feature = "rerun")]
22    pub fn rerun_msg_sender(
23        &self,
24        label: impl Into<EntityPath>,
25    ) -> Result<MsgSender, MsgSenderError> {
26        use rerun::components::Point3D;
27
28        let points: Vec<_> = self
29            .positions
30            .iter()
31            .map(|p| Point3D::new(p.x, p.y, p.z))
32            .collect();
33
34        MsgSender::new(label.into()).with_component(&points)
35    }
36}
37
38impl PointCloud for PointCloudXYZ {
39    type Point = PointXYZ;
40
41    fn with_capacity(capacity: usize) -> Self {
42        Self {
43            positions: Vec::with_capacity(capacity),
44        }
45    }
46
47    fn positions(&self) -> &[Position] {
48        &self.positions
49    }
50
51    fn add_point(&mut self, p: Self::Point) -> &mut Self {
52        self.positions.push(p.pos);
53        self
54    }
55}