Exemplo n.º 1
0
def materials():
    l = 24.0
    elastic = tvtk.CubeSource()
    elastic.set_bounds(0, l, 0, l, -l/2.0, 0.0)
    viscoelastic = tvtk.CubeSource()
    viscoelastic.set_bounds(0, l, 0, l, -l, -l/2.0)
    return [{'name': "elastic",
             'object': elastic.get_output()},
            {'name': "viscoelastic",
            'object': viscoelastic.get_output()}]
Exemplo n.º 2
0
def cube_actor(center=(0, 0, 0), color=colors.blue, opacity=1.0):
    """ Creates a cube and returns the tvtk.Actor. """

    source = tvtk.CubeSource(center=center)
    mapper = tvtk.PolyDataMapper(input=source.output)
    p = tvtk.Property(opacity=opacity, color=color)
    actor = tvtk.Actor(mapper=mapper, property=p)
    return actor
Exemplo n.º 3
0
def prismaticJoint(joint):
    """
  Return a prism and the appropriate static transform.
  """
    axis = e.Vector3d(joint.motionSubspace()[3:])
    s = tvtk.CubeSource(x_length=0.02, y_length=0.1, z_length=0.02)
    quat = e.Quaterniond()
    quat.setFromTwoVectors(axis, e.Vector3d.UnitY())
    return makeActor(s, tuple(axis)), sva.PTransformd(quat)
Exemplo n.º 4
0
 def _glyph_dict_default(self):
     g = {'glyph_source2d': tvtk.GlyphSource2D(glyph_type='arrow', filled=False),
          'arrow_source': tvtk.ArrowSource(),
          'cone_source': tvtk.ConeSource(height=1.0, radius=0.2, resolution=15),
          'cylinder_source': tvtk.CylinderSource(height=1.0, radius=0.15,
                                                 resolution=10),
          'sphere_source': tvtk.SphereSource(),
          'cube_source': tvtk.CubeSource(),
          'axes': tvtk.Axes(symmetric=1)}
     return g
 def test2(self):
     '''展开交互图像窗口的常用流程'''
     s = tvtk.CubeSource(x_length=1.0, y_length=2.0, z_length=3.0)
     m = tvtk.PolyDataMapper(input_connection=s.output_port)
     a = tvtk.Actor(mapper=m)
     r = tvtk.Renderer(background=(0.5, 0.5, 0.5))
     r.add_actor(a)
     w = tvtk.RenderWindow(size=(500, 500))
     w.add_renderer(r)
     i = tvtk.RenderWindowInteractor(render_window=w)
     i.initialize()
     i.start()
Exemplo n.º 6
0
def test01():
    s = tvtk.CubeSource(x_length=1.0, y_length=2.0, z_length=3.0)
    m = tvtk.PolyDataMapper(input_connection=s.output_port)
    a = tvtk.Actor(mapper=m)

    # 1. 创建一个带有Crust的窗口
    gui = GUI()
    win = tvtk.TVTKWithCrustAndBrower()
    win.open()
    win.scene.add_actor(a)

    gui.start_event_loop()
Exemplo n.º 7
0
def source1():
    s = tvtk.CubeSource(x_length=1.0, y_length=2.0, z_length=3.0)
    m = tvtk.PolyDataMapper(input_connection=s.output_port)
    a = tvtk.Actor(mapper=m)

    #创建一个带Crust(Python Shell)的窗口
    gui = GUI()
    win = ivtk.IVTKWithCrustAndBrowser()
    win.open()
    win.scene.add_actor(a)

    #开始界面消息循环
    gui.start_event_loop()
