sampleview.py 23.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# -*- coding: utf-8 -*-
"""
GEPARD - Gepard-Enabled PARticle Detection
Copyright (C) 2018  Lars Bittrich and Josef Brandt, Leibniz-Institut für 
Polymerforschung Dresden e. V. <bittrich-lars@ipfdd.de>    

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program, see COPYING.  
If not, see <https://www.gnu.org/licenses/>.
"""
from PyQt5 import QtCore, QtGui, QtWidgets
import numpy as np
import os
from dataset import DataSet, loadData
25
from ramancom.ramancontrol import RamanControl, simulatedRaman
26 27 28
from opticalscan import OpticalScan
from ramanscanui import RamanScanUI
from detectionview import ParticleDetectionView
29
from analysis.analysisview import ParticleAnalysis
30
from zeissimporter import ZeissImporter
31
from viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContours
32 33
from helperfunctions import polygoncovering, cv2imread_fix
import cv2
34
from ramancom.configRaman import RamanConfigWin
35 36 37 38

class SampleView(QtWidgets.QGraphicsView):
    ScalingChanged = QtCore.pyqtSignal(float)
    
39
    def __init__(self, logpath):
40 41
        super(SampleView, self).__init__()
        
42
        self.logpath = logpath
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        self.item = QtWidgets.QGraphicsPixmapItem()
        self.item.setPos(0, 0)
        self.item.setAcceptedMouseButtons(QtCore.Qt.NoButton)
        self.scaleFactor = 1.0
        scene = QtWidgets.QGraphicsScene(self)
        scene.setItemIndexMethod(QtWidgets.QGraphicsScene.NoIndex)
        scene.addItem(self.item)
        scene.setBackgroundBrush(QtCore.Qt.darkGray)
        self.setScene(scene)
        self.setCacheMode(QtWidgets.QGraphicsView.CacheBackground)
        self.setViewportUpdateMode(QtWidgets.QGraphicsView.BoundingRectViewportUpdate)
        self.setRenderHint(QtGui.QPainter.Antialiasing)
        self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
        self.setResizeAnchor(QtWidgets.QGraphicsView.AnchorViewCenter)
        self.ramanctrl = RamanControl()
58 59 60 61 62 63 64 65 66 67 68 69
        self.simulatedRaman = simulatedRaman        
        #determine, if ramanSwitch is needed:
        self.ramanctrl.connect()
        if not self.ramanctrl.connected:
            QtWidgets.QMessageBox.warning(self, 'Error', 'Please enable Raman Connection')
            return
        if self.ramanctrl.getImageDimensions(mode='bf')[0] == self.ramanctrl.getImageDimensions(mode='df')[0]:
            self.ramanSwitchNeeded = False
        else:
            self.ramanSwitchNeeded = True
        self.ramanctrl.disconnect()
        
70 71 72 73 74 75 76 77 78
        self.drag = None
        self.mode = None
        self.dataset = None
        self.fititems = []
        self.boundaryitems = [[],[]]
        self.scanitems = []
        self.ramanscanitems = []
        self.imgdata = None
        self.isblocked = False
79
        self.contouritem = SegmentationContours(self)
80 81
        scene.addItem(self.contouritem)
        self.detectionwidget = None
82
        self.ramanwidget = RamanScanUI(self.ramanctrl, None, self.logpath, self)
83
        self.ramanwidget.imageUpdate.connect(self.loadPixmap)
84
        self.oscanwidget = OpticalScan(self.ramanctrl, None, self.logpath, self)
85 86
        self.oscanwidget.imageUpdate.connect(self.loadPixmap)
        self.oscanwidget.boundaryUpdate.connect(self.resetBoundary)
87
        self.analysiswidget = None
88
        self.setMinimumSize(600, 600)
89 90
        self.darkenPixmap = False
        self.microscopeMode = None
Hackmet's avatar
Hackmet committed
91
        self.coordTestMode = False
