Exemplo n.º 1
0
 def __init__(self, args):
     '''Init a new View window.'''
     #print(args)
     # create the 3D scene
     s3d = Scene3D(display=True, ren_size=(800, 800))
     if isinstance(args, list):
         if len(args) == 1:
             print(
                 'Please specify the file representing the 3D object to view'
             )
             sys.exit(1)
         elif len(args) == 2:
             file_path = args[1]
         else:
             print(
                 'Please use only one parameter (the path to the file representing the 3D object to view)'
             )
             sys.exit(1)
         (path, ext) = os.path.splitext(file_path)
         ext = ext.strip('.')
         print(ext)
         if ext in ['stl', 'STL']:
             actor = load_STL_actor(path, ext)
         else:
             print('Unrecognized file extenstion: %s' % ext)
             sys.exit(1)
     elif isinstance(args, Grain):
         actor = grain_3d(args)
     elif isinstance(args, Orientation):
         l = Lattice.cubic(1.0)
         (a, b, c) = l._lengths
         grid = lattice_grid(l)
         actor = lattice_edges(grid)
         actor.SetOrigin(a / 2, b / 2, c / 2)
         actor.AddPosition(-a / 2, -b / 2, -c / 2)
         apply_orientation_to_actor(actor, args)
     elif isinstance(args, Lattice):
         (a, b, c) = args._lengths
         actor = lattice_3d(args)
         actor.SetOrigin(a / 2, b / 2, c / 2)
         actor.AddPosition(-a / 2, -b / 2, -c / 2)
     elif isinstance(args, np.ndarray):
         actor = show_array(args)
     elif isinstance(args, vtk.vtkActor):
         actor = args
     else:
         raise ValueError('unsupported object type: {0}'.format(type(args)))
     bounds = actor.GetBounds()
     size = (bounds[1] - bounds[0], bounds[3] - bounds[2],
             bounds[5] - bounds[4])  # bounds[1::2]
     print(size)
     axes = axes_actor(length=np.mean(size), fontSize=60)
     s3d.add(axes)
     s3d.add(actor)
     cam = setup_camera(size)
     cam.SetFocalPoint(0.5 * (bounds[0] + bounds[1]),
                       0.5 * (bounds[2] + bounds[3]),
                       0.5 * (bounds[4] + bounds[5]))
     s3d.set_camera(cam)
     s3d.render(key_pressed_callback=True)
Exemplo n.º 2
0
    def __init__(self, arg):
        """Init a new View window.

        :param arg: a descriptor of the object to view, it can be an instance of `Grain`, `Orientation`, `Lattice`,
        a vtkActor, a 3D numpy array or the path to a STL file.
        """
        # create the 3D scene
        s3d = Scene3D(display=True, ren_size=(800, 800))
        if isinstance(arg, str):
            (path, ext) = os.path.splitext(arg)
            ext = ext.strip('.')
            print(ext)
            if ext in ['stl', 'STL']:
                actor = load_STL_actor(path, ext)
            else:
                print('Unrecognized file extension: %s' % ext)
                sys.exit(1)
        elif isinstance(arg, Grain):
            actor = grain_3d(arg)
        elif isinstance(arg, Orientation):
            l = Lattice.cubic(1.0)
            (a, b, c) = l._lengths
            grid = lattice_grid(l)
            actor = lattice_edges(grid)
            actor.SetOrigin(a / 2, b / 2, c / 2)
            actor.AddPosition(-a / 2, -b / 2, -c / 2)
            apply_orientation_to_actor(actor, arg)
        elif isinstance(arg, Lattice):
            (a, b, c) = arg._lengths
            actor = lattice_3d(arg)
            actor.SetOrigin(a / 2, b / 2, c / 2)
            actor.AddPosition(-a / 2, -b / 2, -c / 2)
        elif isinstance(arg, np.ndarray):
            if arg.ndim != 3:
                print('Only 3D arrays can be viewed with this method.')
                sys.exit(1)
            actor = show_array(arg)
        elif isinstance(arg, vtk.vtkActor):
            actor = arg
        else:
            raise ValueError('unsupported object type: {0}'.format(type(arg)))
        bounds = actor.GetBounds()
        size = (bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4])  # bounds[1::2]
        print(size)
        axes = axes_actor(length=np.mean(size), fontSize=60)
        s3d.add(axes)
        s3d.add(actor)
        cam = setup_camera(size)
        cam.SetFocalPoint(0.5 * (bounds[0] + bounds[1]), 0.5 * (bounds[2] + bounds[3]), 0.5 * (bounds[4] + bounds[5]))
        s3d.set_camera(cam)
        s3d.render(key_pressed_callback=True)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
