import base64
from ddapp import vtkAll as vtk
from ddapp.shallowCopy import shallowCopy

def encodePolyData(polyData):
    w = vtk.vtkPolyDataWriter()
    w.WriteToOutputStringOn()
    w.SetInput(polyData)
    w.Write()
    return base64.b64encode(w.GetOutputStdString())

def decodePolyData(data):
    r = vtk.vtkPolyDataReader()
    r.ReadFromInputStringOn()
    r.SetInputString(base64.b64decode(data))
    r.Update()
    return shallowCopy(r.GetOutput())

@@ -1,18 +1,4 @@
-import base64%0A
 from
@@ -39,407 +39,896 @@
 dapp
-.shallowCopy import shallowCopy%0A%0Adef encodePolyData(polyData):%0A    w = vtk.vtkPolyDataWriter()%0A    w.WriteToOutputStringOn()%0A    w.SetInput(polyData)%0A    w.Write()%0A    return base64.b64encode(w.GetOutputStdString())%0A%0Adef decodePolyData(data):%0A    r = vtk.vtkPolyDataReader()%0A    r.ReadFromInputStringOn()%0A    r.SetInputString(base64.b64decode(data))%0A    r.Update()%0A    return shallowCopy(r.GetOutput())
+ import vtkNumpy as vnp%0Aimport numpy as np%0A%0Adef encodePolyData(polyData):%0A    '''Given a vtkPolyData, returns a numpy int8 array that contains%0A    the serialization of the data.  This array can be passed to the%0A    decodePolyData function to construct a new vtkPolyData object from%0A    the serialized data.'''%0A%0A    charArray = vtk.vtkCharArray()%0A    vtk.vtkCommunicator.MarshalDataObject(polyData, charArray)%0A    numpyArray = vnp.numpy_support.vtk_to_numpy(charArray)%0A    assert numpyArray.dtype == np.int8%0A    return numpyArray%0A%0Adef decodePolyData(data):%0A    '''Given a numpy int8 array, deserializes the data to construct a new%0A    vtkPolyData object and returns the result.'''%0A%0A    charArray = vnp.getVtkFromNumpy(data)%0A    assert isinstance(charArray, vtk.vtkCharArray)%0A    polyData = vtk.vtkPolyData()%0A    vtk.vtkCommunicator.UnMarshalDataObject(charArray, polyData)%0A    return polyData
 %0A

implement a better method for vtk data serialization