Ejemplo n.º 1
0
    def do_label_automatically(self, info):
        #figure out c1, c2, c3
        #        c1,c2,c3 = 3*(None,)
        #        for e in self.electrodes:
        #            if len(e.corner) == 0:
        #                continue
        #            elif len(e.corner) > 1:
        #                error_dialog('Wrong corners specified, check again')
        #                return
        #
        #            elif 'corner 1' in e.corner:
        #                c1 = e
        #            elif 'corner 2' in e.corner:
        #                c2 = e
        #            elif 'corner 3' in e.corner:
        #                c3 = e
        #
        #        if c1 is None or c2 is None or c3 is None:
        #            error_dialog('Not all corners were specified')
        #            return

        cur_geom = self.model._grid_geom[self.cur_grid]
        if cur_geom == 'user-defined' and self.naming_convention != 'line':
            from color_utils import mayavi2traits_color
            from name_holder import GeometryNameHolder, GeomGetterWindow
            nameholder = GeometryNameHolder(
                geometry=cur_geom,
                color=mayavi2traits_color(self.model._colors[self.cur_grid]))
            geomgetterwindow = GeomGetterWindow(holder=nameholder)

            if geomgetterwindow.edit_traits().result:
                cur_geom = geomgetterwindow.geometry
            else:
                error_dialog("User did not specify any geometry")
                return

        import pipeline as pipe
        if self.naming_convention == 'line':
            pipe.fit_grid_to_line(
                self.electrodes,
                #c1.asiso(), c2.asiso(), c3.asiso(), cur_geom,
                delta=self.labeling_delta,
                rho_loose=self.labeling_rho + 10,
                epsilon=self.labeling_epsilon)

        else:
            pipe.fit_grid_by_fixed_points(self.electrodes,
                                          cur_geom,
                                          delta=self.labeling_delta,
                                          rho=self.labeling_rho,
                                          rho_strict=self.labeling_rho - 10,
                                          rho_loose=self.labeling_rho + 15,
                                          epsilon=self.labeling_epsilon,
                                          mindist=0,
                                          maxdist=36)

        self.naming_following_labeling(cur_geom=cur_geom)
Ejemplo n.º 2
0
    def do_label_automatically(self, info):
        #figure out c1, c2, c3
#        c1,c2,c3 = 3*(None,)
#        for e in self.electrodes:
#            if len(e.corner) == 0:
#                continue
#            elif len(e.corner) > 1:
#                error_dialog('Wrong corners specified, check again')
#                return
#    
#            elif 'corner 1' in e.corner:
#                c1 = e
#            elif 'corner 2' in e.corner:
#                c2 = e
#            elif 'corner 3' in e.corner:
#                c3 = e
#
#        if c1 is None or c2 is None or c3 is None:
#            error_dialog('Not all corners were specified')
#            return
    
        cur_geom = self.model._grid_geom[self.cur_grid]
        if cur_geom=='user-defined' and self.naming_convention != 'line':
            from color_utils import mayavi2traits_color
            from name_holder import GeometryNameHolder, GeomGetterWindow
            nameholder = GeometryNameHolder(
                geometry=cur_geom,
                color=mayavi2traits_color(
                    self.model._colors[self.cur_grid]))
            geomgetterwindow = GeomGetterWindow(holder=nameholder)

            if geomgetterwindow.edit_traits().result:
                cur_geom = geomgetterwindow.geometry
            else:
                error_dialog("User did not specify any geometry")
                return

        import pipeline as pipe
        if self.naming_convention == 'line':
            pipe.fit_grid_to_line(self.electrodes, 
                #c1.asiso(), c2.asiso(), c3.asiso(), cur_geom, 
                delta=self.labeling_delta,
                rho_loose=self.labeling_rho+10,
                epsilon=self.labeling_epsilon)

        else:
            pipe.fit_grid_by_fixed_points(self.electrodes, cur_geom,
                delta=self.labeling_delta, 
                rho=self.labeling_rho, 
                rho_strict=self.labeling_rho-10, 
                rho_loose=self.labeling_rho+15,
                epsilon=self.labeling_epsilon, 
                mindist=0, maxdist=36)

        self.naming_following_labeling(cur_geom=cur_geom)
Ejemplo n.º 3
0
    def _postprocessing_effect_electrode_reposition(self):
        if self.cur_sel is None:
            error_dialog("No electrode specified to move")
            return

        pd = self.model.panel2d
        image_name = pd.currently_showing.name
        px,py,pz,_ = pd.pins[image_name][pd.current_pin]

        if image_name=='t1':
            px,py,pz = pd.map_cursor((px,py,pz), pd.images['t1'][2])
            
        self.model.move_electrode( self.cur_sel, (px,py,pz),
            in_ras=(image_name=='t1'), as_postprocessing=True )
