示例#1
0
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()
示例#2
0
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()
示例#3
0
    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
示例#4
0
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
示例#5
0
def line(renderer=renderer):
    source = tvtk.LineSource()
    # mapper
    mapper = tvtk.PolyDataMapper()
    mapper.set_input_data(source.output)
     
    # actor
    actor = tvtk.Actor()
    actor.property.line_width = 10
    actor.mapper = mapper
    renderer.add_actor(actor)
    return actor
示例#6
0
    def plot_atoms_3d(self, fig, a, x, y, z):
        #
        #       !!! works on our molecules only !!!
        #       todo: use some python libraries to draw any molecule

        #       always in order: X, H, H, H, H, O
        sphere_radius = [0.3, 0.1, 0.1, 0.1, 0.1, 0.2]
        sphere_color = [(0.0, 0.5, 0.5), (0.1, 0.1, 0.1), (0.1, 0.1, 0.1),
                        (0.1, 0.1, 0.1), (0.1, 0.1, 0.1), (1.0, 0.0, 0.0)]

        #       draw atoms
        #       ----------
        atom = []
        for i in range(len(x)):
            sphere = tvtk.SphereSource(center=(x[i], y[i], z[i]),
                                       radius=sphere_radius[i],
                                       theta_resolution=80,
                                       phi_resolution=80)
            sphere_mapper = tvtk.PolyDataMapper()
            configure_input_data(sphere_mapper, sphere.output)
            sphere.update()
            p = tvtk.Property(opacity=0.8, color=sphere_color[i])
            sphere_actor = tvtk.Actor(mapper=sphere_mapper, property=p)
            fig.scene.add_actor(sphere_actor)
            atom.append(sphere_actor)

#       draw bonds
#       ----------
#       always in order: X, H, H, H, H, O
        pairs = [[0, 1], [0, 2], [5, 3], [5, 4]]
        bond = []
        for i in range(len(pairs)):
            p1 = (x[pairs[i][0]], y[pairs[i][0]], z[pairs[i][0]])
            p2 = (x[pairs[i][1]], y[pairs[i][1]], z[pairs[i][1]])
            line = tvtk.LineSource(point1=p1, point2=p2)
            line_mapper = tvtk.PolyDataMapper()
            configure_input_data(line_mapper, line.output)
            line.update()
            tvtk.Property(opacity=0.8)
            line_actor = tvtk.Actor(mapper=line_mapper)
            line_actor.property.line_width = 1.9
            line_actor.property.color = (0.4, 0.4, 0.4)
            fig.scene.add_actor(line_actor)
            bond.append(line_actor)
示例#7
0
 def __source_dict_default(self):
     """Default value for source dict."""
     sd = {
         'arrow': tvtk.ArrowSource(),
         'cone': tvtk.ConeSource(),
         'cube': tvtk.CubeSource(),
         'cylinder': tvtk.CylinderSource(),
         'disk': tvtk.DiskSource(),
         'earth': tvtk.EarthSource(),
         'line': tvtk.LineSource(),
         'outline': tvtk.OutlineSource(),
         'plane': tvtk.PlaneSource(),
         'point': tvtk.PointSource(),
         'polygon': tvtk.RegularPolygonSource(),
         'sphere': tvtk.SphereSource(),
         'superquadric': tvtk.SuperquadricSource(),
         'textured sphere': tvtk.TexturedSphereSource(),
         'glyph2d': tvtk.GlyphSource2D()
     }
     return sd
示例#8
0
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)
  # https://github.com/enthought/mayavi/blob/ac5c8e316335078c25461a0bce4a724ae86f1836/tvtk/tests/test_tvtk.py#L586
  apd.add_input_data(ls.output)
  apd.add_input_data(ps.output)

  # pdm = tvtk.PolyDataMapper(input=apd.output)
  # arcPdm = tvtk.PolyDataMapper(input=arcSource.output)
  pdm = 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)# https://github.com/enthought/mayavi/issues/521
  pdm.input_connection = apd.output_port

  prop = tvtk.Property(color=color)
  # https://github.com/enthought/mayavi/issues/521
  # arcPdm.input_connection = arcSource.output_port
  actor = tvtk.Actor(mapper=pdm, property=prop)
  actor.property.color = color
  actor.user_transform = tvtk.Transform()

  return actor, sva.PTransformd.Identity()
