gausplat_renderer/scene/point/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Point cloud scene representation.

pub mod points;

pub use gausplat_loader::source::colmap;
pub use points::*;

/// 3D point.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Point {
    /// Normalized color in RGB space.
    pub color_rgb: [f32; 3],
    /// Position in world space.
    pub position: [f64; 3],
}

impl From<colmap::Point> for Point {
    #[inline]
    fn from(point: colmap::Point) -> Self {
        Self {
            color_rgb: point.color_rgb_normalized(),
            position: point.position,
        }
    }
}

impl From<Point> for colmap::Point {
    #[inline]
    fn from(point: Point) -> Self {
        let color_rgb = point.color_rgb;
        let position = point.position;
        Self {
            color_rgb: [
                color_rgb[0].mul_add(255.0, 0.5).clamp(0.0, 255.0) as u8,
                color_rgb[1].mul_add(255.0, 0.5).clamp(0.0, 255.0) as u8,
                color_rgb[2].mul_add(255.0, 0.5).clamp(0.0, 255.0) as u8,
            ],
            position,
        }
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn from_and_into_colmap_point() {
        use super::*;

        let point = Point {
            color_rgb: [0.2509804, 0.5019608, 0.7529412],
            position: [1.0, 2.0, 3.0],
        };
        let colmap_point = colmap::Point {
            color_rgb: [64, 128, 192],
            position: [1.0, 2.0, 3.0],
        };

        assert_eq!(Point::from(colmap_point), point);
        assert_eq!(colmap::Point::from(point), colmap_point);
    }
}