# script works well in ParaView 4.1 using 2 or 3 pvservers
# in PV4.2, the update extents are always set to the whole_extent on all processes.
#
# Written by Jean M. Favre, Swiss National Supercomputing Center
# date: Wed Oct  1 13:23:06 CEST 2014

try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()

ProgrammableSource1 = ProgrammableSource( guiName="ProgrammableSource1", OutputDataSetType='vtkRectilinearGrid', PythonPath='', ScriptRequestInformation='dims = [8,4,4]\nexecutive = self.GetExecutive()\noutInfo = executive.GetOutputInformation(0)\noutInfo.Set(executive.WHOLE_EXTENT(), 0, dims[0]-1, 0, dims[1]-1, 0, dims[2]-1)\noutInfo.Set(vtk.vtkAlgorithm.CAN_PRODUCE_SUB_EXTENT(), 1)\n', Script='rg = self.GetRectilinearGridOutput()\nexecutive = self.GetExecutive()\noutInfo = executive.GetOutputInformation(0)\npid = outInfo.Get(executive.UPDATE_PIECE_NUMBER())\nf = open(format("/tmp/p.%d.txt" % pid), "w")\nf.write(format("pid = %d\\n" % pid))\n\nexts = [executive.UPDATE_EXTENT().Get(outInfo, i) for i in xrange(6)]\nwhole = [executive.WHOLE_EXTENT().Get(outInfo, i) for i in xrange(6)]\ndims = [exts[1]-exts[0]+1, exts[3]-exts[2]+1, exts[5]-exts[4]+1]\nrg.SetExtent(exts)\nf.write(format("update_exts = %d,%d,%d,%d,%d,%d\\n" % (exts[0], exts[1],exts[2], exts[3],exts[4], exts[5])))\nf.write(format("dims = %d,%d,%d\\n" % (dims[0], dims[1],dims[2])))\nf.close()\nimport math\nphi =[0]\ntheta = [0]\nR = [.53]\nfor i in range(1,whole[1]+1):\n  phi.append(i*2*math.pi/(whole[1]-1))\n\nfor i in range(1,whole[3]+1):\n  theta.append(i*math.pi/(whole[3]-1))\n\nfor i in range(1,whole[5]+1):\n  R.append(.53+i*(1.53-0.53)/(whole[5]-1))\n\nVTKphi = vtk.vtkFloatArray()\nVTKphi.SetNumberOfTuples(dims[0])\n\nVTKtheta = vtk.vtkFloatArray()\nVTKtheta.SetNumberOfTuples(dims[1])\n\nVTKR =vtk.vtkFloatArray()\nVTKR.SetNumberOfTuples(dims[2])\n\nfor i in range(dims[0]):\n  VTKphi.SetValue(i, phi[i+exts[0]])\nfor j in range(dims[1]):\n  VTKtheta.SetValue(j, theta[j+exts[2]])\nfor k in range(dims[2]):\n  VTKR.SetValue(k, R[k+exts[4]])\n\nrg.SetXCoordinates(VTKphi)\nrg.SetYCoordinates(VTKtheta)\nrg.SetZCoordinates(VTKR)' )

view = GetRenderView()

rep0 = Show()
rep0.Representation = 'Surface With Edges'

Render()
view.ResetCamera()
