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

open('ttt.foam','a').close()

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
renderView1.ViewSize = [1280, 960]

# create a new 'OpenFOAMReader'
OFReaderParams = {'MeshRegions':[],'CellArrays':[],'Decomposepolyhedra':1,'Createcelltopointfiltereddata':0,'CaseType':'Decomposed Case'}
foam = OpenFOAMReader(FileName='ttt.foam',**OFReaderParams)
foam.MeshRegions = ['HULL']
foam.CellArrays = [ 'wallShearStress' ]

# get animation scene
animationScene1 = GetAnimationScene()
animationScene1.UpdateAnimationUsingDataTimeSteps()
animationScene1.GoToLast()

foamDisplay = Show(foam, renderView1)
foamDisplay.Representation = 'Surface'

ColorBy(foamDisplay, ('CELLS', 'wallShearStress', 'Magnitude' ))
foamDisplay.SetScalarBarVisibility(renderView1, True)
LUT = GetColorTransferFunction('wallShearStress')
LUT.RescaleTransferFunction(0.0,0.01)

print 'creating D3'
d31 = D3(Input=foam)
d31.MinimalMemory = 0
d31.MinimumNumberOfGhostLevels = 0

print 'creating cell data to point data'
cellDatatoPointData1 = CellDatatoPointData(Input=d31)
cellDatatoPointData1.PassCellData = 1

print 'creating mask points'
maskPoints1 = MaskPoints(Input=cellDatatoPointData1)
maskPoints1.OnRatio = 200
maskPoints1.MaximumNumberofPoints = 50000000
maskPoints1.ProportionallyDistributeMaximumNumberOfPoints = 1
maskPoints1.RandomSampling = 1
maskPoints1.RandomSamplingMode = 'Randomized Id Strides' #'Spatially Stratified Random Sampling' 'Random Sampling' # 
maskPoints1Display = Show(maskPoints1, renderView1)

print 'creating stream tracer'
streamTracerWithCustomSource1 = StreamTracerWithCustomSource(Input=cellDatatoPointData1,
	SeedSource=maskPoints1)

# Properties modified on streamTracerWithCustomSource1
streamTracerWithCustomSource1.Vectors = ['POINTS', 'wallShearStress']
streamTracerWithCustomSource1.SurfaceStreamlines = 1
streamTracerWithCustomSource1.ComputeVorticity = 0

streamTracerWithCustomSource1Display = Show(streamTracerWithCustomSource1, renderView1)
streamTracerWithCustomSource1Display.Representation = 'Surface'
streamTracerWithCustomSource1Display.DiffuseColor = [0.0, 0.0, 0.0]  
streamTracerWithCustomSource1Display.LineWidth = 2.
streamTracerWithCustomSource1Display.RenderLinesAsTubes = 1

renderView1.CameraPosition = [10, 4., 0.14]
renderView1.CameraFocalPoint = [3.5, 0, 0.15]
renderView1.CameraViewUp = [0,0,1]
renderView1.CameraParallelScale = 1.0

imageName = "{}_{}.png".format('wallShearStress_streaklines','wing')
print "writing to image",imageName
WriteImage(imageName,Magnification=2)



