def from_experiment(experiment, show_lab_frame=True): """Create a 3D scene associated with an experimental setup. :param experiment: an instance of the `Experiment` class with all the setup parameters. :return: a `Scene3d` instance ready to display. """ from pymicro.view.vtk_utils import box_3d, axes_actor, apply_translation_to_actor, detector_3d s3d = Scene3D() if show_lab_frame: # display the coordinate axes axes = axes_actor() s3d.add(axes) # display the sample bb = experiment.sample.geo.get_bounding_box() sample_bb = box_3d(origin=bb[0], size=bb[1]) apply_translation_to_actor(sample_bb, experiment.sample.position) s3d.add(sample_bb) # display the detectors for i in range(experiment.get_number_of_detectors()): det = detector_3d(experiment.detectors[i], show_axes=True, see_reference=False) s3d.add(det) return s3d
import numpy as np import vtk from pymicro.view.vtk_utils import lattice_3d, unit_arrow_3d, axes_actor, text, setup_camera, \ apply_orientation_to_actor, set_opacity from pymicro.view.scene3d import Scene3D from pymicro.crystal.microstructure import Orientation from pymicro.crystal.lattice import Lattice, HklDirection s3d = Scene3D(display=False, ren_size=(600, 600)) s3d.name = 'euler_angles_and_orientation_matrix' euler_angles = np.array([142.8, 32.0, 214.4]) (phi1, Phi, phi2) = euler_angles orientation = Orientation.from_euler(euler_angles) g = orientation.orientation_matrix() lab_frame = axes_actor(1, fontSize=50) lab_frame.SetCylinderRadius(0.02) s3d.add(lab_frame) crystal_frame = axes_actor(0.6, fontSize=50, axisLabels=None) crystal_frame.SetCylinderRadius(0.05) collection = vtk.vtkPropCollection() crystal_frame.GetActors(collection) for i in range(collection.GetNumberOfItems()): collection.GetItemAsObject(i).GetProperty().SetColor(0.0, 0.0, 0.0) apply_orientation_to_actor(crystal_frame, orientation) s3d.add(crystal_frame) a = 1.0 l = Lattice.face_centered_cubic(a) fcc_lattice = lattice_3d(l, crystal_orientation=orientation)
l = Lattice.triclinic(a, b, c, alpha, beta, gamma) triclinic = lattice_3d(l) apply_translation_to_actor(triclinic, (9.5, 9.5, 0.0)) # add actors to the 3d scene s3d.add(cubic) s3d.add(tetragonal) s3d.add(orthorombic) s3d.add(hexagonal) s3d.add(rhombohedral) s3d.add(monoclinic) s3d.add(triclinic) # add axes actor axes = axes_actor(length=0.5) transform = vtk.vtkTransform() transform.Translate(-0.5, -0.5, 0.0) axes.SetUserTransform(transform) s3d.add(axes) # set up camera cam = vtk.vtkCamera() cam.SetViewUp(0, 0, 1) cam.SetPosition(7, 4, 3) cam.SetFocalPoint(5.5, 5.5, 0) cam.SetClippingRange(-20, 20) cam.Dolly(0.2) s3d.set_camera(cam) s3d.render()
calc.add_integ_field(field_name, field) vtk_mesh = calc.build_vtk() # initialize a 3d scene s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name) # create mapper and mesh actor lut = rand_cmap(N=40, first_is_black=False, table_range=(0, 39)) mesh = show_mesh(vtk_mesh, map_scalars=True, lut=lut, show_edges=True, edge_color=(0.2, 0.2, 0.2), edge_line_width=0.5) s3d.add(mesh) # add axes actor axes = axes_actor(50, fontSize=60) s3d.add(axes) # set up camera and render cam = setup_camera(size=(100, 100, 100)) s3d.set_camera(cam) s3d.render() # thumbnail for the image gallery from matplotlib import image image_name = base_name + '.png' image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
Create a 3d scene with a cubic crystal lattice at the center. Hkl planes are added to the lattice and their normal displayed. A sphere is added to show how a pole figure can be constructed. ''' base_name = os.path.splitext(__file__)[0] s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name) orientation = Orientation.from_euler(numpy.array([142.8, 32.0, 214.4])) pf = PoleFigure(hkl='111') pf.microstructure.grains.append(Grain(1, orientation)) pole_figure = pole_figure_3d(pf, radius=1.0, show_lattice=True) # add all actors to the 3d scene s3d.add(pole_figure) axes = axes_actor(1.0, fontSize=60) s3d.add(axes) # set up camera cam = setup_camera(size=(1, 1, 1)) cam.SetViewUp(0, 0, 1) cam.SetPosition(0, -4, 0) cam.SetFocalPoint(0, 0, 0) s3d.set_camera(cam) s3d.render() # thumbnail for the image gallery from matplotlib import image image_name = base_name + '.png' image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
data_dir = '../data' scan_name = 'pure_Ti_216x216x141_uint16.raw' scan_path = os.path.join(data_dir, scan_name) data = HST_read(scan_path, autoparse_filename=True) size = data.shape print 'done reading, volume size is ', size # add all the grains grains = show_grains(data) s3d.add(grains) # add outline outline = box_3d(size=size, line_color=(0., 0., 0.)) s3d.add(outline) # add axes actor axes = axes_actor(0.5 * size[0], fontSize=60) s3d.add(axes) cam = setup_camera(size=(size)) cam.SetPosition(2.0 * size[0], 0.0 * size[1], 2.0 * size[2]) cam.Dolly(0.75) s3d.set_camera(cam) s3d.render() # thumbnail for the image gallery from matplotlib import image image_name = base_name + '.png' image.thumbnail(image_name, 'thumb_' + image_name, 0.2)
''' # create the 3D scene base_name = os.path.splitext(__file__)[0] s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name) # create the unit lattice cell l = Lattice.face_centered_cubic(1.0) # create the slip planes and the cubic lattice actor hklplanes = HklPlane.get_family('111') cubic = lattice_3d_with_planes(l, hklplanes, origin='mid', \ crystal_orientation=None, show_normal=True, plane_opacity=0.5) s3d.add(cubic) # add axes actor axes = axes_actor(0.5, fontSize=50) s3d.add(axes) # set up camera and render cam = setup_camera(size=(1, 1, 1)) cam.SetFocalPoint(0, 0, 0) cam.SetPosition(4, -1.5, 1.5) # change the position to something better cam.Dolly(1.2) # get a little closer s3d.set_camera(cam) s3d.render() # thumbnail for the image gallery from matplotlib import image image_name = base_name + '.png' image.thumbnail(image_name, 'thumb_' + image_name, 0.2)