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 plotLetter(self, mlab): line = self.objList[0] v1 = [ line.x[1] - line.x[0], line.y[1] - line.y[0], line.z[1] - line.z[0] ] v2 = [ line.x[2] - line.x[1], line.y[2] - line.y[1], line.z[2] - line.z[1] ] v1 = numpy.array(v1) v2 = numpy.array(v2) v1 = v1 / numpy.linalg.norm(v1) v2 = v2 / numpy.linalg.norm(v2) vtext = tvtk.VectorText() vtext.text = self.letter text_mapper = tvtk.PolyDataMapper() configure_input_data(text_mapper, vtext.get_output()) vtext.update() p2 = tvtk.Property(color=(self.color[0], self.color[1], self.color[2])) text_actor = tvtk.Follower(mapper=text_mapper, property=p2) text_actor.position = (0, 0, 0) auxx = text_actor._get_x_range() auxy = text_actor._get_y_range() yc = (auxy[1] - auxy[0]) / 2 alpha = self.b / (2 * yc) xm = (auxx[1] + auxx[0]) * alpha / 2 y0 = auxy[0] vCorr = (self.a / 2 - xm) * v1 - y0 * v2 text_actor.orientation = self.orientation text_actor.scale = numpy.array([alpha, alpha, 1]) auxx = text_actor._get_x_range() auxy = text_actor._get_y_range() text_actor.position = (line.x[0] + vCorr[0], line.y[0] + vCorr[1], line.z[0] + vCorr[2]) fig = mlab.gcf() fig.scene.add_actor(text_actor) return mlab
def setup_pipeline(self): """Override this method so that it *creates* the tvtk pipeline. This method is invoked when the object is initialized via `__init__`. Note that at the time this method is called, the tvtk data pipeline will *not* yet be setup. So upstream data will not be available. The idea is that you simply create the basic objects and setup those parts of the pipeline not dependent on upstream sources and filters. You should also set the `actors` attribute up at this point. """ self.vector_text = tvtk.VectorText(text=self.text) self.outputs = [self.vector_text] self.actor = Actor() self._text_changed(self.text)
cylinder_mapper = tvtk.PolyDataMapper() configure_input_data(cylinder_mapper, cylinder.output) cylinder.update() p = tvtk.Property(opacity=0.3, color=(0, 0, 1)) cylinder_actor = tvtk.Actor(position=(7, 0, 1), mapper=cylinder_mapper, property=p, orientation=(90, 0, 90)) v.scene.add_actor(cylinder_actor) # Create a line between the two spheres line = tvtk.LineSource(point1=(0, 0, 0), point2=(7, 0, 1)) line_mapper = tvtk.PolyDataMapper() configure_input_data(line_mapper, line.output) line.update() line_actor = tvtk.Actor(mapper=line_mapper) v.scene.add_actor(line_actor) # And display text vtext = tvtk.VectorText() vtext.text = 'Mayavi' text_mapper = tvtk.PolyDataMapper() configure_input_data(text_mapper, vtext.get_output()) vtext.update() p2 = tvtk.Property(color=(0, 0.3, 0.3)) text_actor = tvtk.Follower(mapper=text_mapper, property=p2) text_actor.position = (0, 0, 0) v.scene.add_actor(text_actor) # Choose a view angle, and display the figure mlab.view(85, -17, 15, [3.5, -0.3, -0.8]) mlab.show()