Exemplo n.º 1
0
    def __set_pure_state__(self, state):
        # Pop the transformation matrix for the box widget.
        mat = state.pop('matrix')
        # Now set their state.
        set_state(self, state, first=['widget_mode'], ignore=['*'])
        # Set state of rest of the attributes ignoring the widget_mode.
        set_state(self, state, ignore=['widget_mode'])

        # Set the transformation for Box widget.
        tfm = tvtk.Transform()
        tfm.set_matrix(cPickle.loads(mat))
        w = self._widget_dict['Box']
        w.set_transform(tfm)

        # Some widgets need some cajoling to get their setup right.
        w = self.widget
        # Set the input.
        if len(self.inputs) > 0:
            w.input = self.inputs[0].outputs[0]
        w.update_traits()
        mode = self.widget_mode
        if mode == 'Plane':
            wd = state._widget_dict[mode]
            w.origin = wd.origin
            w.normal = wd.normal
            w.update_placement()
        self.update_implicit_function()
        # Set the widgets trait so that the widget is rendered if needed.
        self.widgets = [w]
Exemplo n.º 2
0
 def _redraw_background_plane(self):
     if self.construction and self.scene:
         if self._bg_plane_width == self.construction.width and self._bg_plane_height == self.construction.height:
             return
         if self._bg_plane_actor:
             self.scene.remove_actor(self._bg_plane_actor)
         if self._axis:
             self.scene.remove_actor(self._axis)
         w, h = self.construction.width, self.construction.height
         plane = tvtk.PlaneSource(x_resolution=int(w), y_resolution=int(h))
         scalation = tvtk.Transform()
         scalation.scale((w, h, 1))
         scale_plane = tvtk.TransformPolyDataFilter(transform=scalation,
                                                    input=plane.output)
         self._bg_plane_actor = tvtk.Actor(mapper=tvtk.PolyDataMapper(
             input=scale_plane.output))
         self._bg_plane_actor.property.set(representation='wireframe',
                                           line_stipple_pattern=0xF0F0,
                                           opacity=0.15)
         self.scene.add_actor(self._bg_plane_actor)
         self._axis = tvtk.CubeAxesActor2D(
             camera=self.scene.camera,
             z_axis_visibility=False,
             corner_offset=0,
             bounds=[-w / 2, w / 2, -h / 2, h / 2, 0, 0])
         self.scene.add_actor(self._axis)
         self._bg_plane_picker = tvtk.CellPicker(tolerance=0,
                                                 pick_from_list=True)
         self._bg_plane_picker.pick_list.append(self._bg_plane_actor)
         self._bg_plane_width, self._bg_plane_height = self.construction.width, self.construction.height
Exemplo n.º 3
0
    def _calc_grid(self, radius, resolution_x, resolution_y):

        fil = self.probe_filter

        coords = []

        if self.Selected_Source == 'CitcomSGrid':

            for i in xrange(12):

                coords += self.citcomsgrid.coords_of_cap(
                    radius, self.theta, self.phi, i)

            grid = tvtk.UnstructuredGrid()

            #Connectivity for 2d-Data
            #There is no need to interpolate with the CitcomS grid surface. If this is however
            #wanted uncomment this code to create the CitcomS surface information
            #for capnr in xrange(12):
            #    i=1
            #    for n in xrange((resolution_x+1)*(resolution_y+1) - (resolution_x+1)):
            #        if i%(resolution_x+1)!=0 :
            #            n0 = n+(capnr*((resolution_x+1)*(resolution_y+1)))
            #            n1 = n0+1
            #            n2 = n0+resolution_y+1
            #            n3 = n2+1
            #            grid.insert_next_cell(8,[n0,n1,n2,n3])
            #        i+=1

            ##

            grid.points = coords
            fil.input = grid

        if self.Selected_Source == 'Sphere':
            sphere = tvtk.SphereSource()
            sphere.radius = radius
            sphere.theta_resolution = resolution_x
            sphere.phi_resolution = resolution_y

            #Rotate the Sphere so that the poles are at the right location
            transL = tvtk.Transform()
            trans1 = tvtk.TransformPolyDataFilter()
            trans2 = tvtk.TransformPolyDataFilter()
            trans1.input = sphere.output
            transL.rotate_y(90)
            transL.update()
            trans1.transform = transL
            trans1.update()
            trans2.input = trans1.output
            transL.rotate_z(90)
            transL.update()
            trans2.transform = transL
            trans2.update()

            fil.input = trans2.output

        fil.update()
Exemplo n.º 4
0
 def __get_pure_state__(self):
     d = super(ImplicitWidgets, self).__get_pure_state__()
     for attr in ('_first', '_busy', '_observer_id', 'widget',
                  'implicit_function'):
         d.pop(attr, None)
     # The box widget requires a transformation matrix to be pickled.
     tfm = tvtk.Transform()
     w = self._widget_dict['Box']
     w.get_transform(tfm)
     d['matrix'] = cPickle.dumps(tfm.matrix)
     return d
Exemplo n.º 5
0
    def setup_pipeline(self):
        """Override this method so that it *creates* the tvtk
        pipeline.

        This method is invoked when the object is initialized via
        `__init__`.  Note that at the time this method is called, the
        tvtk data pipeline will *not* yet be setup.  So upstream data
        will not be available.  The idea is that you simply create the
        basic objects and setup those parts of the pipeline not
        dependent on upstream sources and filters.  You should also
        set the `actors` attribute up at this point.
        """

        self._trfm.transform = tvtk.Transform()
        # Setup the glyphs.
        self.glyph_source = self.glyph_dict['glyph_source2d']
Exemplo n.º 6
0
    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))
        tf.input = arrow.output

        mapper = tvtk.PolyDataMapper()
        mapper.input = tf.output

        self.actor = actor = tvtk.Follower()
        actor.mapper = mapper
        prop = actor.property
        prop.color = 0, 1, 1
        prop.ambient = 0.5
        prop.diffuse = 0.5
Exemplo n.º 7
0
 def setup_pipeline(self):
     self._transform = tvtk.Transform()
     self.widget = tvtk.BoxWidget(place_factor=1.1)
     self.filter = tvtk.TransformFilter()
     super(TransformData, self).setup_pipeline()
Exemplo n.º 8
0
 def setup_pipeline(self):
     self.widget = ImplicitWidgets()
     self._transform = tvtk.Transform()
     self.filter = tvtk.ClipDataSet()
     self.widget.on_trait_change(self._handle_widget, 'widget')
     super(DataSetClipper, self).setup_pipeline()
Exemplo n.º 9
0
def callback(widget, event):
    """This callback sets the transformation of the cone using that
    setup by the the box."""
    t = tvtk.Transform()
    bw.get_transform(t)
    bw.prop3d.user_transform = t