@@ -2,8 +2,8 @@ use std::fs::File;
22use std:: io:: BufReader ;
33
44use :: e57:: { E57Reader , Point } ;
5- use ndarray:: { array , Array2 , Ix2 } ;
6- use numpy:: { IntoPyArray , PyArray } ;
5+ use ndarray:: Ix2 ;
6+ use numpy:: PyArray ;
77use pyo3:: prelude:: * ;
88
99/// Extracts the xml contents from an e57 file.
@@ -38,25 +38,22 @@ fn read_points<'py>(py: Python<'py>, filepath: &str) -> PyResult<&'py PyArray<f6
3838 } ;
3939 let pc = file. pointclouds ( ) ;
4040 let pc = pc. first ( ) . expect ( "files contain pointclouds" ) ;
41- let mut arr = Array2 :: zeros ( ( pc. records as usize , 3 ) ) ;
42-
41+ let mut vec = Vec :: new ( ) ;
4342 let iter = file
4443 . pointcloud ( pc)
4544 . expect ( "this file contains a pointcloud" ) ;
46- for ( i , p ) in iter. enumerate ( ) {
45+ for p in iter {
4746 let p = p. expect ( "Unable to read next point" ) ;
4847 let p = Point :: from_values ( p, & pc. prototype )
4948 . expect ( "failed to convert raw point to simple point" ) ;
50- let mut row = arr. row_mut ( i) ;
5149 if let Some ( c) = p. cartesian {
5250 if let Some ( invalid) = p. cartesian_invalid {
53- if invalid != 0 {
51+ if invalid != 0 {
5452 continue ;
5553 }
56- }
54+ }
5755
58- let coordinates = array ! [ c. x, c. y, c. z] ;
59- row. assign ( & coordinates) ;
56+ vec. push ( vec ! [ c. x, c. y, c. z] ) ;
6057 } else if let Some ( s) = p. spherical {
6158 if let Some ( invalid) = p. spherical_invalid {
6259 if invalid != 0 {
@@ -67,12 +64,11 @@ fn read_points<'py>(py: Python<'py>, filepath: &str) -> PyResult<&'py PyArray<f6
6764 let x = s. range * cos_ele * f64:: cos ( s. azimuth ) ;
6865 let y = s. range * cos_ele * f64:: sin ( s. azimuth ) ;
6966 let z = s. range * f64:: sin ( s. elevation ) ;
70- let coordinates = array ! [ x, y, z] ;
71- row. assign ( & coordinates) ;
67+ vec. push ( vec ! [ x, y, z] ) ;
7268 }
7369 }
74-
75- Ok ( arr . into_pyarray ( py ) )
70+ let pyarray = PyArray :: from_vec2 ( py , & vec ) . unwrap ( ) ;
71+ Ok ( pyarray )
7672}
7773
7874/// e57 pointcloud file reading.
0 commit comments