Esempio n. 1
0
    def __init__(self, anato=None, app=None):

        # UI init
        QtGui.QWidget.__init__(self)
        self.ui = uic.loadUi("electrodeEditor.ui", self)
        self.setWindowTitle('Electrode editor')

        # Init of variables
        self.app = app
        self.cylinders = {}
        self.displayed = {}
        #self.elementIndex = 1
        self.currentColorHue = 0
        self.typeColors = {}

        # Linking UI elements to functions
        self.connect(self.exitButton, QtCore.SIGNAL('clicked()'), self.quit)
        self.connect(self.openButton, QtCore.SIGNAL('clicked()'), self.open)
        self.connect(self.saveButton, QtCore.SIGNAL('clicked()'), self.save)
        self.connect(self.addButton, QtCore.SIGNAL('clicked()'),
                     self.addCylinder)
        self.connect(self.updateButton, QtCore.SIGNAL('clicked()'),
                     self.updateCylinder)
        self.connect(self.deleteButton, QtCore.SIGNAL('clicked()'),
                     self.deleteCylinder)
        self.connect(self.axisCombo,
                     QtCore.SIGNAL('currentIndexChanged(QString)'),
                     self.axisChanged)
        #self.connect(self.typeCombo, QtCore.SIGNAL('currentIndexChanged(QString)'), self.updateName)

        self.cylinderList.sortItems(QtCore.Qt.AscendingOrder)
        self.connect(
            self.cylinderList,
            QtCore.SIGNAL(
                "currentItemChanged(QListWidgetItem*,QListWidgetItem*)"),
            self.cylinderListClick)  #itemClicked

        # Anatomist windows
        if anato is None:
            self.a = anatomist.Anatomist('-b')
        else:
            self.a = anato
        layout = QtGui.QHBoxLayout(self.anatomistBox)
        self.axWindow = self.a.createWindow('Axial', no_decoration=True)
        self.sagWindow = self.a.createWindow('Sagittal', no_decoration=True)
        self.corWindow = self.a.createWindow('Coronal', no_decoration=True)
        self.wins = [self.axWindow, self.sagWindow, self.corWindow]
        [w.setHasCursor(0) for w in self.wins]
        self.sagWindow.setParent(self.anatomistBox)
        self.axWindow.setParent(self.anatomistBox)
        self.corWindow.setParent(self.anatomistBox)
        layout.addWidget(self.sagWindow.getInternalRep())
        layout.addWidget(self.axWindow.getInternalRep())
        layout.addWidget(self.corWindow.getInternalRep())
Esempio n. 2
0
 def changeDisplay(self, index, object):
     '''
     Changes display on user's demand
     index : int between 0 and 3
     object : object to display
     '''
     a = ana.Anatomist('-b')
     views = ['Axial', 'Sagittal', 'Coronal', '3D']
     new_view = views[index]
     self.disableButton(index)
     self.createNewWindow(new_view)
     a.addObjects(object, self.new_awindow)
Esempio n. 3
0
    def showPopup(self, object):
        '''
        Defines the dimensions of the popup which is a QWidget
        QWidget is added to self.popups in order to keep the widget
        but beeing able to replace the object inside

        '''
        a = ana.Anatomist('-b')
        self.layout.addWidget(self.window)
        self.popups.append(self.popup_window)
        index = len(self.popups) - 1
        self.popups[index].setWindowTitle(object.name)
        #Create empty view (Axial, Sagittal,...)
        self.createNewWindow()
        self.setObject(object)
        #Add object into view
        a.addObjects(object, self.new_awindow)
        self.popups[index].show()
Esempio n. 4
0
    def createNewWindow(self, wintype='Axial'):
        '''
        Opens a new window in the vertical layout
        Function is nearly the same as createWindow in AnaSimpleViewer2
        Default display each time a new popup opens is 'Axial' view
        '''
        a = ana.Anatomist('-b')
        w = a.createWindow(wintype, no_decoration=True, options={'hidden': 1})
        w.setAcceptDrops(False)

        #Set wanted view button checked and others unchecked
        views = ['Axial', 'Sagittal', 'Coronal', '3D']
        index = views.index(wintype)
        self.disableButton(index)

        #Delete object if there is already one
        if self.newViewLay.itemAt(0):
            self.newViewLay.itemAt(0).widget().deleteLater()

        x = 0
        y = 0
        i = 0
        if not hasattr(self, '_winlayouts'):
            self._winlayouts = [[0, 0], [0, 0]]
        else:
            freeslot = False
            for y in (0, 1):
                for x in (0, 1):
                    i = i + 1
                    if not self._winlayouts[x][y]:
                        freeslot = True
                        break
                if freeslot:
                    break
        self.newViewLay.addWidget(w.getInternalRep())
        self.new_awindow = w
        self._winlayouts[x][y] = 1

        if wintype == '3D':
            a.execute('SetControl', windows=[w], control='LeftSimple3DControl')
            a.execute('Camera',
                      windows=[self.new_awindow],
                      view_quaternion=[0.404603, 0.143829, 0.316813, 0.845718])
        else:
            a.execute('SetControl', windows=[w], control='Simple2DControl')
            a.assignReferential(a.mniTemplateRef, w)
            # force redrawing in MNI orientation
            # (there should be a better way to do so...)
            if wintype == 'Axial':
                w.muteAxial()
                print('MUTEAXIAL', w.muteAxial)
            elif wintype == 'Coronal':
                w.muteCoronal()
            elif wintype == 'Sagittal':
                w.muteSagittal()
            elif wintype == 'Oblique':
                w.muteOblique()
        # set a black background
        a.execute('WindowConfig',
                  windows=[w],
                  light={'background': [0., 0., 0., 1.]},
                  view_size=(500, 600))
