Exemplo n.º 1
0
    def highlight_nodes(self, nids, model_name='', add_actor=True):
        """
        Highlights a series of nodes

        Parameters
        ----------
        nids : int, List[int]
            the nodes to apply a message to
        model_name : str, List[str]
            the name of the actor to highlight the nodes for

        """
        npoints = len(nids)
        all_nids = self.gui.get_node_ids(model_name=model_name, ids=None)
        all_xyz = self.gui.get_xyz_cid0(model_name=model_name)
        i = np.searchsorted(all_nids, nids)
        xyz = all_xyz[i, :]

        #ugrid = vtk.vtkUnstrucuturedGrid()
        points = numpy_to_vtk_points(xyz, points=None, dtype='<f', deep=1)
        ugrid = create_unstructured_point_grid(points, npoints)
        actor = self.gui.mouse_actions.create_highlighted_actor(
            ugrid, representation='points', add_actor=add_actor)
        self.gui.vtk_interactor.Render()
        return actor
Exemplo n.º 2
0
def create_highlighted_actors(
        gui,
        grid: vtk.vtkUnstructuredGrid,
        all_nodes=None,
        nodes=None,
        set_node_scalars=True,
        all_elements=None,
        elements=None,
        set_element_scalars=True,
        add_actors: bool = False) -> List[vtk.vtkLODActor]:
    """creates nodes & element highlighted objects"""
    actors = []
    nnodes = 0
    nelements = 0
    if nodes is not None:
        nnodes = len(nodes)
        assert len(all_nodes) >= nnodes

    if elements is not None:
        nelements = len(elements)
        assert len(all_elements) >= nelements
    assert nnodes + nelements > 0

    if nnodes:
        point_ids = np.searchsorted(all_nodes, nodes)
        output_data = grid.GetPoints().GetData()
        points_array = vtk_to_numpy(output_data)  # yeah!

        point_array2 = points_array[point_ids, :]
        points2 = numpy_to_vtk_points(point_array2)

        ugrid = create_unstructured_point_grid(points2, nnodes)
        if set_node_scalars:
            point_ids_array = numpy_to_vtk(nodes)
            ugrid.GetPointData().SetScalars(point_ids_array)
        actor = create_highlighted_actor(gui,
                                         ugrid,
                                         representation='points',
                                         add_actor=add_actors)
        actors.append(actor)

    if nelements:
        cell_ids = np.searchsorted(all_elements, elements)

        selection_node = create_vtk_selection_node_by_cell_ids(cell_ids)
        ugrid = extract_selection_node_from_grid_to_ugrid(grid, selection_node)
        if set_element_scalars:
            element_ids_array = numpy_to_vtk(elements)
            ugrid.GetPointData().SetScalars(None)
            ugrid.GetCellData().SetScalars(element_ids_array)
        actor = create_highlighted_actor(gui,
                                         ugrid,
                                         representation='wire',
                                         add_actor=add_actors)
        actors.append(actor)
    return actors
Exemplo n.º 3
0
def create_filtered_point_ugrid(ugrid, nids, nids2):
    """
    We need to filter the nodes that were filtered by the
    numpy setdiff1d, so we don't show extra points

    """
    #unused_pointsu = ugrid.GetPoints()
    output_data = ugrid.GetPoints().GetData()
    points_array = vtk_to_numpy(output_data)  # yeah!

    isort_nids = np.argsort(nids)
    nids = nids[isort_nids]
    inids = np.searchsorted(nids, nids2)

    points_array_sorted = points_array[isort_nids, :]
    point_array2 = points_array_sorted[inids, :]
    points2 = numpy_to_vtk_points(point_array2)

    npoints = len(nids2)
    ugrid = create_unstructured_point_grid(points2, npoints)
    return ugrid
Exemplo n.º 4
0
    def get_inside_point_ids(self, ugrid, ugrid_flipped):
        """
        The points that are returned from the frustum, despite being
        defined as inside are not all inside.  The cells are correct
        though.  If you determine the cells outside the volume and the
        points associated with that, and boolean the two, you can find
        the points that are actually inside.

        In other words, ``points`` corresponds to the points inside the
        volume and barely outside.  ``point_ids_flipped`` corresponds to
        the points entirely outside the volume.

        Parameters
        ==========
        ugrid : vtk.vtkUnstructuredGrid()
            the "inside" grid
        ugrid_flipped : vtk.vtkUnstructuredGrid()
            the outside grid

        Returns
        =======
        ugrid : vtk.vtkUnstructuredGrid()
            an updated grid that has the correct points
        nids : (n, ) int ndarray
            the node_ids
        """
        nids = None
        points = ugrid.GetPointData()
        if points is None:
            return ugrid, nids

        ids = points.GetArray('Ids')
        if ids is None:
            return ugrid, nids

        # all points associated with the correctly selected cells are returned
        # but we get extra points for the cells that are inside and out
        point_ids = vtk_to_numpy(ids)
        nids = self.parent.get_node_ids(self.name, point_ids)

        # these are the points outside the box/frustum (and also include the bad point)
        points_flipped = ugrid_flipped.GetPointData()
        ids_flipped = points_flipped.GetArray('Ids')
        point_ids_flipped = vtk_to_numpy(ids_flipped)
        nids_flipped = self.parent.get_node_ids(self.name, point_ids_flipped)
        #nids = self.parent.gui.get_reverse_node_ids(self.name, point_ids_flipped)

        # setA - setB
        nids2 = np.setdiff1d(nids, nids_flipped, assume_unique=True)

        #narrays = points.GetNumberOfArrays()
        #for iarray in range(narrays):
        #name = points.GetArrayName(iarray)
        #print('iarray=%s name=%r' % (iarray, name))

        #------------------
        if self.representation == 'points':
            # we need to filter the nodes that were filtered by the
            # numpy setdiff1d, so we don't show extra points
            pointsu = ugrid.GetPoints()
            output_data = ugrid.GetPoints().GetData()
            points_array = numpy_support.vtk_to_numpy(output_data)  # yeah!

            isort_nids = np.argsort(nids)
            nids = nids[isort_nids]
            inids = np.searchsorted(nids, nids2)

            points_array_sorted = points_array[isort_nids, :]
            point_array2 = points_array_sorted[inids, :]
            points2 = numpy_to_vtk_points(point_array2)

            npoints = len(nids2)
            ugrid = create_unstructured_point_grid(points2, npoints)
        nids = nids2
        return ugrid, nids