Can't write vtkFieldData to vtkImageData/VTI file using vtkXMLImageWriter

Hello -

I am trying to write some simple text strings to a vti file, like author, description, etc. It looks like vtkFieldData is the way to go but I seem to be missing some critical piece of knowledge. I created the following to illustrate the issue. I can see that my string data is part of the ImageData but something happens and it doesn’t end up in the XML like I’d expect…

// For Writing
  console.log("Start-")
  const writer = vtkXMLImageDataWriter.newInstance();
  writer.setFormat(vtkXMLWriter.FormatTypes.ASCII);

  // Write some data 
  var  stringArray = vtkStringArray.newInstance({
    values: ['this is a string'],
    dataType: 'string', // values encoding
    size: 1,
    name: 'one'
  });

  // put in field
  const fieldData = vtkFieldData.newInstance();
  fieldData.addArray(stringArray);
  stringArray.setName('one');
  
  // Create vtkImageData
  const imageData = vtkImageData.newInstance();

  // Set the dimensions of the image
  const dims = [1, 1, 1]; // Single cell with dimensions (1, 1, 1)
  imageData.setDimensions(...dims);
  imageData.setSpacing(1, 1, 1); // Set spacing to 1 in all directions
  imageData.setOrigin(0, 0, 0); // Set the origin to (0, 0, 0)
  
  //Add the vtkFieldData to the vtkImageData
  imageData.setFieldData(fieldData);

  //check
  var i =0;
  const field = imageData.getFieldData();
  while (field.getArray(i) != null){
    console.log("Field " + i + " Name: " + field.getArray(i).getName() + " " + field.getArray(i).getData());
    i++;
  }

  const contents =   writer.write(imageData);

…at console.log I get what I expect…

Field 0 Name: one this is a string

…but my XML ‘contents’ contains no sign of FieldData or my string. What am I missing?

<?xml version="1.0"?><VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor=""><ImageData WholeExtent="0 0 0 0 0 0" Origin="0 0 0" Spacing="1 1 1" Direction="1 0 0 0 1 0 0 0 1"><Piece Extent="0 0 0 0 0 0"><PointData/><CellData/></Piece></ImageData></VTKFile>

Which version of vtk.js? The string arrays and fielddata have been fixed/added recently (couple of weeks ago)

vtk.js@26.9.15… update to vtk.js@28.4.1 no change

I think the writer doesn’t yet support string arrays, but it shouldn’t be too much effort to do so.

More than “no string arrays support”, it seems that vtkXMLWriter does not even try to export “fieldData”, while vtkXMLReader does support importing “fieldData”.

Feel free to create PR that add “fieldData” export support.