Python vtk.vtkDataSetMapper() Examples

The following are 9 code examples of vtk.vtkDataSetMapper(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vtk , or try the search function .
Example #1
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 6 votes vote down vote up
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() 
Example #2
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 5 votes vote down vote up
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() 
Example #3
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 5 votes vote down vote up
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() 
Example #4
Source File: show_lidar_vtk.py    From Det3D with Apache License 2.0 5 votes vote down vote up
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 
Example #5
Source File: vtk_helpers.py    From NURBS-Python with MIT License 4 votes vote down vote up
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 
Example #6
Source File: vtk_helpers.py    From NURBS-Python with MIT License 4 votes vote down vote up
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 
Example #7
Source File: vtkhelpers.py    From pcloudpy with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def actor_from_unstructuredgrid(data):
    mapper = vtkDataSetMapper()
    mapper.SetInput(data)
    actor = vtkActor()
    actor.SetMapper(mapper)
    return actor 
Example #8
Source File: renderer.py    From pyvista with MIT License 4 votes vote down vote up
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 
Example #9
Source File: plotting.py    From pyvista with MIT License 4 votes vote down vote up
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