def check_depth_peeling(number_of_peels=100, occlusion_ratio=0.0): """Check if depth peeling is available. Attempts to use depth peeling to see if it is available for the current environment. Returns ``True`` if depth peeling is available and has been successfully leveraged, otherwise ``False``. """ # Try Depth Peeling with a basic scene source = _vtk.vtkSphereSource() mapper = _vtk.vtkPolyDataMapper() mapper.SetInputConnection(source.GetOutputPort()) actor = _vtk.vtkActor() actor.SetMapper(mapper) # requires opacity < 1 actor.GetProperty().SetOpacity(0.5) renderer = _vtk.vtkRenderer() renderWindow = _vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) renderWindow.SetOffScreenRendering(True) renderWindow.SetAlphaBitPlanes(True) renderWindow.SetMultiSamples(0) renderer.AddActor(actor) renderer.SetUseDepthPeeling(True) renderer.SetMaximumNumberOfPeels(number_of_peels) renderer.SetOcclusionRatio(occlusion_ratio) renderWindow.Render() return renderer.GetLastRenderingUsedDepthPeeling() == 1
def __init__(self, show_actor=False, actor_scale=1, line_width=1.0, symmetric=False): """Initialize a new axes descriptor.""" super().__init__() self.mapper = None self.actor = None self.SetSymmetric(symmetric) # Add the axes mapper self.mapper = _vtk.vtkPolyDataMapper() self.mapper.SetInputConnection(self.GetOutputPort()) # Add the axes actor self.actor = _vtk.vtkActor() self.actor.SetMapper(self.mapper) self.actor.SetVisibility(show_actor) self.actor.SetScale(actor_scale) prop = self.actor.GetProperty() prop.SetLineWidth(line_width)
def create_axes_orientation_box(line_width=1, text_scale=0.366667, edge_color='black', x_color=None, y_color=None, z_color=None, xlabel='X', ylabel='Y', zlabel='Z', x_face_color='red', y_face_color='green', z_face_color='blue', color_box=False, label_color=None, labels_off=False, opacity=0.5): """Create a Box axes orientation widget with labels. Parameters ---------- line_width : float, optional The width of the marker lines. text_scale : float, optional Size of the text relative to the faces. edge_color : str or sequence, optional Color of the edges. x_color : str or sequence, optional Color of the x axis text. y_color : str or sequence, optional Color of the y axis text. z_color : str or sequence, optional Color of the z axis text. xlabel : str, optional Text used for the x axis. ylabel : str, optional Text used for the y axis. zlabel : str, optional Text used for the z axis. x_face_color : str or sequence, optional Color used for the x axis arrow. Defaults to theme axes parameters. y_face_color : str or sequence, optional Color used for the y axis arrow. Defaults to theme axes parameters. z_face_color : str or sequence, optional Color used for the z axis arrow. Defaults to theme axes parameters. color_box : bool, optional Enable or disable the face colors. Otherwise, box is white. label_color : str or sequence, optional Color of the labels. labels_off : bool, optional Enable or disable the text labels for the axes. opacity : float, optional Opacity in the range of ``[0, 1]`` of the orientation box. Returns ------- vtk.vtkAnnotatedCubeActor Annotated cube actor. Examples -------- Create and plot an orientation box >>> import pyvista >>> actor = pyvista.create_axes_orientation_box( ... line_width=1, text_scale=0.53, ... edge_color='black', x_color='k', ... y_color=None, z_color=None, ... xlabel='X', ylabel='Y', zlabel='Z', ... color_box=False, ... labels_off=False, opacity=1.0) >>> pl = pyvista.Plotter() >>> _ = pl.add_actor(actor) >>> pl.show() """ if x_color is None: x_color = pyvista.global_theme.axes.x_color if y_color is None: y_color = pyvista.global_theme.axes.y_color if z_color is None: z_color = pyvista.global_theme.axes.z_color if edge_color is None: edge_color = pyvista.global_theme.edge_color axes_actor = _vtk.vtkAnnotatedCubeActor() axes_actor.SetFaceTextScale(text_scale) if xlabel is not None: axes_actor.SetXPlusFaceText(f"+{xlabel}") axes_actor.SetXMinusFaceText(f"-{xlabel}") if ylabel is not None: axes_actor.SetYPlusFaceText(f"+{ylabel}") axes_actor.SetYMinusFaceText(f"-{ylabel}") if zlabel is not None: axes_actor.SetZPlusFaceText(f"+{zlabel}") axes_actor.SetZMinusFaceText(f"-{zlabel}") axes_actor.SetFaceTextVisibility(not labels_off) axes_actor.SetTextEdgesVisibility(False) # axes_actor.GetTextEdgesProperty().SetColor(parse_color(edge_color)) # axes_actor.GetTextEdgesProperty().SetLineWidth(line_width) axes_actor.GetXPlusFaceProperty().SetColor(parse_color(x_color)) axes_actor.GetXMinusFaceProperty().SetColor(parse_color(x_color)) axes_actor.GetYPlusFaceProperty().SetColor(parse_color(y_color)) axes_actor.GetYMinusFaceProperty().SetColor(parse_color(y_color)) axes_actor.GetZPlusFaceProperty().SetColor(parse_color(z_color)) axes_actor.GetZMinusFaceProperty().SetColor(parse_color(z_color)) axes_actor.GetCubeProperty().SetOpacity(opacity) # axes_actor.GetCubeProperty().SetEdgeColor(parse_color(edge_color)) axes_actor.GetCubeProperty().SetEdgeVisibility(True) axes_actor.GetCubeProperty().BackfaceCullingOn() if opacity < 1.0: # Hide the text edges axes_actor.GetTextEdgesProperty().SetOpacity(0) if color_box: # Hide the cube so we can color each face axes_actor.GetCubeProperty().SetOpacity(0) axes_actor.GetCubeProperty().SetEdgeVisibility(False) cube = pyvista.Cube() cube.clear_data() # remove normals face_colors = np.array([parse_color(x_face_color), parse_color(x_face_color), parse_color(y_face_color), parse_color(y_face_color), parse_color(z_face_color), parse_color(z_face_color), ]) face_colors = (face_colors * 255).astype(np.uint8) cube.cell_data['face_colors'] = face_colors cube_mapper = _vtk.vtkPolyDataMapper() cube_mapper.SetInputData(cube) cube_mapper.SetColorModeToDirectScalars() cube_mapper.Update() cube_actor = _vtk.vtkActor() cube_actor.SetMapper(cube_mapper) cube_actor.GetProperty().BackfaceCullingOn() cube_actor.GetProperty().SetOpacity(opacity) prop_assembly = _vtk.vtkPropAssembly() prop_assembly.AddPart(axes_actor) prop_assembly.AddPart(cube_actor) actor = prop_assembly else: actor = axes_actor _update_axes_label_color(actor, label_color) return actor
def create_axes_orientation_box(line_width=1, text_scale=0.366667, edge_color='black', x_color=None, y_color=None, z_color=None, xlabel='X', ylabel='Y', zlabel='Z', x_face_color='red', y_face_color='green', z_face_color='blue', color_box=False, label_color=None, labels_off=False, opacity=0.5,): """Create a Box axes orientation widget with labels.""" if x_color is None: x_color = rcParams['axes']['x_color'] if y_color is None: y_color = rcParams['axes']['y_color'] if z_color is None: z_color = rcParams['axes']['z_color'] if edge_color is None: edge_color = rcParams['edge_color'] axes_actor = _vtk.vtkAnnotatedCubeActor() axes_actor.SetFaceTextScale(text_scale) if xlabel is not None: axes_actor.SetXPlusFaceText(f"+{xlabel}") axes_actor.SetXMinusFaceText(f"-{xlabel}") if ylabel is not None: axes_actor.SetYPlusFaceText(f"+{ylabel}") axes_actor.SetYMinusFaceText(f"-{ylabel}") if zlabel is not None: axes_actor.SetZPlusFaceText(f"+{zlabel}") axes_actor.SetZMinusFaceText(f"-{zlabel}") axes_actor.SetFaceTextVisibility(not labels_off) axes_actor.SetTextEdgesVisibility(False) # axes_actor.GetTextEdgesProperty().SetColor(parse_color(edge_color)) # axes_actor.GetTextEdgesProperty().SetLineWidth(line_width) axes_actor.GetXPlusFaceProperty().SetColor(parse_color(x_color)) axes_actor.GetXMinusFaceProperty().SetColor(parse_color(x_color)) axes_actor.GetYPlusFaceProperty().SetColor(parse_color(y_color)) axes_actor.GetYMinusFaceProperty().SetColor(parse_color(y_color)) axes_actor.GetZPlusFaceProperty().SetColor(parse_color(z_color)) axes_actor.GetZMinusFaceProperty().SetColor(parse_color(z_color)) axes_actor.GetCubeProperty().SetOpacity(opacity) # axes_actor.GetCubeProperty().SetEdgeColor(parse_color(edge_color)) axes_actor.GetCubeProperty().SetEdgeVisibility(True) axes_actor.GetCubeProperty().BackfaceCullingOn() if opacity < 1.0: # Hide the text edges axes_actor.GetTextEdgesProperty().SetOpacity(0) if color_box: # Hide the cube so we can color each face axes_actor.GetCubeProperty().SetOpacity(0) axes_actor.GetCubeProperty().SetEdgeVisibility(False) cube = pyvista.Cube() cube.clear_arrays() # remove normals face_colors = np.array([parse_color(x_face_color), parse_color(x_face_color), parse_color(y_face_color), parse_color(y_face_color), parse_color(z_face_color), parse_color(z_face_color), ]) face_colors = (face_colors * 255).astype(np.uint8) cube.cell_arrays['face_colors'] = face_colors cube_mapper = _vtk.vtkPolyDataMapper() cube_mapper.SetInputData(cube) cube_mapper.SetColorModeToDirectScalars() cube_mapper.Update() cube_actor = _vtk.vtkActor() cube_actor.SetMapper(cube_mapper) cube_actor.GetProperty().BackfaceCullingOn() cube_actor.GetProperty().SetOpacity(opacity) prop_assembly = _vtk.vtkPropAssembly() prop_assembly.AddPart(axes_actor) prop_assembly.AddPart(cube_actor) actor = prop_assembly else: actor = axes_actor update_axes_label_color(actor, label_color) return actor