I have a vtkMultiBlockDataSet that contains some vtkUnstructuredGrids and some vtkPolyData objects. I want to be able to put data on the cells of the vtkUnstructuredGrids such that each cell contains an arbitrary number of elements, e.g.:
vtkAbstractArray* celFaces = myUnstructuredGrid->GetCellData()->GetAbstractArray("cellFaces");
// cellFaces is a two dimensional array, where each i'th element contains an arbitrary number of j elements.
Ragged arrays possible, but not in a way that will behave or perform well; you must create a vtkVariantArray and assign a vtkDataArray to each cell’s value. This is slow, consumes a lot of memory, and is hard to use for visualizations (such as coloring cells).
VTK is not really designed for ragged arrays. A more performant but less dynamic method to accommodate ragged arrays is to store a single offset per cell into a single vtkDataArray held in the dataset’s field-data. But then every filter that needs access to values must know how to use the offset to obtain the set of values for the cell.
vtkPointData requires arrays that have a tuple for each point
vtkCellData requires arrays that have a tuple for each cell
vtkFieldData has no constraints on the number of tuples (but also cannot be used directly to color geometry, etc. since there is no context that specifies how the arrays map to any geometry).
Just put your one big array in the field data (inherited from vtkDataObject) and your offset array in the cell-data.