Skip to content

Commit 5fe94d9

Browse files
committed
wip: try to read spherical coordinates
1 parent fefecac commit 5fe94d9

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fs::File;
22
use std::io::BufReader;
3-
use std::ops::AddAssign;
43

54
use ::e57::{E57Reader, Point};
65
use ndarray::{array, Array2, Ix2};
@@ -18,7 +17,7 @@ fn raw_xml(filepath: &str) -> PyResult<String> {
1817
Err(e) => {
1918
return Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(
2019
e.to_string(),
21-
))
20+
));
2221
}
2322
};
2423
let xml_string = String::from_utf8(xml.unwrap())?;
@@ -34,7 +33,7 @@ fn read_points<'py>(py: Python<'py>, filepath: &str) -> PyResult<&'py PyArray<f6
3433
Err(e) => {
3534
return Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(
3635
e.to_string(),
37-
))
36+
));
3837
}
3938
};
4039
let pc = file.pointclouds();
@@ -48,10 +47,28 @@ fn read_points<'py>(py: Python<'py>, filepath: &str) -> PyResult<&'py PyArray<f6
4847
let p = p.expect("Unable to read next point");
4948
let p = Point::from_values(p, &pc.prototype)
5049
.expect("failed to convert raw point to simple point");
50+
let mut row = arr.row_mut(i);
5151
if let Some(c) = p.cartesian {
52+
if let Some(invalid) = p.cartesian_invalid {
53+
if invalid != 0 {
54+
continue;
55+
}
56+
}
57+
5258
let coordinates = array![c.x, c.y, c.z];
53-
let mut row = arr.row_mut(i);
54-
row.add_assign(&coordinates);
59+
row.assign(&coordinates);
60+
} else if let Some(s) = p.spherical {
61+
if let Some(invalid) = p.spherical_invalid {
62+
if invalid != 0 {
63+
continue;
64+
}
65+
}
66+
let cos_ele = f64::cos(s.elevation);
67+
let x = s.range * cos_ele * f64::cos(s.azimuth);
68+
let y = s.range * cos_ele * f64::sin(s.azimuth);
69+
let z = s.range * f64::sin(s.elevation);
70+
let coordinates = array![x, y, z];
71+
row.assign(&coordinates);
5572
}
5673
}
5774

tests/test_e57.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import e57
12
import numpy as np
23
import pytest
34

4-
import e57
5-
65

76
def test_raw_xml():
87
raw_xml = e57.raw_xml(r"testdata/bunnyFloat.e57")
@@ -15,6 +14,13 @@ def test_read_points():
1514
assert len(pointcloud) == 30_571
1615

1716

17+
def test_read_points_spherical():
18+
pointcloud = e57.read_points(r"testdata/pipeSpherical.e57")
19+
assert isinstance(pointcloud, np.ndarray)
20+
assert len(pointcloud) == 1_220
21+
assert pointcloud[0][0] == pytest.approx(-0.32225147)
22+
23+
1824
def test_box_dimensions():
1925
pointcloud: np.ndarray = e57.read_points(r"testdata/bunnyFloat.e57")
2026
max_coords = pointcloud.max(0, None, False, -np.inf)

0 commit comments

Comments
 (0)