Hello everyone
I just started developing in VTK and working with ParaView. I currently try to change the threshold filter a little bit and create my own plugin out of it. Now I ran into a problem. I think it has mainly to do with the fact that I’m using “vtkRectilinearGrid” data, but I don’t really see how I can convert that.
I’m able to render the data in VTK, but then I receive a “full cube”. Even the voxels with value 0 get rendered somehow. I can apply a threshold in ParaView and then receive the correct voxels in the middle which correspond to my desired shape.
If a add the vtk threshold I get a blank window in VTK. My code looks like this:
reader = vtk.vtkXMLRectilinearGridReader()
reader.SetFileName("shape.vtr")
reader.WholeSlicesOff()
reader.Update()
rg0 = vtk.vtkRectilinearGrid()
rg0.DeepCopy(reader.GetOutput())
cube_mapper = vtk.vtkDataSetMapper()
cube_mapper.SetInputData(rg0)
opt = vtk.vtkPolyData()
th = vtk.vtkThreshold()
th.SetInputData(cube_mapper.GetOutputPort())
th.ThresholdBetween(0.0, 100.0)
th.Update()
opt.ShallowCopy(th.GetOutput())
cube_mapper2 = vtk.vtkDataSetMapper()
cube_mapper2.SetInputData(opt)
# Connect the mapper to an actor
cube_actor = vtk.vtkActor()
cube_actor.SetMapper(cube_mapper2)
cube_actor.GetProperty().SetColor(1.0, 0.0, 0.0)
# Create a renderer and add the cube actor to it
renderer = vtk.vtkRenderer()
renderer.SetBackground(0.0, 0.0, 0.0)
renderer.AddActor(cube_actor)
# Create a render window
render_window = vtk.vtkRenderWindow()
render_window.SetWindowName("Simple VTK scene")
render_window.SetSize(400, 400)
render_window.AddRenderer(renderer)
# Create an interactor
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(render_window)
# Initialize the interactor and start the
# rendering loop
interactor.Initialize()
render_window.Render()
interactor.Start()
I hope this is enough information to debug the problem. I see how VTK uses those pipelines and I have a feeling that I connected some layers which do not make a lot of sense