Skip to content

Commit

Permalink
chore: skip invalid point and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pnwatin committed Aug 16, 2023
1 parent 8cff01a commit f1a1ad1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 46 deletions.
50 changes: 26 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
{
Expand All @@ -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) => {
Expand All @@ -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);
});
Expand Down
23 changes: 1 addition & 22 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -48,27 +48,6 @@ pub fn get_rotations_and_translations(
(rotation, translation)
}

pub fn extract_coordinates(p: &e57::Point) -> Option<Point3<f64>> {
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 {
Expand Down

0 comments on commit f1a1ad1

Please sign in to comment.