<filename>PyMieSim/Tools/Plots.py
import numpy    as np
from mayavi     import mlab
from tvtk.tools import visual
import mayavi

from PyMieSim.Tools.PlotsUtils  import *


def ConfigScene(Figure):
    Figure.scene.camera.position = [7.753408373270355, 5.411094810050305, 6.741205673921455]
    Figure.scene.camera.focal_point = [2.548315108254079, -0.3408664124878614, -1.4290773273122794]
    Figure.scene.camera.view_angle = 30.0
    Figure.scene.camera.view_up = [0.886604810463808, -0.2862046807226228, -0.36334390155181734]
    Figure.scene.camera.clipping_range = [0.02607868406541729, 26.078684065417292]


def UnstructuredAmplitude(Mesh, Scalar = None, Name = '', Source=True, Axes=True):
    Figure = mlab.figure(figure=None, size=(600,300))

    visual.set_viewer(Figure)
    UnstructuredMesh(Scalar, Mesh.CartCoord[0], Mesh.CartCoord[1], Mesh.CartCoord[2], Source, Axes, (0,2,0), Figure, Name='Etheta', Orientation='vertical')

    mlab.show()


def UnstructuredMesh(Scalar, x, y, z, Source, Axes, Origin, Figure, Name = '', ColorMap='RdBu', ColorBar=True, Orientation='vertical'):
    ImReal = mlab.points3d(x-3, y, z, Scalar.real, mode = 'sphere', scale_mode = 'none', colormap = CMAP)

    ImImag = mlab.points3d(x+3, y, z, Scalar.imag, mode = 'sphere', scale_mode = 'none', colormap = CMAP)



    mlab.text3d(-3, 0, 3, 'Real', scale = 0.5)
    mlab.text3d(+3, 0, 3, 'Imag', scale = 0.5)

    if ColorBar == True:
        mlab.colorbar(object            = ImReal,
                      label_fmt         = "%.0e",
                      nb_labels         = 5,
                      title             = f'Real part',
                      orientation       = 'vertical' )

        mlab.colorbar(object            = ImImag,
                      label_fmt         = "%.0e",
                      nb_labels         = 5,
                      title             = f'Imag part',
                      orientation       = 'horizontal' )


    if Source is not False:
        WavenumberArrow(Figure, Origin=(-3,0,-3), Scale=1)
        WavenumberArrow(Figure, Origin=(+3,0,-3), Scale=1)

    if Axes is not False:
        AddUnitSphere(Num = 50, Radius = 1., Origin = (-3, 0, 0), Figure = Figure)
        AddUnitSphere(Num = 50, Radius = 1., Origin = (+3, 0, 0), Figure = Figure)

    ConfigScene(Figure)

    return Figure, 0


def StructuredMesh(x, y, z, Source, Axes, Origin, Figure, ColorMap='RdBu', ColorBar=True, Scalar=None, Orientation='vertical'):
    if Scalar is not None:
        im = mlab.mesh(x, y+Origin[1], z, scalars=Scalar, colormap=ColorMap, figure=Figure)
    else:
        im = mlab.mesh(x, y+Origin[1], z, colormap=ColorMap, figure=Figure)

    mlab.mesh(x, y+Origin[1], z, representation='wireframe', color=(0, 0, 0), line_width=0.05, figure=Figure, opacity=0.01)

    if Axes is not False:
        AddUnitAxes(Figure=Figure, Scale=2.5, Origin=Origin, ScaleTube=0.7)

    ConfigScene(Figure)

    return Figure, im


# -

<filename>PyMieSim/Tools/Plots.py
import numpy    as np
from mayavi     import mlab
from tvtk.tools import visual
import mayavi

from PyMieSim.Tools.PlotsUtils  import *


def ConfigScene(Figure):
    Figure.scene.camera.position = [7.753408373270355, 5.411094810050305, 6.741205673921455]
    Figure.scene.camera.focal_point = [2.548315108254079, -0.3408664124878614, -1.4290773273122794]
    Figure.scene.camera.view_angle = 30.0
    Figure.scene.camera.view_up = [0.886604810463808, -0.2862046807226228, -0.36334390155181734]
    Figure.scene.camera.clipping_range = [0.02607868406541729, 26.078684065417292]


def UnstructuredAmplitude(Mesh, Scalar = None, Name = '', Source=True, Axes=True):
    Figure = mlab.figure(figure=None, size=(600,300))

    visual.set_viewer(Figure)
    UnstructuredMesh(Scalar, Mesh.CartCoord[0], Mesh.CartCoord[1], Mesh.CartCoord[2], Source, Axes, (0,2,0), Figure, Name='Etheta', Orientation='vertical')

    mlab.show()


def UnstructuredMesh(Scalar, x, y, z, Source, Axes, Origin, Figure, Name = '', ColorMap='RdBu', ColorBar=True, Orientation='vertical'):
    ImReal = mlab.points3d(x-3, y, z, Scalar.real, mode = 'sphere', scale_mode = 'none', colormap = CMAP)

    ImImag = mlab.points3d(x+3, y, z, Scalar.imag, mode = 'sphere', scale_mode = 'none', colormap = CMAP)



    mlab.text3d(-3, 0, 3, 'Real', scale = 0.5)
    mlab.text3d(+3, 0, 3, 'Imag', scale = 0.5)

    if ColorBar == True:
        mlab.colorbar(object            = ImReal,
                      label_fmt         = "%.0e",
                      nb_labels         = 5,
                      title             = f'Real part',
                      orientation       = 'vertical' )

        mlab.colorbar(object            = ImImag,
                      label_fmt         = "%.0e",
                      nb_labels         = 5,
                      title             = f'Imag part',
                      orientation       = 'horizontal' )


    if Source is not False:
        WavenumberArrow(Figure, Origin=(-3,0,-3), Scale=1)
        WavenumberArrow(Figure, Origin=(+3,0,-3), Scale=1)

    if Axes is not False:
        AddUnitSphere(Num = 50, Radius = 1., Origin = (-3, 0, 0), Figure = Figure)
        AddUnitSphere(Num = 50, Radius = 1., Origin = (+3, 0, 0), Figure = Figure)

    ConfigScene(Figure)

    return Figure, 0


def StructuredMesh(x, y, z, Source, Axes, Origin, Figure, ColorMap='RdBu', ColorBar=True, Scalar=None, Orientation='vertical'):
    if Scalar is not None:
        im = mlab.mesh(x, y+Origin[1], z, scalars=Scalar, colormap=ColorMap, figure=Figure)
    else:
        im = mlab.mesh(x, y+Origin[1], z, colormap=ColorMap, figure=Figure)

    mlab.mesh(x, y+Origin[1], z, representation='wireframe', color=(0, 0, 0), line_width=0.05, figure=Figure, opacity=0.01)

    if Axes is not False:
        AddUnitAxes(Figure=Figure, Scale=2.5, Origin=Origin, ScaleTube=0.7)

    ConfigScene(Figure)

    return Figure, im


# -
