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()
# -*- coding: utf-8 -*- from tvtk.api import tvtk from scpy2.tvtk.tvtkhelp import ivtk_scene, event_loop cs = tvtk.ConeSource(height=3.0, radius=1.0, resolution=36) m = tvtk.PolyDataMapper(input_connection=cs.output_port) a = tvtk.Actor(mapper=m) win = ivtk_scene([a]) win.scene.isometric_view() event_loop()
from tvtk.api import tvtk r1 = 0.5 r2 = 0.9 cs1 = tvtk.CylinderSource(height=1, radius=r2, resolution=32) cs2 = tvtk.CylinderSource(height=1.1, radius=r1, resolution=32) triangle1 = tvtk.TriangleFilter(input_connection=cs1.output_port) triangle2 = tvtk.TriangleFilter(input_connection=cs2.output_port) bf = tvtk.BooleanOperationPolyDataFilter() bf.operation = "difference" bf.set_input_connection(0, triangle1.output_port) bf.set_input_connection(1, triangle2.output_port) m = tvtk.PolyDataMapper(input_connection=bf.output_port, scalar_visibility=False) a = tvtk.Actor(mapper=m) a.property.color = 0.5, 0.5, 0.5 from scpy2.tvtk.tvtkhelp import ivtk_scene, event_loop scene = ivtk_scene([a]) 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()
# -*- coding: utf-8 -*- from .example_cut_plane import read_data from tvtk.api import tvtk from scpy2.tvtk.tvtkhelp import ivtk_scene, event_loop, make_outline plot3d = read_data() grid = plot3d.output.get_block(0) contours = tvtk.ContourFilter() contours.set_input_data(grid) contours.generate_values(8, grid.point_data.scalars.range) mapper = tvtk.PolyDataMapper(scalar_range=grid.point_data.scalars.range, input_connection=contours.output_port) actor = tvtk.Actor(mapper=mapper) actor.property.opacity = 0.3 outline_actor = make_outline(grid) win = ivtk_scene([actor, outline_actor]) win.scene.isometric_view() event_loop()
# -*- coding: utf-8 -*- from example_cut_plane import read_data from tvtk.api import tvtk if __name__ == "__main__": plot3d = read_data() contours = tvtk.ContourFilter(input = plot3d.output) contours.generate_values(8, plot3d.output.point_data.scalars.range) #{1} mapper = tvtk.PolyDataMapper(input = contours.output, scalar_range = plot3d.output.point_data.scalars.range) #{2} actor = tvtk.Actor(mapper = mapper) actor.property.opacity = 0.3 #{3} # StructuredGridÍø¸ñµÄÍâ¿ò outline = tvtk.StructuredGridOutlineFilter(input = plot3d.output) outline_mapper = tvtk.PolyDataMapper(input = outline.output) outline_actor = tvtk.Actor(mapper = outline_mapper) outline_actor.property.color = 0.3, 0.3, 0.3 from scpy2.tvtk.tvtkhelp import ivtk_scene win = ivtk_scene([actor, outline_actor]) win.scene.isometric_view() from pyface.api import GUI gui = GUI() gui.start_event_loop()
input = plot3d.output, source = sphere.output, step_length = 0.0001, integration_direction = "forward", integrator = tvtk.RungeKutta4()) #{3} tube = tvtk.TubeFilter( #{4} input = streamer.output, radius = 0.05, number_of_sides = 6, vary_radius = "vary_radius_by_scalar") tube_mapper = tvtk.PolyDataMapper( input = tube.output, scalar_range = plot3d.output.point_data.scalars.range) tube_actor = tvtk.Actor(mapper = tube_mapper) tube_actor.property.backface_culling = True ###2### # StructuredGrid网格的外框 outline = tvtk.StructuredGridOutlineFilter(input = plot3d.output) outline_mapper = tvtk.PolyDataMapper(input = outline.output) outline_actor = tvtk.Actor(mapper = outline_mapper) outline_actor.property.color = 0.3, 0.3, 0.3 from scpy2.tvtk.tvtkhelp import ivtk_scene win = ivtk_scene([outline_actor, sphere_actor, tube_actor, arrows_actor]) win.scene.isometric_view() from pyface.api import GUI gui = GUI() gui.start_event_loop()