from vtkmodules.all import *


def main():
    # Setup background
    colors = vtkNamedColors()
    bkg = map(lambda x: x / 255.0, [192, 192, 192, 255])
    colors.SetColor("BkgColor", *bkg)

    # Setup VTK reader
    reader = vtkStructuredGridReader()
    reader.SetFileName(r"media/density.vtk")
    reader.Update()

    # Setup points
    points = vtkPointSource()
    points.SetRadius(5.0)
    points.SetCenter(reader.GetOutput().GetCenter())
    points.SetNumberOfPoints(150)

    # Setup stream tracer
    streamTracer = vtkStreamTracer()
    streamTracer.SetInputConnection(reader.GetOutputPort())
    streamTracer.SetSourceConnection(points.GetOutputPort())
    streamTracer.SetMaximumPropagation(100)

    # Instantiate integrator
    integrator = vtkRungeKutta4()
    streamTracer.SetIntegrator(integrator)
    streamTracer.SetInitialIntegrationStep(0.1)
    streamTracer.SetIntegrationDirectionToBoth()
    streamTracer.Update()

    # Setup Mapper
    mapper = vtkDataSetMapper()
    mapper.SetInputConnection(streamTracer.GetOutputPort())

    # Setup Actors
    actor = vtkActor()
    actor.SetMapper(mapper)

    # Setup renderer
    ren = vtkRenderer()
    ren.AddActor(actor)
    ren.ResetCamera()
    ren.SetBackground(colors.GetColor3d("BkgColor"))

    # Setup renderer window
    renWin = vtkRenderWindow()
    renWin.AddRenderer(ren)

    # Setup window interactor
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    iren.Initialize()

    # Start rendering
    renWin.Render()
    iren.Start()


if __name__ == '__main__':
    main()

from vtkmodules.all import *


def main():
    # Setup background
    colors = vtkNamedColors()
    bkg = map(lambda x: x / 255.0, [192, 192, 192, 255])
    colors.SetColor("BkgColor", *bkg)

    # Setup VTK reader
    reader = vtkStructuredGridReader()
    reader.SetFileName(r"media/density.vtk")
    reader.Update()

    # Setup points
    points = vtkPointSource()
    points.SetRadius(5.0)
    points.SetCenter(reader.GetOutput().GetCenter())
    points.SetNumberOfPoints(150)

    # Setup stream tracer
    streamTracer = vtkStreamTracer()
    streamTracer.SetInputConnection(reader.GetOutputPort())
    streamTracer.SetSourceConnection(points.GetOutputPort())
    streamTracer.SetMaximumPropagation(100)

    # Instantiate integrator
    integrator = vtkRungeKutta4()
    streamTracer.SetIntegrator(integrator)
    streamTracer.SetInitialIntegrationStep(0.1)
    streamTracer.SetIntegrationDirectionToBoth()
    streamTracer.Update()

    # Setup Mapper
    mapper = vtkDataSetMapper()
    mapper.SetInputConnection(streamTracer.GetOutputPort())

    # Setup Actors
    actor = vtkActor()
    actor.SetMapper(mapper)

    # Setup renderer
    ren = vtkRenderer()
    ren.AddActor(actor)
    ren.ResetCamera()
    ren.SetBackground(colors.GetColor3d("BkgColor"))

    # Setup renderer window
    renWin = vtkRenderWindow()
    renWin.AddRenderer(ren)

    # Setup window interactor
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    iren.Initialize()

    # Start rendering
    renWin.Render()
    iren.Start()


if __name__ == '__main__':
    main()

# Setup background # Setup VTK reader # Setup points # Setup stream tracer # Instantiate integrator # Setup Mapper # Setup Actors # Setup renderer # Setup renderer window # Setup window interactor # Start rendering