Skip to content

Commit 56c9e31

Browse files
committed
feature: Add pointcloud reading.
1 parent 4d0e411 commit 56c9e31

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/lib.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ fn raw_xml(filepath: &str) -> PyResult<String> {
1515
let xml = E57Reader::raw_xml(reader);
1616
let xml = match &xml {
1717
Ok(_) => xml,
18-
Err(e) => return Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string())),
18+
Err(e) => {
19+
return Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(
20+
e.to_string(),
21+
))
22+
}
1923
};
2024
let xml_string = String::from_utf8(xml.unwrap())?;
2125
Ok(xml_string)
@@ -27,29 +31,30 @@ fn read_points<'py>(py: Python<'py>, filepath: &str) -> PyResult<&'py PyArray<f6
2731
let file = E57Reader::from_file(filepath);
2832
let mut file = match file {
2933
Ok(file) => file,
30-
Err(e) => return Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string())),
34+
Err(e) => {
35+
return Err(PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(
36+
e.to_string(),
37+
))
38+
}
3139
};
32-
let pc = file
33-
.pointclouds();
34-
let pc = pc
35-
.first()
36-
.expect("files contain pointclouds");
37-
let mut arr = Array2::zeros((pc.records as usize, 3 ));
40+
let pc = file.pointclouds();
41+
let pc = pc.first().expect("files contain pointclouds");
42+
let mut arr = Array2::zeros((pc.records as usize, 3));
3843

3944
let iter = file
4045
.pointcloud(pc)
4146
.expect("this file contains a pointcloud");
4247
for (i, p) in iter.enumerate() {
4348
let p = p.expect("Unable to read next point");
44-
let p = Point::from_values(p, &pc.prototype).expect("failed to convert raw point to simple point");
49+
let p = Point::from_values(p, &pc.prototype)
50+
.expect("failed to convert raw point to simple point");
4551
if let Some(c) = p.cartesian {
4652
let coordinates = array![c.x, c.y, c.z];
4753
let mut row = arr.row_mut(i);
4854
row.add_assign(&coordinates);
4955
}
5056
}
5157

52-
5358
Ok(arr.into_pyarray(py))
5459
}
5560

0 commit comments

Comments
 (0)