pointrain_core/pc/
xyz_rgb_normal.rs

1use crate::{
2    traits::{PointCloud, PointCloudWithColor, PointCloudWithNormal},
3    types::{Float, Normal, Position, Rgb},
4};
5
6#[derive(Debug, Default, Clone, Copy, PartialEq)]
7pub struct PointXYZRgbNormal {
8    pub pos: Position,
9    pub normal: Normal,
10    pub color: Rgb,
11    pub curvature: Float,
12}
13
14#[derive(Debug, Default, Clone)]
15pub struct PointCloudXYZRgbNormal {
16    positions: Vec<Position>,
17    colors: Vec<Rgb>,
18    normals: Vec<Normal>,
19    curvatures: Vec<Float>,
20}
21
22impl PointCloudXYZRgbNormal {
23    pub fn new() -> Self {
24        Self::default()
25    }
26}
27
28impl PointCloud for PointCloudXYZRgbNormal {
29    type Point = PointXYZRgbNormal;
30
31    fn with_capacity(capacity: usize) -> Self {
32        Self {
33            positions: Vec::with_capacity(capacity),
34            colors: Vec::with_capacity(capacity),
35            normals: Vec::with_capacity(capacity),
36            curvatures: Vec::with_capacity(capacity),
37        }
38    }
39
40    fn positions(&self) -> &[Position] {
41        &self.positions
42    }
43
44    fn add_point(&mut self, p: Self::Point) -> &mut Self {
45        self.positions.push(p.pos);
46        self.colors.push(p.color);
47        self.normals.push(p.normal);
48        self.curvatures.push(p.curvature);
49        self
50    }
51}
52
53impl PointCloudWithColor for PointCloudXYZRgbNormal {
54    fn colors(&self) -> &[Rgb] {
55        &self.colors
56    }
57}
58
59impl PointCloudWithNormal for PointCloudXYZRgbNormal {
60    fn normals(&self) -> &[Normal] {
61        &self.normals
62    }
63
64    fn curvatures(&self) -> &[Float] {
65        &self.curvatures
66    }
67}