# vtkCellPicker ignores block visibility in vtkMultiBlockDataSet

**URL:** https://discourse.vtk.org/t/vtkcellpicker-ignores-block-visibility-in-vtkmultiblockdataset/16462
**Category:** Support
**Created:** [June 17, 2026, 8:41am UTC](https://discourse.vtk.org/t/vtkcellpicker-ignores-block-visibility-in-vtkmultiblockdataset/16462 "2026-06-17T08:41:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![MaxNumerique](https://discourse.vtk.org/user_avatar/discourse.vtk.org/maxnumerique/32/10673_2.png) [@MaxNumerique](https://discourse.vtk.org/u/MaxNumerique)
#### Post date: [June 17, 2026, 8:41am UTC](https://discourse.vtk.org/t/vtkcellpicker-ignores-block-visibility-in-vtkmultiblockdataset/16462/1 "2026-06-17T08:41:35Z")

</div>

Hi everyone !

When hiding a block of a **vtkMultiBlockDataSet** using **vtkCompositeDataDisplayAttributes.SetBlockVisibility(block, False)**, **vtkCellPicker** still picks the hidden block when a pick operation is performed.

It seems the picker intersects the raw input dataset directly without checking block visibility set on the composite mapper. Is this behavior expected, and is there a built-in way to avoid picking hidden blocks?

Reproduction Code :

```python
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkRenderingOpenGL2 import vtkCompositePolyDataMapper2
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkCompositeDataDisplayAttributes,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
    vtkCellPicker
)

def main():
    # 1. Create a MultiBlockDataSet with two concentric spheres
    root = vtkMultiBlockDataSet()

    # Inner sphere
    sphere1 = vtkSphereSource()
    sphere1.SetCenter(0, 0, 0)
    sphere1.SetRadius(1.0)
    sphere1.Update()
    root.SetBlock(0, sphere1.GetOutput())

    # Outer sphere 2
    sphere2 = vtkSphereSource()
    sphere2.SetCenter(0, 0, 0)
    sphere2.SetRadius(2.0)
    sphere2.Update()
    root.SetBlock(1, sphere2.GetOutput())

    # Setup rendering using the composite mapper
    renderer = vtkRenderer()
    renderWindow = vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    
    renderWindowInteractor = vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    mapper = vtkCompositePolyDataMapper2()
    mapper.SetInputDataObject(root)

    # Hide the outer sphere (block 1) using display attributes
    attributes = vtkCompositeDataDisplayAttributes()
    mapper.SetCompositeDataDisplayAttributes(attributes)
    attributes.SetBlockVisibility(root.GetBlock(1), False)

    actor = vtkActor()
    actor.SetMapper(mapper)
    renderer.AddActor(actor)
    renderer.ResetCamera()
    renderWindow.Render()

    # Pick at the center of the window
    picker = vtkCellPicker()
    size = renderWindow.GetSize()
    picker.Pick(size[0] / 2, size[1] / 2, 0, renderer)
    
    print("Flat block index picked:", picker.GetFlatBlockIndex())
    # Expected: 1 (the visible inner sphere)
    # Actual: 2 (the hidden outer sphere)

    renderWindowInteractor.Start()

if __name__ == ' __main__':
    main()

```

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [June 17, 2026, 1:34pm UTC](https://discourse.vtk.org/t/vtkcellpicker-ignores-block-visibility-in-vtkmultiblockdataset/16462/2 "2026-06-17T13:34:46Z")

</div>

Welcome to VTK, @MaxNumerique!

Looking at the source for `vtkCellPicker` and `vtkPicker`, neither considers the visibilities for individual blocks in `vtkCompositeDataDisplayAttributes` when making the pick - they consider only the visibility and pickability of the entire actor for the composite dataset. That definitely sounds like a bug, and an understandable one since pickers predate the composite data display attributes in VTK’s development.

As a workaround, you could try to swap in `vtkHardwarePicker` for your `vtkCellPicker`, which should take into account block visibility in the picking process.

---

<div class="post-metadata">

### Author: ![MaxNumerique](https://discourse.vtk.org/user_avatar/discourse.vtk.org/maxnumerique/32/10673_2.png) [@MaxNumerique](https://discourse.vtk.org/u/MaxNumerique)
#### Post date: [June 17, 2026, 1:50pm UTC](https://discourse.vtk.org/t/vtkcellpicker-ignores-block-visibility-in-vtkmultiblockdataset/16462/3 "2026-06-17T13:50:00Z")

</div>

Thank you very much for the explanation and suggestion!

Here is the workaround I was using to filter the pick result:

- Perform the pick with **vtkCellPicker.Pick(…)**.
- Retrieve the flat block index using **picker.GetFlatBlockIndex()**.
- Locate the corresponding block **vtkDataObject** from the composite dataset.
- Retrieve the attributes using **mapper.GetCompositeDataDisplayAttributes()**.
- Check if the block is visible with **attributes.GetBlockVisibility(block)**. If it returns **False** , I discard the pick result.

This works, but I will test swapping the picker to **vtkHardwarePicker** as you suggested to see if it natively handles block visibility.

Thanks again!

---

<div class="post-metadata">

### Author: ![MaxNumerique](https://discourse.vtk.org/user_avatar/discourse.vtk.org/maxnumerique/32/10673_2.png) [@MaxNumerique](https://discourse.vtk.org/u/MaxNumerique)
#### Post date: [June 18, 2026, 8:20am UTC](https://discourse.vtk.org/t/vtkcellpicker-ignores-block-visibility-in-vtkmultiblockdataset/16462/4 "2026-06-18T08:20:03Z")

</div>

Hi,

Thank you for the suggestion to try `vtkHardwarePicker`. I tested it, but unfortunately, it is not reliable for thin geometries in my dataset (such as lines/edges only a few pixels wide) where picking was quite capricious compared to `vtkCellPicker`.

As a result, I had to stick to `vtkCellPicker` and implement a custom workaround: when block visibility changes, I construct a pruned `vtkMultiBlockDataSet` physically removing the hidden blocks and feed it to a dedicated `pick_mapper`. During the pick, I temporarily swap the actor’s mapper to this `pick_mapper` to prevent the picker from intersecting hidden geometry.

---

<div class="post-metadata">

### Author: ![lgivord](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lgivord/32/3543_2.png) [@lgivord](https://discourse.vtk.org/u/lgivord)
#### Post date: [June 18, 2026, 9:52am UTC](https://discourse.vtk.org/t/vtkcellpicker-ignores-block-visibility-in-vtkmultiblockdataset/16462/5 "2026-06-18T09:52:32Z")

</div>

It would be nice to track this bug/limitation, @MaxNumerique do you think you can open an issue [here](https://gitlab.kitware.com/vtk/vtk/-/work_items) ?

---

<div class="post-metadata">

### Author: ![MaxNumerique](https://discourse.vtk.org/user_avatar/discourse.vtk.org/maxnumerique/32/10673_2.png) [@MaxNumerique](https://discourse.vtk.org/u/MaxNumerique)
#### Post date: [June 18, 2026, 2:26pm UTC](https://discourse.vtk.org/t/vtkcellpicker-ignores-block-visibility-in-vtkmultiblockdataset/16462/6 "2026-06-18T14:26:37Z")

</div>

Sure !

I’ve created the issue :

[https://gitlab.kitware.com/vtk/vtk/-/work\_items?sort=created\_date&state=opened&first\_page\_size=20&show=eyJpaWQiOiIyMDA4MyIsImZ1bGxfcGF0aCI6InZ0ay92dGsiLCJpZCI6NTMzNjk5fQ%3D%3D](https://gitlab.kitware.com/vtk/vtk/-/work_items?sort=created_date&state=opened&first_page_size=20&show=eyJpaWQiOiIyMDA4MyIsImZ1bGxfcGF0aCI6InZ0ay92dGsiLCJpZCI6NTMzNjk5fQ%3D%3D)
