[vtkusers] Point rendering : how to filter values with a vtkLookupTable
Malcolm Drummond
malcolm at geovision.co.za
Thu Feb 5 03:46:32 EST 2004
Hi David, Aurélien
I find that I have to set the actors opacity to something less than 1 for
the scalar opacity values to have any effect, see following script ... not
sure if this is just because I'm colouring direct with unsigned char. Works
with both mappers.
# begin ------------------
package require vtk
# Create the RenderWindow, Renderer and RenderWindowInteractor
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
# create a 2*2 cell/3*3 pt structuredgrid
vtkPoints points
points InsertNextPoint -1 1 0
points InsertNextPoint 0 1 0
points InsertNextPoint 1 1 0
points InsertNextPoint -1 0 0
points InsertNextPoint 0 0 0
points InsertNextPoint 1 0 0
points InsertNextPoint -1 -1 0
points InsertNextPoint 0 -1 0
points InsertNextPoint 1 -1 0
vtkUnsignedCharArray faceColors
faceColors SetNumberOfComponents 4
faceColors SetNumberOfTuples 4
faceColors SetComponent 0 0 0
faceColors SetComponent 0 1 255
faceColors SetComponent 0 2 0
faceColors SetComponent 0 3 255
faceColors SetComponent 1 0 0
faceColors SetComponent 1 1 255
faceColors SetComponent 1 2 0
faceColors SetComponent 1 3 175
faceColors SetComponent 2 0 0
faceColors SetComponent 2 1 255
faceColors SetComponent 2 2 0
faceColors SetComponent 2 3 100
faceColors SetComponent 3 0 0
faceColors SetComponent 3 1 255
faceColors SetComponent 3 2 0
faceColors SetComponent 3 3 25
vtkStructuredGrid sgrid
sgrid SetDimensions 3 3 1
sgrid SetPoints points
[sgrid GetCellData] SetScalars faceColors
faceColors Modified
vtkStructuredGridGeometryFilter sggf
sggf SetInput sgrid
vtkPolyDataMapper spdm
spdm SetInput [sggf GetOutput]
vtkDataSetMapper mapper
mapper SetInput sgrid
#mapper SetScalarModeToUseCellData
vtkActor actor
actor SetMapper mapper
#actor SetMapper mapper spdm
[actor GetProperty] SetOpacity 0.999
vtkCylinderSource cyl
cyl SetResolution 10
vtkPolyDataMapper pdm
pdm SetInput [cyl GetOutput]
vtkActor cylinder
cylinder SetMapper pdm
[cylinder GetProperty] SetColor 0 0 1
# Add the actors to the renderer, set the background and size
ren1 AddActor actor
ren1 AddActor cylinder
ren1 SetBackground 1 1 1
renWin SetSize 256 256
# render the image
#iren SetUserMethod {wm deiconify .vtkInteract}
iren Initialize
wm withdraw .
# end -----------------
Regards
Malcolm
----- Original Message -----
From: <David.Pont at ForestResearch.co.nz>
To: "REGAT-BARREL Aurélien" <arbvtk at yahoo.fr>
Cc: "VTK" <vtkusers at vtk.org>; <vtkusers-admin at vtk.org>
Sent: Thursday, February 05, 2004 5:35 AM
Subject: Re: [vtkusers] Point rendering : how to filter values with a
vtkLookupTable
Hi Aurélien,
could you try creating a separate lookuptable as in my example rather
than mapper->GetLookupTable ? and make sure to call SetRange (etc) before
Build?
Otherwise it might be due to a difference between vtkDataSetMapper and
vtkPolyDataMapper?
regards
Dave P
REGAT-BARREL
Aurélien To:
David.Pont at forestresearch.co.nz
<arbvtk at yahoo.fr> cc: VTK
<vtkusers at vtk.org>, vtkusers-admin at vtk.org
Sent by: Subject: Re: [vtkusers]
Point rendering : how to filter values
vtkusers-admin at vt with a vtkLookupTable
k.org
05/02/2004 12:45
Hello David,
I had tried your solution but I failed to use it. I don't understand why it
doesn't work :
mapper = vtkDataSetMapper()
mapper.SetInput( cloud )
mapper.SetScalarRange( cloud.GetScalarRange() )
lut = mapper.GetLookupTable()
lut.Build()
lut.SetTableValue( 0, 0, 0, 0, 0 )
Black points are still visible... :-(
Do you have a simple example of a vtkStructuredPoints or vtkStructuredGrid
build by hand on wich you can choose each point value color. Here is my
Python code that doesn't work :
from vtk import *
def main():
math = vtkMath()
# 20x10x10 points
nx = 20
ny = 10
nz = 10
scalars = vtkUnsignedCharArray()
for z in range(0, nz):
for y in range(0, ny):
for x in range(0, nx):
if x < 5:
scalars.InsertNextTuple1( 0 )
else:
scalars.InsertNextTuple1( math.Random( 0, 255 ) + 1 )
cloud = vtkStructuredPoints()
cloud.SetDimensions( nx, ny, nz )
cloud.SetOrigin( 0, 0, 0 )
cloud.SetSpacing( 1, 1, 1 )
cloud.GetPointData().SetScalars( scalars )
mapper = vtkDataSetMapper()
mapper.SetInput( cloud )
mapper.SetScalarRange( cloud.GetScalarRange() )
lut = mapper.GetLookupTable()
lut.Build()
lut.SetTableValue( 0, 0, 0, 0, 0 )
actor = vtkActor()
actor.SetMapper( mapper )
ren = vtkRenderer()
ren.AddActor( actor )
ren.SetBackground( 1, 1, 1 )
renWin = vtkRenderWindow()
renWin.AddRenderer( ren )
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow( renWin )
renWin.SetSize( 500, 500 )
renWin.Render()
iren.Start()
if __name__ == '__main__':
main()
I don't understand what is wrong.
Thanks for your help.
David.Pont at ForestResearch.co.nz wrote:
Hi Aurélien,
The code fragment below constructs a greyscale lookuptable with 5
colors. After the call to Build one color is changed so that alpha is 0.
Data values mapped into this color in the lookuptable will be transparent.
vtkLookupTable *lut1 = vtkLookupTable::New();
lut1->SetRange( 0, 0.5 );
lut1->SetNumberOfColors( 5 );
lut1->SetHueRange( 0, 0 );
lut1->SetSaturationRange( 0, 0 );
lut1->SetValueRange( 0, 1 );
lut1->Build();
lut1->SetTableValue( 1, 0, 0, 0, 0 ); // make one band
disappear, note: rgb values not important
vtkPolyDataMapper *pdm1 = vtkPolyDataMapper::New();
pdm1->SetInput( clpd1->GetOutput() );
pdm1->SetScalarRange( 0, 0.5 );
pdm1->SetLookupTable( lut1 );
pdm1->ScalarVisibilityOn();
You should be able to use appropriate values for SetRange,
SetNumberOfColors, SetTableValue and SetScalarRange to hide parts of your
dataset. This worked for me on polydata surfaces, I am not sure about
rendering points, but I would expect it to work.
bon chance
Dave Pont
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
Créez votre Yahoo! Mail
_______________________________________________
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