[vtkusers] Point rendering : how to filter values with a vtkLookupTable

REGAT-BARREL Aurélien arbvtk at yahoo.fr
Thu Feb 5 05:17:04 EST 2004


Hello,
I tested your script without changing the opacity to 0.999 and it worked.
I have modified it inr order to get a 3x3x3 grid => 4x2 cells with 1 transparent. It work but it is not the cell but its faces that are invisible (see the screenshot).
It works only with the vtkDataSetMapper, there is noting with vtkPolyDataMapper.
My Python code :
 
from vtk import *
def main():
    # Create the RenderWindow, Renderer and RenderWindowInteractor
    ren1 = vtkRenderer()
    renWin = vtkRenderWindow()
    renWin.AddRenderer( ren1 )
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow( renWin )
    
    # create a 2*2 cell/3*3 pt structuredgrid
    points = vtkPoints()
    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 )
    points.InsertNextPoint( -1, 1, 1 )
    points.InsertNextPoint( 0, 1, 1 )
    points.InsertNextPoint(  1,  1,  1 )
    points.InsertNextPoint( -1,  0,  1 )
    points.InsertNextPoint(  0,  0,  1 )
    points.InsertNextPoint(  1,  0,  1 )
    points.InsertNextPoint( -1, -1,  1 )
    points.InsertNextPoint(  0, -1,  1 )
    points.InsertNextPoint(  1, -1,  1 )
    points.InsertNextPoint( -1, 1, 2 )
    points.InsertNextPoint( 0, 1, 2 )
    points.InsertNextPoint(  1,  1,  2 )
    points.InsertNextPoint( -1,  0,  2 )
    points.InsertNextPoint(  0,  0,  2 )
    points.InsertNextPoint(  1,  0,  2 )
    points.InsertNextPoint( -1, -1,  2 )
    points.InsertNextPoint(  0, -1,  2 )
    points.InsertNextPoint(  1, -1,  2 )
    faceColors = vtkUnsignedCharArray()
    faceColors.SetNumberOfComponents( 4 )
    faceColors.SetNumberOfTuples( 8 )
    faceColors.SetComponent( 0, 0, 0 )
    faceColors.SetComponent( 0, 1, 0 )
    faceColors.SetComponent( 0, 2, 0 )
    faceColors.SetComponent( 0, 3, 0 )
    faceColors.SetComponent( 1, 0, 32 )
    faceColors.SetComponent( 1, 1, 32 )
    faceColors.SetComponent( 1, 2, 32 )
    faceColors.SetComponent( 1, 3, 255 )
    faceColors.SetComponent( 2, 0, 64 )
    faceColors.SetComponent( 2, 1, 64 )
    faceColors.SetComponent( 2, 2, 64 )
    faceColors.SetComponent( 2, 3, 255 )
    faceColors.SetComponent( 3, 0, 96 )
    faceColors.SetComponent( 3, 1, 96 )
    faceColors.SetComponent( 3, 2, 96 )
    faceColors.SetComponent( 3, 3, 255 )
    faceColors.SetComponent( 4, 0, 128 )
    faceColors.SetComponent( 4, 1, 128 )
    faceColors.SetComponent( 4, 2, 128 )
    faceColors.SetComponent( 4, 3, 255 )
    faceColors.SetComponent( 5, 0, 160 )
    faceColors.SetComponent( 5, 1, 160 )
    faceColors.SetComponent( 5, 2, 160 )
    faceColors.SetComponent( 5, 3, 255 )
    faceColors.SetComponent( 6, 0, 192 )
    faceColors.SetComponent( 6, 1, 192 )
    faceColors.SetComponent( 6, 2, 192 )
    faceColors.SetComponent( 6, 3, 255 )
    faceColors.SetComponent( 7, 0, 224 )
    faceColors.SetComponent( 7, 1, 224 )
    faceColors.SetComponent( 7, 2, 224 )
    faceColors.SetComponent( 7, 3, 255 )
    sgrid = vtkStructuredGrid()
    sgrid.SetDimensions( 3, 3, 3 )
    sgrid.SetPoints( points )
    sgrid.GetCellData().SetScalars( faceColors )
    faceColors.Modified()
#     sggf = vtkStructuredGridGeometryFilter()
#     sggf.SetInput( sgrid )
#     spdm = vtkPolyDataMapper()
#     spdm.SetInput( sggf.GetOutput() )
    mapper = vtkDataSetMapper()
    mapper.SetInput( sgrid )
    mapper.SetScalarModeToUseCellData()
    actor = vtkActor()
    actor.SetMapper( mapper )
#    actor.SetMapper( spdm )
#    actor.GetProperty().SetOpacity( 0.999 )

    # Add the actors to the renderer, set the background and size
    ren1.AddActor( actor )
    ren1.SetBackground( 0.5, 0, 1 )
    renWin.SetSize( 256, 256 )
    # render the image
    renWin.Render()
    iren.Start()
    
if __name__ == '__main__':
    main()

Malcolm Drummond <malcolm at geovision.co.za> wrote:
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: 
To: "REGAT-BARREL Aurélien" 
Cc: "VTK" ; 
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
cc: VTK
, 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:


		
---------------------------------
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/00a39348/attachment.htm>


More information about the vtkusers mailing list