[Paraview] 3D point cloud with color

Pat Marion pat.marion at kitware.com
Tue Feb 21 15:00:14 EST 2012


Hi Giulio,

After applying Table to Points, you should have a dataset with R, G, and B
data arrays.  You could use the the Python Calculator filter with an
expression:  [R, G, B] to combine the three arrays into a single array, but
ParaView will only color points if the array type is unsigned char, and the
Python Calculator will output double.  Perhaps someone else can offer an
answer to that problem.

But, I have some existing numpy code that does a very similar thing, I have
modified it to fit your file format:

Given test.txt:

1.0 0.0 0.0 255 0.0 0.0
2.0 0.0 0.0 0.0 255 0.0
3.0 0.0 0.0 0.0 0.0 255


Apply the Programmable Source with the following python code:


inputFile = 'test.txt'

import numpy

data = numpy.genfromtxt(inputFile, delimiter=' ')
assert(data.shape[1] == 6)

numberOfPoints = data.shape[0]

points = vtk.vtkPoints()
points.SetNumberOfPoints(numberOfPoints)

colors = vtk.vtkUnsignedCharArray()
colors.SetName("RGB255")
colors.SetNumberOfComponents(3)
colors.SetNumberOfTuples(numberOfPoints)

for i in xrange(numberOfPoints):
    points.SetPoint(i, data[i][:3])
    colors.SetTuple(i, data[i][3:])

polyData = vtk.vtkPolyData()
polyData.SetPoints(points)
polyData.GetPointData().AddArray(colors)

mask = vtk.vtkMaskPoints()
mask.SetOnRatio(1)
mask.GenerateVerticesOn()
mask.SingleVertexPerCellOn()
mask.SetInput(polyData)
mask.Update()

self.GetOutput().ShallowCopy(mask.GetOutput())




If your colors are between 0.0 and 1.0, you'll have to edit the line

   colors.SetTuple(i, data[i][3:])

to convert to 0 to 255.


Pat

On Tue, Feb 21, 2012 at 1:44 PM, Giulio Reina <giulio.reina at unisalento.it>wrote:

> Hi,****
>
> ** **
>
> I have been working with 3D stereo reconstruction. So, I have huge 3d
> point clouds co-registered with color in this format [X Y Z R G B] (the
> first three vector columns specify the location of the single point and the
> last three one its color in RGB space). I have been trying to display the
> data in Paraview without success.****
>
> ** **
>
> I use the “table to points” filter to show the 3D coordinates but then I
> do not know  how to specify the color of each single point using its RGB
> components. Can you please help me out?****
>
> ** **
>
> Cheers,****
>
> ** **
>
> Giulio****
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20120221/70a653e6/attachment.htm>


More information about the ParaView mailing list