[vtkusers] vtkUniformGrid blanking
Favre Jean
jfavre at cscs.ch
Thu Apr 7 07:22:32 EDT 2011
From: vtkusers-bounces at vtk.org [vtkusers-bounces at vtk.org] on behalf of Alexandre Boucher [afboucher at gmail.com]
Sent: Tuesday, April 05, 2011 10:24 PM
To: vtkusers at vtk.org
Subject: [vtkusers] vtkUniformGrid blanking
Hello,
For some reason I am unable to use the blanking capability of the vtkUniformGrid class. I am interested in blanking cells (do not work on point either). For example the following (pyhton) code does not blank anything. What am I doing wrong.
-------------------------------------------------------------------
Your grid construction is actually correct, but your choice of which mapper to use is not. Your default mapper does not support blanking. You should choose a filter which works on cells (for example vtkCellCenters) and see if it does the subsetting correctly. I have done this with a modified version of your code. My conclusion is that "yes, the blanking you have set in you grid is correct".
import vtk
uGrid = vtk.vtkUniformGrid()
uGrid.SetExtent(0,35, 0,35, 0,35)
uGrid.SetOrigin(0, 0,0)
uGrid.SetSpacing(1,1,1)
uGrid.SetScalarTypeToFloat ()
nCells = uGrid.GetNumberOfCells()
# Set the data vector
data = vtk.vtkFloatArray()
data.SetNumberOfValues(nCells)
data.SetNumberOfComponents(1)
# Set the blanking vector
dataBlank = vtk.vtkUnsignedCharArray()
dataBlank.SetNumberOfValues(nCells)
dataBlank.SetNumberOfComponents(1)
# first set all to 0 blanking
for i in range(nCells):
data.SetValue(i, float(i)/nCells)
dataBlank.SetValue(i, 0)
# then set a sub-set to 1 blanking
for i in range(nCells/2, nCells-1):
dataBlank.SetValue(i, 1)
uGrid.GetCellData().SetScalars(data)
uGrid.SetCellVisibilityArray(dataBlank)
#use cell centers which should only operate on the subset
cc = vtk.vtkCellCenters()
cc.VertexCellsOn()
cc.SetInput(uGrid)
m0 = vtk.vtkDataSetMapper()
m0.SetInput(cc.GetOutput())
actor0 = vtk.vtkActor()
actor0.SetMapper(m0)
# use an outline instead of an opaque box
out = vtk.vtkOutlineFilter()
out.SetInput(uGrid)
mapper = vtk.vtkDataSetMapper()
mapper.SetInput(out.GetOutput())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(500, 500)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren.AddActor(actor)
ren.AddActor(actor0)
iren.Initialize()
renWin.Render()
iren.Start()
-----------------
Jean M. Favre
Scientific Computing Research
Swiss National Supercomputing Center
CH-6928 Manno
Switzerland
More information about the vtkusers
mailing list