def get_line(a, b):
  src = tvtk.LineSource(point1=a, point2=b)
  mapper = tvtk.PolyDataMapper(input=src.output)
  actor = tvtk.Actor(mapper=mapper)
  fig.scene.add_actor(actor)
  return actor
示例#10
0
# The actor is the actually object in the scene.
sphere_actor = tvtk.Actor(position=(0, 0, 0), mapper=sphere_mapper, property=p)
v.scene.add_actor(sphere_actor)

# Create a cylinder
cylinder = tvtk.CylinderSource(center=(0, 0, 0), radius=0.2, resolution=16)
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)
def vtkLine(p1, p2):
  src = tvtk.LineSource(point1=tuple(p1), point2=tuple(p2))
  mapper = tvtk.PolyDataMapper(input=src.output)
  actor = tvtk.Actor(mapper=mapper)
  return actor
示例#12
0
def anim():
  x = 0.2
  y = 0.3
  z = 0.4

  cb1 = sch.Box(x, y, z)
  cb2 = sch.Box(x, y, z)

  pair = sch.CD_Pair(cb1, cb2)

  b1s = tvtk.CubeSource(x_length=x, y_length=y, z_length=z)
  b2s = tvtk.CubeSource(x_length=x, y_length=y, z_length=z)

  b1m = tvtk.PolyDataMapper(input=b1s.output)
  b2m = tvtk.PolyDataMapper(input=b2s.output)

  b1a = tvtk.Actor(mapper=b1m)
  b2a = tvtk.Actor(mapper=b2m)

  line = tvtk.LineSource()
  lineM = tvtk.PolyDataMapper(input=line.output)
  lineA = tvtk.Actor(mapper=lineM)

  b1a.user_transform = tvtk.Transform()
  b2a.user_transform = tvtk.Transform()

  b1T = sva.PTransformd.Identity()
  b2T = sva.PTransformd(Vector3d.UnitZ()*2.)

  setTransform(b1a, b1T)
  setTransform(b2a, b2T)

  viewer = mlab.gcf()
  viewer.scene.add_actors([b1a, b2a, lineA])

  rx = ry = rz = 0.
  t = 0
  while True:
    b1T = sva.PTransformd(sva.RotZ(rz)*sva.RotY(ry)*sva.RotX(rx))
    b2T = sva.PTransformd(Vector3d(0., 0., 2. + np.sin(t)))

    setTransform(b1a, b1T)
    setTransform(b2a, b2T)

    cb1.transform(b1T)
    cb2.transform(b2T)

    p1 = Vector3d()
    p2 = Vector3d()
    pair.distance(p1, p2)

    line.point1 = list(p1)
    line.point2 = list(p2)


    rx += 0.01
    ry += 0.005
    rz += 0.002
    t += 0.05
    viewer.scene.render()
    yield
示例#13
0
vtext = tvtk.VectorText()
vtext.text = str(t[0]) + ' s'
text_mapper = tvtk.PolyDataMapper(input=vtext.get_output())
p2 = tvtk.Property(color=(0.3, 0.3, 0.3))
text_actor = tvtk.Follower(mapper=text_mapper, property=p2)
text_actor.position = (0, -L / 4., 0)
f.scene.add_actor(text_actor)

# start line
mlab.plot3d([0, 0], [-L / 2., L / 2.], [0, 0], figure=f)
# tracks
mlab.plot3d([0, 10.], [-L / 2., -L / 2.], [0, 0], figure=f, line_width=1)
mlab.plot3d([0, 10.], [L / 2., L / 2.], [0, 0], figure=f, line_width=1)

# distance between robots
line = tvtk.LineSource(point1=robot_x_pos, point2=robot_y_pos)
line_mapper = tvtk.PolyDataMapper(input=line.output)
line_actor = tvtk.Actor(mapper=line_mapper)
f.scene.add_actor(line_actor)

# Location of the robot
delta = 0.1
surf_length = 5.
surf_width = .5

X_x, Y_x = np.meshgrid(
    np.arange(x_hat[0, 0, 0] - surf_length, x_hat[0, 0, 0] + surf_length,
              delta),
    np.arange(robot_x.pos[1] - surf_width, robot_x.pos[1] + surf_width, delta))
Z_x = matplotlib.mlab.bivariate_normal(X_x.T, Y_x.T, P[0, 0, 0], .1,
                                       x_hat[0, 0, 0], robot_x.pos[1])