# Problem with my own adapted threshold filter plugin

**URL:** https://discourse.paraview.org/t/problem-with-my-own-adapted-threshold-filter-plugin/5761
**Category:** ParaView Support
**Tags:** python, vtk
**Created:** [November 10, 2020, 4:18pm UTC](https://discourse.paraview.org/t/problem-with-my-own-adapted-threshold-filter-plugin/5761 "2020-11-10T16:18:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Vox3l](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/v/b19c9b/32.png) [@Vox3l](https://discourse.paraview.org/u/Vox3l)
#### Post date: [November 10, 2020, 4:18pm UTC](https://discourse.paraview.org/t/problem-with-my-own-adapted-threshold-filter-plugin/5761/1 "2020-11-10T16:18:01Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![MiguelAngelAGUIRRE](https://discourse.paraview.org/user_avatar/discourse.paraview.org/miguelangelaguirre/32/2986_2.png) [@MiguelAngelAGUIRRE](https://discourse.paraview.org/u/MiguelAngelAGUIRRE)
#### Post date: [November 10, 2020, 6:47pm UTC](https://discourse.paraview.org/t/problem-with-my-own-adapted-threshold-filter-plugin/5761/2 "2020-11-10T18:47:50Z")

</div>

Hello,

I don’t know how to solve your particular problem, however, everytime I need info about VTK and Python I use this reference:

[https://lorensen.github.io/VTKExamples/site/Python/](https://lorensen.github.io/VTKExamples/site/Python/)

I hope it helps

Miguel

---

<div class="post-metadata">

### Author: ![Andrew\_Maclean](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@Andrew\_Maclean](https://discourse.paraview.org/u/Andrew_Maclean)
#### Post date: [November 11, 2020, 7:19am UTC](https://discourse.paraview.org/t/problem-with-my-own-adapted-threshold-filter-plugin/5761/3 "2020-11-11T07:19:39Z")

</div>

There will be a new site appearing real soon. I’ll announce it here as well as in VTK Discourse when it goes live.
