Beispiel #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()}]
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        Primitive.__init__(self, **kwargs)
        self.source = tvtk.CubeSource()
        self.polyDataMapper = tvtk.PolyDataMapper()
        self.polyDataMapper.input = self.source.output

        self.actor = tvtk.Actor(mapper=self.polyDataMapper)
        self.handle_arguments(*args, **kwargs)
Beispiel #3
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
Beispiel #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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
0
"""
# Author: Prabhu Ramachandran <*****@*****.**>
# Copyright (c) 2004-2006, Enthought, Inc.
# License: BSD Style.

from enthought.tvtk.api import tvtk

# 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',
                 input=pd)

# Note that VTK's vtkGlyph.SetSource is special because it has two
Beispiel #8
0
#! /usr/bin/env python

# Copyright 2009 Thomas Neumann
#
# Redistribution of this file is permitted under
# the terms of the GNU Public License (GPL) version 2.

from enthought.tvtk.api import tvtk
import numpy as N
from model import Joint, Element, Construction, ElementMaterial

# ----------- 3D models ------------
# completely free joint: represented by a sphere
joint_model_movable = tvtk.SphereSource(phi_resolution=24, theta_resolution=24, radius=0.15).output
# unmovable joint: represented by a solid cube
joint_model_unmovable = tvtk.CubeSource(x_length=0.7, y_length=0.7, z_length=0.5).output
# ground in x direction
collect = tvtk.AppendPolyData()
collect.add_input(tvtk.CubeSource(x_length=0.7, y_length=0.2, z_length=0.25, center=(0, -0.5, 0)).output)
collect.add_input(tvtk.SphereSource(radius=0.11, center=(-0.18, -0.3, 0), phi_resolution=24, theta_resolution=24).output)
collect.add_input(tvtk.SphereSource(radius=0.11, center=(0.18, -0.3, 0), phi_resolution=24, theta_resolution=24).output)
collect.add_input(tvtk.ConeSource(center=(0,-0.05,0), direction=(0,1,0), height=0.3, radius=0.35, resolution=16).output)
joint_model_movable_x = collect.output
# ground in y direction
collect = tvtk.AppendPolyData()
collect.add_input(tvtk.CubeSource(x_length=0.2, y_length=0.7, z_length=0.25, center=(-0.5, 0, 0)).output)
collect.add_input(tvtk.SphereSource(radius=0.11, center=(-0.3, -0.18, 0), phi_resolution=24, theta_resolution=24).output)
collect.add_input(tvtk.SphereSource(radius=0.11, center=(-0.3, 0.18, 0), phi_resolution=24, theta_resolution=24).output)
collect.add_input(tvtk.ConeSource(center=(-0.05,0,0), direction=(1,0,0), height=0.3, radius=0.35, resolution=16).output)
joint_model_movable_y = collect.output
Beispiel #9
0
def domain():
    l = 24.0
    domain = tvtk.CubeSource()
    domain.set_bounds(0, l, 0, l, -l, 0.0)
    return domain.get_output()
#!/usr/bin/env python

from enthought.tvtk.api import tvtk

cube = tvtk.CubeSource()

map = tvtk.PolyDataMapper(input=cube.output)

act = tvtk.Actor(mapper=map)

ren = tvtk.Renderer()
ren.add_actor(act)

renwin = tvtk.RenderWindow()
renwin.add_renderer(ren)

iren = tvtk.RenderWindowInteractor(render_window=renwin)
iren.initialize()
iren.start()