@@ -12,6 +12,8 @@ pub struct E57 {
1212 pub points : Py < PyArray < f64 , Ix2 > > ,
1313 #[ pyo3( get) ]
1414 pub color : Py < PyArray < f32 , Ix2 > > ,
15+ #[ pyo3( get) ]
16+ pub intensity : Py < PyArray < f32 , Ix2 > > ,
1517}
1618
1719/// Extracts the xml contents from an e57 file.
@@ -34,7 +36,7 @@ fn raw_xml(filepath: &str) -> PyResult<String> {
3436
3537/// Extracts the point data from an e57 file.
3638#[ pyfunction]
37- unsafe fn read_points < ' py > ( py : Python < ' py > , filepath : & str ) -> PyResult < E57 > {
39+ unsafe fn read_points ( py : Python < ' _ > , filepath : & str ) -> PyResult < E57 > {
3840 let file = E57Reader :: from_file ( filepath) ;
3941 let mut file = match file {
4042 Ok ( file) => file,
@@ -46,8 +48,9 @@ unsafe fn read_points<'py>(py: Python<'py>, filepath: &str) -> PyResult<E57> {
4648 } ;
4749 let pc = file. pointclouds ( ) ;
4850 let pc = pc. first ( ) . expect ( "files contain pointclouds" ) ;
51+ let mut point_vec = Vec :: with_capacity ( pc. records as usize * 3 ) ;
4952 let mut color_vec = Vec :: with_capacity ( pc. records as usize * 3 ) ;
50- let mut vec = Vec :: with_capacity ( pc. records as usize * 3 ) ;
53+ let mut intensity_vec = Vec :: with_capacity ( pc. records as usize ) ;
5154 let mut nrows = 0 ;
5255 for pointcloud in file. pointclouds ( ) {
5356 let mut iter = file
@@ -61,7 +64,7 @@ unsafe fn read_points<'py>(py: Python<'py>, filepath: &str) -> PyResult<E57> {
6164 for p in iter {
6265 let p = p. expect ( "Unable to read next point" ) ;
6366 if let CartesianCoordinate :: Valid { x, y, z } = p. cartesian {
64- vec . extend ( [ x, y, z] ) ;
67+ point_vec . extend ( [ x, y, z] ) ;
6568 nrows += 1
6669 }
6770 // if let Some(intensity) = p.intensity{
@@ -70,19 +73,26 @@ unsafe fn read_points<'py>(py: Python<'py>, filepath: &str) -> PyResult<E57> {
7073 if let Some ( color) = p. color {
7174 color_vec. extend ( [ color. red , color. green , color. blue ] )
7275 }
76+ if let Some ( intensity) = p. intensity {
77+ intensity_vec. push ( intensity)
78+ }
7379 }
7480 }
75- if color_vec. len ( ) == vec. len ( ) {
76- Ok ( E57 {
77- points : Py :: from ( PyArray :: from_vec ( py, vec) . reshape ( ( nrows, 3 ) ) . unwrap ( ) ) ,
78- color : Py :: from ( PyArray :: from_vec ( py, color_vec) . reshape ( ( nrows, 3 ) ) . unwrap ( ) ) ,
79- } )
80- } else {
81- Ok ( E57 {
82- points : Py :: from ( PyArray :: from_vec ( py, vec) . reshape ( ( nrows, 3 ) ) . unwrap ( ) ) ,
83- color : Py :: from ( PyArray :: new ( py, ( 0 , 3 ) , false ) ) ,
84- } )
81+ let n_points = point_vec. len ( ) / 3 ;
82+ let n_colors = color_vec. len ( ) / 3 ;
83+ let n_intensities = intensity_vec. len ( ) ;
84+ let mut e57 = E57 {
85+ points : Py :: from ( PyArray :: from_vec ( py, point_vec) . reshape ( ( nrows, 3 ) ) . unwrap ( ) ) ,
86+ color : Py :: from ( PyArray :: new ( py, ( 0 , 3 ) , false ) ) ,
87+ intensity : Py :: from ( PyArray :: new ( py, ( 0 , 1 ) , false ) ) ,
88+ } ;
89+ if n_colors == n_points {
90+ e57. color = Py :: from ( PyArray :: from_vec ( py, color_vec) . reshape ( ( nrows, 3 ) ) . unwrap ( ) )
91+ }
92+ if n_intensities == n_points {
93+ e57. intensity = Py :: from ( PyArray :: from_vec ( py, intensity_vec) . reshape ( ( nrows, 1 ) ) . unwrap ( ) )
8594 }
95+ Ok ( e57)
8696}
8797
8898/// e57 pointcloud file reading.
0 commit comments