sphere = tvtk.SphereSource(center=(2, center[1], center[2]), radius=2, phi_resolution=6, theta_resolution=6) sphere_mapper = tvtk.PolyDataMapper(input_connection=sphere.output_port) sphere_actor = tvtk.Actor(mapper=sphere_mapper) sphere_actor.property.set(representation="wireframe", color=(0, 0, 0)) streamer = tvtk.StreamLine(step_length=0.0001, integration_direction="forward", integrator=tvtk.RungeKutta4()) streamer.set_input_data(grid) streamer.set_source_connection(sphere.output_port) tube = tvtk.TubeFilter(input_connection=streamer.output_port, radius=0.05, number_of_sides=6, vary_radius="vary_radius_by_scalar") tube_mapper = tvtk.PolyDataMapper(input_connection=tube.output_port, scalar_range=grid.point_data.scalars.range) tube_actor = tvtk.Actor(mapper=tube_mapper) tube_actor.property.backface_culling = True outline_actor = make_outline(grid) win = ivtk_scene([outline_actor, sphere_actor, tube_actor, arrows_actor]) win.scene.isometric_view() event_loop()
# 创建颜色映射表 import pylab as pl lut = tvtk.LookupTable() lut.table = pl.cm.cool(np.arange(0, 256)) * 255 # 显示StructuredGrid中的一个网格面 plane = tvtk.StructuredGridGeometryFilter(extent=(0, 100, 0, 100, 6, 6)) plane.set_input_data(grid) plane_mapper = tvtk.PolyDataMapper(input_connection=plane.output_port, lookup_table=lut) plane_mapper.scalar_range = grid.scalar_range plane_actor = tvtk.Actor(mapper=plane_mapper) lut2 = tvtk.LookupTable() lut2.table = pl.cm.cool(np.arange(0, 256)) * 255 cut_plane = tvtk.Plane(origin=grid.center, normal=(-0.287, 0, 0.9579)) cut = tvtk.Cutter(cut_function=cut_plane) cut.set_input_data(grid) cut_mapper = tvtk.PolyDataMapper(lookup_table=lut2, input_connection=cut.output_port) cut_actor = tvtk.Actor(mapper=cut_mapper) outline_actor = make_outline(grid) from scpy2.tvtk.tvtkhelp import ivtk_scene, event_loop win = ivtk_scene([plane_actor, cut_actor, outline_actor]) win.scene.isometric_view() event_loop()