[vtkusers] vtkBandedPolyDataContourFilter and scalars on cells
Uwe Schlifkowitz
schlifkowitz at intales.com
Thu Dec 18 05:24:35 EST 2014
Hi,
I need to create something like a vtkBandedPolyDataContourFilter using
cell data instead of point data.
To clarify, here is the example from
http://vtk.org/Wiki/VTK/Examples/Cxx/VisualizationAlgorithms/BandedPolyDataContourFilter
translated to Python (see below).
Essentially, I want to use something like
polyData.GetCellData().SetScalars(scalars) instead of
polyData.GetPointData().SetScalars(scalars) around line 80, but this
results in the following error later in the code:
ERROR: In
/build/buildd/vtk6-6.0.0/Filters/Modeling/vtkBandedPolyDataContourFilter.cxx,
line 232
vtkBandedPolyDataContourFilter (0x2cbc5d0): No input data!
Does anyone know a solution or maybe a better way to achieve what I
want? I'm using python-vtk6 on Ubuntu 14.04.
Thanks,
Uwe
#!/usr/bin/env python
import sys
import vtk
def main():
pts = vtk.vtkPoints()
pts.InsertPoint(0, 0, 0, 0)
pts.InsertPoint(1, 0, 1, 0)
pts.InsertPoint(2, 0, 2, 0)
pts.InsertPoint(3, 1, 0, 0)
pts.InsertPoint(4, 1, 1, 0)
pts.InsertPoint(5, 1, 2, 0)
pts.InsertPoint(6, 2, 0, 0)
pts.InsertPoint(7, 2, 2, 0)
pts.InsertPoint(8, 3, 0, 0)
pts.InsertPoint(9, 3, 1, 0)
pts.InsertPoint(10, 3, 2, 0)
pts.InsertPoint(11, 4, 0, 0)
pts.InsertPoint(12, 6, 0, 0)
pts.InsertPoint(13, 5, 2, 0)
pts.InsertPoint(14, 7, 0, 0)
pts.InsertPoint(15, 9, 0, 0)
pts.InsertPoint(16, 7, 2, 0)
pts.InsertPoint(17, 9, 2, 0)
pts.InsertPoint(18, 10, 0, 0)
pts.InsertPoint(19, 12, 0, 0)
pts.InsertPoint(20, 10, 1, 0)
pts.InsertPoint(21, 12, 1, 0)
pts.InsertPoint(22, 10, 2, 0)
pts.InsertPoint(23, 12, 2, 0)
pts.InsertPoint(24, 10, 3, 0)
pts.InsertPoint(25, 12, 3, 0)
polys = vtk.vtkCellArray()
polys.InsertNextCell(4)
polys.InsertCellPoint(14)
polys.InsertCellPoint(15)
polys.InsertCellPoint(17)
polys.InsertCellPoint(16)
polys.InsertNextCell(3)
polys.InsertCellPoint(11)
polys.InsertCellPoint(12)
polys.InsertCellPoint(13)
scalars = vtk.vtkFloatArray()
scalars.SetNumberOfTuples (26)
scalars.SetTuple1(0, 0)
scalars.SetTuple1(1, 50)
scalars.SetTuple1(2, 100)
scalars.SetTuple1(3, 0)
scalars.SetTuple1(4, 50)
scalars.SetTuple1(5, 100)
scalars.SetTuple1(6, 10)
scalars.SetTuple1(7, 90)
scalars.SetTuple1(8, 10)
scalars.SetTuple1(9, 50)
scalars.SetTuple1(10, 90)
scalars.SetTuple1(11, 10)
scalars.SetTuple1(12, 40)
scalars.SetTuple1(13, 100)
scalars.SetTuple1(14, 0)
scalars.SetTuple1(15, 60)
scalars.SetTuple1(16, 40)
scalars.SetTuple1(17, 100)
scalars.SetTuple1(18, 0)
scalars.SetTuple1(19, 25)
scalars.SetTuple1(20, 25)
scalars.SetTuple1(21, 50)
scalars.SetTuple1(22, 50)
scalars.SetTuple1(23, 75)
scalars.SetTuple1(24, 75)
scalars.SetTuple1(25, 100)
polyData = vtk.vtkPolyData()
polyData.SetPoints(pts)
polyData.SetPolys(polys)
polyData.GetPointData().SetScalars(scalars)
#polyData.GetCellData().SetScalars(scalars) # <--- i want this
bf = vtk.vtkBandedPolyDataContourFilter()
if vtk.VTK_MAJOR_VERSION < 6:
bf.SetInput(polyData)
else:
bf.SetInputData(polyData)
bf.GenerateValues(3, 25, 75)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(bf.GetOutputPort())
mapper.SetScalarModeToUseCellData()
mapper.SetScalarRange (0, 4)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Create the RenderWindow, Renderer and both Actors
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Add the actors to the renderer, set the background and size
ren1.AddActor(actor)
renWin.SetSize (300 ,80)
renWin.Render()
ren1.GetActiveCamera().Zoom(3)
renWin.Render()
iren.Start()
if __name__ == "__main__":
sys.exit(main())
--
INTALES GmbH Engineering Solutions
Uwe Schlifkowitz -- Software Engineer
Innsbrucker Str. 1, A-6161 Natters
Phone: +43 512 54611120 -- schlifkowitz at intales.com
More information about the vtkusers
mailing list