本文整理汇总了Python中mayavi.mlab.view方法的典型用法代码示例。如果您正苦于以下问题:Python mlab.view方法的具体用法?Python mlab.view怎么用?Python mlab.view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mayavi.mlab
的用法示例。
在下文中一共展示了mlab.view方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_lidar_simple
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def draw_lidar_simple(pc, color=None):
''' Draw lidar points. simplest set up. '''
fig = mlab.figure(figure=None, bgcolor=(0,0,0), fgcolor=None, engine=None, size=(1600, 1000))
if color is None: color = pc[:,2]
#draw points
mlab.points3d(pc[:,0], pc[:,1], pc[:,2], color, color=None, mode='point', colormap = 'gnuplot', scale_factor=1, figure=fig)
#draw origin
mlab.points3d(0, 0, 0, color=(1,1,1), mode='sphere', scale_factor=0.2)
#draw axis
axes=np.array([
[2.,0.,0.,0.],
[0.,2.,0.,0.],
[0.,0.,2.,0.],
],dtype=np.float64)
mlab.plot3d([0, axes[0,0]], [0, axes[0,1]], [0, axes[0,2]], color=(1,0,0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[1,0]], [0, axes[1,1]], [0, axes[1,2]], color=(0,1,0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[2,0]], [0, axes[2,1]], [0, axes[2,2]], color=(0,0,1), tube_radius=None, figure=fig)
mlab.view(azimuth=180, elevation=70, focalpoint=[ 12.0909996 , -1.04700089, -2.03249991], distance=62.0, figure=fig)
return fig
示例2: render_body
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def render_body(self):
from mayavi import mlab
body = self.to_body()
mask, bounds = body.get_seeded_component(CONFIG.postprocessing.closing_shape)
fig = mlab.figure(size=(1280, 720))
if self.target is not None:
target_grid = mlab.pipeline.scalar_field(self.target)
target_grid.spacing = CONFIG.volume.resolution
target_grid = mlab.pipeline.iso_surface(target_grid, contours=[0.5], color=(1, 0, 0), opacity=0.1)
grid = mlab.pipeline.scalar_field(mask)
grid.spacing = CONFIG.volume.resolution
mlab.pipeline.iso_surface(grid, color=(0, 1, 0), contours=[0.5], opacity=0.6)
mlab.orientation_axes(figure=fig, xlabel='Z', zlabel='X')
mlab.view(azimuth=45, elevation=30, focalpoint='auto', roll=90, figure=fig)
mlab.show()
示例3: draw_gt_boxes3d
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def draw_gt_boxes3d(gt_boxes3d, fig, color=(1,1,1), line_width=2, draw_text=True, text_scale=(1,1,1), color_list=None):
''' Draw 3D bounding boxes
Args:
gt_boxes3d: numpy array (n,8,3) for XYZs of the box corners
fig: mayavi figure handler
color: RGB value tuple in range (0,1), box line color
line_width: box line width
draw_text: boolean, if true, write box indices beside boxes
text_scale: three number tuple
color_list: a list of RGB tuple, if not None, overwrite color.
Returns:
fig: updated fig
'''
num = len(gt_boxes3d)
for n in range(num):
b = gt_boxes3d[n]
if color_list is not None:
color = color_list[n]
if draw_text: mlab.text3d(b[4,0], b[4,1], b[4,2], '%d'%n, scale=text_scale, color=color, figure=fig)
for k in range(0,4):
#http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html
i,j=k,(k+1)%4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
i,j=k+4,(k+1)%4 + 4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
i,j=k,k+4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
#mlab.show(1)
#mlab.view(azimuth=180, elevation=70, focalpoint=[ 12.0909996 , -1.04700089, -2.03249991], distance=62.0, figure=fig)
return fig
示例4: show_lidar_with_boxes
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def show_lidar_with_boxes(pc_velo, objects, calib,
img_fov=False, img_width=None, img_height=None, fig=None):
''' Show all LiDAR points.
Draw 3d box in LiDAR point cloud (in velo coord system) '''
if not fig:
fig = mlab.figure(figure="KITTI_POINT_CLOUD", bgcolor=(0,0,0), fgcolor=None, engine=None, size=(1250, 550))
if img_fov:
pc_velo = get_lidar_in_image_fov(pc_velo, calib, 0, 0, img_width, img_height)
draw_lidar(pc_velo, fig1=fig)
for obj in objects:
if obj.type=='DontCare':continue
# Draw 3d bounding box
box3d_pts_2d, box3d_pts_3d = kitti_utils.compute_box_3d(obj, calib.P)
box3d_pts_3d_velo = calib.project_rect_to_velo(box3d_pts_3d)
# Draw heading arrow
ori3d_pts_2d, ori3d_pts_3d = kitti_utils.compute_orientation_3d(obj, calib.P)
ori3d_pts_3d_velo = calib.project_rect_to_velo(ori3d_pts_3d)
x1,y1,z1 = ori3d_pts_3d_velo[0,:]
x2,y2,z2 = ori3d_pts_3d_velo[1,:]
draw_gt_boxes3d([box3d_pts_3d_velo], fig=fig, color=(0,1,1), line_width=2, draw_text=False)
mlab.plot3d([x1, x2], [y1, y2], [z1,z2], color=(0.5,0.5,0.5), tube_radius=None, line_width=1, figure=fig)
mlab.view(distance=90)
示例5: plot_sphere_func
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def plot_sphere_func(f, grid='Clenshaw-Curtis', beta=None, alpha=None, colormap='jet', fignum=0, normalize=True):
#TODO: All grids except Clenshaw-Curtis have holes at the poles
# TODO: update this function now that we changed the order of axes in f
import matplotlib
matplotlib.use('WxAgg')
matplotlib.interactive(True)
from mayavi import mlab
if normalize:
f = (f - np.min(f)) / (np.max(f) - np.min(f))
if grid == 'Driscoll-Healy':
b = f.shape[0] / 2
elif grid == 'Clenshaw-Curtis':
b = (f.shape[0] - 2) / 2
elif grid == 'SOFT':
b = f.shape[0] / 2
elif grid == 'Gauss-Legendre':
b = (f.shape[0] - 2) / 2
if beta is None or alpha is None:
beta, alpha = meshgrid(b=b, grid_type=grid)
alpha = np.r_[alpha, alpha[0, :][None, :]]
beta = np.r_[beta, beta[0, :][None, :]]
f = np.r_[f, f[0, :][None, :]]
x = np.sin(beta) * np.cos(alpha)
y = np.sin(beta) * np.sin(alpha)
z = np.cos(beta)
mlab.figure(fignum, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(600, 400))
mlab.clf()
mlab.mesh(x, y, z, scalars=f, colormap=colormap)
#mlab.view(90, 70, 6.2, (-1.3, -2.9, 0.25))
mlab.show()
示例6: draw_gt_boxes3d
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def draw_gt_boxes3d(gt_boxes3d, fig, color=(1,1,1), line_width=1, draw_text=True, text_scale=(1,1,1), color_list=None):
''' Draw 3D bounding boxes
Args:
gt_boxes3d: numpy array (n,8,3) for XYZs of the box corners
fig: mayavi figure handler
color: RGB value tuple in range (0,1), box line color
line_width: box line width
draw_text: boolean, if true, write box indices beside boxes
text_scale: three number tuple
color_list: a list of RGB tuple, if not None, overwrite color.
Returns:
fig: updated fig
'''
num = len(gt_boxes3d)
for n in range(num):
b = gt_boxes3d[n]
if color_list is not None:
color = color_list[n]
if draw_text: mlab.text3d(b[4,0], b[4,1], b[4,2], '%d'%n, scale=text_scale, color=color, figure=fig)
for k in range(0,4):
#http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html
i,j=k,(k+1)%4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
i,j=k+4,(k+1)%4 + 4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
i,j=k,k+4
mlab.plot3d([b[i,0], b[j,0]], [b[i,1], b[j,1]], [b[i,2], b[j,2]], color=color, tube_radius=None, line_width=line_width, figure=fig)
#mlab.show(1)
#mlab.view(azimuth=180, elevation=70, focalpoint=[ 12.0909996 , -1.04700089, -2.03249991], distance=62.0, figure=fig)
return fig
示例7: test_surface_normals
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def test_surface_normals(plot=False, skip_asserts=False,
write_reference=False):
"Test the surface normals of a horseshoe mesh"
sim = openmodes.Simulation()
mesh = sim.load_mesh(osp.join(mesh_dir, 'horseshoe_rect.msh'))
part = sim.place_part(mesh)
basis = sim.basis_container[part]
r, rho = basis.integration_points(mesh.nodes, triangle_centres)
normals = mesh.surface_normals
r = r.reshape((-1, 3))
if write_reference:
write_2d_real(osp.join(reference_dir, 'surface_r.txt'), r)
write_2d_real(osp.join(reference_dir, 'surface_normals.txt'), normals)
r_ref = read_2d_real(osp.join(reference_dir, 'surface_r.txt'))
normals_ref = read_2d_real(osp.join(reference_dir, 'surface_normals.txt'))
if not skip_asserts:
assert_allclose(r, r_ref)
assert_allclose(normals, normals_ref)
if plot:
from mayavi import mlab
mlab.figure()
mlab.quiver3d(r[:, 0], r[:, 1], r[:, 2],
normals[:, 0], normals[:, 1], normals[:, 2],
mode='cone')
mlab.view(distance='auto')
mlab.show()
示例8: CurvilinearPlotLine
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def CurvilinearPlotLine(mesh, TotalDisp=None, QuantityToPlot=None, plot_on_faces=True,
ProjectionFlags=None, interpolation_degree=20, EquallySpacedPoints=False, PlotActualCurve=False,
plot_points=False, plot_edges=True, plot_surfaces=True, point_radius=0.02, colorbar=False, color=None, figure=None,
show_plot=True, save=False, filename=None, save_tessellation=False):
"""High order curved line mesh plots, based on high order nodal FEM.
"""
if not isinstance(mesh,Mesh):
raise TypeError("mesh has to be an instance of type {}".format(Mesh))
if mesh.element_type != "line":
raise RuntimeError("Calling line plotting function with element type {}".format(mesh.element_type))
if TotalDisp is None:
TotalDisp = np.zeros_like(mesh.points)
tmesh = PostProcess.TessellateLines(mesh, TotalDisp, QuantityToPlot=QuantityToPlot,
ProjectionFlags=ProjectionFlags, interpolation_degree=interpolation_degree,
EquallySpacedPoints=EquallySpacedPoints, plot_points=plot_points,
plot_edges=plot_edges, plot_on_faces=plot_on_faces)
# UNPACK
x_edges = tmesh.x_edges
y_edges = tmesh.y_edges
z_edges = tmesh.z_edges
nnode = tmesh.nnode
nelem = tmesh.nelem
nsize = tmesh.nsize
# Xplot = tmesh.points
# Tplot = tmesh.elements
vpoints = tmesh.vpoints
connections = tmesh.elements
import os
os.environ['ETS_TOOLKIT'] = 'qt4'
from mayavi import mlab
if figure is None:
figure = mlab.figure(bgcolor=(1,1,1),fgcolor=(1,1,1),size=(1000,800))
# PLOT LINES
if plot_points:
h_points = mlab.points3d(vpoints[:,0],vpoints[:,1],vpoints[:,2],color=(0,0,0),mode='sphere',scale_factor=point_radius)
# PLOT CURVED EDGES
if plot_edges:
src = mlab.pipeline.scalar_scatter(x_edges.T.copy().flatten(), y_edges.T.copy().flatten(), z_edges.T.copy().flatten())
src.mlab_source.dataset.lines = connections
lines = mlab.pipeline.stripper(src)
h_edges = mlab.pipeline.surface(lines, color = (0,0,0), line_width=2)
mlab.view(azimuth=0, roll=0)
mlab.show()
return
示例9: draw_lidar
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def draw_lidar(
point_cloud: np.ndarray, bird: bool = True, colormap: str = "jet", fig: Optional[Figure] = None, bgcolor: Color = (0, 0, 0), fig_size: FigSize = (200, 200), focalpoint: Coordinate = (0, 0, 0), elevation: int = 0, distance: float = 62.0
) -> Figure:
"""Render a :ref:`PointCloud` with a 45 degree viewing frustum from worm-vehicle.
Creates a Mayavi figure, draws a point cloud. Since the majority of interesting objects and
scenarios are found closeby to the ground, we want to see the objects near the ground expressed
in the full range of the colormap. Since returns on power lines, trees, and buildings
will dominate and dilute the colormap otherwise, we clip the colors so that all points
beyond a certain z-elevation (height) share the same color at the edge of the colormap.
We choose anything beyond the 90th percentile as a height outlier.
Args:
point_cloud: The pointcloud to render
fig: A pre-existing Mayavi figure to render to
bgcolor: The background color
colormap: "spectral" or "gnuplot" or "jet" are best
Returns:
Updated or created Mayavi figure
"""
if fig is None:
fig = mlab.figure(figure=None, bgcolor=bgcolor, fgcolor=None, engine=None, size=fig_size)
'''
z_thresh = np.percentile(point_cloud[:, 2], 90)
thresholded_heights = point_cloud[:, 2].copy()
# Colors of highest points will be clipped to all lie at edge of colormap
thresholded_heights[thresholded_heights > z_thresh] = 5
'''
tmp = [point_cloud]
for i in range(1,201):
tmp.append(point_cloud+0.0001*i)
tmp.append(point_cloud-0.0001*i)
point_cloud = np.concatenate(tmp, 0)
# draw points
fig = plot_points_3D_mayavi(
#points=point_cloud, fig=fig, per_pt_color_strengths=thresholded_heights, fixed_color=None, colormap=colormap
points=point_cloud, bird=bird, fig=fig, per_pt_color_strengths=None, fixed_color=None, colormap=colormap
)
fig = draw_coordinate_frame_at_origin(fig)
mlab.view(
azimuth=180, elevation=elevation, focalpoint=focalpoint, distance=distance, figure=fig
)
return fig
示例10: draw_lidar
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def draw_lidar(pc, color=None, fig1=None, bgcolor=(0,0,0), pts_scale=1, pts_mode='point', pts_color=None):
''' Draw lidar points
Args:
pc: numpy array (n,3) of XYZ
color: numpy array (n) of intensity or whatever
fig: mayavi figure handler, if None create new one otherwise will use it
Returns:
fig: created or used fig
'''
#if fig1 is None: fig1 = mlab.figure(figure="point cloud", bgcolor=bgcolor, fgcolor=None, engine=None, size=(1600, 1000))
mlab.clf(figure=None)
if color is None: color = pc[:,2]
mlab.points3d(pc[:,0], pc[:,1], pc[:,2], color, color=pts_color, mode=pts_mode, colormap = 'gnuplot', scale_factor=pts_scale, figure=fig1)
#draw origin
mlab.points3d(0, 0, 0, color=(1,1,1), mode='sphere', scale_factor=0.2)
#draw axis
axes=np.array([
[2.,0.,0.,0.],
[0.,2.,0.,0.],
[0.,0.,2.,0.],
],dtype=np.float64)
mlab.plot3d([0, axes[0,0]], [0, axes[0,1]], [0, axes[0,2]], color=(1,0,0), tube_radius=None, figure=fig1)
mlab.plot3d([0, axes[1,0]], [0, axes[1,1]], [0, axes[1,2]], color=(0,1,0), tube_radius=None, figure=fig1)
mlab.plot3d([0, axes[2,0]], [0, axes[2,1]], [0, axes[2,2]], color=(0,0,1), tube_radius=None, figure=fig1)
# draw fov (todo: update to real sensor spec.)
fov=np.array([ # 45 degree
[20., 20., 0.,0.],
[20.,-20., 0.,0.],
],dtype=np.float64)
mlab.plot3d([0, fov[0,0]], [0, fov[0,1]], [0, fov[0,2]], color=(1,1,1), tube_radius=None, line_width=1, figure=fig1)
mlab.plot3d([0, fov[1,0]], [0, fov[1,1]], [0, fov[1,2]], color=(1,1,1), tube_radius=None, line_width=1, figure=fig1)
# draw square region
TOP_Y_MIN=-20
TOP_Y_MAX=20
TOP_X_MIN=0
TOP_X_MAX=40
TOP_Z_MIN=-2.0
TOP_Z_MAX=0.4
x1 = TOP_X_MIN
x2 = TOP_X_MAX
y1 = TOP_Y_MIN
y2 = TOP_Y_MAX
mlab.plot3d([x1, x1], [y1, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig1)
mlab.plot3d([x2, x2], [y1, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig1)
mlab.plot3d([x1, x2], [y1, y1], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig1)
mlab.plot3d([x1, x2], [y2, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig1)
#mlab.orientation_axes()
mlab.view(azimuth=180, elevation=70, focalpoint=[ 12.0909996 , -1.04700089, -2.03249991], distance=60.0, figure=fig1)
return fig1
示例11: draw_lidar
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def draw_lidar(pc, color=None, fig=None, bgcolor=(0,0,0), pts_scale=1, pts_mode='point', pts_color=None):
''' Draw lidar points
Args:
pc: numpy array (n,3) of XYZ
color: numpy array (n) of intensity or whatever
fig: mayavi figure handler, if None create new one otherwise will use it
Returns:
fig: created or used fig
'''
if fig is None: fig = mlab.figure(figure=None, bgcolor=bgcolor, fgcolor=None, engine=None, size=(1600, 1000))
if color is None: color = pc[:,2]
mlab.points3d(pc[:,0], pc[:,1], pc[:,2], color, color=pts_color, mode=pts_mode, colormap = 'gnuplot', scale_factor=pts_scale, figure=fig)
#draw origin
mlab.points3d(0, 0, 0, color=(1,1,1), mode='sphere', scale_factor=0.2)
#draw axis
axes=np.array([
[2.,0.,0.,0.],
[0.,2.,0.,0.],
[0.,0.,2.,0.],
],dtype=np.float64)
mlab.plot3d([0, axes[0,0]], [0, axes[0,1]], [0, axes[0,2]], color=(1,0,0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[1,0]], [0, axes[1,1]], [0, axes[1,2]], color=(0,1,0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[2,0]], [0, axes[2,1]], [0, axes[2,2]], color=(0,0,1), tube_radius=None, figure=fig)
# draw fov (todo: update to real sensor spec.)
fov=np.array([ # 45 degree
[20., 20., 0.,0.],
[20.,-20., 0.,0.],
],dtype=np.float64)
mlab.plot3d([0, fov[0,0]], [0, fov[0,1]], [0, fov[0,2]], color=(1,1,1), tube_radius=None, line_width=1, figure=fig)
mlab.plot3d([0, fov[1,0]], [0, fov[1,1]], [0, fov[1,2]], color=(1,1,1), tube_radius=None, line_width=1, figure=fig)
# draw square region
TOP_Y_MIN=-20
TOP_Y_MAX=20
TOP_X_MIN=0
TOP_X_MAX=40
TOP_Z_MIN=-2.0
TOP_Z_MAX=0.4
x1 = TOP_X_MIN
x2 = TOP_X_MAX
y1 = TOP_Y_MIN
y2 = TOP_Y_MAX
mlab.plot3d([x1, x1], [y1, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig)
mlab.plot3d([x2, x2], [y1, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig)
mlab.plot3d([x1, x2], [y1, y1], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig)
mlab.plot3d([x1, x2], [y2, y2], [0,0], color=(0.5,0.5,0.5), tube_radius=0.1, line_width=1, figure=fig)
#mlab.orientation_axes()
mlab.view(azimuth=180, elevation=70, focalpoint=[ 12.0909996 , -1.04700089, -2.03249991], distance=62.0, figure=fig)
return fig
示例12: plot
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def plot(self, figname=None, size=(300, 325), view=(30, 30), color=(1.0, 1.0, 1.0)):
fig = mlab.figure(size=size)
figure = mlab.gcf()
fig.scene.disable_render = True
figure.scene.background = (0.0, 0.0, 0.0)
mlab.view(0, 90, distance=0.2)
assert (self.structure.natom > 0)
x = self.structure.positions[:, 0]
y = self.structure.positions[:, 1]
z = self.structure.positions[:, 2]
cr = covalent_radius(self.structure.symbols)
s = np.apply_along_axis(np.linalg.norm, 1, self.structure.positions)
mlab.points3d(x, y, z, s, scale_factor=1.0, resolution=8, opacity=1.0,
color=color,
scale_mode='none')
if self.structure.is_crystal:
frame, line1, line2, line3 = self.structure.get_cell().get_path()
mlab.plot3d(frame[:, 0], frame[:, 1], frame[:, 2], tube_radius=.02, color=(1, 1, 1))
mlab.plot3d(line1[:, 0], line1[:, 1], line1[:, 2], tube_radius=.02, color=(1, 1, 1))
mlab.plot3d(line2[:, 0], line2[:, 1], line2[:, 2], tube_radius=.02, color=(1, 1, 1))
mlab.plot3d(line3[:, 0], line3[:, 1], line3[:, 2], tube_radius=.02, color=(1, 1, 1))
else:
for i in range(self.structure.natom - 1):
for j in range(i + 1, self.structure.natom):
vector = self.structure.positions[i] - self.structure.positions[j]
mvector = np.linalg.norm(vector)
uvector = 1.0 / mvector * vector
if 2 * mvector < covalent_radius(self.structure.symbols[i]) + \
covalent_radius(self.structure.symbols[j]):
pair = np.concatenate(
(self.structure.positions[i] - 0.1 * uvector,
self.structure.positions[j] + 0.1 * uvector)).reshape((-1, 3))
mlab.plot3d(pair[:, 0], pair[:, 1], pair[:, 2], tube_radius=0.15, opacity=1.0, color=(1, 1, 1))
mlab.view(distance=12.0)
fig.scene.disable_render = False
if figname is not None:
mlab.savefig(figname)
return figure
示例13: fill_render
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import view [as 别名]
def fill_render(self, model, save_movie=True, **kwargs):
from mayavi import mlab
body = self.to_body()
mask = body.mask
fig = mlab.figure(size=(1280, 720))
if self.target is not None:
target_grid = mlab.pipeline.scalar_field(np.transpose(self.target))
target_grid.spacing = np.flipud(CONFIG.volume.resolution)
target_grid = mlab.pipeline.iso_surface(target_grid, contours=[0.5], color=(1, 0, 0), opacity=0.1)
grid = mlab.pipeline.scalar_field(np.transpose(mask.astype(np.int32)))
grid.spacing = np.flipud(CONFIG.volume.resolution)
contour = mlab.pipeline.iso_surface(grid, color=(0, 1, 0), contours=[0.5], opacity=0.6)
contour.actor.property.backface_culling = True
grid = contour.mlab_source
mlab.orientation_axes(figure=fig)
mlab.view(azimuth=45, elevation=60, focalpoint='auto', figure=fig)
fill_generator = self.fill(model, generator=True, **kwargs)
FRAMES_PER_MOVE = 2
FPS = 60.0
ORBIT_RATE = 0.125
@mlab.animate(delay=int(1000.0/FPS), ui=True)
def animate():
try:
for _, _ in fill_generator:
body = self.to_body()
mask = body.mask
grid.set(scalars=np.transpose(mask.astype(np.int32)))
for _ in range(FRAMES_PER_MOVE):
view = list(mlab.view(figure=fig))
view[0] = (view[0] + ORBIT_RATE * 360.0 / FPS) % 360.0
mlab.view(azimuth=view[0], elevation=view[1], focalpoint='auto')
fig.scene.render()
# fig.scene.movie_maker.animation_step()
yield
except Region.EarlyFillTermination:
pass
fig.scene.movie_maker.record = False
fig.scene.movie_maker.animation_stop()
if save_movie:
fig.scene.movie_maker.record = True
a = animate() # noqa
mlab.show()