def encodePolyData(polyData):
    '''Given a vtkPolyData, returns a numpy int8 array that contains
    the serialization of the data.  This array can be passed to the
    decodePolyData function to construct a new vtkPolyData object from
    the serialized data.'''

    if not hasattr(vtk, 'vtkCommunicator'):
        w = vtk.vtkPolyDataWriter()
        w.WriteToOutputStringOn()
        w.SetInput(polyData)
        w.Write()
        return np.frombuffer(w.GetOutputStdString(), dtype=np.int8)

    charArray = vtk.vtkCharArray()
    vtk.vtkCommunicator.MarshalDataObject(polyData, charArray)
    numpyArray = vnp.numpy_support.vtk_to_numpy(charArray)
    assert numpyArray.dtype == np.int8
    return numpyArray
dataset/ETHPy150Open RobotLocomotion/director/src/python/director/geometryencoder.py/encodePolyData/original