#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

# Create a new 'Render View'
renderView1 = GetRenderView()

RequestData = """
import numpy as np
from vtk.numpy_interface import dataset_adapter as dsa

executive = self.GetExecutive()
outInfo = executive.GetOutputInformation(0)
exts = [executive.UPDATE_EXTENT().Get(outInfo, i) for i in xrange(6)]
whole = [executive.WHOLE_EXTENT().Get(outInfo, i) for i in xrange(6)]
ts = executive.UPDATE_TIME_STEP().Get(outInfo)
print "ts = ", ts
dims = [exts[1]-exts[0]+1, exts[3]-exts[2]+1, exts[5]-exts[4]+1]
global_dims = [whole[1]-whole[0]+1, whole[3]-whole[2]+1, whole[5]-whole[4]+1]
output.SetExtent(exts)
xaxis = np.linspace(-.5, 1., global_dims[0])[exts[0]:exts[1]+1]
yaxis = np.linspace(-1.,1., global_dims[1])[exts[2]:exts[3]+1]
zaxis = np.linspace(-1., .5, global_dims[2])[exts[4]:exts[5]+1]
[xc,yc,zc] = meshgrid(zaxis,yaxis,xaxis, indexing="ij")
data = sqrt(xc**2 + yc**2 + zc**2)
output.PointData.append(data.ravel(), "scalar")
"""

RequestInfo = """
executive = self.GetExecutive ()
outInfo = executive.GetOutputInformation(0)

dims = [11,11,11]
outInfo.Set(executive.WHOLE_EXTENT(), 0, dims[0]-1 , 0, dims[1]-1 , 0, dims[2]-1)
outInfo.Set(vtk.vtkDataObject.SPACING(), 1, 1, 1)
outInfo.Set(vtk.vtkDataObject.ORIGIN(), 0,0,0)
outInfo.Set(vtk.vtkAlgorithm.CAN_PRODUCE_SUB_EXTENT(), 1)
timesteps = (0.,0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35)
#timesteps = (0.,0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55)
outInfo.Remove(executive.TIME_STEPS())

for timestep in timesteps:
  outInfo.Append(executive.TIME_STEPS(), timestep)

outInfo.Remove(executive.TIME_RANGE())
outInfo.Append(executive.TIME_RANGE(), timesteps[0])
outInfo.Append(executive.TIME_RANGE(), timesteps[-1])
"""
# create a new 'Programmable Source'
pS = ProgrammableSource()
pS.OutputDataSetType = 'vtkImageData'
pS.Script = ''
pS.ScriptRequestInformation = ''
pS.PythonPath = ''
pS.Script = RequestData
pS.ScriptRequestInformation = RequestInfo

#pS.UpdatePipelineInformation()
#pS.UpdatePipeline()

rep1 = Show(pS)
Render()

