11use std:: fs:: File ;
22use std:: io:: BufReader ;
3- use std:: ops:: AddAssign ;
43
54use :: e57:: { E57Reader , Point } ;
65use 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
0 commit comments