def make_tube(height, radius, resolution, rx=0, ry=0, rz=0): cs1 = tvtk.CylinderSource(height=height, radius=radius[0], resolution=resolution) cs2 = tvtk.CylinderSource(height=height + 0.1, radius=radius[1], resolution=resolution) triangle1 = tvtk.TriangleFilter(input_connection=cs1.output_port) triangle2 = tvtk.TriangleFilter(input_connection=cs2.output_port) tr = tvtk.Transform() tr.rotate_x(rx) tr.rotate_y(ry) tr.rotate_z(rz) tf1 = tvtk.TransformFilter(transform=tr, input_connection=triangle1.output_port) tf2 = tvtk.TransformFilter(transform=tr, input_connection=triangle2.output_port) bf = tvtk.BooleanOperationPolyDataFilter() bf.operation = "difference" bf.set_input_connection(0, tf1.output_port) bf.set_input_connection(1, tf2.output_port) m = tvtk.PolyDataMapper(input_connection=bf.output_port, scalar_visibility=False) a = tvtk.Actor(mapper=m) return bf, a, tf1, tf2
def difference(pd1, pd2): bf = tvtk.BooleanOperationPolyDataFilter() bf.operation = "difference" bf.set_input_connection(0, pd1.output_port) bf.set_input_connection(1, pd2.output_port) m = tvtk.PolyDataMapper(input_connection=bf.output_port, scalar_visibility=False) a = tvtk.Actor(mapper=m) return bf, a
def _pipeline_default(self): cyl = self.cyl cyl.resolution = 63 #use a prime no to avoid vertex degeneracy # Important to ensure the cylinder end doesn't coincide with the corner of the cube cyl.height = self.thickness - 1 cyl.radius = self.diameter / 2.0 cyl.center = (0, (self.thickness / 2) - 1, 0) print("thickness", self.thickness) print("diameter", self.diameter) size = max(self.thickness, self.diameter) * 2 cube = self.cube cube.set_bounds(0, size, 0, size, 0, size) tf = tvtk.Transform() tf.post_multiply() tf.rotate_x(-45.0) tf.rotate_wxyz(35.26438968275, 0, 0, 1) tfilt = tvtk.TransformFilter(input_connection=cube.output_port) tfilt.transform = tf tri1 = tvtk.TriangleFilter(input_connection=cyl.output_port) tri2 = tvtk.TriangleFilter(input_connection=tfilt.output_port) tri1.update() tri2.update() intersect = tvtk.BooleanOperationPolyDataFilter() intersect.operation = "intersection" intersect.add_input_connection(0, tri1.output_port) intersect.add_input_connection(1, tri2.output_port) intersect.tolerance = 1e-8 tf2 = tvtk.Transform() tf2.rotate_x(90.0) tf2.rotate_y(60.0) orient = tvtk.TransformFilter(input_connection=intersect.output_port, transform=tf2) norm = tvtk.PolyDataNormals(input_connection=orient.output_port) transF = tvtk.TransformFilter(input_connection=norm.output_port, transform=self.transform) self.config_pipeline() return transF
def plot(self): r1, r2 = min(self.radius1, self.radius2), max(self.radius1, self.radius2) self.cs1 = cs1 = tvtk.CylinderSource(height=1, radius=r2, resolution=32) self.cs2 = 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 self.scene.add_actors([a]) self.scene.background = 1, 1, 1 self.scene.reset_zoom()
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()