[Paraview-developers] Reader for point cloud stored on custom binary file
Ellon Paiva
ellonpaiva at gmail.com
Fri Apr 22 11:10:54 EDT 2016
Jean,
I tried your code and I got the following error:
Traceback (most recent call last):
File "<string>", line 19, in <module>
File "<string>", line 18, in RequestData
AttributeError: can't set attribute
Here's my source code:
from struct import unpack_from
from os import stat
import numpy as np
def load_velodyne_points(filename):
num_points = stat(filename).st_size/16
points = np.zeros((4, num_points))
with open(filename, "rb") as f:
# Read all points, convert to floats and assign to
# a column-wise flat view of points
points.T.flat[:] = unpack_from('f'*num_points, f.read())
return points
filename = "worked.bin"
points = load_velodyne_points(filename)
N = points.shape[1]
output.Points = points[0:3,].reshape(N, 3)
output.PointData.append(points[3,], "reflectance")
Which version of paraview are you using? I'm using the 4.0.1 64bit
installed from apt-get on Ubuntu 14.04.4 LTS.
Ellon
On 04/22/2016 04:15 PM, Favre Jean wrote:
>
> my suggestion would be to use some more numpy-oriented features. Your
> "points" array is already a numpy array, you can feed it to the
> vtkPolyData with a simple reshaping. Same for your reflectance array.
> No need for a for-loop
>
> I'd replace your code with this:
>
> filename = "worked.bin"
>
> points = load_velodyne_points(filename)
> N=points.shape[1]
> # use "output" as the pre-defined vtkPolyData object
> output.Points = points[0:3,].reshape(N, 3)
> output.PointData.append(points[3,], "reflectance")
>
> I usually skip building up cells, because I use a PointGaussian
> representation mode. But your needs might differ. Anyway, with the
> changes above, I can read all 3 files without any problem.
>
> -----------------
> Jean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview-developers/attachments/20160422/3c00e98e/attachment-0001.html>
More information about the Paraview-developers
mailing list