Exemplo n.º 1
0
    def __init__(self, new_engine=False, param=None):
        '''
        Input:
            param: object of GraphPlotParam class
        '''
        if param is None:
            param = GraphPlotParam()

        self.TubeColor = param.TubeColor
        self.TubeRadius = param.TubeRadius
        self.GylphColor = param.GylphColor
        self.GylphSize = param.GylphSize

        self.TubeMode = {
            'radius_by_scale': False,
            'radius_by_color': False,
            'type_by_color': False,
            'branching_by_color': False,
            'flow_by_color': False,
            'pressure_by_color': False
        }

        # start engine
        if new_engine:
            from mayavi.core.api import Engine
            e = Engine()
            e.start()

        # source
        self.DataSource = scalar_scatter([], [], [])
        self.Data = self.DataSource.data
        self.Nodes = self.Data.points
        self.Edges = self.Data.lines

        #modules
        self.Glyph = glyph(self.DataSource)
        self.Glyph.glyph.glyph.clamping = True
        self.Glyph.glyph.glyph.scale_factor = 2.0
        self.Glyph.glyph.glyph.range = np.array([0., 1.])
        self.Glyph.glyph.color_mode = 'no_coloring'
        self.Glyph.glyph.scale_mode = 'data_scaling_off'
        self.Glyph.actor.property.representation = 'wireframe'
        self.Glyph.actor.property.color = (0.75, 0.25, 0.25)
        self.Tube = tube(self.Glyph, tube_radius=self.TubeRadius)
        self.TubeSurface = surface(self.Tube, color=self.TubeColor)
        self.Tube.filter.vary_radius = 'vary_radius_off'
        self.TubeSurface.actor.mapper.scalar_visibility = False
Exemplo n.º 2
0
    def __init__(self, s=None, param=None, new_engine=False):
        '''
        input: 
            param: object from StackPlotParam
        '''

        # if s is None:
        #     print('Noe input surface model')
        #     return

        if param is None:
            param = StackPlotParam()

        self.SurfaceColor = param.SurfaceColor
        self.SurfaceOpacity = param.SurfaceOpacity

        # start engine
        if new_engine:
            from mayavi.core.api import Engine
            e = Engine()
            e.start()

        # source
        self.DataSource = scalar_field(
            (np.random.rand(5, 5, 5) > 0.5).astype(int))
        self.DataSource.origin = [0, 0, 0]
        self.Data = self.DataSource.scalar_data
        self.DataSource.origin = np.array([0, 0, 0])

        #modules
        self.Contour = contour(self.DataSource)
        self.Contour.filter.contours = []
        self.Contour.filter.contours = [0.5]
        self.Contour.filter.auto_update_range = False

        self.Surface = None

        self.__UpdateSurface()
Exemplo n.º 3
0
def main():
    # Create the MayaVi engine and start it.
    e = Engine()
    # Starting the engine registers the engine with the registry and
    # notifies others that the engine is ready.
    e.start()

    # Do this if you need to see the MayaVi tree view UI.
    ev = EngineView(engine=e)
    ui = ev.edit_traits()

    # Create a new scene.
    #scene = e.new_scene()
    #renderLearningData('pattern.json')
    #scene = e.new_scene()
    #renderLearningData('pattern2.json')
    #renderLearningData('pattern3.json')
    scene = e.new_scene()
    ExampleRenderer('cluster.json', scene)
    scene = e.new_scene()
    ExampleRenderer('nocluster.json', scene)
    show()
    return e, ui
Exemplo n.º 4
0
def main():
    # Create the MayaVi engine and start it.
    e = Engine()
    # Starting the engine registers the engine with the registry and
    # notifies others that the engine is ready.
    e.start()

    # Do this if you need to see the MayaVi tree view UI.
    ev = EngineView(engine=e)
    ui = ev.edit_traits()

    # Create a new scene.
    scene = e.new_scene()
    # Now create a new scene just for kicks.
    scene1 = e.new_scene()

    # Now setup a normal MayaVi pipeline.
    src = VTKXMLFileReader()
    src.initialize(join(get_data_dir(abspath(__file__)),
                        'fire_ug.vtu'))
    e.add_source(src)
    e.add_module(Outline())
    e.add_module(ScalarCutPlane())
    e.add_module(Streamline())
    return e, ui
