def _surfaceSelectionHelper(rectOrPolygon, view, type, Modifier=None): """ Selects mesh elements on a surface - rectOrPolygon - represents either a rectangle or polygon. If a rectangle, consists of a list containing the bottom left (x1, y1) and top right (x2, y2) corner of a rectangle defining the selection region in the format [x1, y1, x2, y2]. If a polygon, list of points defining the polygon in x-y pairs (e.g., [x1, y1, x2, y2, x3, y3,...]) - view - the view in which to make the selection - type - the type of mesh element: 'POINT', 'CELL', or 'BLOCK' - Modifier - 'ADD', 'SUBTRACT', 'TOGGLE', or None to define whether and how the selection should modify the existing selection. """ if not view.SMProxy.IsA('vtkSMRenderViewProxy'): return # ensure the view has rendered so that the selection is valid paraview.simple.Render(view) if len(rectOrPolygon) == 0: rectOrPolygon = [0, 0, view.ViewSize[0], view.ViewSize[1]] from paraview.vtk import vtkCollection, vtkIntArray selectedReps = vtkCollection() selectionSources = vtkCollection() if type.startswith('POLYGON'): polygon = vtkIntArray() polygon.SetNumberOfComponents(2) for component in rectOrPolygon: polygon.InsertNextValue(component) if type == 'POINT': view.SelectSurfacePoints(rectOrPolygon, selectedReps, selectionSources, 0) elif type == 'CELL' or type == 'BLOCK': view.SelectSurfaceCells(rectOrPolygon, selectedReps, selectionSources, 0) elif type == 'FRUSTUM_POINTS': view.SelectFrustumPoints(rectOrPolygon, selectedReps, selectionSources, 0) elif type == 'FRUSTUM_CELLS': view.SelectFrustumCells(rectOrPolygon, selectedReps, selectionSources, 0) elif type == 'POLYGON_POINTS': view.SelectPolygonPoints(polygon, selectedReps, selectionSources, 0) elif type == 'POLYGON_CELLS': view.SelectPolygonCells(polygon, selectedReps, selectionSources, 0) else: raise RuntimeError("Invalid type %s" % type) _collectSelectionPorts(selectedReps, selectionSources, type == 'BLOCK', Modifier) paraview.simple.Render(view)
# need to barrier to ensure that all ranks have updated. controller = pm.GetGlobalController() controller.Barrier() r = XMLPartitionedImageDataReader(FileName = fname) r.UpdatePipeline() # if we're running in symmetric mode, numcells is the local process's # number of cells. if not, it is the global number of cells and # only the process that reads in this script gets that information numcells = r.GetDataInformation().DataInformation.GetNumberOfCells() # check which mode we're in if pm.GetSymmetricMPIMode() == True: # we're in symmetric mode so we have to do a global reduce for # process 0 to get the global amount of cells to check import paraview.vtk as vtk da = vtk.vtkIntArray() da.SetNumberOfTuples(1) da.SetValue(0, numcells) da2 = vtk.vtkIntArray() da2.SetNumberOfTuples(1) pm.GetGlobalController().Reduce(da, da2, 2, 0) numcells = da2.GetValue(0) if processId == 0 and numcells != 8000: print("ERROR: %s has %d but should have 8000." % (fname, numcells)) sys.exit(1) print("Test passed.")
# need to barrier to ensure that all ranks have updated. controller = pm.GetGlobalController() controller.Barrier() r = XMLPartitionedImageDataReader(FileName=fname) r.UpdatePipeline() # if we're running in symmetric mode, numcells is the local process's # number of cells. if not, it is the global number of cells and # only the process that reads in this script gets that information numcells = r.GetDataInformation().DataInformation.GetNumberOfCells() # check which mode we're in if pm.GetSymmetricMPIMode() == True: # we're in symmetric mode so we have to do a global reduce for # process 0 to get the global amount of cells to check import paraview.vtk as vtk da = vtk.vtkIntArray() da.SetNumberOfTuples(1) da.SetValue(0, numcells) da2 = vtk.vtkIntArray() da2.SetNumberOfTuples(1) pm.GetGlobalController().Reduce(da, da2, 2, 0) numcells = da2.GetValue(0) if processId == 0 and numcells != 8000: print("ERROR: %s has %d but should have 8000." % (fname, numcells)) sys.exit(1) print("Test passed.")