def vtk_convexhull(ch, radius=0.02): from tvtk.api import tvtk poly = tvtk.PolyData() poly.points = ch.points poly.polys = ch.simplices sphere = tvtk.SphereSource(radius=radius) points3d = tvtk.Glyph3D() points3d.set_source_connection(sphere.output_port) points3d.set_input_data(poly) m1 = tvtk.PolyDataMapper() m1.set_input_data(poly) a1 = tvtk.Actor(mapper=m1) a1.property.opacity = 0.3 m2 = tvtk.PolyDataMapper() m2.set_input_data(poly) a2 = tvtk.Actor(mapper=m2) a2.property.representation = "wireframe" a2.property.line_width = 2.0 a2.property.color = (1.0, 0, 0) m3 = tvtk.PolyDataMapper(input_connection=points3d.output_port) a3 = tvtk.Actor(mapper=m3) a3.property.color = (0.0, 1.0, 0.0) return [a1, a2, a3]
def rootSpI(img, list_remove=[], sc=None, lut_range=False, verbose=False): """ case where the data is a spatialimage """ # -- cells are positionned inside a structure, the polydata, and assigned a scalar value. polydata, polydata2 = img2polydata_complexe(img, list_remove=list_remove, sc=sc, verbose=verbose) m = tvtk.PolyDataMapper(input=polydata.output) m2 = tvtk.PolyDataMapper(input=polydata2.output) # -- definition of the scalar range (default : min to max of the scalar value). if sc: ran = [sc[i] for i in sc.keys() if i not in list_remove] if (lut_range != None) and (lut_range != False): print lut_range m.scalar_range = lut_range[0], lut_range[1] else: m.scalar_range = np.min(ran), np.max(ran) else: m.scalar_range = np.min(img), np.max(img) # -- actor that manage changes of view if memory is short. a = tvtk.QuadricLODActor(mapper=m) a.property.point_size = 8 a2 = tvtk.QuadricLODActor(mapper=m2) a2.property.point_size = 8 #scalebar if lut_range != None: sc = tvtk.ScalarBarActor(orientation='vertical', lookup_table=m.lookup_table) return a, a2, sc, m, m2
def convexhull(ch3d): poly = tvtk.PolyData() poly.points = ch3d.points poly.polys = ch3d.simplices sphere = tvtk.SphereSource(radius=0.02) points3d = tvtk.Glyph3D() points3d.set_source_connection(sphere.output_port) points3d.set_input_data(poly) # 绘制凸多面体的面,设置半透明度 m1 = tvtk.PolyDataMapper() m1.set_input_data(poly) a1 = tvtk.Actor(mapper=m1) a1.property.opacity = 0.3 # 绘制凸多面体的边,设置为红色 m2 = tvtk.PolyDataMapper() m2.set_input_data(poly) a2 = tvtk.Actor(mapper=m2) a2.property.representation = "wireframe" a2.property.line_width = 2.0 a2.property.color = (1.0, 0, 0) # 绘制凸多面体的顶点,设置为绿色 m3 = tvtk.PolyDataMapper(input_connection=points3d.output_port) a3 = tvtk.Actor(mapper=m3) a3.property.color = (0.0, 1.0, 0.0) return [a1, a2, a3]
def get_actors(self, scene): actors = [] sList = [self.f1_glyph, self.f2_glyph] cList = [(0, 1, 0), (1, 0, 0)] for s, c in zip(sList, cList): s.radius = 1.0 map = tvtk.PolyDataMapper(input_connection=s.output_port) act = tvtk.Actor(mapper=map, user_transform=self.transform) act.property.color = c actors.append(act) line = tvtk.LineSource(point1=(-100, 0, 0), point2=(100, 0, 0)) t_line = tvtk.TransformFilter( input_connection=line.output_port, transform=self.ellipse_trans.linear_inverse) map = tvtk.PolyDataMapper(input_connection=t_line.output_port) act = tvtk.Actor(mapper=map, user_transform=self.transform) act.property.color = (0, 0, 0) actors.append(act) l1 = tvtk.VectorText(text="F1") l2 = tvtk.VectorText(text="F2") m1 = tvtk.PolyDataMapper(input_connection=l1.output_port) m2 = tvtk.PolyDataMapper(input_connection=l2.output_port) act1 = self.f1_act act2 = self.f2_act act1.mapper = m1 act2.mapper = m2 scale = (5, 5, 5) act1.scale = scale act2.scale = scale act1.property.color = (0, 0, 0) act2.property.color = (0, 0, 0) act1.position = self.focus1 act2.position = self.focus2 def on_editor(new_ed): if new_ed is not None: act1.camera = new_ed._camera act2.camera = new_ed._camera scene.on_trait_change(on_editor, "scene_editor") actors.append(act1) actors.append(act2) for actor in actors: self.actors.append(actor) self.foci_Actors.append(actor) actor.visibility = self.show_foci return self.actors
def get_line(a, b): src = tvtk.LineSource(point1=a, point2=b) if new_tvtk: mapper = tvtk.PolyDataMapper() configure_input(mapper, src) else: mapper = tvtk.PolyDataMapper(input=src.output) actor = tvtk.Actor(mapper=mapper) fig.scene.add_actor(actor) return actor
def __init__(self, triangles, points, scalars=None, **traits): """ Parameters ---------- - triangles : array This contains a list of vertex indices forming the triangles. - points : array Contains the list of points referred to in the triangle list. - scalars : array (optional) Scalars to associate with the points. """ super(FancyTriMesh, self).__init__(**traits) self.points = points self.pd = make_triangle_polydata(triangles, points, scalars) # Update the radii so the default is computed correctly. self._tube_radius_changed(self.tube_radius) self._sphere_radius_changed(self.sphere_radius) scalar_vis = self.scalar_visibility # Extract the edges and show the lines as tubes. self.extract_filter = tvtk.ExtractEdges(input=self.pd) extract_f = self.extract_filter self.tube_filter.trait_set(input=extract_f.output, radius=self.tube_radius) edge_mapper = tvtk.PolyDataMapper(input=self.tube_filter.output, lookup_table=self.lut, scalar_visibility=scalar_vis) edge_actor = _make_actor(mapper=edge_mapper) edge_actor.property.color = self.color # Create the spheres for the points. self.sphere_source.radius = self.sphere_radius spheres = tvtk.Glyph3D(scaling=0, source=self.sphere_source.output, input=extract_f.output) sphere_mapper = tvtk.PolyDataMapper(input=spheres.output, lookup_table=self.lut, scalar_visibility=scalar_vis) sphere_actor = _make_actor(mapper=sphere_mapper) sphere_actor.property.color = self.color if scalars is not None: rs = numpy.ravel(scalars) dr = min(rs), max(rs) self.lut.table_range = dr edge_mapper.scalar_range = dr sphere_mapper.scalar_range = dr self.actors.extend([edge_actor, sphere_actor])
def earth_actor(radius=0.5, opacity=1.0): """ Creates an earth source and returns the actor. """ source = tvtk.EarthSource(radius=radius, on_ratio=16, outline=0) mapper = tvtk.PolyDataMapper(input=source.output) prop = tvtk.Property(opacity=opacity) actor = tvtk.Actor(mapper=mapper, property=prop) return actor
def cylindrical_post(info=None): verts = info['verts'] diameter = info['diameter'] radius = diameter / 2.0 actors = [] verts = numpy.asarray(verts) pd = tvtk.PolyData() np = len(verts) - 1 lines = numpy.zeros((np, 2), numpy.int64) lines[:, 0] = numpy.arange(0, np - 0.5, 1, numpy.int64) lines[:, 1] = numpy.arange(1, np + 0.5, 1, numpy.int64) pd.points = verts pd.lines = lines pt = tvtk.TubeFilter( radius=radius, input=pd, number_of_sides=20, vary_radius='vary_radius_off', ) m = tvtk.PolyDataMapper(input=pt.output) a = tvtk.Actor(mapper=m) a.property.color = 0, 0, 0 a.property.specular = 0.3 actors.append(a) return actors
def init_plot(self): # create a window with 14 plots (7 rows x 2 columns) ## create a window with 8 plots (4 rows x 2 columns) reader = tvtk.OBJReader() reader.file_name = self.mayavi_view.filename mapper = tvtk.PolyDataMapper() mapper.input = reader.output actor = tvtk.Actor() mapper.color_mode = 0x000000 actor.mapper = mapper actor.orientation = (180,0,90) self.scene.add_actor(actor) mlab.points3d(11.5, -1.3, -14) mlab.points3d(-6.6, -1.3, -13.5) mlab.points3d(3,-2,2) mlab.points3d(2, 9.5, -9.5) self.arrows = mlab.quiver3d(self.tail_data[:,0], self.tail_data[:,1], self.tail_data[:,2], self.head_data[:,0], self.head_data[:,1], self.head_data[:,2], scale_mode='vector', scale_factor=1.0) self.dots = mlab.points3d(self.tail_data[:,0], self.tail_data[:,1], self.tail_data[:,2], color=(1,1,0),opacity=0.5,scale_mode='vector', scale_factor=1.0) self.ar = self.arrows.mlab_source self.dot_source = self.dots.mlab_source '''
def test_property_change_notification(self): """Test if changes to properties generate notification events.""" # Create a dummy class to test with. class Junk: def f(self, obj, name, old, new): self.data = obj, name, old, new z = Junk() cs = tvtk.ConeSource() m = tvtk.PolyDataMapper() if vtk_major_version < 6: m.on_trait_change(z.f, 'input') m.input = cs.output self.assertEqual(z.data, (m, 'input', None, cs.output)) m.input = None self.assertEqual(z.data, (m, 'input', cs.output, None)) m.on_trait_change(z.f, 'input', remove=True) m.input = cs.output else: m.on_trait_change(z.f, 'input_connection') m.input_connection = cs.output_port self.assertEqual(z.data, (m, 'input_connection', None, cs.output_port)) m.input_connection = None self.assertEqual(z.data, (m, 'input_connection', cs.output_port, None)) m.on_trait_change(z.f, 'input_connection', remove=True) m.input_connection = cs.output_port a = tvtk.Actor() a.on_trait_change(z.f, 'mapper') a.on_trait_change(z.f, 'property') a.mapper = m self.assertEqual(z.data, (a, 'mapper', None, m)) old = a.property new = tvtk.Property() a.property = new self.assertEqual(z.data, (a, 'property', old, new)) # Check if property notification occurs on add_input/remove_input a = tvtk.AppendPolyData() pd = tvtk.PolyData() if vtk_major_version < 6: a.on_trait_change(z.f, 'input') a.add_input(pd) old, new = None, pd self.assertEqual(z.data, (a, 'input', old, new)) a.remove_input(pd) old, new = pd, None self.assertEqual(z.data, (a, 'input', old, new)) a.remove_all_inputs() old, new = None, None self.assertEqual(z.data, (a, 'input', old, new)) else: a.add_input_data(pd) self.assertEqual(a.input, pd) a.remove_input_data(pd) self.assertEqual(a.input, None) a.remove_all_inputs() self.assertEqual(a.input, None)
def __init__(self, points, **traits): super(MLabBase, self).__init__(**traits) assert len(points[0]) == 3, "The points must be 3D" self.points = points np = len(points) - 1 lines = numpy.zeros((np, 2), 'l') lines[:, 0] = numpy.arange(0, np - 0.5, 1, 'l') lines[:, 1] = numpy.arange(1, np + 0.5, 1, 'l') pd = tvtk.PolyData(points=points, lines=lines) self.poly_data = pd mapper = tvtk.PolyDataMapper() self.mapper = mapper tf = self.tube_filter tf.radius = self.radius if self.use_tubes: configure_input_data(tf, pd) configure_input_data(mapper, tf.output) a = _make_actor(mapper=mapper) a.property.color = self.color self.actors.append(a)
def __init__(self, renwin, **traits): super(Picker, self).__init__(**traits) self.renwin = renwin self.pointpicker = tvtk.PointPicker() self.cellpicker = tvtk.CellPicker() self.worldpicker = tvtk.WorldPointPicker() self.probe_data = tvtk.PolyData() self._tolerance_changed(self.tolerance) # Use a set of axis to show the picked point. self.p_source = tvtk.Axes() self.p_mapper = tvtk.PolyDataMapper() self.p_actor = tvtk.Actor() self.p_source.symmetric = 1 self.p_actor.pickable = 0 self.p_actor.visibility = 0 prop = self.p_actor.property prop.line_width = 2 prop.ambient = 1.0 prop.diffuse = 0.0 self.p_mapper.input = self.p_source.output self.p_actor.mapper = self.p_mapper self.probe_data.points = [[0.0, 0.0, 0.0]] self.ui = None
def __init__(self, x, y, z, scalars, **traits): """ Parameters ---------- - x : array A list of x coordinate values formed using numpy.mgrid. - y : array A list of y coordinate values formed using numpy.mgrid. - z : array A list of z coordinate values formed using numpy.mgrid. - scalars : array Scalars to associate with the points. """ super(Contour3, self).__init__(**traits) triangles, points = make_triangles_points(x, y, z, scalars) self.pd = make_triangle_polydata(triangles, points, scalars) dr = self.pd.point_data.scalars.range self.lut.table_range = dr cf = self.contour_filter configure_input_data(cf, self.pd) cf.generate_values(self.number_of_contours, dr[0], dr[1]) mapper = tvtk.PolyDataMapper(input=cf.output, lookup_table=self.lut, scalar_range=dr) cont_actor = _make_actor(mapper=mapper) self.actors.append(cont_actor)
def draw_cubic_solid(origin,size): actors = [] x = numpy.array([1,0,0]) y = numpy.array([0,1,0]) z = numpy.array([0,0,1]) verts = [ origin + y*size, origin + y*size + x*size, origin + y*size + x*size + z*size, origin + y*size + z*size, origin, origin + x*size, origin + x*size + z*size, origin + z*size] # indexes into verts edges = [ [0,1], [1,2], [2,3], [3,0], [4,5], [5,6], [6,7], [7,4], [4,0], [5,1], [6,2], [7,3] ] pd = tvtk.PolyData() pd.points = verts pd.lines = edges if 1: pt = tvtk.TubeFilter(radius=0.0254*0.5,input=pd, number_of_sides=12, vary_radius='vary_radius_off', ) m = tvtk.PolyDataMapper(input=pt.output) a = tvtk.Actor(mapper=m) a.property.color = .9, .9, .9 a.property.specular = 0.3 actors.append(a) return actors
def linesBody(mb, bodyName, successorJointsName): """ Return a mesh represented by lines and the appropriate static transform. """ apd = tvtk.AppendPolyData() sources = [] # create a line from the body base to the next joint for s in map(mb.jointIndexByName, successorJointsName[bodyName]): X_s = mb.transform(s) sources.append(tvtk.LineSource(point1=(0., 0., 0.), point2=tuple(X_s.translation()))) # add an empty source to avoid a warning if AppendPolyData have 0 source if len(sources) == 0: sources.append(tvtk.PointSource(radius=0.)) map(lambda s: apd.add_input(s.output), sources) apd.update() pdm = tvtk.PolyDataMapper() pdm.input_connection = apd.output_port actor = tvtk.Actor(mapper=pdm) actor.property.color = (0., 0., 0.) actor.user_transform = tvtk.Transform() return actor, sva.PTransformd.Identity()
def drawsoma(): pts = self.mitral.soma.points center = misc.centroid(pts) # calc. soma radius radius = 0. for p in pts: radius += misc.distance(p, center) radius /= len(pts) radius *= cone_factor # versor u = tuple( misc.versor(self.mitral.apic.points[0], self.mitral.apic.points[1])) src = tvtk.ConeSource(center=tuple(center[0:3]), radius=radius, height=radius, direction=u, resolution=20) mapper = tvtk.PolyDataMapper(input=src.output) actor = tvtk.Actor(mapper=mapper) fig.scene.add_actor(actor) actor.property.color = self.soma_color return actor
def __init__(self, X=sva.PTransformd.Identity(), length=0.1, text=''): """ Create a 3D axis. """ self._X = X self.axesActor = tvtk.AxesActor(total_length=(length, ) * 3, axis_labels=False) self.axesActor.user_transform = tvtk.Transform() textSource = tvtk.TextSource(text=text, backing=False) # textPdm = tvtk.PolyDataMapper(input=textSource.output) textPdm = tvtk.PolyDataMapper() # https://stackoverflow.com/questions/35089379/how-to-fix-traiterror-the-input-trait-of-a-instance-is-read-only # configure_input_data(textPdm, textSource.output_port) # https://github.com/enthought/mayavi/issues/521 textPdm.input_connection = textSource.output_port #self.textActor = tvtk.Actor(mapper=textPdm) self.textActor = tvtk.Follower(mapper=textPdm) # take the maximum component of the bound and use it to scale it m = max(self.textActor.bounds) scale = length / m self.textActor.scale = (scale, ) * 3 # TODO compute the origin well... self.textActor.origin = ( -(self.textActor.bounds[0] + self.textActor.bounds[1]) / 2., -(self.textActor.bounds[2] + self.textActor.bounds[3]) / 2., -(self.textActor.bounds[4] + self.textActor.bounds[5]) / 2., ) ySize = self.textActor.bounds[3] * 1.2 self.X_text = sva.PTransformd(e.Vector3d(0., -ySize, 0.)) self._transform()
def main(hdf5_animation_file): weights = None with h5py.File(hdf5_animation_file, 'r') as f: verts = f['verts'].value tris = f['tris'].value if 'weights' in f: weights = f['weights'].value pd = tvtk.PolyData(points=verts[0], polys=tris) normals = tvtk.PolyDataNormals(input=pd, splitting=False) actor = tvtk.Actor(mapper=tvtk.PolyDataMapper(input=normals.output)) actor.property.set(edge_color=(0.5, 0.5, 0.5), ambient=0.0, specular=0.15, specular_power=128., shading=True, diffuse=0.8) fig = mlab.figure(bgcolor=(1,1,1)) fig.scene.add_actor(actor) @mlab.animate(delay=40, ui=False) def animation(): for i in count(): if weights is not None: w_str = ",".join(["%0.2f"] * weights.shape[1]) print ("Frame %d Weights = " + w_str) % tuple([i] + weights[i].tolist()) frame = i % len(verts) pd.points = verts[frame] fig.scene.render() yield a = animation() fig.scene.z_minus_view() mlab.show()
def __init__(self, linear, angular, frame, linColor, angColor): """ Create the visualization of a 6D vector with a linear and angular part. Parameter: linear: 3d linear component (e.Vector3d) angular: 3d angular component (e.Vector3d) frame: vector frame (sva.PTransformd) linColor: linear component color (float, float, float) angColor: angular component color (float, float, float) """ self.linearActor, X_l = self._createVector(linear, frame, linColor) self.angularActor, X_a = self._createVector(angular, frame, angColor) # create a Arc around the angular axis # The arc must turn around the X axis (Arrow default axis) angNorm = angular.norm() angNormW = angNorm*0.3 arcSource = tvtk.ArcSource(point1=(angNorm/2., -angNormW, -angNormW), point2=(angNorm/2., -angNormW, angNormW), center=(angNorm/2., 0., 0.), negative=True, resolution=20) arcPdm = tvtk.PolyDataMapper(input=arcSource.output) self.arcActor = tvtk.Actor(mapper=arcPdm) self.arcActor.property.color = angColor self.arcActor.user_transform = tvtk.Transform() # apply the angular transform setActorTransform(self.arcActor, X_a)
def __init__(self, X=sva.PTransformd.Identity(), length=0.1, text=''): """ Create a 3D axis. """ self._X = X self.axesActor = tvtk.AxesActor(total_length=(length, ) * 3, axis_labels=False) self.axesActor.user_transform = tvtk.Transform() textSource = tvtk.TextSource(text=text, backing=False) textPdm = tvtk.PolyDataMapper(input=textSource.output) #self.textActor = tvtk.Actor(mapper=textPdm) self.textActor = tvtk.Follower(mapper=textPdm) # take the maximum component of the bound and use it to scale it m = max(self.textActor.bounds) scale = length / m self.textActor.scale = (scale, ) * 3 # TODO compute the origin well... self.textActor.origin = ( -(self.textActor.bounds[0] + self.textActor.bounds[1]) / 2., -(self.textActor.bounds[2] + self.textActor.bounds[3]) / 2., -(self.textActor.bounds[4] + self.textActor.bounds[5]) / 2., ) ySize = self.textActor.bounds[3] * 1.2 self.X_text = sva.PTransformd(e.Vector3d(0., -ySize, 0.)) self._transform()
def meshBody(fileName, scale=(1., 1., 1.)): """ Return a mesh actor and the appropriate static transform. """ reader = FILE_READER[splitext(fileName)[1]](file_name=fileName) output = reader.output # if a scale is set we have to apply it if map(float, scale) != [1., 1., 1.]: tpdf_transform = tvtk.Transform() tpdf_transform.identity() tpdf_transform.scale(scale) tpdf = tvtk.TransformPolyDataFilter(input=reader.output, transform=tpdf_transform) tpdf.update() output = tpdf.output # compute mesh normal to have a better render and reverse mesh normal # if the scale flip them pdn = tvtk.PolyDataNormals(input=output) pdn.update() output = pdn.output pdm = tvtk.PolyDataMapper(input=output) actor = tvtk.Actor(mapper=pdm) actor.user_transform = tvtk.Transform() return actor, sva.PTransformd.Identity()
def main(hdf5_animation_file, sid='50004', pid='jiggle_on_toes'): with h5py.File(hdf5_animation_file, 'r') as f: verts = f[sid + '_' + pid].value.transpose([2, 0, 1]) tris = f['faces'].value pd = tvtk.PolyData(points=verts[0], polys=tris) normals = tvtk.PolyDataNormals(input=pd, splitting=False) actor = tvtk.Actor(mapper=tvtk.PolyDataMapper(input=normals.output)) actor.property.set(edge_color=(0.5, 0.5, 0.5), ambient=0.0, specular=0.15, specular_power=128., shading=True, diffuse=0.8) fig = mlab.figure(bgcolor=(1, 1, 1)) fig.scene.add_actor(actor) @mlab.animate(delay=40, ui=False) def animation(): for i in count(): frame = i % len(verts) pd.points = verts[frame] fig.scene.render() yield a = animation() fig.scene.z_minus_view() mlab.show()
def __init__(self, x, y, z, scalars=None, **traits): """ Parameters ---------- - x : array A list of x coordinate values formed using numpy.mgrid. - y : array A list of y coordinate values formed using numpy.mgrid. - z : array A list of z coordinate values formed using numpy.mgrid. - scalars : array (optional) Scalars to associate with the points. """ super(Surf, self).__init__(**traits) triangles, points = make_triangles_points(x, y, z, scalars) self.pd = make_triangle_polydata(triangles, points, scalars) mapper = tvtk.PolyDataMapper(input=self.pd, lookup_table=self.lut, scalar_visibility=self.scalar_visibility) if scalars is not None: rs = numpy.ravel(scalars) dr = min(rs), max(rs) mapper.scalar_range = dr self.lut.table_range = dr actor = _make_actor(mapper=mapper) actor.property.trait_set(color=self.color) self.actors.append(actor)
def _render_mesh(self, mesh_type="surface", ambient_light=0.0, specular_light=0.0, alpha=1.0): from tvtk.api import tvtk pd = tvtk.PolyData() pd.points = self.points pd.polys = self.trilist pd.point_data.t_coords = self.tcoords_per_point mapper = tvtk.PolyDataMapper() mapper.set_input_data(pd) p = tvtk.Property( representation=mesh_type, opacity=alpha, ambient=ambient_light, specular=specular_light, ) actor = tvtk.Actor(mapper=mapper, property=p) # Get the pixels from our image class which are [0, 1] and scale # back to valid pixels. Then convert to tvtk ImageData. texture = self.texture.pixels_with_channels_at_back(out_dtype=np.uint8) if self.texture.n_channels == 1: texture = np.stack([texture] * 3, axis=-1) image_data = np.flipud(texture).ravel() image_data = image_data.reshape([-1, 3]) image = tvtk.ImageData() image.point_data.scalars = image_data image.dimensions = self.texture.width, self.texture.height, 1 texture = tvtk.Texture() texture.set_input_data(image) actor.texture = texture self.figure.scene.add_actors(actor) self._actors.append(actor)
def __init__(self, points, vectors=None, scalars=None, **traits): super(Glyphs, self).__init__(**traits) if vectors is not None: assert len(points) == len(vectors) if scalars is not None: assert len(points) == len(scalars) self.points = points self.vectors = vectors self.scalars = scalars polys = numpy.arange(0, len(points), 1, 'l') polys = numpy.reshape(polys, (len(points), 1)) pd = tvtk.PolyData(points=points, polys=polys) if self.vectors is not None: pd.point_data.vectors = vectors pd.point_data.vectors.name = 'vectors' if self.scalars is not None: pd.point_data.scalars = scalars pd.point_data.scalars.name = 'scalars' self.poly_data = pd configure_input_data(self.glyph, pd) if self.glyph_source: self.glyph.source = self.glyph_source.output mapper = tvtk.PolyDataMapper(input=self.glyph.output) actor = _make_actor(mapper=mapper) actor.property.color = self.color self.actors.append(actor)
def __init__(self, renwin, **traits): super(Picker, self).__init__(**traits) self.pointpicker = tvtk.PointPicker() self.cellpicker = tvtk.CellPicker() self.worldpicker = tvtk.WorldPointPicker() self.probe_data = tvtk.PolyData() # Use a set of axis to show the picked point. self.p_source = tvtk.Axes() self.p_mapper = tvtk.PolyDataMapper() self.p_actor = tvtk.Actor() self.p_source.symmetric = 1 self.p_actor.pickable = 0 self.p_actor.visibility = 0 prop = self.p_actor.property prop.line_width = 2 prop.ambient = 1.0 prop.diffuse = 0.0 configure_input(self.p_mapper, self.p_source) self.p_actor.mapper = self.p_mapper self.probe_data.points = [[0.0, 0.0, 0.0]] self.text_rep = tvtk.TextRepresentation() self.text_widget = tvtk.TextWidget() self.data = PickedData(renwin=renwin) self.data.text_actor = tvtk.TextActor() self.text_setup() self.widgets = False
def __init__(self, x, y, z, warp=1, scale=[1.0, 1.0, 1.0], f_args=(), f_kwargs=None, **traits): super(SurfRegularC, self).__init__(**traits) if f_kwargs is None: f_kwargs = {} data, actor = make_surf_actor(x, y, z, warp, scale, *f_args, **f_kwargs) mapper = actor.mapper mapper.lookup_table = self.lut self.lut.table_range = mapper.scalar_range self.data = data dr = data.point_data.scalars.range cf = self.contour_filter configure_input_data(cf, data) cf.generate_values(self.number_of_contours, dr[0], dr[1]) mapper = tvtk.PolyDataMapper(input=cf.output, lookup_table=self.lut) cont_actor = _make_actor(mapper=mapper) self.actors.extend([actor, cont_actor])
def pointcloud_as_vtk_actor(points, pt_colors=None, point_size=5.0, alpha=1.0): pd = pointcloud_as_vtk_polydata(points, pt_colors) mapper = tvtk.PolyDataMapper() configure_input(mapper, pd) actor = tvtk.Actor(mapper=mapper) actor.property.set(point_size=point_size, opacity=alpha) return actor, pd
def visualize_point_correspondences(source_pts, target_pts, ij_corr=None, scalars=None, point_size=10): if ij_corr is None: if source_pts.shape != target_pts.shape: raise ValueError( "must have same amount of source and target points, or specify ij_corr parameter" ) ij_corr = np.column_stack( (np.arange(len(source_pts)), np.arange(len(target_pts)))) p = source_pts[ij_corr[:, 0]] p2 = target_pts[ij_corr[:, 1]] pd = tvtk.PolyData(points=p, verts=np.r_[:len(p)].reshape((-1, 1))) actor = tvtk.Actor(mapper=tvtk.PolyDataMapper()) configure_input_data(actor.mapper, pd) actor.property.point_size = point_size if scalars is not None: pd.point_data.scalars = scalars actor.mapper.scalar_range = scalars.min(), scalars.max() mlab.gcf().scene.add_actor(actor) class Ctrl(ta.HasTraits): alpha = ta.Range(0., 1.) def _alpha_changed(self): pd.points = p + self.alpha * (p2 - p) mlab.gcf().scene.render() Ctrl().configure_traits()
def endEffectorBody(X_s, size, color): """ Return a end effector reprsented by a plane and the appropriate static transform. """ apd = tvtk.AppendPolyData() ls = tvtk.LineSource(point1=(0., 0., 0.), point2=tuple(X_s.translation())) p1 = (sva.PTransformd(e.Vector3d.UnitX() * size) * X_s).translation() p2 = (sva.PTransformd(e.Vector3d.UnitY() * size) * X_s).translation() ps = tvtk.PlaneSource(origin=tuple(X_s.translation()), point1=tuple(p1), point2=tuple(p2), center=tuple(X_s.translation())) apd.add_input(ls.output) apd.add_input(ps.output) pdm = tvtk.PolyDataMapper(input=apd.output) actor = tvtk.Actor(mapper=pdm) actor.property.color = color actor.user_transform = tvtk.Transform() return actor, sva.PTransformd.Identity()