from ddapp import vtkAll as vtk
from ddapp import vtkNumpy as vnp
import numpy as np

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.'''

    charArray = vtk.vtkCharArray()
    vtk.vtkCommunicator.MarshalDataObject(polyData, charArray)
    numpyArray = vnp.numpy_support.vtk_to_numpy(charArray)
    assert numpyArray.dtype == np.int8
    return numpyArray

def decodePolyData(data):
    '''Given a numpy int8 array, deserializes the data to construct a new
    vtkPolyData object and returns the result.'''

    charArray = vnp.getVtkFromNumpy(data)
    assert isinstance(charArray, vtk.vtkCharArray)
    polyData = vtk.vtkPolyData()
    vtk.vtkCommunicator.UnMarshalDataObject(charArray, polyData)
    return polyData

@@ -59,16 +59,58 @@
  as vnp%0A
+from ddapp.shallowCopy import shallowCopy%0A
 import n
@@ -384,24 +384,254 @@
 d data.'''%0A%0A
+    if not hasattr(vtk, 'vtkCommunicator'):%0A        w = vtk.vtkPolyDataWriter()%0A        w.WriteToOutputStringOn()%0A        w.SetInput(polyData)%0A        w.Write()%0A        return np.frombuffer(w.GetOutputStdString(), dtype=np.int8)%0A%0A
     charArra
@@ -937,16 +937,16 @@
 t a new%0A
-
     vtkP
@@ -984,24 +984,241 @@
 result.'''%0A%0A
+    if not hasattr(vtk, 'vtkCommunicator'):%0A        r = vtk.vtkPolyDataReader()%0A        r.ReadFromInputStringOn()%0A        r.SetInputString(str(data.data))%0A        r.Update()%0A        return shallowCopy(r.GetOutput())%0A%0A
     charArra

add code to geometryencoder.py to support mac homebrew vtk