92 93 94 95 96 97 98 99 100 101 102 103 104 105
        
    def takeScreenshot(self):
        #TODO:
        #LIMIT SCREENSHOT TO ACTUAL VIEWSIZE OF LOADED IMAGE...
        #hide scrollbars
        self.setHorizontalScrollBarPolicy(1)
        self.setVerticalScrollBarPolicy(1)
        #capture screen
        screen = QtWidgets.QApplication.primaryScreen()
        self.repaint()
        screenshot = screen.grabWindow(self.winId())
        #unhide scrollbars
        self.setHorizontalScrollBarPolicy(0)
        self.setVerticalScrollBarPolicy(0)
106
        
107 108 109 110 111 112 113 114 115 116 117 118
        fname = self.dataset.path + '/screenshot.png'
        validFileName = False
        incr = 1
        while not validFileName:
            if not os.path.exists(fname):
                validFileName = True
            else:
                fname = self.dataset.path + '/screenshot ({}).png'.format(incr)
                incr += 1
        screenshot.save(fname , 'png')
        QtWidgets.QMessageBox.about(self, 'Message', 'Saved as {} to project directory.'.format(fname.split('/')[-1]))
                    
119 120 121 122 123 124 125 126 127 128 129 130
    def closeEvent(self, event):
        reply = QtWidgets.QMessageBox.question(self, 'Message',
            "Are you sure to quit?", QtWidgets.QMessageBox.Yes | 
            QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)

        if reply == QtWidgets.QMessageBox.Yes:
            self.disconnectRaman()
            self.saveDataSet()
            event.accept()
            self.oscanwidget.close()
            if self.detectionwidget is not None:
                self.detectionwidget.close()
131 132
            if self.analysiswidget is not None:
                self.analysiswidget.close()
133 134 135
            self.ramanwidget.close()
        else:
            event.ignore()
136 137 138 139 140
    
    def configureRamanControl(self):
        self.configWin = RamanConfigWin(self)
        self.configWin.show()
    
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    def saveDataSet(self):
        if self.dataset is not None:
            self.dataset.save()
        
    @QtCore.pyqtSlot() 
    def zoomIn(self):
        self.scaleImage(1.25)

    @QtCore.pyqtSlot() 
    def zoomOut(self):
        self.scaleImage(0.8)

    @QtCore.pyqtSlot() 
    def normalSize(self):
        self.scaleFactor = 1.0
        self.setTransform(QtGui.QTransform.fromScale(1., 1.))
        self.announceScaling()

    @QtCore.pyqtSlot() 
    def fitToWindow(self):
Hackmet's avatar
Hackmet committed
161
#        print("fitting to Window")
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
        brect = self.item.sceneBoundingRect()
        self.fitInView(0, 0, brect.width(), brect.height(), QtCore.Qt.KeepAspectRatio)
        self.scaleFactor = self.transform().m11()
        self.announceScaling()
        
    def switchMode(self, mode, loadnew=False):
        if mode is None:
            return
        assert mode in ["OpticalScan", "ParticleDetection", "RamanScan", "ParticleAnalysis"]
        self.oscanwidget.setVisible(False)
        if self.detectionwidget is not None:
            self.detectionwidget.close()
            self.detectionwidget.destroy()
        self.ramanwidget.setVisible(False)
        self.contouritem.resetContours([])
        self.mode = mode
178
        self.loadPixmap(self.microscopeMode)
179 180 181
        if mode == "OpticalScan":
            self.oscanwidget.setVisible(True)
            self.oscanwidget.resetDataset(self.dataset)
182
            
183
        elif mode == "ParticleDetection":
184 185 186 187 188 189
            if self.detectionwidget is None:
                self.detectionwidget = ParticleDetectionView(self.imgdata, self.dataset, self)
                self.detectionwidget.show()
                self.detectionwidget.imageUpdate.connect(self.detectionUpdate)
                self.detectionwidget.detectionFinished.connect(self.activateMaxMode)
            
190 191 192
        elif mode == "RamanScan":
            self.ramanwidget.resetDataset(self.dataset)
            self.ramanwidget.setVisible(True)
193 194 195 196 197
            
        elif mode == "ParticleAnalysis":
            if self.ramanwidget.isVisible():
                self.ramanwidget.setVisible(False)
            if self.analysiswidget is None:
Hackmet's avatar
Hackmet committed
198
                print('creating new analysiswidget')
199
                self.analysiswidget = ParticleAnalysis(self.dataset, self)
