Example for extracting a single cell from a polydata into a new dataset


could anyone provide me with an example for doing the following operation:
Let’s say I have a polydata.
I want to extract one cell (knowing its ID) into a new dataset (which I will then display as a wireframe to highlight that cell).
@Sebastien_Jourdain suggested doing shallow copy of my polydata but I’m not sure how to do that and then only having a single cell in that copy ?
Is it because the copy only deals with points and I then have to manually build my single cell ?
Thanks for your help

const selection = vtkPolyData.newInstance();
const selection.shallowCopy(originalDS);
// selection.getCellData().clear();
const cell = [];
const targetCellId = 234;
let cellOffset = 0;
let currentCellId = 0;
const originalCells = originalDS.getPolys().getData(); // assuming only polys

// find cell
while (currentCellId < targetCellId) {
  cellOffset += originalCells[cellOffset] + 1;

// extract a copy of the found one
for (let i = 0; i <= originalCells[cellOffset]; i++) {

// override the original cells with the one we created

Great thanks a lot !