Example #1
0
    def coord_event_handling(self, event, emitting=True):
        # 1) get two coords from the event canvas, and 3rd from the fixed axis
        # 2) determine which are the transverse images
        if event.xdata == None or event.ydata == None:
            # must have been a stray hit
            return
        if self._was_resized:
            for fig in self.figs:
                fig.draw(save=True)
            print 'saved plots'
            self._was_resized = False
        fig = self.canvas_lookup[event.canvas]
        fig_limits = fig.xlim + fig.ylim
        # be safe with the coordinates
        pu = np.clip(event.xdata, fig_limits[0], fig_limits[1])
        pv = np.clip(event.ydata, fig_limits[2], fig_limits[3])
        fig_idx = self.figs.index(fig)
        # these will be the indices in an xyz list that correspond to pu,pv,
        # and also to the indices of the figures/images to update
        ui, vi = transverse_plane_lookup(fig_idx)
        xyz = self._xyz_position[:]
        xyz[ui] = pu
        xyz[vi] = pv
        self._xyz_position = xyz[:]

        self._update_crosshairs()

        # THE REST SHOULD BE TRIGGERED ON SOME KIND OF XYZ SIGNAL
        if emitting:
            self.emit_states(ui, vi)
Example #2
0
    def _cut_plane(self, ax, coord, **interp_kw):
        """
        For a given axis in {SAG, COR, AXI}, make a plane cut in the
        volume at the coordinate value.

        Parameters
        ----------
        ax : int
            axis label in {SAG, COR, AXI} (defined in xipy.slicing)
        coord : float
            coordinate value along this axis
        interp_kw : dict
            Keyword args for the interpolating machinery
            (ie, ndimage.map_coordinates keyword args)
            
        Returns
        _______
        plane : ndarray
            The transverse plane sampled at the grid points and fixed axis
            coordinate for the given args
        """
    
        # a little hokey
        grid_lookup = {SAG: ('xshape', 'xgrid'),
                       COR: ('yshape', 'ygrid'),
                       AXI: ('zshape', 'zgrid')}
        sname, gname= grid_lookup[ax]
        ii, jj = transverse_plane_lookup(ax)
        grid = getattr(self, gname)
        shape = getattr(self, sname)
        coords = np.empty((3, grid.shape[0]), 'd')
        coords[ax] = self._closest_grid_pt(coord, ax)
        coords[ii] = grid[:,0]; coords[jj] = grid[:,1]
        pln = self.interpolator.evaluate(coords, **interp_kw).reshape(shape)
        if self._masking:
            m_pln = self.m_interpolator.evaluate(coords, mode='constant',
                                                 cval=-10).reshape(shape)
            return np.ma.masked_where(m_pln < 0.5, pln)
        return pln