[vtkusers] vtkLookupTable with vtkStructuredPoints or vtkStructuredGrid : How it works ???
REGAT-BARREL Aurélien
arbvtk at yahoo.fr
Wed Feb 4 19:07:36 EST 2004
Hello everybody,
I am still trying to blank zero-value points in my vtkStrcuturedPoints. I have done it via a vtkThreshold filter but it generate a new DataSet and it is very slow.
So I have tried to change black points opacity in the lookuptable build by the mapper but it fails.
Here is the interesting code :
mapper = vtkDataSetMapper()
mapper.SetInput( cloud )
mapper.SetScalarRange( cloud.GetScalarRange() )
lut = mapper.GetLookupTable()
lut.Build()
lut.SetTableValue( 0, 0, 0, 0, 0 )
It does nothing, why ?
I thought that it was a limitation of vtkStructuredGrid (because a point is used to render more than one cell, see the 2 screenshots to see what I mean) and I changed my code to use a vtkStructuredGrid. It is the same thing... Why ?
Python examples :
vtkStructuredPoints (first screenshot)
from vtk import *
def main():
math = vtkMath()
# 20x10x10 points
nx = 20
ny = 10
nz = 10
# create the cloud of 20x10x10 points
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 )
# create mapper + change black points opacity
mapper = vtkDataSetMapper()
mapper.SetInput( cloud )
mapper.SetScalarRange( cloud.GetScalarRange() )
lut = mapper.GetLookupTable()
lut.Build()
lut.SetTableValue( 0, 0, 0, 0, 0 )
# render it
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()
vtkStructuredGrid (second screenshot)
from vtk import *
def main():
math = vtkMath()
# 20x10x10 points
nx = 20
ny = 10
nz = 10
# create the cloud of 20x10x10 points
points = vtkPoints()
for z in range(0, nz+1):
for y in range(0, ny+1):
for x in range(0, nx+1):
points.InsertNextPoint( x, y, z )
cloud = vtkStructuredGrid()
cloud.SetDimensions( nx + 1, ny + 1, nz + 1 )
cloud.SetPoints( points )
values = vtkUnsignedCharArray()
for z in range(0, nz):
for y in range(0, ny):
for x in range(0, nx):
if x < 5:
values.InsertNextValue( 0 )
else:
values.InsertNextValue( math.Random( 0, 255 ) )
cloud.GetCellData().SetScalars( values );
# create mapper + change black points opacity
mapper = vtkDataSetMapper()
mapper.SetInput( cloud )
mapper.SetScalarRange( cloud.GetScalarRange() )
lut = mapper.GetLookupTable()
lut.Build()
lut.SetTableValue( 0, 0, 0, 0, 0 )
# render it
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()
Thanks for your help.
Aurélien REGAT-BARREL
---------------------------------
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
Créez votre Yahoo! Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040205/8dad543f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: points.jpg
Type: image/pjpeg
Size: 19094 bytes
Desc: points.jpg
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040205/8dad543f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: grid.jpg
Type: image/pjpeg
Size: 20476 bytes
Desc: grid.jpg
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040205/8dad543f/attachment-0001.bin>
More information about the vtkusers
mailing list