Exemplo n.º 5
0
def main():
    # Create the MayaVi engine and start it.
    e = Engine()
    # Starting the engine registers the engine with the registry and
    # notifies others that the engine is ready.
    e.start()

    # Do this if you need to see the MayaVi tree view UI.
    ev = EngineView(engine=e)
    ui = ev.edit_traits()

    # Create a new scene.
    scene = e.new_scene()
    # Now create a new scene just for kicks.
    scene1 = e.new_scene()

    # Now setup a normal MayaVi pipeline.
    src = VTKXMLFileReader()
    src.initialize(join(get_data_dir(abspath(__file__)),
                        'fire_ug.vtu'))
    e.add_source(src)
    e.add_module(Outline())
    e.add_module(ScalarCutPlane())
    e.add_module(Streamline())
    return e, ui
Exemplo n.º 6
0
Created on Fri Dec 21 12:59:31 2018

@author: Schmulius
"""
from mayavi.modules.scalar_cut_plane import ScalarCutPlane

from pyface.timer.api import Timer
from mayavi.core.api import Engine

from mayavi.core.base import Base
from mayavi.core.module import Module
from mayavi.core.lut_manager import LUTManager
from mayavi.core.common import handle_children_state, exception
from mayavi.core.pipeline_info import PipelineInfo

scp = Engine()
scp.start()
scene = scp.new_scene()

scp = ScalarCutPlane()  # set scp as ScalarCutPlane() module
# add module to the scene
scp.implicit_plane.normal = (1, 0, 0)  # set normal to Ox axis
# set origin to (i=10, j=25, k=25) i.e. integers for a structured grid
scp.implicit_plane.origin = (10, 25, 25)
# set origin to (x=1.0, y=2.5, z=2.5) i.e. reals for unstructured grids
# scp.implicit_plane.origin = (1.0, 2.5, 2.5)
scp.implicit_plane.widget.enabled = True
scp.actor.property.diffuse = 0.0  # set some color properties
scp.actor.property.ambient = 1.0  #
scp.actor.property.opacity = 1.0  #
#scp.module_manager.scalar_lut_manager.data_range = [0, 1]
Exemplo n.º 7
0
# -*- coding: utf-8 -*-
"""
Spyder Editor
"""

import os
from mayavi.core.api import Engine
from mayavi.sources.vtk_file_reader import VTKFileReader
from mayavi.modules.surface import Surface

vtkFile_l = '/Users/richad/bin/lh.vtk'
vtkFile_r = '/Users/richad/bin/rh.vtk'

# Create the MayaVi engine and start it.
engine = Engine()
engine.start()
#scene = engine.new_scene()

# Read in VTK file and add as source
surface1 = Surface()
reader1 = VTKFileReader()
reader1.initialize(vtkFile_l)
engine.add_source(reader1)
engine.add_filter(surface1, reader1)

surface2 = Surface()
reader2 = VTKFileReader()
reader2.initialize(vtkFile_r)
engine.add_source(reader2)
engine.add_filter(surface2, reader2)
#import networkx as nx
import os
from mayavi.core.api import Engine
from mayavi.sources.vtk_file_reader import VTKFileReader
from mayavi.modules.surface import Surface

vtkFile = 'flow.vtk'

# Create the MayaVi engine and start it.
engine = Engine()
engine.start()
scene = engine.new_scene()

# Read in VTK file and add as source
reader = VTKFileReader()
reader.initialize(vtkFile)
engine.add_source(reader)

# Add Surface Module
surface = Surface()
engine.add_module(surface)

# Move the camera
scene.scene.camera.elevation(-70)

# Save scene to image file
scene.scene.save_png('image.png')

# Create a GUI instance and start the event loop.
# This stops the window from closing
from enthought.pyface.api import GUI
gui = GUI()
Exemplo n.º 9
0
from mayavi.mlab import *
from os.path import join, dirname
import numpy

import sys
import vtk
from mayavi.sources.vtk_file_reader import VTKFileReader
from mayavi.sources.api import VTKXMLFileReader
import os
from pyface.timer.api import Timer
from mayavi.core.api import Engine
from mayavi.sources.vtk_file_reader import VTKFileReader
from mayavi.modules.surface import Surface
from mayavi.modules.scalar_cut_plane import ScalarCutPlane

engine = Engine()
engine.start()
scene = engine.new_scene()

#vtkFile = 'simple.vtk'
vtkFile = '/volumes/esd01/docs/jloos/data_small/runs_elmerice_refined/Mesh60_200500_0/Bump_0001.pvtu'

#reader = VTKFileReader()
#reader = VTKXMLFileReader()

#reader.initialize(vtkFile)
#engine.add_source(reader)

# Add Surface Module
#surface = Surface()
#engine.add_module(surface),
Exemplo n.º 10
0
"""
Created on Mon Jan  4 18:14:18 2016

