pub fn compute_normals<'a, T: BorrowedBuffer<'a>, P: PointType + KdPoint + Copy>(
point_cloud: &'a T,
k_nn: usize,
) -> Vec<(Vector3<f64>, f64)>
Expand description
Normal Estimation Algorithm returns a vector of quintuplets where each quintuplet has the following values: (current point, normal_vector, curvature). It iterates over all points in the buffer and constructs new point buffers of size k_nn. Make sure that knn >= 3 holds as it is not possible to construct a plane over less than three point
§Panics
Panics if the number of k nearest neighbors is less than 3 or the point cloud has less than 3 elements.
§Examples
#[repr(C, packed)]
#[derive(PointType, Debug, Clone, Copy, bytemuck::AnyBitPattern, bytemuck::NoUninit)]
struct SimplePoint {
#[pasture(BUILTIN_POSITION_3D)]
pub position: Vector3<f64>,
#[pasture(BUILTIN_INTENSITY)]
pub intensity: u16,
}
impl KdPoint for SimplePoint {
type Scalar = f64;
type Dim = typenum::U3;
fn at(&self, k: usize) -> f64 {
let position = self.position;
position[k]
}
}
fn main() {
let points = vec![
SimplePoint {
position: Vector3::new(11.0, 22.0, 154.0),
intensity: 42,
},
SimplePoint {
position: Vector3::new(12.0, 23.0, 0.0),
intensity: 84,
},
SimplePoint {
position: Vector3::new(103.0, 84.0, 2.0),
intensity: 84,
},
SimplePoint {
position: Vector3::new(101.0, 0.0, 1.0),
intensity: 84,
},
];
let interleaved = points.into_iter().collect::<VectorBuffer>();
let solution_vec = compute_normals::<VectorBuffer, SimplePoint>(&interleaved, 4);
for solution in solution_vec {
println!(
"Point: {:?}, n_x: {}, n_y: {}, n_z: {}, curvature: {}",
solution.0, solution.0[0], solution.0[1], solution.0[2], solution.1
);
}
}