200 201
                self.analysiswidget.showMaximized()
            else:
Hackmet's avatar
Hackmet committed
202
                print('show maximized already exisiting analysiswidget')
203 204 205 206 207 208 209 210 211
                self.analysiswidget.showMaximized()
            
#            self.ramanwidget.setVisible(False)
            if self.detectionwidget is not None:
                self.detectionwidget.setVisible(False)
            
            #show legend:
            self.imparent.legend.show()    
        
212 213 214 215
        if loadnew:
            self.fitToWindow()
        self.imparent.updateModes(mode, self.getMaxMode())
        
216
    def open(self, fname):       
217
        self.saveDataSet()
Hackmet's avatar
Hackmet committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
        
        #close all widgets
        for widget in [self.detectionwidget, self.ramanwidget, self.oscanwidget, self.analysiswidget]:
            if widget is not None:
                widget.close()
                widget.destroy()
                del widget
                
        self.contouritem.resetContours()
#        if self.dataset is not None:
#            del self.dataset
#            self.scene().removeItem(self.contouritem)
#            del self.contouritem
#            self.contouritem = SegmentationContours(self)
#            self.scene().addItem(self.contouritem)
Hackmet's avatar
Hackmet committed
233
            
234
        self.dataset = loadData(fname)
235
        self.setMicroscopeMode()
236 237 238
        self.imparent.setWindowTitle(self.dataset.name + (" SIMULATION" if simulatedRaman else ""))
        self.imgdata = None
        self.activateMaxMode(loadnew=True)
239
        self.imparent.snapshotAct.setEnabled(True)
240
        
241 242 243 244 245 246 247
    def importProject(self, fname):
        zimp = ZeissImporter(fname, self.ramanctrl, self)
        if zimp.validimport:
            zimp.exec()
            if zimp.result() == QtWidgets.QDialog.Accepted:
                self.open(zimp.gepardname)
        
248 249 250 251 252
    def new(self, fname):
        self.saveDataSet()
        if self.dataset is not None:
            self.dataset.save()
        self.dataset = DataSet(fname, newProject=True)
253
        self.setMicroscopeMode()
254 255 256
        self.imparent.setWindowTitle(self.dataset.name + (" SIMULATION" if simulatedRaman else ""))
        self.imgdata = None
        self.activateMaxMode(loadnew=True)
257 258 259 260 261 262 263
        self.imparent.snapshotAct.setEnabled(True)
    
    def setMicroscopeMode(self):
        if self.ramanSwitchNeeded:
            self.imparent.ramanSwitch.connectToSampleView()
            self.imparent.ramanSwitch.show()
        self.microscopeMode = ('df' if self.imparent.ramanSwitch.df_btn.isChecked() else 'bf')
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    
    @QtCore.pyqtSlot()    
    def activateMaxMode(self, loadnew=False):
        mode = self.getMaxMode()
        self.imparent.updateModes(self.mode, self.getMaxMode())
        self.switchMode(mode, loadnew=loadnew)
        
    def blockUI(self):
        self.isblocked = True
        self.imparent.blockUI()
        
    def unblockUI(self):
        self.isblocked = False
        self.imparent.unblockUI(self.ramanctrl.connected)
        self.imparent.updateModes(self.mode, self.getMaxMode())
        
    def getMaxMode(self):
        if self.dataset is None:
            return None
        if not self.ramanctrl.connected:
            self.connectRaman()
        if not self.ramanctrl.connected:
            return None
        maxmode = "OpticalScan"
        if os.path.exists(self.dataset.getImageName()):
            maxmode = "ParticleDetection"
            if len(self.dataset.ramanpoints)>0:
                maxmode = "RamanScan"
292
            if self.dataset.ramanscandone:        #uncomment!!
293 294 295 296
                maxmode = "ParticleAnalysis"
        return maxmode
        
    def mousePressEvent(self, event):
297 298
#        if event.button()==QtCore.Qt.RightButton:
        if event.button()==QtCore.Qt.MiddleButton:
299 300 301 302 303 304 305 306 307 308 309 310 311 312
            self.drag = event.pos()
        elif event.button()==QtCore.Qt.LeftButton and self.mode in ["OpticalScan", "RamanScan"] \
             and event.modifiers()==QtCore.Qt.ControlModifier:
            p0 = self.mapToScene(event.pos())
            if self.dataset is not None and self.dataset.pshift is not None:
                if self.dataset.readin:
                    reply = QtWidgets.QMessageBox.critical(self, 'Dataset is newly read from disk!',
                        "Coordinate systems might have changed since. Do you want to continue with saved coordinates?", 
                        QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
            
                    if reply == QtWidgets.QMessageBox.Yes:
                        self.dataset.readin = False
                    else:
                        return
313 314 315
                x, y, z = self.dataset.mapToLengthRaman([p0.x(), p0.y()], 
                                                         microscopeMode=self.microscopeMode,
                                                         noz=(False if self.mode=="RamanScan" else True))
316 317 318 319 320 321
                if z is not None:
                    assert z>-100.
                self.ramanctrl.moveToAbsolutePosition(x, y, z)
        elif event.button()==QtCore.Qt.LeftButton and self.mode=="ParticleDetection":
            p0 = self.mapToScene(event.pos())
            self.detectionwidget.setImageCenter([p0.x(), p0.y()])
322 323 324
#        elif event.button()==QtCore.Qt.LeftButton and self.mode=="ParticleAnalysis":
#            p0 = self.mapToScene(event.pos())
        
325 326 327 328 329 330 331 332 333 334
        else:
            p0 = self.mapToScene(event.pos())
            super(SampleView, self).mousePressEvent(event)
            
    def mouseMoveEvent(self, event):
        if self.drag is not None:
            p0 = event.pos()
            move = self.drag-p0
            self.horizontalScrollBar().setValue(move.x() + self.horizontalScrollBar().value())
            self.verticalScrollBar().setValue(move.y() + self.verticalScrollBar().value())
335
            
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
            self.drag = p0
        else:
            super(SampleView, self).mouseMoveEvent(event)
                        
    def mouseReleaseEvent(self, event):
        self.drag = None
        super(SampleView, self).mouseReleaseEvent(event)
        
    def wheelEvent(self, event):
        factor = 1.01**(event.angleDelta().y()/8)
        self.scaleImage(factor)

    def scaleImage(self, factor):
        if factor<1 and not self.imparent.zoomOutAct.isEnabled():
            return
        if factor>1 and not self.imparent.zoomInAct.isEnabled():
            return
        self.scaleFactor *= factor      
        self.scale(factor, factor)
        self.announceScaling()
        
    def announceScaling(self):
358
        pixelscale = (self.dataset.pixelscale_df if self.microscopeMode == 'df' else self.dataset.pixelscale_bf)
359
        if self.dataset is None or pixelscale is None:
360 361
            self.ScalingChanged.emit(-1.0)
        else:
362
            self.ScalingChanged.emit(pixelscale/self.scaleFactor)           ##CURRENTLY ONLY DARKFIELD!!! FIX NEEDED!!!
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
        
    def connectRaman(self):
        if not self.ramanctrl.connect():
            msg = QtWidgets.QMessageBox()
            msg.setText("Connection failed! Please enable remote control.")
            msg.exec()
        else:
            mode = self.getMaxMode()
            self.switchMode(mode)
        self.imparent.updateConnected(self.ramanctrl.connected)
    
    def disconnectRaman(self):
        self.ramanctrl.disconnect()
        self.imparent.updateConnected(self.ramanctrl.connected)

378
    @QtCore.pyqtSlot(str)
379 380 381 382 383
    def detectionUpdate(self):
        self.contouritem.resetContours(self.dataset.particlecontours)
        self.prepareAnalysis()
        self.update()

384 385
    @QtCore.pyqtSlot(str) 
    def loadPixmap(self, microscope_mode='df'):
386 387 388 389 390 391 392 393 394 395 396 397
        self.clearItems()
        if self.dataset is None:
            self.item.setPixmap(QtGui.QPixmap())
        else:
            data = self.imgdata
            fname = self.dataset.getImageName()
            if self.mode == "ParticleDetection" or self.mode == "ParticleAnalysis":
                self.contouritem.resetContours(self.dataset.particlecontours)
            if data is None and os.path.exists(fname):
                data = cv2.cvtColor(cv2imread_fix(fname), cv2.COLOR_BGR2RGB)
                self.imgdata = data
            if data is not None:
398
                
399 400 401 402 403
                height, width, channel = data.shape
                bytesPerLine = 3 * width
                pix = QtGui.QPixmap()
                pix.convertFromImage(QtGui.QImage(data.data, 
                                width, height, bytesPerLine, QtGui.QImage.Format_RGB888))
404
                
405
                self.item.setPixmap(pix)
406 407 408 409 410 411 412 413 414
                
                if self.darkenPixmap:
                    self.scene().setBackgroundBrush(QtGui.QColor(5, 5, 5))
                    self.item.setOpacity(0.2)
                else:
                    self.scene().setBackgroundBrush(QtCore.Qt.darkGray)
                    self.item.setOpacity(1)
                
                
415 416 417 418
            else:
                self.item.setPixmap(QtGui.QPixmap())
            if self.mode == "OpticalScan":
                for i, p in zip(self.dataset.fitindices, self.dataset.fitpoints):
419
                    p = self.dataset.mapToPixel(p, mode=microscope_mode, force=True)
420 421 422 423 424 425 426 427 428 429
                    fititem = FitPosIndicator(i+1, pos=p)
                    self.scene().addItem(fititem)
                    self.fititems.append(fititem)                    
            if self.mode == "ParticleDetection" or self.mode == "ParticleAnalysis":
                self.prepareAnalysis()
            else:
                self.fitToWindow()
    
    @QtCore.pyqtSlot()        
    def resetScanPositions(self):
430
        micMode = ('df' if self.oscanwidget.df_btn.isChecked() else 'bf')
431 432 433 434 435 436
        for item in self.scanitems:
            self.scene().removeItem(item)
        edges, nodes = self.boundaryitems
        boundary = []
        for n in nodes:
            p = n.pos().x(), n.pos().y()
437
            boundary.append(self.dataset.mapToLength(p, self.microscopeMode, force=True))
438
        boundary = np.array(boundary)
439
#        print(boundary)
440
        self.dataset.boundary = boundary
441 442 443 444 445
        if micMode == 'df':
            width, height, angle = self.dataset.imagedim_df
        else:
            width, height, angle = self.dataset.imagedim_bf
        
446 447 448 449 450 451 452 453 454 455
        margin = min(width, height)*0.02
        wx, wy = width-margin, height-margin
        print(wx,wy)
        p1 = polygoncovering(boundary, wx, wy)
        b2 = boundary.copy()
        b2 = b2[:,[1,0]]
        p2 = polygoncovering(b2, wy, wx)
        if len(p2)<len(p1):
            p1 = [[pi[1],pi[0]] for pi in p2]
        self.dataset.grid = p1
456 457 458 459
        if self.microscopeMode == 'df':
            wxs, wys = width/self.dataset.pixelscale_df, height/self.dataset.pixelscale_df
        else:
            wxs, wys = width/self.dataset.pixelscale_bf, height/self.dataset.pixelscale_bf
460
        
461 462
        self.scanitems = []
        for i, p in enumerate(p1):
463
            p = self.dataset.mapToPixel(p, self.microscopeMode, force=True)
464 465 466 467 468 469
            s = ScanIndicator(i+1, wxs, wys, p)
            self.scene().addItem(s)
            self.scanitems.append(s)
    
    @QtCore.pyqtSlot()        
    def resetBoundary(self):
470
        micMode = self.microscopeMode
471 472 473 474 475 476 477
        edges, nodes = self.boundaryitems
        for item in edges:
            self.scene().removeItem(item)
        for item in nodes:
            self.scene().removeItem(item)
        edges, nodes = [], []
        for p in self.dataset.boundary:
478
            p = self.dataset.mapToPixel(p, micMode, force=True)
479 480 481 482 483 484 485 486 487 488
            n = Node(p, self)
            nodes.append(n)
            self.scene().addItem(n)
        for i in range(len(nodes)):
            e = Edge(nodes[i-1], nodes[i])
            edges.append(e)
            self.scene().addItem(e)
        self.boundaryitems = edges, nodes
        self.resetScanPositions()
        
489
    @QtCore.pyqtSlot(int, bool)
490 491
    def selectContour(self, index, centerOn=True):
        if self.analysiswidget is not None:
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
            if self.analysiswidget.uniquePolymers is not None:
                #the index is the contour index, find particle index:
                specIndex = self.analysiswidget.particles2spectra[index][0]  #select first spectrum of partoicle
                self.analysiswidget.currentParticleIndex = index
                self.analysiswidget.currentSpectrumIndex = specIndex
                
                selectedPolymer = self.analysiswidget.currentPolymers[specIndex]
                try:
                    self.analysiswidget.polymerIndex = self.analysiswidget.uniquePolymers.index(selectedPolymer)
                except:
                    print(selectedPolymer)
                    raise
                
                #subparticleIndex
                partIndicesOfThatPolymer = self.analysiswidget.indices[self.analysiswidget.polymerIndex]
                subPartInd = partIndicesOfThatPolymer.index(index)
                
                #disconnect analysis widgets:
                self.analysiswidget.particleSelector.valueChanged.disconnect()
                self.analysiswidget.spectrumSelector.valueChanged.disconnect()
                self.analysiswidget.polymerComboBox.currentIndexChanged.disconnect()
                
                #set widgets...
                self.analysiswidget.particleSelector.setValue(subPartInd+1)
                self.analysiswidget.particleSelector.setMaximum(len(partIndicesOfThatPolymer))
                
                self.analysiswidget.spectrumSelector.setValue(1)
                self.analysiswidget.spectrumSelector.setMaximum(len(self.analysiswidget.particles2spectra[index]))
                
                selectedPolymer = self.analysiswidget.currentPolymers[specIndex]
                self.analysiswidget.polymerIndex = self.analysiswidget.uniquePolymers.index(selectedPolymer)
                self.analysiswidget.polymerComboBox.setCurrentIndex(self.analysiswidget.polymerIndex)
               
                #reconnect all widgets:
                self.analysiswidget.particleSelector.valueChanged.connect(self.analysiswidget.selectParticle)
                self.analysiswidget.spectrumSelector.valueChanged.connect(self.analysiswidget.selectSpectrum)
                self.analysiswidget.polymerComboBox.currentIndexChanged.connect(self.analysiswidget.displayNewPolymerType)
                
                self.analysiswidget.updateSpecPlot(centerOn=centerOn)

532
    
533 534 535 536 537
    def prepareAnalysis(self):
        self.clearItems()
        if self.dataset.ramanscansortindex is not None and len(self.dataset.ramanscansortindex)>0:
            data = []
            for i in self.dataset.ramanscansortindex:
538 539
#                data.append(list(self.dataset.ramanpoints[i])+list(self.dataset.particlestats[i]))
                data.append(list(self.dataset.ramanpoints[i]))  #particlestats are not needed here. Plus, they dont need to match spectra indices anymore..
540 541 542 543 544 545 546 547 548 549 550
            for i in range(len(data)):
                item = RamanScanIndicator(self, i+1, 20, (data[i][0],data[i][1]))
                self.scene().addItem(item)
                self.ramanscanitems.append(item)
                
    def highLightRamanIndex(self, index):
        if index < len(self.ramanscanitems):
            for item in self.ramanscanitems:
                item.setHighLight(False)
            self.ramanscanitems[index].setHighLight(True)
    
551 552 553 554 555 556 557 558 559 560
    def centerOnRamanIndex(self, index, centerOn=True, highlightContour=True):
        if centerOn:
            self.centerOn(self.ramanscanitems[index])
            
#        if highlightContour:
#            self.contouritem.selectedContours = []
#        else:
#            self.ensureVisible(self.ramanscanitems[index])
        
        
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
    def clearItems(self):
        for item in self.fititems:
            self.scene().removeItem(item)
        self.fititems = []
        for item in self.scanitems:
            self.scene().removeItem(item)
        edges, nodes = self.boundaryitems
        for item in edges:
            self.scene().removeItem(item)
        for item in nodes:
            self.scene().removeItem(item)
        self.scanitems = []
        self.boundaryitems = [], []
        for item in self.ramanscanitems:
            self.scene().removeItem(item)
576
        self.ramanscanitems = []
Hackmet's avatar
Hackmet committed
577

578