本文整理汇总了Python中vtk.vtkDataSetMapper方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.vtkDataSetMapper方法的具体用法?Python vtk.vtkDataSetMapper怎么用?Python vtk.vtkDataSetMapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vtk
的用法示例。
在下文中一共展示了vtk.vtkDataSetMapper方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: uns_highlightPoint
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def uns_highlightPoint(self, grid, cellid):
if self.actorpt is not None:
self._vtkren.RemoveActor(self.actorpt)
if grid is None:
return
filter = vtk.vtkUnstructuredGridGeometryFilter()
if VTK_VERSION_MAJOR < 6:
filter.SetInput(grid)
else:
filter.SetInputData(grid)
filter.CellClippingOn()
filter.SetCellMinimum(cellid)
filter.SetCellMaximum(cellid)
mapper = vtk.vtkDataSetMapper()
mapper.SetInputConnection(filter.GetOutputPort())
self.actorpt = vtk.vtkActor()
self.actorpt.SetMapper(mapper)
self.actorpt.GetProperty().SetColor(0, 1, 0)
self.actorpt.GetProperty().SetLineWidth(2)
self.actorpt.GetProperty().SetRepresentationToWireframe()
self.actorpt.PickableOff()
self.actorpt.DragableOff()
self._vtkren.AddActor(self.actorpt)
self._iren.Render()
示例2: actor_from_unstructuredgrid
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def actor_from_unstructuredgrid(data):
mapper = vtkDataSetMapper()
mapper.SetInput(data)
actor = vtkActor()
actor.SetMapper(mapper)
return actor
示例3: selectionCellId
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def selectionCellId(self, grid, ptid):
if self.actorpt is not None:
self._vtkren.RemoveActor(self.actorpt)
if grid is None:
return
ids = vtk.vtkIdTypeArray()
ids.SetNumberOfComponents(1)
ids.InsertNextValue(ptid)
selectionNode = vtk.vtkSelectionNode()
selectionNode.SetFieldType(0)
selectionNode.SetContentType(4)
selectionNode.SetSelectionList(ids)
selection = vtk.vtkSelection()
selection.AddNode(selectionNode)
extractSelection = vtk.vtkExtractSelection()
if VTK_VERSION_MAJOR < 8:
raise RuntimeError("VTK version is too old, please upgrade")
extractSelection.SetInputData(0, grid)
extractSelection.SetInputData(1, selection)
extractSelection.Update()
selected = vtk.vtkUnstructuredGrid()
selected.ShallowCopy(extractSelection.GetOutput())
selectedMapper = vtk.vtkDataSetMapper()
if VTK_VERSION_MAJOR < 8:
raise RuntimeError("VTK version is too old, please upgrade")
selectedMapper.SetInputData(selected)
self.actorpt = vtk.vtkActor()
self.actorpt.SetMapper(selectedMapper)
self.actorpt.GetProperty().SetColor(0, 1, 0)
self.actorpt.GetProperty().SetPointSize(6)
self.actorpt.PickableOff()
self.actorpt.DragableOff()
self._vtkren.AddActor(self.actorpt)
self._iren.Render()
示例4: selectionPointId
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def selectionPointId(self, grid, ptid):
if self.actorpt is not None:
self._vtkren.RemoveActor(self.actorpt)
if grid is None:
return
ids = vtk.vtkIdTypeArray()
ids.SetNumberOfComponents(1)
ids.InsertNextValue(ptid)
selectionNode = vtk.vtkSelectionNode()
selectionNode.SetFieldType(1)
selectionNode.SetContentType(4)
selectionNode.SetSelectionList(ids)
selection = vtk.vtkSelection()
selection.AddNode(selectionNode)
extractSelection = vtk.vtkExtractSelection()
if VTK_VERSION_MAJOR < 8:
raise RuntimeError("VTK version is too old, please upgrade")
extractSelection.SetInputData(0, grid)
extractSelection.SetInputData(1, selection)
extractSelection.Update()
selected = vtk.vtkUnstructuredGrid()
selected.ShallowCopy(extractSelection.GetOutput())
selectedMapper = vtk.vtkDataSetMapper()
if VTK_VERSION_MAJOR < 8:
raise RuntimeError("VTK version is too old, please upgrade")
selectedMapper.SetInputData(selected)
self.actorpt = vtk.vtkActor()
self.actorpt.SetMapper(selectedMapper)
self.actorpt.GetProperty().SetColor(0, 1, 0)
self.actorpt.GetProperty().SetPointSize(6)
self.actorpt.PickableOff()
self.actorpt.DragableOff()
self._vtkren.AddActor(self.actorpt)
self._iren.Render()
示例5: draw_grid
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def draw_grid():
xArray = vtk.vtkDoubleArray()
yArray = vtk.vtkDoubleArray()
zArray = vtk.vtkDoubleArray()
for x in range(-60, 61):
xArray.InsertNextValue(x)
# for y in range(-10, 10):
# yArray.InsertNextValue(y)
for y in range(0, 1):
yArray.InsertNextValue(y)
for z in range(-80, 80):
zArray.InsertNextValue(z)
grid = vtk.vtkRectilinearGrid()
grid.SetDimensions(121, 1, 161)
grid.SetXCoordinates(xArray)
grid.SetYCoordinates(yArray)
grid.SetZCoordinates(zArray)
# print(grid.GetPoint(0))
gridMapper = vtk.vtkDataSetMapper()
gridMapper.SetInputData(grid)
gridActor = vtk.vtkActor()
gridActor.SetMapper(gridMapper)
gridActor.GetProperty().SetColor(0.75, 0.75, 0)
gridActor.GetProperty().SetOpacity(0.1)
# import pdb; pdb.set_trace()
return gridActor
示例6: create_actor_hexahedron
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def create_actor_hexahedron(grid, color, **kwargs):
""" Creates a VTK actor for rendering voxels using hexahedron elements.
:param grid: grid
:type grid: ndarray
:param color: actor color
:type color: list
:return: a VTK actor
:rtype: vtkActor
"""
# Keyword arguments
array_name = kwargs.get('name', "")
array_index = kwargs.get('index', 0)
# Create hexahedron elements
points = vtk.vtkPoints()
hexarray = vtk.vtkCellArray()
for j, pt in enumerate(grid):
tmp = vtk.vtkHexahedron()
fb = pt[0]
for i, v in enumerate(fb):
points.InsertNextPoint(v)
tmp.GetPointIds().SetId(i, i + (j * 8))
ft = pt[-1]
for i, v in enumerate(ft):
points.InsertNextPoint(v)
tmp.GetPointIds().SetId(i + 4, i + 4 + (j * 8))
hexarray.InsertNextCell(tmp)
# Create an unstructured grid object and add points & hexahedron elements
ugrid = vtk.vtkUnstructuredGrid()
ugrid.SetPoints(points)
ugrid.SetCells(tmp.GetCellType(), hexarray)
# ugrid.InsertNextCell(tmp.GetCellType(), tmp.GetPointIds())
# Map unstructured grid to the graphics primitives
mapper = vtk.vtkDataSetMapper()
mapper.SetInputDataObject(ugrid)
mapper.SetArrayName(array_name)
mapper.SetArrayId(array_index)
# Create an actor and set its properties
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(*color)
# Return the actor
return actor
示例7: create_actor_delaunay
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def create_actor_delaunay(pts, color, **kwargs):
""" Creates a VTK actor for rendering triangulated plots using Delaunay triangulation.
Keyword Arguments:
* ``d3d``: flag to choose between Delaunay2D (``False``) and Delaunay3D (``True``). *Default: False*
:param pts: points
:type pts: vtkFloatArray
:param color: actor color
:type color: list
:return: a VTK actor
:rtype: vtkActor
"""
# Keyword arguments
array_name = kwargs.get('name', "")
array_index = kwargs.get('index', 0)
use_delaunay3d = kwargs.get("d3d", False)
# Create points
points = vtk.vtkPoints()
points.SetData(pts)
# Create a PolyData object and add points
polydata = vtk.vtkPolyData()
polydata.SetPoints(points)
# Apply Delaunay triangulation on the poly data object
triangulation = vtk.vtkDelaunay3D() if use_delaunay3d else vtk.vtkDelaunay2D()
triangulation.SetInputData(polydata)
# Map triangulated surface to the graphics primitives
mapper = vtk.vtkDataSetMapper()
mapper.SetInputConnection(triangulation.GetOutputPort())
mapper.SetArrayName(array_name)
mapper.SetArrayId(array_index)
# Create an actor and set its properties
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(*color)
# Return the actor
return actor
示例8: add_orientation_widget
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def add_orientation_widget(self, actor, interactive=None, color=None,
opacity=1.0):
"""Use the given actor in an orientation marker widget.
Color and opacity are only valid arguments if a mesh is passed.
Parameters
----------
actor : vtk.vtkActor or pyvista.Common
The mesh or actor to use as the marker.
color : string, optional
The color of the actor.
opacity : int or float, optional
Opacity of the marker.
"""
if isinstance(actor, pyvista.Common):
mapper = vtk.vtkDataSetMapper()
mesh = actor.copy()
mesh.clear_arrays()
mapper.SetInputData(mesh)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
prop = actor.GetProperty()
if color is not None:
prop.SetColor(parse_color(color))
prop.SetOpacity(opacity)
if hasattr(self, 'axes_widget'):
# Delete the old one
self.axes_widget.EnabledOff()
self.Modified()
del self.axes_widget
if interactive is None:
interactive = rcParams['interactive']
self.axes_widget = vtk.vtkOrientationMarkerWidget()
self.axes_widget.SetOrientationMarker(actor)
if hasattr(self.parent, 'iren'):
self.axes_widget.SetInteractor(self.parent.iren)
self.axes_widget.SetEnabled(1)
self.axes_widget.SetInteractive(interactive)
self.axes_widget.SetCurrentRenderer(self)
self.Modified()
return self.axes_widget
示例9: add_lines
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkDataSetMapper [as 别名]
def add_lines(self, lines, color=(1, 1, 1), width=5, label=None, name=None):
"""Add lines to the plotting object.
Parameters
----------
lines : np.ndarray or pyvista.PolyData
Points representing line segments. For example, two line segments
would be represented as:
np.array([[0, 0, 0], [1, 0, 0], [1, 0, 0], [1, 1, 0]])
color : string or 3 item list, optional, defaults to white
Either a string, rgb list, or hex color string. For example:
color='white'
color='w'
color=[1, 1, 1]
color='#FFFFFF'
width : float, optional
Thickness of lines
name : str, optional
The name for the added actor so that it can be easily updated.
If an actor of this name already exists in the rendering window, it
will be replaced by the new actor.
Return
------
actor : vtk.vtkActor
Lines actor.
"""
if not isinstance(lines, np.ndarray):
raise TypeError('Input should be an array of point segments')
lines = pyvista.lines_from_points(lines)
# Create mapper and add lines
mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(lines)
rgb_color = parse_color(color)
# legend label
if label:
if not isinstance(label, str):
raise TypeError('Label must be a string')
self._labels.append([lines, label, rgb_color])
# Create actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetLineWidth(width)
actor.GetProperty().EdgeVisibilityOn()
actor.GetProperty().SetEdgeColor(rgb_color)
actor.GetProperty().SetColor(rgb_color)
actor.GetProperty().LightingOff()
# Add to renderer
self.add_actor(actor, reset_camera=False, name=name, pickable=False)
return actor