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.
hexahedronGrid = vtk.vtkUnstructuredGrid()
hexahedronGridMapper = vtk.vtkDataSetMapper()
hexahedronGridActor = vtk.vtkActor()
CellPickerk can get the original Cell id:
def CellPickerCallback(caller, eventId):
clickPos = iren.GetEventPosition()
x = int(clickPos)
y = int(clickPos)
picker = vtk.vtkCellPicker()
picker.Pick(x, y, 0, ren1)
iSel = picker.GetCellId()
if -1 != iSel:
print(“Cell ID:” + str(iSel))
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) y = int(clickPos) 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))
I’m having the same problem using ActiViz 9.2. I’m curious how did you solve the problem
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.