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 __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 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 __init__(self): self.el = 0.0 self.az = 0.0 # Create an arrow. arrow = tvtk.ArrowSource() # Transform it suitably so it is oriented correctly. t = tvtk.Transform() tf = tvtk.TransformFilter() tf.transform = t t.rotate_y(90.0) t.translate((-2, 0, 0)) configure_input_data(tf, arrow.output) mapper = tvtk.PolyDataMapper() configure_input(mapper, tf) self.actor = actor = tvtk.Follower() actor.mapper = mapper prop = actor.property prop.color = 0, 1, 1 prop.ambient = 0.5 prop.diffuse = 0.5