def quiver3d(self, x, y, z, u, v, w, color, scale, mode, resolution=8, glyph_height=None, glyph_center=None, glyph_resolution=None, opacity=1.0, scale_mode='none', scalars=None, backface_culling=False, line_width=2., name=None): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=FutureWarning) factor = scale vectors = np.c_[u, v, w] points = np.vstack(np.c_[x, y, z]) n_points = len(points) offset = np.arange(n_points) * 3 cell_type = np.full(n_points, vtk.VTK_VERTEX) cells = np.c_[np.full(n_points, 1), range(n_points)] grid = UnstructuredGrid(offset, cells, cell_type, points) grid.point_arrays['vec'] = vectors if scale_mode == 'scalar': grid.point_arrays['mag'] = np.array(scalars) scale = 'mag' else: scale = False if mode == '2darrow': return _arrow_glyph(grid, factor) elif mode == 'arrow' or mode == '3darrow': self.plotter.add_mesh(grid.glyph(orient='vec', scale=scale, factor=factor), color=color, opacity=opacity, backface_culling=backface_culling) elif mode == 'cone': cone = vtk.vtkConeSource() if glyph_height is not None: cone.SetHeight(glyph_height) if glyph_center is not None: cone.SetCenter(glyph_center) if glyph_resolution is not None: cone.SetResolution(glyph_resolution) cone.Update() geom = cone.GetOutput() self.plotter.add_mesh(grid.glyph(orient='vec', scale=scale, factor=factor, geom=geom), color=color, opacity=opacity, backface_culling=backface_culling) elif mode == 'cylinder': cylinder = vtk.vtkCylinderSource() cylinder.SetHeight(glyph_height) cylinder.SetRadius(0.15) cylinder.SetCenter(glyph_center) cylinder.SetResolution(glyph_resolution) cylinder.Update() # fix orientation tr = vtk.vtkTransform() tr.RotateWXYZ(90, 0, 0, 1) trp = vtk.vtkTransformPolyDataFilter() trp.SetInputData(cylinder.GetOutput()) trp.SetTransform(tr) trp.Update() geom = trp.GetOutput() self.plotter.add_mesh(grid.glyph(orient='vec', scale=scale, factor=factor, geom=geom), color=color, opacity=opacity, backface_culling=backface_culling)
def quiver3d(self, x, y, z, u, v, w, color, scale, mode, resolution=8, glyph_height=None, glyph_center=None, glyph_resolution=None, opacity=1.0, scale_mode='none', scalars=None, backface_culling=False, line_width=2., name=None): _check_option('mode', mode, ALLOWED_QUIVER_MODES) with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=FutureWarning) factor = scale vectors = np.c_[u, v, w] points = np.vstack(np.c_[x, y, z]) n_points = len(points) cell_type = np.full(n_points, vtk.VTK_VERTEX) cells = np.c_[np.full(n_points, 1), range(n_points)] args = (cells, cell_type, points) if not VTK9: args = (np.arange(n_points) * 3,) + args grid = UnstructuredGrid(*args) grid.point_arrays['vec'] = vectors if scale_mode == 'scalar': grid.point_arrays['mag'] = np.array(scalars) scale = 'mag' else: scale = False if mode == '2darrow': return _arrow_glyph(grid, factor), grid elif mode == 'arrow': alg = _glyph( grid, orient='vec', scalars=scale, factor=factor ) mesh = pyvista.wrap(alg.GetOutput()) else: if mode == 'cone': glyph = vtk.vtkConeSource() glyph.SetCenter(0.5, 0, 0) glyph.SetRadius(0.15) elif mode == 'cylinder': glyph = vtk.vtkCylinderSource() glyph.SetRadius(0.15) else: assert mode == 'sphere', mode # guaranteed above glyph = vtk.vtkSphereSource() if mode == 'cylinder': if glyph_height is not None: glyph.SetHeight(glyph_height) if glyph_center is not None: glyph.SetCenter(glyph_center) if glyph_resolution is not None: glyph.SetResolution(glyph_resolution) # fix orientation glyph.Update() tr = vtk.vtkTransform() tr.RotateWXYZ(90, 0, 0, 1) trp = vtk.vtkTransformPolyDataFilter() trp.SetInputData(glyph.GetOutput()) trp.SetTransform(tr) glyph = trp glyph.Update() geom = glyph.GetOutput() mesh = grid.glyph(orient='vec', scale=scale, factor=factor, geom=geom) _add_mesh( self.plotter, mesh=mesh, color=color, opacity=opacity, backface_culling=backface_culling )
def quiver3d(self, x, y, z, u, v, w, color, scale, mode, resolution=8, glyph_height=None, glyph_center=None, glyph_resolution=None, opacity=1.0, scale_mode='none', scalars=None, colormap=None, backface_culling=False, line_width=2., name=None, glyph_width=None, glyph_depth=None, glyph_radius=0.15, solid_transform=None): _check_option('mode', mode, ALLOWED_QUIVER_MODES) with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=FutureWarning) factor = scale vectors = np.c_[u, v, w] points = np.vstack(np.c_[x, y, z]) n_points = len(points) cell_type = np.full(n_points, vtk.VTK_VERTEX) cells = np.c_[np.full(n_points, 1), range(n_points)] args = (cells, cell_type, points) if not VTK9: args = (np.arange(n_points) * 3, ) + args grid = UnstructuredGrid(*args) if scalars is not None: _point_data(grid)['scalars'] = np.array(scalars) scalars = 'scalars' _point_data(grid)['vec'] = vectors if scale_mode == 'scalar': scale = scalars scalars = None elif scale_mode == 'vector': scale = True else: scale = False if mode == '2darrow': return _arrow_glyph(grid, factor), grid elif mode == 'arrow': alg = _glyph(grid, orient='vec', scalars=scale, factor=factor) mesh = pyvista.wrap(alg.GetOutput()) else: tr = None if mode == 'cone': glyph = vtk.vtkConeSource() glyph.SetCenter(0.5, 0, 0) if glyph_radius is not None: glyph.SetRadius(glyph_radius) elif mode == 'cylinder': glyph = vtk.vtkCylinderSource() if glyph_radius is not None: glyph.SetRadius(glyph_radius) elif mode == 'oct': glyph = vtk.vtkPlatonicSolidSource() glyph.SetSolidTypeToOctahedron() else: assert mode == 'sphere', mode # guaranteed above glyph = vtk.vtkSphereSource() if mode == 'cylinder': if glyph_height is not None: glyph.SetHeight(glyph_height) if glyph_center is not None: glyph.SetCenter(glyph_center) if glyph_resolution is not None: glyph.SetResolution(glyph_resolution) tr = vtk.vtkTransform() tr.RotateWXYZ(90, 0, 0, 1) elif mode == 'oct': if solid_transform is not None: assert solid_transform.shape == (4, 4) tr = vtk.vtkTransform() tr.SetMatrix( solid_transform.astype(np.float64).ravel()) if tr is not None: # fix orientation glyph.Update() trp = vtk.vtkTransformPolyDataFilter() trp.SetInputData(glyph.GetOutput()) trp.SetTransform(tr) glyph = trp glyph.Update() geom = glyph.GetOutput() mesh = grid.glyph(orient='vec', scale=scale, factor=factor, geom=geom) actor = _add_mesh(self.plotter, mesh=mesh, color=color, opacity=opacity, scalars=scalars, colormap=colormap, show_scalar_bar=False, backface_culling=backface_culling) return actor, mesh