[vtkusers] How to color objects with RGB/HSV information?

Immo Trinks trinks at esc.cam.ac.uk
Mon Jun 21 11:20:17 EDT 2004


Hi Julien,

thank you very much! Dropping the glyphing did the trick.
The following tcl script does the job for the data file given below.
For some reason it won't plot the points if I don't define the polygon.

For my application I am plotting 861529 points obtained from a 3D laser 
scanner of a cliff face for geological studies.
Currently I just include a dummy Polygon since I haven't got a proper surface 
grid.
Have a look at 
http://bullard.esc.cam.ac.uk~/trinks/beach.jpg
if you would like to see a screenshot.
Thanks again!

Immo


##########################################
# load the necessary VTK libraries.
package require vtk
package require vtkinteraction
package require vtktesting

vtkPolyDataReader reader
reader SetFileName "test.vtk"

vtkPolyDataMapper mapper
mapper SetInput [reader GetOutput]
mapper SelectColorArray "colour"

vtkActor Points
Points SetMapper mapper
Points SetScale 1 1 1
[Points GetProperty] SetPointSize  10
Points SetPosition 0 0 0
Points SetScale 1 1 1
[Points GetProperty] SetOpacity 1
[Points GetProperty] SetColor 1 1 1
mapper SetScalarMode 3
[Points GetProperty] SetRepresentationToPoints

vtkRenderer ren1
ren1 AddActor2D Points
ren1 SetBackground 1 1 1

vtkRenderWindow renWin 
renWin AddRenderer ren1
renWin SetSize 700 700

vtkRenderWindowInteractor iren 
iren SetRenderWindow renWin 

vtkCamera cam1
cam1 Elevation 90
cam1 SetFocalPoint -15.48  16.44  -0.50
cam1 SetViewUp 0 0 1
cam1 SetPosition -20 20 0
ren1 SetActiveCamera cam1
ren1 ResetCamera

iren Initialize 
########################################

Test-file "test.vtk" with 4 points:

# vtk DataFile Version 3.0
####
ASCII
DATASET POLYDATA

POINTS 4 float
 0.0  0.0  0.0
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  1.0  1.0

POLYGONS 1 5
4 0 1 2 3

POINT_DATA 4
VECTORS colour unsigned_char
 255  0  0
 0  255  0
 0   0 255
 255   0 255



###############################################################



On Monday 21 Jun 2004 09:21, you wrote:
> Hi Immo,
>
> I've never done VTK scripting so I can't tell...
> Just an hint: try to load with a script the file I sent you with the
> coloured triangle.
> For a first step, try not to use the glyph filter because it may not be
> setting correctly the default scalar value to use.
> The code looks pretty correct however, you are probably very close to your
> goal.
>
> Sth like this (not tested):
>
> package require vtk
> package require vtkinteraction
>
> vtkPolyDataReader reader
> reader SetFileName "triangle.vtk"
>
> vtkPolyDataMapper mapper
> mapper SetInput [reader GetOutput]
>
> vtkActor actor
> actor SetMapper mapper
>
> # create a window to render into
> vtkRenderWindow renWin
> vtkRenderer ren1
> renWin AddRenderer ren1
>
> # create an interactor
> vtkRenderWindowInteractor iren
> iren SetRenderWindow renWin
>
> # add the sphere
> ren1 AddActor actor
>
> # Render an image; since no lights/cameras specified, created automatically
> renWin Render
>
>
> -- Julien
>
>
> -----Message d'origine-----
> De : Immo Trinks [mailto:trinks at esc.cam.ac.uk]
> Envoyé : vendredi 18 juin 2004 18:06
> À : vtkusers at vtk.org
> Cc : ALIZIER Julien AUSY; vtkusers at public.kitware.com
> Objet : Re: [vtkusers] How to color objects with RGB/HSV information?
>
>
> Thank you very much Julien.
> Yes, this example data works with ParaView.
> I am just not seeing how to achieve the same result with a script.
> I use the Tcl script below and wonder what I am missing.
> Any suggestions?
> Immo
>
>
> vtkPolyDataReader reader
> reader SetFileName "data.vtk"
> reader SetVectorsName "colour"
>
> vtkSphereSource ball
> ball SetRadius 0.1
>
> vtkGlyph3D glyph
> glyph SetInput [reader GetOutput]
> glyph SetSource [ball GetOutput]
>
> vtkPolyDataMapper mapper
> mapper SetInput [glyph GetOutput]
> mapper SetColorModeToDefault
> mapper SetScalarModeToUsePointFieldData
>
> vtkActor points
> points SetMapper mapper
>
> On Friday 18 Jun 2004 11:55, ALIZIER Julien AUSY wrote:
> > Hi again,
> >
> > This file works in ParaView :
> >
> > <begin>
> > # vtk DataFile Version 3.0
> > ####
> > ASCII
> > DATASET POLYDATA
> >
> > POINTS 3 float
> >  0.0  0.0  0.0
> >  1.0  0.0  0.0
> >  0.0  1.0  0.0
> >
> > POLYGONS 1 4
> > 3 0 1 2
> >
> > POINT_DATA 3
> > VECTORS colour unsigned_char
> >  255  0  0
> >  0  255  0
> >  0    0 255
> > <end>
> >
> > -- Julien
> >
> >
> >
> > -----Message d'origine-----
> > De : Immo Trinks [mailto:trinks at esc.cam.ac.uk]
> > Envoyé : jeudi 17 juin 2004 23:28
> > À : vtkusers at public.kitware.com
> > Objet : [vtkusers] How to color objects with RGB/HSV information?
> >
> >
> > Dear vtkUsers and vtkDeveloppers
> >
> > Could you please help me with the following problem:
> > I have a polydata set with xyz points and RGB vectors assigned to the
> > points
> >
> > (see example below).
> > How can I color the pixels using RGB or HSV information?
> > Searching the archives and reading the book I haven't found any example
> > explaining the assignment of three color values to an object via a lookup
> > table.
> > I know how to color objects with one scalar value for each object.
> > But I do not understand how to assign color to objects using three RGB or
> > HSV
> > values.
> > Is it correct to load the RGB information as vector or shall I use
>
> scalars?
>
> > I could as well provide HSV values instead of RGB if this would make the
> > process easier.
> > Thank you very much for any help!
> >
> > Immo
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at:
> > <http://public.kitware.com/cgi-bin/vtkfaq> Follow this link to
> > subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list