def test_multi_renderers(): plotter = vtki.Plotter(shape=(2, 2), off_screen=OFF_SCREEN) loc = (0, 0) plotter.add_text('Render Window 0', loc=loc, font_size=30) sphere = vtki.Sphere() plotter.add_mesh(sphere, loc=loc, scalars=sphere.points[:, 2]) plotter.add_scalar_bar('Z', vertical=True) loc = (0, 1) plotter.add_text('Render Window 1', loc=loc, font_size=30) plotter.add_mesh(vtki.Cube(), loc=loc, show_edges=True) loc = (1, 0) plotter.add_text('Render Window 2', loc=loc, font_size=30) plotter.add_mesh(vtki.Arrow(), color='y', loc=loc, show_edges=True) plotter.subplot(1, 1) plotter.add_text('Render Window 3', loc=loc, font_size=30) plotter.add_mesh(vtki.Cone(), color='g', loc=loc, show_edges=True, backface_culling=True) plotter.add_bounding_box(render_lines_as_tubes=True, line_width=5) plotter.show_bounds(all_edges=True) plotter.update_bounds_axes() plotter.plot()
import vtki import numpy as np # Make a grid: x, y, z = np.meshgrid(np.linspace(-5, 5, 20), np.linspace(-5, 5, 20), np.linspace(-5, 5, 5)) grid = vtki.StructuredGrid(x, y, z) vectors = np.sin(grid.points)**3 # Compute a direction for the vector field grid.point_arrays['mag'] = np.linalg.norm(vectors, axis=1) grid.point_arrays['vec'] = vectors # Make a geometric obhect to use as the glyph geom = vtki.Arrow() # This could be any dataset # Perform the glyph glyphs = grid.glyph(orient='vec', scale='mag', factor=0.8, geom=geom) # plot using the plotting class p = vtki.Plotter() p.add_mesh(glyphs) p.show()
def test_remove_points_fail(): arrow = vtki.Arrow([0, 0, 0], [1, 0, 0]) with pytest.raises(Exception): arrow.remove_points(range(10))
def test_tri_filter(): arrow = vtki.Arrow([0, 0, 0], [1, 1, 1]) assert arrow.faces.size % 4 arrow.tri_filter(inplace=True) assert not (arrow.faces.size % 4)
def test_arrow(): surf = vtki.Arrow([0, 0, 0], [1, 1, 1]) assert np.any(surf.points) assert np.any(surf.faces)
Geometric Objects ~~~~~~~~~~~~~~~~~ The "Hello, world!" of VTK """ import vtki ################################################################################ # This runs through several of the available geomoetric objects available in VTK # which ``vtki`` provides simple conveinance methods for generating. # # Let's run through creating a few geometric objects! cyl = vtki.Cylinder() arrow = vtki.Arrow() sphere = vtki.Sphere() plane = vtki.Plane() line = vtki.Line() box = vtki.Box() cone = vtki.Cone() poly = vtki.Polygon() disc = vtki.Disc() ################################################################################ # Now let's plot them all in one window p = vtki.Plotter(shape=(3, 3)) # Top row p.subplot(0,0) p.add_mesh(cyl, color='tan', show_edges=True)