# How to select a hexahedral cell using HardwareSelector

**URL:** https://discourse.vtk.org/t/how-to-select-a-hexahedral-cell-using-hardwareselector/2062
**Category:** Support
**Created:** [November 7, 2019, 11:28am UTC](https://discourse.vtk.org/t/how-to-select-a-hexahedral-cell-using-hardwareselector/2062 "2019-11-07T11:28:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kknnnyy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/b5a626/32.png) [@kknnnyy](https://discourse.vtk.org/u/kknnnyy)
#### Post date: [November 7, 2019, 11:28am UTC](https://discourse.vtk.org/t/how-to-select-a-hexahedral-cell-using-hardwareselector/2062/1 "2019-11-07T11:28:07Z")

</div>

I want to use vtkhardwareselector to get the hexahedral cell id in unstructuredgrid, so I found a problem after converting unstructuredgrid to polydata. The cell id of the three faces of the hexahedral cell in the corner is different. Is there any way to correctly extract the hexahedron? To ensure that all face ids of a hexahedral cell are the same, just like in paraview. And The reason for not using vtkcellpicker is that it is very slow.

---

<div class="post-metadata">

### Author: ![kknnnyy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/b5a626/32.png) [@kknnnyy](https://discourse.vtk.org/u/kknnnyy)
#### Post date: [November 9, 2019, 5:10am UTC](https://discourse.vtk.org/t/how-to-select-a-hexahedral-cell-using-hardwareselector/2062/2 "2019-11-09T05:10:22Z")

</div>

Actor:  
…  
hexahedronGrid = vtk.vtkUnstructuredGrid()  
…  
hexahedronGridMapper = vtk.vtkDataSetMapper()  
hexahedronGridMapper.SetInputData(hexahedronGrid)  
hexahedronGridActor = vtk.vtkActor()  
hexahedronGridActor.SetMapper(hexahedronGridMapper)

CellPickerk can get the original Cell id:

def CellPickerCallback(caller, eventId):  
clickPos = iren.GetEventPosition()  
x = int(clickPos[0])  
y = int(clickPos[1])  
picker = vtk.vtkCellPicker()  
picker.Pick(x, y, 0, ren1)  
iSel = picker.GetCellId()  
if -1 != iSel:  
print(“Cell ID:” + str(iSel))

[https://discourse.vtk.org/uploads/default/original/2X/c/c194d42bb28ccc53116b1ff42ad3c2f3b69ae436.mp4](https://discourse.vtk.org/uploads/default/original/2X/c/c194d42bb28ccc53116b1ff42ad3c2f3b69ae436.mp4)

It can be seen that the hardware selector did not get the original cell ID.

```
def hardwareSelectionCallback(caller, eventId):
    clickPos = iren.GetEventPosition()
    x = int(clickPos[0])
    y = int(clickPos[1])
    hardSel = vtk.vtkHardwareSelector()
    hardSel.SetRenderer(ren1)
    hardSel.SetFieldAssociation(vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS)
    hardSel.SetArea(x, y, x + 1, y + 1)
    res = hardSel.Select()
    numNodes = res.GetNumberOfNodes()
    if (numNodes < 1):
        print("No Cell")
    else:
        sel_node = res.GetNode(0)
        cellId = sel_node.GetSelectionList().GetValue(0)
        print("CellId:" + str(cellId))

```

[https://discourse.vtk.org/uploads/default/original/2X/2/2b372d0e1e09dda2e8688024da44adc81a5a0a3a.mp4](https://discourse.vtk.org/uploads/default/original/2X/2/2b372d0e1e09dda2e8688024da44adc81a5a0a3a.mp4)

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [October 30, 2022, 1:00am UTC](https://discourse.vtk.org/t/how-to-select-a-hexahedral-cell-using-hardwareselector/2062/3 "2022-10-30T01:00:02Z")

</div>

Hi,  
I’m having the same problem using ActiViz 9.2. I’m curious how did you solve the problem  
Thanks

---

<div class="post-metadata">

### Author: ![reload0236](https://discourse.vtk.org/user_avatar/discourse.vtk.org/reload0236/32/7307_2.png) [@reload0236](https://discourse.vtk.org/u/reload0236)
#### Post date: [June 19, 2023, 7:54am UTC](https://discourse.vtk.org/t/how-to-select-a-hexahedral-cell-using-hardwareselector/2062/4 "2023-06-19T07:54:53Z")

</div>

Here comes the saver!  
The critical problem is made by vtkDataSetMapper. The most important procedure makes vtkHardwareSelector working is vtkMapper::ProcessSelectorPixelBuffers, but the implementation from vtkDataSetMapper is left empty, the work is done by the descendant of vtkPolyDataMapper.  
So there are 2 methods:  
1. Use vtkDataSetSurfaceFilter to extract polyData, then bind actor with vtkPolyDataMapper.  
2. Make your own version of vtkDataSetMapper, implementing the ProcessSelectorPixelBuffers  
function by inner PolyDataMapper as the proxy.

---

<div class="post-metadata">

### Author: ![MarKara](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@MarKara](https://discourse.vtk.org/u/MarKara)
#### Post date: [July 13, 2023, 5:17pm UTC](https://discourse.vtk.org/t/how-to-select-a-hexahedral-cell-using-hardwareselector/2062/5 "2023-07-13T17:17:29Z")

</div>

Yes, thanks