Ejemplo n.º 4
0
    def do_linear_interpolation(self, info):
        #TODO does not feed back coordinates to model, 
        #which is important for snapping

        if self.cur_sel is None:
            return
        elif self.cur_sel.special_name == '':
            return
        
        if len(self.cur_sel.geom_coords) == 0:
            error_dialog("Specify geom_coords before linear interpolation")
            return

        x,y = self.cur_sel.geom_coords

        x_low = self._find_closest_neighbor(self.cur_sel, 'x', '-')
        x_hi = self._find_closest_neighbor(self.cur_sel, 'x', '+')
        y_low = self._find_closest_neighbor(self.cur_sel, 'y', '-')
        y_hi = self._find_closest_neighbor(self.cur_sel, 'y', '+')

        loc = None

        #handle simplest case of electrode directly in between others
        if x_low is not None and x_hi is not None:
            xl = x_low.geom_coords[0]
            xh = x_hi.geom_coords[0]
            ratio = (x - xl) / (xh - xl)
        
            loc = np.array(x_low.iso_coords) + (np.array(x_hi.iso_coords)-
                np.array(x_low.iso_coords))*ratio

        elif y_low is not None and y_hi is not None:
            yl = y_low.geom_coords[1]
            yh = y_hi.geom_coords[1]
            ratio = (y - yl) / (yh - yl)
        
            loc = np.array(y_low.iso_coords) + (np.array(y_hi.iso_coords)-
                np.array(y_low.iso_coords))*ratio

        #handle poorer case of electrode on end of line
        if x_low is not None and loc is None:
            x_lower = self._find_closest_neighbor(x_low, 'x', '-')
            xl = x_low.geom_coords[0]
            xll = x_lower.geom_coords[0]
            if xl == xll+1:
                loc = 2*np.array(x_low.iso_coords) - np.array(
                    x_lower.iso_coords)

        if x_hi is not None and loc is None:
            x_higher = self._find_closest_neighbor(x_hi, 'x', '+')
            xh = x_hi.geom_coords[0]
            xhh = x_higher.geom_coords[0]
            if xh == xhh-1:
                loc = 2*np.array(x_hi.iso_coords) - np.array(
                    x_higher.iso_coords)

        #import pdb
        #pdb.set_trace()

        if y_low is not None and loc is None:
            y_lower = self._find_closest_neighbor(y_low, 'y', '-')
            yl = y_low.geom_coords[1]
            yll = y_lower.geom_coords[1]
            if yl == yll+1:
                loc = 2*np.array(y_low.iso_coords) - np.array(
                    y_lower.iso_coords)
        
        if y_hi is not None and loc is None:
            y_higher = self._find_closest_neighbor(y_hi, 'y', '+')
            yh = y_hi.geom_coords[1]
            yhh = y_higher.geom_coords[1]
            if yh == yhh-1:
                loc = 2*np.array(y_hi.iso_coords) - np.array(
                    y_higher.iso_coords)
    
        if loc is not None:
            self.cur_sel.iso_coords = tuple(loc)
            self.cur_sel.special_name = 'Linearly interpolated electrode'
        else:
            error_dialog('No line for simple linear interpolation\n'
                'Better algorithm needed')

        # translate the electrode into RAS space
        import pipeline as pipe
        
        aff = self.model.acquire_affine()
        pipe.translate_electrodes_to_surface_space( [self.cur_sel], aff,
            subjects_dir=self.model.subjects_dir, subject=self.model.subject)

        pipe.linearly_transform_electrodes_to_isotropic_coordinate_space(
            [self.cur_sel], self.model.ct_scan,
            isotropization_type = ('deisotropize' if self.model.isotropize
                else 'copy_to_ct'))

        # add this electrode to the grid model so that it can be visualized
        self.model.add_electrode_to_grid(self.cur_sel, self.cur_grid)
Ejemplo n.º 5
0
    def do_label_automatically(self, info):
        #figure out c1, c2, c3
        c1,c2,c3 = 3*(None,)
        for e in self.electrodes:
            if len(e.corner) == 0:
                continue
            elif len(e.corner) > 1:
                error_dialog('Wrong corners specified, check again')
                return
    
            elif 'corner 1' in e.corner:
                c1 = e
            elif 'corner 2' in e.corner:
                c2 = e
            elif 'corner 3' in e.corner:
                c3 = e

        if c1 is None or c2 is None or c3 is None:
            error_dialog('Not all corners were specified')
            return
    
        cur_geom = self.model._grid_geom[self.cur_grid]
        if cur_geom=='user-defined' and self.naming_convention != 'line':
            from color_utils import mayavi2traits_color
            from name_holder import GeometryNameHolder, GeomGetterWindow
            nameholder = GeometryNameHolder(
                geometry=cur_geom,
                color=mayavi2traits_color(
                    self.model._colors[self.cur_grid]))
            geomgetterwindow = GeomGetterWindow(holder=nameholder)

            if geomgetterwindow.edit_traits().result:
                cur_geom = geomgetterwindow.geometry
            else:
                error_dialog("User did not specify any geometry")
                return

        import pipeline as pipe
        if self.naming_convention == 'line':
            pipe.fit_grid_to_line(self.electrodes, c1.asct(), c2.asct(),
                c3.asct(), cur_geom, delta=self.model.delta,
                rho_loose=self.model.rho_loose)
            #do actual labeling
            for elec in self.model._grids[self.cur_grid]:
                _,y = elec.geom_coords
                index = y+1
                elec.name = '%s%i'%(self.name_stem, index)

        else:
            pipe.fit_grid_to_plane(self.electrodes, c1.asct(), c2.asct(), 
                c3.asct(), cur_geom)

            #do actual labeling
            for elec in self.model._grids[self.cur_grid]:
                x,y = elec.geom_coords
                if self.naming_convention=='grid':
                    #index = y*np.max(cur_geom) + x + 1
                    index = x*np.min(cur_geom) + y + 1
                else: #reverse_grid
                    #index = x*np.min(cur_geom) + y + 1
                    index = y*np.max(cur_geom) + x + 1
                
                elec.name = '%s%i'%(self.name_stem, index)