Exemplo n.º 8
0
def test01():
    # 1. 创建数据源,设置参数,并且将参数映射给数据m
    s = tvtk.CubeSource(x_length=1.0, y_length=2.0, z_length=3.0)
    m = tvtk.PolyDataMapper(input_connection=s.output_port)
    # 2. 创建背景和行为(可以转动),并且将行为送给 背景
    a = tvtk.Actor(mapper=m)
    r = tvtk.Renderer(background=(0, 0, 0))
    r.add_actor(a)
    # 3. 创建左面窗口的大小,并且将渲染器放入窗口
    w = tvtk.RenderWindow(size=(300, 300))
    w.add_renderer(r)

    # 4. 创建交互界面,将窗口放入
    i = tvtk.RenderWindowInteractor(render_window=w)

    i.initialize()
    i.start()
    def test4(self):
        s = tvtk.CubeSource(x_length=1.0, y_length=2.0, z_length=3.0)
        m = tvtk.PolyDataMapper(input_connection=s.output_port)
        a = tvtk.Actor(mapper=m)

        gui = GUI()
        # win=ivtk.IVTKWithCrust()
        # win=ivtk.IVTK()
        win = ivtk.IVTKWithCrustAndBrowser()
        win.open()
        win.scene.add_actor(a)

        dialog = win.control.centralWidget().widget(0).widget(0)
        from pyface.qt import QtCore
        dialog.setWindowFlags(QtCore.Qt.WindowFlags(0x00000000))
        dialog.show()

        gui.start_event_loop()
Exemplo n.º 10
0
def show_points(xyzs, colors=None, voxelize=False, res=0.05, polydata=None,
                vtkfiletag="visvtk", renderer=renderer):

    if polydata is None:
        polydata = tvtk.PolyData()
    #zMin = xyzs[:, 2].min()
    #zMax = xyzs[:, 2].max()
    #mapper.scalar_range = (zMin, zMax)
    #mapper.scalar_visibility = 1
    polydata.points = xyzs

    # http://www.vtk.org/Wiki/VTK/Tutorials/GeometryTopology
    # VTK strongly divides GEOMETRY from TOPOLOGY. What most users would
    # think of as "points" are actually "points + vertices" in VTK. The
    # geometry is ALWAYS simply a list of coordinates - the topology
    # represents the connectedness of these coordinates. If no topology at
    # all is specified, then, as far as VTK is aware, there is NOTHING to
    # show. If you want to see points, you must tell VTK that each point
    # is independent of the rest by creating a vertex (a 0-D topology) at
    # each point.
    verts = np.arange(0, xyzs.shape[0], 1, 'l') # point ids
    verts.shape = (xyzs.shape[0], 1) # make it a column vector
    polydata.verts = verts

    if voxelize:
        cubesrc = tvtk.CubeSource()
        cubesrc.x_length = res
        cubesrc.y_length = res
        cubesrc.z_length = res
        glyph3d = tvtk.Glyph3D()
        glyph3d.source = cubesrc.output
        glyph3d.input = polydata
        glyph3d.update()
        polydata = glyph3d.output
        normals = compute_polydata_normals(polydata)
        color_polydata_by_normals(polydata, normals)
    else:
        if colors is None:
            colors = np.abs(xyzs[:, 2]/ np.max(xyzs[:, 2]))

        polydata.point_data.scalars = colors
        polydata.point_data.scalars.name = 'scalars'

    return visualise(polydata, vtkfiletag=vtkfiletag, renderer=renderer)
Exemplo n.º 11
0
def test_source():

    # 创建一个长方体数据源,并且同时设置其长宽高
    s = tvtk.CubeSource(x_length=1.0, y_length=2.0, z_length=3.0)
    # 使用PolyDataMapper将数据转换为图形数据
    m = tvtk.PolyDataMapper(input_connection=s.output_port)
    # 创建一个Actor
    a = tvtk.Actor(mapper=m)
    # 创建一个Renderer,将Actor添加进去
    r = tvtk.Renderer(background=(0, 0, 0))
    r.add_actor(a)
    # 创建一个RenderWindow(窗口),将Renderer添加进去
    w = tvtk.RenderWindow(size=(300, 300))
    w.add_renderer(r)
    # 创建一个RenderWindowInteractor(窗口的交互工具)
    i = tvtk.RenderWindowInteractor(render_window=w)
    # 开启交互
    i.initialize()
    i.start()
