import os
from paraview.simple import *


def load_SurfaceLIC_plugin():
    """Load the SurfaceLIC plugin.

    """
    simplepath = os.path.dirname(paraview.simple.__file__)
    libpath = os.path.abspath(os.path.join(simplepath, '../../'))
    plugin = os.path.join(libpath, 'libSurfaceLIC.so')
    LoadPlugin(plugin, remote=True, ns=globals())


load_SurfaceLIC_plugin()
paraview.simple._DisableFirstRenderCameraReset()

# Create a new 'Render View'
renderView1 = CreateView('RenderView')
renderView1.ViewSize = [1009, 780]
renderView1.AxesGrid = 'GridAxes3DActor'
renderView1.CenterOfRotation = [1.0, 0.5, 2.0]
renderView1.LightSwitch = 0
renderView1.StereoType = 0
renderView1.CameraPosition = [-2.5151404262690797, -10.147138356707089, 0.35390994963439704]
renderView1.CameraFocalPoint = [0.5433616841040119, -2.0042071922068643, 2.0005136815636706]
renderView1.CameraViewUp = [-0.9166006838305547, 0.2882559637035741, 0.27704094605433954]
renderView1.CameraParallelScale = 2.29128784747792
renderView1.CameraParallelProjection = 1
renderView1.Background = [0.32, 0.34, 0.43]

# create a new 'XDMF Reader'
mixedxmf = XDMFReader(FileNames=['./Mixed.xmf'])
mixedxmf.PointArrayStatus = ['VectorValue']
mixedxmf.GridStatus = ['Mixed_0', 'Mixed_1']

slice1 = Slice(Input=mixedxmf)
slice1.SliceType = 'Plane'
slice1.SliceOffsetValues = [0.0]

locations = [
        [1.0, 0.5, 2.0],
        [1.5293281441171462, 0.5603399713445835, 1.9124528509720051]
        ]
normals = [
        [0.9804160215401342, 0.11176106032331021, -0.16215390868808785],
        [0.9804160215401342, 0.11176106032331021, -0.16215390868808785]
        ]

slice1.SliceType.Origin = locations[0]
slice1.SliceType.Normal = normals[0]

vectorValueLUT = GetColorTransferFunction('VectorValue')
vectorValueLUT.RGBPoints = [150.0, 0.231373, 0.298039, 0.752941, 1200.0, 0.865003, 0.865003, 0.865003, 2250.0, 0.705882, 0.0156863, 0.14902]
vectorValueLUT.ScalarRangeInitialized = 1.0

# get opacity transfer function/opacity map for 'VectorValue'
vectorValuePWF = GetOpacityTransferFunction('VectorValue')
vectorValuePWF.Points = [150.0, 0.0, 0.5, 0.0, 2250.0, 1.0, 0.5, 0.0]
vectorValuePWF.ScalarRangeInitialized = 1

slice1Display = Show(slice1, renderView1)
slice1Display.SetRepresentationType('Surface LIC')
slice1Display.ColorArrayName = ['POINTS', 'VectorValue']
slice1Display.LookupTable = vectorValueLUT

for n, location in enumerate(locations):
    slice1.SliceType.Origin = locations[n]
    slice1.SliceType.Normal = normals[n]
    slice1Display.UpdatePipeline()
    filename = 'Mixed_test_{:02d}.png'.format(n)
    SaveScreenshot(filename,
                   magnification=1,
                   quality=100,
                   view=renderView1)
