Skip to content

Commit

Permalink
chore: bump to e57 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pnwatin committed Aug 16, 2023
1 parent 1d14a99 commit 8cff01a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 62 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.72"
clap = { version = "4.3.21", features = ["derive"] }
e57 = "0.5.1"
e57 = "0.6.0"
indicatif = { version = "0.17.6", features = ["rayon"] }
las = "0.8.1"
nalgebra = "0.32.3"
Expand Down
8 changes: 4 additions & 4 deletions src/extended_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub struct ExtendedPoint {

impl From<OriginalPoint> for ExtendedPoint {
fn from(point: OriginalPoint) -> Self {
let rgb_color = if let (Some(col), None) = (&point.color, point.color_invalid) {
let rgb_color = if point.color_invalid == 0 {
las::Color {
red: to_u16(col.red),
green: to_u16(col.green),
blue: to_u16(col.blue),
red: to_u16(point.color.red),
green: to_u16(point.color.green),
blue: to_u16(point.color.blue),
}
} else {
las::Color::default()
Expand Down
24 changes: 9 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ fn main() -> Result<()> {
}
};

let transform = get_transform(&pointcloud);
let transform = pointcloud
.clone()
.transform
.unwrap_or(e57::Transform::default());
let (rotation, translation) = get_rotations_and_translations(&transform);

let mut builder = las::Builder::from((1, 4));
Expand Down Expand Up @@ -111,7 +114,7 @@ fn main() -> Result<()> {
};

let iter = match e57_reader
.pointcloud(&pointcloud)
.pointcloud_simple(&pointcloud)
.context("Unable to get point cloud iterator")
{
Ok(i) => i,
Expand All @@ -126,27 +129,18 @@ fn main() -> Result<()> {
let data: Vec<_> = iter.collect();

data.par_iter().for_each(|p| {
let value = match p {
Ok(value) => value,
Err(e) => {
eprintln!("Error encountered: {}", e);
return ();
}
};
let p = match e57::Point::from_values(value.clone(), &pointcloud.prototype)
.context("Failed to convert raw point to simple point")
{
let point = match p {
Ok(p) => p,
Err(e) => {
eprintln!("Error encountered: {}", e);
return ();
}
};

if let Some(xyz) = extract_coordinates(&p) {
if let Some(xyz) = extract_coordinates(&point) {
let xyz = rotation.transform_point(&xyz) + translation;
let las_rgb = ExtendedPoint::from(p.clone()).rgb_color;
let las_intensity = get_intensity(p.intensity, p.intensity_invalid);
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,
Expand Down
60 changes: 20 additions & 40 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ pub fn construct_las_path(input_path: &str, output_path: &str, index: usize) ->
Ok(las_path)
}

pub fn get_transform(pointcloud: &e57::PointCloud) -> e57::Transform {
pointcloud.transform.clone().unwrap_or(e57::Transform {
rotation: e57::Quaternion {
w: 1.0,
x: 0.0,
y: 0.0,
z: 0.0,
},
translation: e57::Translation {
x: 0.0,
y: 0.0,
z: 0.0,
},
})
}

pub fn get_rotations_and_translations(
transform: &e57::Transform,
) -> (UnitQuaternion<f64>, Vector3<f64>) {
Expand All @@ -65,35 +49,31 @@ pub fn get_rotations_and_translations(
}

pub fn extract_coordinates(p: &e57::Point) -> Option<Point3<f64>> {
if let Some(ref c) = p.cartesian {
if let Some(invalid) = p.cartesian_invalid {
if invalid != 0 {
return None;
}
}
Some(Point3::new(c.x, c.y, c.z))
} else if let Some(ref s) = p.spherical {
if let Some(invalid) = p.spherical_invalid {
if invalid != 0 {
return None;
}
}
let cos_ele = f64::cos(s.elevation);
Some(Point3::new(
s.range * cos_ele * f64::cos(s.azimuth),
s.range * cos_ele * f64::sin(s.azimuth),
s.range * f64::sin(s.elevation),
))
} else {
None
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: Option<f32>, intensity_invalid: Option<u8>) -> u16 {
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.unwrap_or(0) == 1 {
if intensity_invalid == 1 {
return 0;
}

return (intensity.unwrap_or(0.0).clamp(0.0, 1.0) * 65535.0) as u16;
return (intensity.clamp(0.0, 1.0) * 65535.0) as u16;
}

0 comments on commit 8cff01a

Please sign in to comment.