from pymicro.view.scene3d import Scene3D
from pymicro.view.vtk_utils import *
from vtk.util.colors import white, grey, black, lamp_black

if __name__ == '__main__':
    '''
    Create a 3d scene with a tomographic view of a polymer foam.
    The shape is displayed using a simple contour filter. Bounding box
    and axes are also added to the scene.
    '''

    # Create the 3D scene
    base_name = os.path.splitext(__file__)[0]
    s3d = Scene3D(display=False,
                  ren_size=(800, 800),
                  name=base_name,
                  background=black)

    data_dir = '../data'
    scan = 'mousse_250x250x250_uint8.raw'
    im_file = os.path.join(data_dir, scan)
    s_size = scan[:-4].split('_')[-2].split('x')
    s_type = scan[:-4].split('_')[-1]
    size = [int(s_size[0]), int(s_size[1]), int(s_size[2])]
    data = read_image_data(im_file, size, data_type=s_type, verbose=True)

    print 'adding bounding box'
    outline = data_outline(data)
    outline.GetProperty().SetColor(white)
    s3d.add(outline)
Exemplo n.º 5
0
from math import sqrt
import numpy as np
from pymicro.view.scene3d import Scene3D
from pymicro.view.vtk_utils import *
from pymicro.crystal.lattice import HklPlane
from pymicro.crystal.microstructure import Orientation
'''
Create a 3d scene with a hexagonal crystal lattice.
The usual hexagonal prism is displayed with the unit cell highlighted.
'''
# Create the 3D scene
base_name = os.path.splitext(__file__)[0]
s3d = Scene3D(display=False, ren_size=(800, 800), name=base_name)

# hexagonal lattice
a = 0.295  # nm
c = 0.468  # nm
l = Lattice.hexagonal(a, c)
l._basis = [(0., 0., 0.), (2. / 3, 1. / 3, 1. / 2)]  # hexagonal compact basis

hcp1 = vtk.vtkAssembly()
grid = lattice_grid(l)
Vertices1 = lattice_vertices(grid, sphereRadius=0.1 * a)
Vertices1.GetProperty().SetColor(0, 0, 0)
# hcp1.AddPart(Edges1)
hcp1.AddPart(Vertices1)
hcp1.RotateZ(180)
offset = l.matrix[0] + l.matrix[1]
hcp1.SetOrigin(offset)
hcp1.AddPosition(-offset)
s3d.add(hcp1)
Exemplo n.º 6
0
probe_mapper.SetScalarModeToUseCellData()
probe_mapper.ScalarVisibilityOn()
probe_mapper.SetScalarRange(field_min, field_max)
probeActor = vtk.vtkActor()
probeActor.SetMapper(probe_mapper)

# color bar
bar = color_bar(field, lut, fmt, num_labels=5, font_size=20)

# create axes actor
axes = axes_actor(5.0, fontSize=60)
apply_translation_to_actor(axes, (-15, 0, 0))

# create the 3D scene
base_name = os.path.splitext(__file__)[0]
s3d = Scene3D(display=False)
s3d.add(probeActor)
s3d.add(axes)
s3d.add(bar)
s3d.name = base_name
s3d.renWin.SetSize(800, 800)

cam = setup_camera(size=size)
cam.SetFocalPoint(0., -3., 0.)
cam.SetViewUp(0., 1., 0.)
cam.SetPosition([-45., 20., 55.])

s3d.set_camera(cam)
s3d.render()

# thumbnail for the image gallery
Exemplo n.º 7
0
from pymicro.view.vtk_utils import *
from pymicro.view.vtk_anim import *
from pymicro.view.scene3d import Scene3D
from pymicro.crystal.microstructure import Orientation
from pymicro.crystal.lattice import Lattice

s3d = Scene3D(display=True, ren_size=(600, 600))
euler_angles = np.array([142.8, 32.0, 214.4])
(phi1, Phi, phi2) = euler_angles
orientation = Orientation.from_euler(euler_angles)

scene = vtkAnimationScene(s3d.get_renderer(), s3d.renWin.GetSize())
scene.save_image = True
scene.timer_incr = 1
scene.timer_end = 179
scene.verbose = False
scene.prefix = 'euler_angles_anim'

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.04)
collection = vtk.vtkPropCollection()
crystal_frame.GetActors(collection)
for i in range(collection.GetNumberOfItems()):
    collection.GetItemAsObject(i).GetProperty().SetColor(0.0, 0.0, 0.0)
crystal_frame.SetVisibility(0)
s3d.add(crystal_frame)