#--------------------------------------------------------------------------------------- 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 surface = Surface() engine.add_module(surface, obj=None) # Set timestep for visualisation # only depends on pvtu, choose random pvtu and then set time step #vtkxml_file_reader = engine.scenes[0].children[0] #vtkxml_file_reader.name = 'VTK XML file (ForwardRemesh100M20L0004.pvtu) (timeseries)' #vtkxml_file_reader.file_path = '/Volumes/esd01/docs/jloos/data_small/runs_elmerice_refined/Mesh20_5001000_0_0.1/Mesh/ForwardRemesh100M20L0004.pvtu' vtkxml_file_reader.timestep = 3
# 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()
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