def csvMapGraph(options,
                agraphs=None,
                window=None,
                displayProp=None,
                palette=None,
                propPrefix=None,
                csvfilename=None,
                filterCol=None,
                filterExpr=None,
                min=None,
                max=None):
    '''csvMapGraph( options, agraphs=None, window=None, displayProp=None,
  palette=None, propPrefix=None, csvfilename=None )

  read a CSV-like file, extract numeric figures on sulci from it and map it
  on a sulci graph displayed in anatomist.

  Paramters:

  options: command-line parsing options of siCsvMapGraph (see the help of this
    command)
  agraphs: existing anatomist graph(s) on which to map data. If not specified, a
    graph is read from the options.graphname parameter.
  window: existing anatomist window in which the sulci graph will be displayed.
    If not specified, a new window will be opened.
  displayProp: when several data are read at the same time, specifies which
    one will be currently displayed. If not specified, the first data column
    will be used.
  palette: color palette to apply to the graph display. May be either an
    anatomist palette object, or a parameters dictionary, corresponding to the
    parameters of the SetObjectPalette command (see
    http://brainvisa.info/doc/anatomist-4.0/html/fr/programmation/commands.html#SetObjectPalette)
  propPrefix: data read from the CSV file are stored in the graph nodes as
    properties. The prefix is used in the properties names. If not specified,
    'csv' is used
  csvfilename: if specified, overrides options.csvfilename for convenience

  Return values: aobjects, awindows
  '''
    if csvfilename is None:
        csvfilename = options.csvfilename
    if csvfilename is None:
        parseOpts([sys.argv[0], '-h'])
        sys.exit(1)
    # read
    ft = sigraph.FoldLabelsTranslator(options.transfile)
    sigraph.si().setLabelsTranslPath(options.transfile)
    labels, sulci_data, mode = read_csv(csvfilename,
                                        options.columns,
                                        operator=options.operator,
                                        filterCol=filterCol,
                                        filterExpr=filterExpr)
    if options.summarycsvfilename:
        write_summary_csv(options.summarycsvfilename, labels, sulci_data, mode)

    # graph
    if not options.graphname: return
    from soma import aims
    graphs = []
    if agraphs:
        if isinstance(agraphs, anatomist.Anatomist.AGraph):
            agraphs = [agraphs]
        graphs = [x.graph() for x in agraphs]
    else:
        r = aims.Reader(options={'subobjectsfilter': 1})
        graphs = [r.read(f) for f in options.graphname]
        for g in graphs:
            ft.translate(g, options.label_attribute, options.label_attribute)

    # mesh
    for mfile in options.meshname:
        m = aims.read(mfile)
    else:
        m = None
    if propPrefix is None:
        propPrefix = 'csv'

    for g in graphs:
        for v in g.vertices():
            if v.getSyntax() != 'fold': continue
            if mode in ('sulci', 'label', 'name'):
                try:
                    l = v[options.label_attribute]
                    data = getdata(sulci_data, v[options.label_attribute])
                except exceptions.KeyError:
                    continue
            elif mode == 'nodes':
                try:
                    data = getdata(sulci_data, str(int(v['index'])))
                except exceptions.KeyError:
                    continue
            for i, h in enumerate(labels):
                v[propPrefix + '_mean_' + h] = data[0][i]
                if options.log and data[0][i] != 0:
                    v[propPrefix + '_log_mean_' + h] = numpy.log(data[0][i])
                elif options.log10 and data[0][i] != 0:
                    v[propPrefix + '_log_mean_' + h] = numpy.log10(data[0][i])
                # add only no-null std
                if data[1][i]: v[propPrefix + '_std_' + h] = data[1][i]
                v[propPrefix + '_sum_' + h] = data[2][i]

    a = anatomist.Anatomist()
    aobjects = []
    if not agraphs:
        agraphs = [a.toAObject(g) for g in graphs]
        aobjects = agraphs
    if displayProp is None:
        displayProp = propPrefix + '_mean_' + labels[0]
    for ag in agraphs:
        ag.setColorMode(ag.PropertyMap)
        ag.setColorProperty(displayProp)
        #modified to get the palette as imput argument
        palette = a.getPalette(palette)
        if palette is not None:
            if isinstance(palette, a.APalette):
                #modified to get min and max values as imputs
                ag.setPalette(palette,
                              minVal=min,
                              maxVal=max,
                              absoluteMode=True)
                #ag.setPalette( palette )
            else:  # dict
                a.execute('SetObjectPalette', objects=[ag], **palette)
        ag.notifyObservers()
        if m:
            am = a.toAObject(m)
            aobjects.append(am)
    if window is not None:
        win = window
        wins = []
    else:
        win = a.createWindow(wintype='3D')
        wins = [win]
    win.setHasCursor(0)
    win.addObjects(aobjects, add_graph_nodes=True)
    return aobjects, wins