From f1a1ad1f5de45cfb4113eb29e4f1125b48e51e97 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 16 Aug 2023 19:17:04 +0200 Subject: [PATCH] chore: skip invalid point and refactor --- src/main.rs | 50 ++++++++++++++++++++++++++------------------------ src/utils.rs | 23 +---------------------- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/src/main.rs b/src/main.rs index d9050fa..4ce8176 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use e57::E57Reader; use extended_point::ExtendedPoint; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; use las::Write; +use nalgebra::Point3; use rayon::prelude::*; use std::sync::Mutex; use uuid::Uuid; @@ -113,7 +114,7 @@ fn main() -> Result<()> { } }; - let iter = match e57_reader + let mut pointcloud_reader = match e57_reader .pointcloud_simple(&pointcloud) .context("Unable to get point cloud iterator") { @@ -123,12 +124,11 @@ fn main() -> Result<()> { return (); } }; + pointcloud_reader.skip_invalid(true); println!("Saving pointcloud {} ...", index); - let data: Vec<_> = iter.collect(); - - data.par_iter().for_each(|p| { + pointcloud_reader.for_each(|p| { let point = match p { Ok(p) => p, Err(e) => { @@ -137,26 +137,28 @@ fn main() -> Result<()> { } }; - if let Some(xyz) = extract_coordinates(&point) { - let xyz = rotation.transform_point(&xyz) + translation; - let las_rgb = ExtendedPoint::from(point.clone()).rgb_color; - let las_intensity = get_intensity(point.intensity, point.intensity_invalid); - - let las_point = las::Point { - x: xyz.x, - y: xyz.y, - z: xyz.z, - intensity: las_intensity, - color: Some(las_rgb), - ..Default::default() - }; - - let mut writer_guard = writer.lock().unwrap(); - match writer_guard.write(las_point) { - Ok(_) => (), - Err(_e) => return, - }; - } + let xyz = rotation.transform_point(&Point3::new( + point.cartesian.x, + point.cartesian.y, + point.cartesian.z, + )) + translation; + let las_rgb = ExtendedPoint::from(point.clone()).rgb_color; + let las_intensity = get_intensity(point.intensity, point.intensity_invalid); + + let las_point = las::Point { + x: xyz.x, + y: xyz.y, + z: xyz.z, + intensity: las_intensity, + color: Some(las_rgb), + ..Default::default() + }; + + let mut writer_guard = writer.lock().unwrap(); + match writer_guard.write(las_point) { + Ok(_) => (), + Err(_e) => return, + }; progress_bar.inc(1); }); diff --git a/src/utils.rs b/src/utils.rs index 3b563a4..38f15c5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Result}; -use nalgebra::{Point3, Quaternion, UnitQuaternion, Vector3}; +use nalgebra::{Quaternion, UnitQuaternion, Vector3}; use std::path::{Path, PathBuf}; pub fn to_u16(value: f32) -> u16 { @@ -48,27 +48,6 @@ pub fn get_rotations_and_translations( (rotation, translation) } -pub fn extract_coordinates(p: &e57::Point) -> Option> { - if p.cartesian_invalid == 2 && p.spherical_invalid == 2 { - return None; - } - - if p.cartesian_invalid == 0 { - return Some(Point3::new(p.cartesian.x, p.cartesian.y, p.cartesian.z)); - } - - if p.spherical_invalid == 0 { - let cos_ele = f64::cos(p.spherical.elevation); - return Some(Point3::new( - p.spherical.range * cos_ele * f64::cos(p.spherical.azimuth), - p.spherical.range * cos_ele * f64::sin(p.spherical.azimuth), - p.spherical.range * f64::sin(p.spherical.elevation), - )); - } - - return None; -} - pub fn get_intensity(intensity: f32, intensity_invalid: u8) -> u16 { // A value of zero means the intensity is valid, 1 means invalid. if intensity_invalid == 1 {