vtkHardwareSelector highlight the selected face of cube

Thanks for your advice! If I understood you correctly, this is how it should work:

const apiSpecificRenderWindow = interactor.getView()
const selector = apiSpecificRenderWindow.getSelector()

selector.setRenderer(renderer)
selector.setFieldAssociation(FieldAssociations.FIELD_ASSOCIATION_CELLS)

const numCells = source.getNumberOfCells()
const cellIds = new Array(numCells).fill().map((_, i) => i)
  const cellIdArray = vtkDataArray.newInstance({
    values: cellIds,
    name: 'CellIds',
  })
  source.getCellData().setScalars(cellIdArray)

const lookupTable = vtkColorTransferFunction.newInstance()
for (let i = 0; i <= source.getNumberOfCells(); i++) {
    lookupTable.addRGBPoint(i, 1, 1, 1)
  }

mapper.setLookupTable(lookupTable)
mapper.setScalarRange(0, numCells - 1)
mapper.setColorModeToMapScalars()

  let previousCellId = -1 // Keep track of the previously selected cell

  interactor.onMouseMove((e) => {
    const pos = e.position
    selector.setArea(pos.x - 1, pos.y - 1, pos.x + 1, pos.y + 1)
    const selection = selector.select()

    if (selection.length) {
      const cellId = selection[0].getSelectionList()[0]

      if (cellId >= 0 && cellId < source.getNumberOfCells()) {
        if (cellId !== previousCellId) {
          // If a cell was previously selected, revert its color to white
          if (previousCellId >= 0) {
            lookupTable.addRGBPoint(previousCellId, 1, 1, 1)
          }

          // Highlight the newly selected cell in green
          lookupTable.addRGBPoint(cellId, 0, 1, 0)

          // Update the previousCellId to the currently selected cell
          previousCellId = cellId

          renderWindow.render()
        }
      }
    } else {
      // No cell is selected, revert the previously selected cell to white
      if (previousCellId >= 0) {
        lookupTable.addRGBPoint(previousCellId, 1, 1, 1)
        previousCellId = -1 // Reset the previous cell ID
        renderWindow.render()
      }
    }
  })

And it does work, but only with small geometries (for example, I’m currently testing a geometry with 12 cells, i.e. a simple parallelepiped), but when I decided to load a complex geometry with 80,000+ cells, the application simply froze and did not respond. It is obvious to me that this is due to two loops over the array of the number of cells, which is very resource-intensive. Is there a way to get around this? Or did I just make a mistake when transferring your words to code?

If you want to run the tests, I can share with you two of my vtp files…

Thanks!