Пример #1
0
def cpy_to_vtk(cpy):
    pd = tvtk.AppendPolyData()
    names = []
    for name, (points, panels) in cpy.iteritems():
        p = tvtk.PolyData(points=points, polys=panels)
        names.append(name)
        p.cell_data.scalars = len(names) * np.ones(panels.shape[0])
        pd.add_input(p)
    return names, pd
Пример #2
0
    def test_property_change_notification(self):
        """Test if changes to properties generate notification events."""

        # Create a dummy class to test with.
        class Junk:
            def f(self, obj, name, old, new):
                self.data = obj, name, old, new

        z = Junk()
        cs = tvtk.ConeSource()
        m = tvtk.PolyDataMapper()
        m.on_trait_change(z.f, 'input')
        m.input = cs.output
        self.assertEqual(z.data, (m, 'input', None, cs.output))
        m.input = None
        self.assertEqual(z.data, (m, 'input', cs.output, None))
        m.on_trait_change(z.f, 'input', remove=True)
        m.input = cs.output
        a = tvtk.Actor()
        a.on_trait_change(z.f, 'mapper')
        a.on_trait_change(z.f, 'property')
        a.mapper = m
        self.assertEqual(z.data, (a, 'mapper', None, m))
        old = a.property
        new = tvtk.Property()
        a.property = new
        self.assertEqual(z.data, (a, 'property', old, new))

        # Check if property notification occurs on add_input/remove_input
        a = tvtk.AppendPolyData()
        a.on_trait_change(z.f, 'input')
        pd = tvtk.PolyData()
        a.add_input(pd)
        old, new = None, pd
        self.assertEqual(z.data, (a, 'input', old, new))
        a.remove_input(pd)
        old, new = pd, None
        self.assertEqual(z.data, (a, 'input', old, new))
        a.remove_all_inputs()
        old, new = None, None
        self.assertEqual(z.data, (a, 'input', old, new))
Пример #3
0
# 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


# ----------- Materials ------------
Пример #4
0
                        resizable=True, width=700, height=600
                        )
                        
    
                        
                        
if __name__=="__main__":
    graph = tvtk.RandomGraphSource()
    
    layout = tvtk.GraphLayout(input_connection=graph.output_port,
                            layout_strategy=tvtk.Simple2DLayoutStrategy())
    
    poly = tvtk.GraphToPolyData(input_connection=layout.output_port)
    
    s = tvtk.SphereSource()
    
    glyph = tvtk.Glyph3D(input_connection=poly.output_port,
                        source=s.output)
                        
    app = tvtk.AppendPolyData()
    app.add_input_connection(glyph.output_port)
    app.add_input_connection(poly.output_port)
    
    map = tvtk.PolyDataMapper(input_connection=app.output_port)
    
    act = tvtk.Actor(mapper=map)
    
    demo = ActorView()
    demo.scene.add_actor(act)
    demo.configure_traits()
    
Пример #5
0
 def test_append_poly_data_input(self):
     """Test if AppendPolyData has its get_input wrapped right."""
     a = tvtk.AppendPolyData()
     self.assertEqual(hasattr(a, 'get_input'), True)
     self.assertEqual(a.input, None)