Exemplo n.º 12
0
def ShowACube(x, y, z, backgroundcolor=(0, 0, 0)):
    #立方体源
    s = tvtk.CubeSource(x_length=x, y_length=y, z_length=z)
    #转换源为图形数据
    m = tvtk.PolyDataMapper(input_connection=s.output_port)
    #创建Actor,并将图形数据接入
    a = tvtk.Actor(mapper=m)
    #创建渲染,并将Actor接入
    r = tvtk.Renderer(background=backgroundcolor)
    r.add_actor(a)
    #创建窗口,并将渲染接入
    w = tvtk.RenderWindow(size=(900, 900))
    w.add_renderer(r)
    #创建交互,并将窗口接入
    i = tvtk.RenderWindowInteractor(render_window=w)

    #开始运行
    i.initialize()
    i.start()
Exemplo n.º 13
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
Exemplo n.º 14
0
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 20 17:50:15 2017

@author: Administrator
"""

from tvtk.api import tvtk
 
# 创建一个长方体数据源,并且同时设置其长宽高
s = tvtk.CubeSource(x_length=1.0, y_length=2.0, z_length=3.0)
# 使用PolyDataMapper将数据转换为图形数据
m = tvtk.PolyDataMapper(input_connection=s.output_port)
# 创建一个Actor
a = tvtk.Actor(mapper=m)
# 创建一个Renderer,将Actor添加进去
r = tvtk.Renderer(background=(0, 0, 0))
r.add_actor(a)
# 创建一个RenderWindow(窗口),将Renderer添加进去
w = tvtk.RenderWindow(size=(300,300))
w.add_renderer(r)
# 创建一个RenderWindowInteractor(窗口的交互工具)
i = tvtk.RenderWindowInteractor(render_window=w)
# 开启交互
i.initialize()
i.start()
Exemplo n.º 15
0
# License: BSD Style.

from numpy import arange, zeros, uint8, exp, sqrt, pi

from tvtk.api import tvtk
from tvtk.common import configure_input_data, configure_source_data

# Source for glyph.  Note that you need to pick a source that has
# texture co-ords already set.  If not you'll have to generate them.
# This is easily done -- its just a 2d array of (u,v) coords each
# between [0, 1] that you can set via something like
# point_data.t_coords = <array>.
#
# In this case CubeSource already defines texture coords for us (as of
# VTK-4.4).
cs = tvtk.CubeSource(x_length=2, y_length=1.0, z_length=0.5)

# Create input for the glyph -- the sources are placed at these input
# points.
pts = [[1, 1, 1], [0, 0, 0], [-1, -1, -1]]
pd = tvtk.PolyData(points=pts, polys=[[0], [1], [2]])
# Orientation/scaling is as per the vector attribute.
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
pd.point_data.vectors = vecs

# Create the glyph3d and set up the pipeline.
g = tvtk.Glyph3D(scale_mode='data_scaling_off', vector_mode='use_vector')
configure_input_data(g, pd)

# Note that VTK's vtkGlyph.SetSource is special because it has two
# call signatures: SetSource(src) and SetSource(int N, src) (which
Exemplo n.º 16
0
    def vtk_actors(self):
        if (self.actors is None):
            self.actors = []
            points = _getfem_to_tvtk_points(self.sl.pts())
            (triangles, cv2tr) = self.sl.splxs(2)
            triangles = numpy.array(triangles.transpose(), 'I')
            data = tvtk.PolyData(points=points, polys=triangles)
            if self.scalar_data is not None:
                data.point_data.scalars = numpy.array(self.scalar_data)
            if self.vector_data is not None:
                data.point_data.vectors = numpy.array(self.vector_data)
            if self.glyph_name is not None:
                mask = tvtk.MaskPoints()
                mask.maximum_number_of_points = self.glyph_nb_pts
                mask.random_mode = True
                mask.input = data

                if self.glyph_name == 'default':
                    if self.vector_data is not None:
                        self.glyph_name = 'arrow'
                    else:
                        self.glyph_name = 'ball'

                glyph = tvtk.Glyph3D()
                glyph.scale_mode = 'scale_by_vector'
                glyph.color_mode = 'color_by_scalar'
                #glyph.scale_mode = 'data_scaling_off'
                glyph.vector_mode = 'use_vector'  # or 'use_normal'
                glyph.input = mask.output
                if self.glyph_name == 'arrow':
                    glyph.source = tvtk.ArrowSource().output
                elif self.glyph_name == 'ball':
                    glyph.source = tvtk.SphereSource().output
                elif self.glyph_name == 'cone':
                    glyph.source = tvtk.ConeSource().output
                elif self.glyph_name == 'cylinder':
                    glyph.source = tvtk.CylinderSource().output
                elif self.glyph_name == 'cube':
                    glyph.source = tvtk.CubeSource().output
                else:
                    raise Exception("Unknown glyph name..")
                #glyph.scaling = 1
                #glyph.scale_factor = self.glyph_scale_factor
                data = glyph.output

            if self.show_faces:
                ##                if self.deform is not None:
                ##                    data.point_data.vectors = array(numarray.transpose(self.deform))
                ##                    warper = tvtk.WarpVector(input=data)
                ##                    data = warper.output
                ##                lut = tvtk.LookupTable()
                ##                lut.hue_range = 0.667,0
                ##                c=gf_colormap('tripod')
                ##                lut.number_of_table_values=c.shape[0]
                ##                for i in range(0,c.shape[0]):
                ##                    lut.set_table_value(i,c[i,0],c[i,1],c[i,2],1)

                self.mapper = tvtk.PolyDataMapper(input=data)
                self.mapper.scalar_range = self.scalar_data_range
                self.mapper.scalar_visibility = True
                # Create mesh actor for display
                self.actors += [tvtk.Actor(mapper=self.mapper)]
            if self.show_edges:
                (Pe, E1, E2) = self.sl.edges()
                if Pe.size:
                    E = numpy.array(
                        numpy.concatenate((E1.transpose(), E2.transpose()),
                                          axis=0), 'I')
                    edges = tvtk.PolyData(points=_getfem_to_tvtk_points(Pe),
                                          polys=E)
                    mapper_edges = tvtk.PolyDataMapper(input=edges)
                    actor_edges = tvtk.Actor(mapper=mapper_edges)
                    actor_edges.property.representation = 'wireframe'
                    #actor_edges.property.configure_traits()
                    actor_edges.property.color = self.edges_color
                    actor_edges.property.line_width = self.edges_width
                    actor_edges.property.ambient = 0.5
                    self.actors += [actor_edges]
            if self.sl.nbsplxs(1):
                # plot tubes
                (seg, cv2seg) = self.sl.splxs(1)
                seg = numpy.array(seg.transpose(), 'I')
                data = tvtk.Axes(origin=(0, 0, 0),
                                 scale_factor=0.5,
                                 symmetric=1)
                data = tvtk.PolyData(points=points, lines=seg)
                tube = tvtk.TubeFilter(radius=0.4,
                                       number_of_sides=10,
                                       vary_radius='vary_radius_off',
                                       input=data)
                mapper = tvtk.PolyDataMapper(input=tube.output)
                actor_tubes = tvtk.Actor(mapper=mapper)
                #actor_tubes.property.representation = 'wireframe'
                actor_tubes.property.color = self.tube_color
                #actor_tubes.property.line_width = 8
                #actor_tubes.property.ambient = 0.5

                self.actors += [actor_tubes]

            if self.use_scalar_bar:
                self.scalar_bar = tvtk.ScalarBarActor(
                    title=self.scalar_data_name,
                    orientation='horizontal',
                    width=0.8,
                    height=0.07)
                self.scalar_bar.position_coordinate.coordinate_system = 'normalized_viewport'
                self.scalar_bar.position_coordinate.value = 0.1, 0.01, 0.0
                self.actors += [self.scalar_bar]

            if (self.lookup_table is not None):
                self.set_colormap(self.lookup_table)

        return self.actors
Exemplo n.º 17
0
 def _get_primitive(self):
     return tvtk.CubeSource(center=self.center,
                            x_length=self.x_length,
                            y_length=self.y_length,
                            z_length=self.z_length)
Exemplo n.º 18
0
def domain():
    domain = tvtk.CubeSource()
    domain.set_bounds(-1000/40.0, 1000/40.0, -500/40.0, 500/40.0, -400/40.0, 0.0)
    return domain.get_output()
Exemplo n.º 19
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
Exemplo n.º 20
0
def test03():
    s = tvtk.CubeSource(x_length=1.0, y_length=2.0, z_length=3.0)
    m = tvtk.PolyDataMapper(input_connection=s.output_port)