I use vtkUnstructuredGrid to store cell dates , and I want replace a cell to a vtkEmptyCell . But fail.
I’m pretty confident that just replacing the Types
array at id cellId
to VTK_EMPTY_CELL
should work, if the cell is already allocated. This way you can just shallow-copy the unstructured grid and save memory. Let me write an example:
vtkSmartPointer<vtkUnstructuredGrid> EditUnstructuredGrid(
vtkUnstructuredGrid* input, vtkIdList* cellIds)
{
vtkSmartPointer<vtkUnstructuredGrid> output = vtkSmartPointer<vtkUnstructuredGrid>::New();
output->ShallowCopy(input);
// We need a new types array with a deep copy so we don't edit the input.
vtkNew<vtkUnsignedCharArray> types;
types->DeepCopy(input->GetCellTypesArray());
// We reset the cells in the output with the new types array
output->SetCells(types, output->GetCells(), output->GetFaceLocations(), output->GetFaces());
// We can now edit the types
for (vtkIdType i = 0; i < cellIds->GetNumberOfIds(); ++i)
{
types->SetValue(cellIds->GetId(i), VTK_EMPTY_CELL);
}
// WARNING This only works because an empty cell always has less points than
// any other cell. If you replace a VTK_LINE with a VTK_TRIANGLE,
// you'll be messing up the cell array.
return output;
}
thank you sir! your example is work well in my software.