[Paraview] I: 3D point cloud with color

Andrew Maclean andrew.amaclean at gmail.com
Mon Feb 27 18:32:42 EST 2012


There is a problem in your C++ code.
You need to do something like this (these are snippets from my code):
  vtkSmartPointer<vtkUnsignedCharArray> rgb =
vtkSmartPointer<vtkUnsignedCharArray>::New();
  rgb->SetNumberOfComponents(3); // red,green,blue
  rgb->SetName("color");

...
Fill the unsigned array with the rgb values.
...

Then do:
  p->GetPointData()->SetVectors(rgb);

Note the SetVectors(), what you are doing is just inserting normals
through   polydata->GetPointData()->SetNormals(normals);
and these are doubles not unsigned int.

Once this is done load up ParaView and the resulting vtp file. Hit
Apply and you should see the points in colour. Make sure you are using
the most recent version of ParaView.


I can also confirm that the python script I sent you (designed to be
used as a programmable filter) also works Ok.
Load the attached CSV file into ParaView.
Select the TableToPointsFilter and makew dure the X-,Y-,Z- columns
correspond to z,y,x.
Check "Keep All Data Arrays".
Hit Apply
Then select ProgrammableFilter
Make sure the Oputput Data Set Type is the Same as Input
and copy this code into it:
#-----------------------------------------------------------------------------------
# Copy colour as (r, g, b) into a single unsigned char array.
pdi = self.GetPolyDataInput()
pdo = self.GetPolyDataOutput()
pdo.SetPoints(pdi.GetPoints())
np = pdo.GetNumberOfPoints()
a = vtk.vtkUnsignedCharArray()
a.SetNumberOfComponents(3)
a.SetNumberOfTuples(np)
a.SetName("color")
r = pdi.GetPointData().GetArray("r")
g = pdi.GetPointData().GetArray("g")
b = pdi.GetPointData().GetArray("b")
for i in range(np):
	a.SetValue(i*3, r.GetValue(i))
	a.SetValue(i*3+1, g.GetValue(i))
	a.SetValue(i*3+2, b.GetValue(i))

pdo.GetPointData().AddArray(a)
#-----------------------------------------------------------------------------------
Hit Apply
In the Display Tab:
Uncheck Map Scalars
Select Color by color
And you should see two blue points and a red and a green point.

Andrew


On Mon, Feb 27, 2012 at 6:57 PM, Giulio Reina
<giulio.reina at unisalento.it> wrote:
> Hi all,
>
> Following  David's suggestion, I came up with the code attached that turns
> the starting data file (rgb.txt, of the type [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)) into a parsed vtp format. Unfortunately, when I
> try to open the VTP file in Paraview (after applying a Glyph filter) the
> results are not what I expect, i.e. one point red, one point green, two
> points blue.
>
> I would greatly appreciate if someone could help me put reading correctly
> the VTP file, I should admit that I'm not very familiar with the use of vtp
> files in Paraview,
>
> Cheers
>
> Giulio
>
>
>
>
> -----Messaggio originale-----
> Da: David Doria [mailto:daviddoria at gmail.com]
> Inviato: giovedì 23 febbraio 2012 02:48
> A: giulio.reina at unisalento.it
> Cc: paraview at paraview.org
> Oggetto: Re: [Paraview] 3D point cloud with color
>
>>> 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?
>
> If you're more comfortable in c++ you could use VTK to parse the file,
> construct a polydata, and then write a vtp file. Here are the examples you'd
> need:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/InfoVis/ReadDelimitedFile
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/WriteVTP
>
> Then Paraview can easily read this vtp file.
>
> David



-- 
___________________________________________
Andrew J. P. Maclean

___________________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rgb.csv
Type: text/csv
Size: 111 bytes
Desc: not available
URL: <http://www.paraview.org/pipermail/paraview/attachments/20120228/20d2f40a/attachment.csv>


More information about the ParaView mailing list