@author: ethansolomon
"""

import os
from mayavi.core.api import Engine
from mayavi.sources.vtk_file_reader import VTKFileReader
from mayavi.modules.surface import Surface

vtkFile_l = 'lh.vtk'
vtkFile_r = 'rh.vtk'

# Create the MayaVi engine and start it.
engine = Engine()
engine.start()
scene = engine.new_scene()

# Read in VTK file and add as source
reader1 = VTKFileReader()
reader1.initialize(vtkFile_l)
engine.add_source(reader1)

# Add Surface Module
surface = Surface()
engine.add_module(surface)

# Move the camera
scene.scene.camera.elevation(90)
scene.scene.camera.azimuth(-180)
Exemplo n.º 11
0
# mlab surface defined with the points and element
surface = mlab.pipeline.triangular_mesh_source(points[:,0], points[:,1], points[:,2], element) 

# For readability, define a variable as the _vtk_obj from the surface.
# This will be the surface data in the .stl file.
surface_vtk = surface.outputs[0]._vtk_obj

stlWriter = vtk.vtkSTLWriter()
# Set the file name
stlWriter.SetFileName('test_surface.stl')
# Set the input for the stl writer. surface.output[0]._vtk_obj is a polydata object
stlWriter.SetInput(surface_vtk)
# Write the stl file
stlWriter.Write()

# View the .stl surface that was just written-----------------------------------------------
from mayavi.core.api import Engine

engine = Engine()
# Create a new figure and add that figure to the engine
fig = mlab.figure(engine = engine)
# Open the stl file
surface_data = engine.open('test_surface.stl')
# Add the opened surface to the pipeline
opened_surface = mlab.pipeline.surface(surface_data)
# Add a module to show the opened surface
mlab.pipeline.surface(opened_surface, figure = fig)
# Show the scene
mlab.show()
Exemplo n.º 12
0
from mayavi.core.module import Module
from mayavi.core.lut_manager import LUTManager
from mayavi.core.common import handle_children_state, exception
from mayavi.core.pipeline_info import PipelineInfo
from mayavi import mlab
from mayavi import tools
from numpy import array

#---------------------------------------------------------------------------------------
#__________________________________ start mayavi engine _______________________________#
#---------------------------------------------------------------------------------------
try:
    engine = mayavi.engine
except NameError:
    from mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()

#---------------------------------------------------------------------------------------
#__________________________________ load data ____________________________________#
#---------------------------------------------------------------------------------------

vtkxml_file_reader = engine.open(
    '/Volumes/esd01/docs/jloos/data_small/runs_elmerice_refined/Mesh20_5001000_0_0.1/Mesh/ForwardRemesh100M20L0011.pvtu'
)
# Set time-step for visualisation; depending on simulation setting time-step cann range between
# 0.1 and 0.5 = 2 (two time sizes 1a)
from mayavi.modules.surface import Surface
Exemplo n.º 13
0
from mayavi import mlab


# View the .stl surface that was just written-----------------------------------------------
from mayavi.core.api import Engine

# Create an engine
engine = Engine()

# Create a new figure and add that figure to the engine
#fig = mlab.figure(engine = engine)

# Open the stl file
surface_data = engine.open('Crystal I - polyhedronp.stl')

# Add the opened surface to the pipeline
opened_surface = mlab.pipeline.surface(surface_data,representation='surface')
opened_surface.actor.property.specular = .99
opened_surface.actor.property.specular_power = 100 #15.0
opened_surface.actor.property.specular_color = (1, 1, 1)
opened_surface.actor.property.diffuse = .8
opened_surface.actor.property.ambient = 0
opened_surface.actor.property.interpolation = 'phong'



# Lighting
lm = engine.current_scene.scene.light_manager
lm.number_of_lights = 4
ABCDangle = 30