示例#1
0
def fill_vtk_unstructured_grid_results(model: pyNastranH5, vtk_ugrid: vtk.vtkUnstructuredGrid,
                                       eids: np.ndarray) -> None:
    point_data = vtk_ugrid.GetPointData()
    cell_data = vtk_ugrid.GetCellData()
    for i, res in model.results.items():
        if res.location == 'node':
            names, resultsi = res.get_results()
            for name, result in zip(names, resultsi):
                print(name)
                #name = 'cat'
                result.SetName(name)
                point_data.AddArray(result)

                # remove
                #point_data.SetActiveVectors(name)
                #point_data.SetVectors(result)
        elif res.location == 'element':
            res.eids = eids
            names, resultsi = res.get_results()
            for name, result in zip(names, resultsi):
                print(name)
                #name = 'cat'
                result.SetName(name)
                cell_data.AddArray(result)
                #cell_data.SetScalars(result)
        else:
            raise NotImplementedError(res)
示例#2
0
def get_inside_point_ids(
    gui,
    ugrid: vtk.vtkUnstructuredGrid,
    ugrid_flipped: vtk.vtkUnstructuredGrid,
    model_name: str,
    representation: str = 'points'
) -> Tuple[vtk.vtkUnstructuredGrid, List[int]]:
    """
    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 = gui.get_node_ids(model_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 = gui.get_node_ids(model_name, point_ids_flipped)
    #nids = gui.gui.get_reverse_node_ids(model_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 representation == 'points':
        # we need to filter the nodes that were filtered by the
        # numpy setdiff1d, so we don't show extra points
        ugrid = create_filtered_point_ugrid(ugrid, nids, nids2)

    nids = nids2
    return ugrid, nids