modern_icp/point_cloud/
iterator.rs1use nalgebra::Scalar;
2
3use super::{MaskedPointCloud, PointCloudPoint};
4
5#[derive(Debug, Copy)]
6pub struct PointCloudIterator<'a, T: Scalar + Copy, const D: usize> {
7 pub(super) target: &'a MaskedPointCloud<'a, T, D>,
8 pub(super) cur_index: usize,
9}
10
11impl<'a, T: Scalar + Copy, const D: usize> Clone for PointCloudIterator<'a, T, D> {
12 fn clone(&self) -> Self {
13 *self
14 }
15}
16
17impl<'a, T: Scalar + Copy, const D: usize> Iterator for PointCloudIterator<'a, T, D> {
18 type Item = &'a PointCloudPoint<T, D>;
19
20 fn next(&mut self) -> Option<Self::Item> {
21 let res = if self.cur_index >= self.target.masked_and_ordered_to_plain_index.len() {
22 None
23 } else {
24 let index = self.target.masked_and_ordered_to_plain_index[self.cur_index];
25 Some(&self.target.point_cloud[index])
26 };
27
28 self.cur_index += 1;
29 res
30 }
31}
32
33impl<'a, T: Scalar + Copy, const D: usize> ExactSizeIterator for PointCloudIterator<'a, T, D> {
34 fn len(&self) -> usize {
35 self.target.masked_and_ordered_to_plain_index.len()
36 }
37}