Ejemplo n.º 1
0
 def warnAndQuit(self,msg):
     """
     Display alert and (maybe) quit the plugin
     """
     self.lasagna.alert = alert(self.lasagna,alertText=msg)
     self.lasagna.stopPlugin(self.__module__) #This will call self.closePlugin
     self.lasagna.pluginActions[self.__module__].setChecked(False) #Uncheck the menu item associated with this plugin's name
Ejemplo n.º 2
0
    def __init__(self, lasagna_serving, parent=None):

        super(plugin, self).__init__(
            lasagna_serving
        )  # This calls the LasagnaPlugin constructor which in turn calls subsequent constructors

        # Is the Elastix binary in the system path?
        if which('elastix') is None:
            # TODO: does not stop properly. Have to uncheck and recheck the plugin menu item to get it to run a second time.
            from lasagna.alert import alert
            self.alert = alert(
                lasagna_serving,
                'The elastix binary does not appear to be in your path.<br>Not starting plugin.'
            )
            self.lasagna.pluginActions[self.__module__].setChecked(
                False
            )  # Uncheck the menu item associated with this plugin's name
            self.deleteLater()
            return
        else:
            print("Using elastix binary at " + which('elastix'))

        # re-define some default properties that were originally defined in LasagnaPlugin
        self.pluginShortName = 'Elastix'  # Appears on the menu
        self.pluginLongName = 'registration of images'  # Can be used for other purposes (e.g. tool-tip)
        self.pluginAuthor = 'Rob Campbell'

        # This is the file name we monitor during running
        self.elastixLogName = 'elastix.log'

        # Create widgets defined in the designer file
        self.setupUi(self)
        self.show()

        # The dictionary which will store the command components
        # the param files and output are separate as they are stored in the list view and ouput path text edit box
        self.elastix_cmd = {
            'f': '',  # fixed image
            'm': ''  # moving image
        }

        # A dictionary for storing location of temporary parameter files
        # Temporary parameter files are created as the user edits them and are
        # removed when the registration starts
        self.tmpParamFiles = {}

        # Create some properties which we will need
        self.fixedStackPath = ''  # absolute path to reference image
        self.movingStackPath = ''  # absolute path to sample image

        # Set up the list view on Tab 2
        self.paramItemModel = QtGui.QStandardItemModel(self.paramListView)
        self.paramListView.setModel(self.paramItemModel)

        # Link signals to slots
        # Tab 1 - Loading data
        self.loadFixed.released.connect(self.loadFixed_slot)
        self.loadMoving.released.connect(self.loadMoving_slot)
        self.originalMovingImage = None  # The original moving image is stored here
        self.originalMovingFname = None

        # Flip axis
        self.flipAxis1.released.connect(lambda: self.flipAxis_Slot(0))
        self.flipAxis2.released.connect(lambda: self.flipAxis_Slot(1))
        self.flipAxis3.released.connect(lambda: self.flipAxis_Slot(2))

        # Rotate axis
        self.rotAxis1.released.connect(lambda: self.rotAxis_Slot(0))
        self.rotAxis2.released.connect(lambda: self.rotAxis_Slot(1))
        self.rotAxis3.released.connect(lambda: self.rotAxis_Slot(2))

        # Swap axes
        self.swapAxis1_2.released.connect(lambda: self.swapAxis_Slot(0, 1))
        self.swapAxis2_3.released.connect(lambda: self.swapAxis_Slot(1, 2))
        self.swapAxis3_1.released.connect(lambda: self.swapAxis_Slot(2, 0))

        self.saveModifiedMovingStack.released.connect(
            self.saveModifiedMovingStack_slot)

        # Tab 2 - Building the registration command
        self.outputDirSelect_button.released.connect(self.selectOutputDir_slot)
        self.removeParameter.released.connect(self.removeParameter_slot)
        self.loadParamFile.released.connect(self.loadParamFile_slot)
        self.moveParamUp_button.released.connect(self.moveParamUp_button_slot)
        self.moveParamDown_button.released.connect(
            self.moveParamDown_button_slot)

        # Tab 3 - parameter file
        self.plainTextEditParam.textChanged.connect(
            self.plainTextEditParam_slot)
        self.comboBoxParam.activated.connect(
            self.comboBoxParamLoadOnSelect_slot)

        # Tab 4: running
        self.runElastix_button.released.connect(self.runElastix_button_slot)
        self.runElastix_button.setEnabled(False)
        # Start a QTimer to poll for finished analyses
        self.finishedMonitorTimer = QtCore.QTimer()
        self.finishedMonitorTimer.timeout.connect(self.analysisFinished_slot)
        self.finishedMonitorTimer.start(
            2500)  # Number of milliseconds between poll events
        self.listofDirectoriesWithRunningAnalyses = []
        # Set up list view on the running tab
        self.runningAnalysesItemModel = QtGui.QStandardItemModel(
            self.runningRegistrations_ListView)
        self.runningRegistrations_ListView.setModel(
            self.runningAnalysesItemModel)

        # Tab 5: results
        self.resultsItemModel = QtGui.QStandardItemModel(
            self.registrationResults_ListView)
        self.registrationResults_ListView.setModel(self.resultsItemModel)
        self.registrationResults_ListView.clicked.connect(
            self.resultImageClicked_Slot)
        self.resultImages_Dict = {
        }  # the keys are result image file names and the values are the result images
        self.showHighlightedResult_radioButton.toggled.connect(
            self.overlayRadioButtons_Slot)
        self.showOriginalMovingImage_radioButton.toggled.connect(
            self.overlayRadioButtons_Slot)

        # Clear all image stacks
        self.lasagna.removeIngredientByType('imagestack')

        # -------------------------------------------------------------------------------------
        # The following will either be hugely changed or deleted when the plugin is no longer
        # under heavy development
        debug = False  # runs certain things quickly to help development
        if debug and os.path.expanduser(
                "~"
        ) == '/home/rob':  #Ensure only I can trigger this. Ensures that it doesn't activate if I accidently push with debug enabled
            self.fixedStackPath = '/mnt/data/TissueCyte/registrationTests/regPipelinePrototype/YH84_150507_target.mhd'
            self.movingStackPath = '/mnt/data/TissueCyte/registrationTests/regPipelinePrototype/YH84_150507_moving.mhd'
            do_real_load = True
            if do_real_load:
                self.loadFixed_slot(self.fixedStackPath)
                self.loadMoving_slot(self.movingStackPath)
                self.lasagna.initialiseAxes()
            do_param_file = True
            if do_param_file:
                # load param file list
                param_files = [
                    '/mnt/data/TissueCyte/registrationTests/regPipelinePrototype/Par0000affine.txt',
                    '/mnt/data/TissueCyte/registrationTests/regPipelinePrototype/Par0000bspline.txt'
                ]
                param_files = [
                    '/mnt/data/TissueCyte/registrationTests/regPipelinePrototype/Par0000affine_quick.txt'
                ]
                self.loadParamFile_slot(param_files)

            self.outputDir_label.setText(
                self.absToRelPath(
                    '/mnt/data/TissueCyte/registrationTests/regPipelinePrototype/reg2'
                ))
            self.updateWidgets_slot()
            self.tabWidget.setCurrentIndex(3)
Ejemplo n.º 3
0
    def __init__(self, lasagna_serving, parent=None):

        super(plugin, self).__init__(lasagna_serving)  # This calls the LasagnaPlugin constructor which in turn calls subsequent constructors

        # Is the Transformix (or Elastix) binary in the system path?
        # We search for both in case we in the future add the ability to calculate inverse transforms and other good stuff
        if which('transformix') is None or which('elastix') is None:
            #TODO: does it stop properly? Will we have to uncheck and recheck the plugin menu item to get it to run a second time?
            from lasagna.alert import alert
            self.alert = alert(lasagna_serving,
                               'The elastix or transformix binaries do not appear'
                               ' to be in your path.<br>Not starting plugin.')
            self.lasagna.pluginActions[self.__module__].setChecked(False)  # Uncheck the menu item associated with this plugin's name
            self.deleteLater()
            return
        else:
            print("Using transformix binary at " + which('transformix'))
            print("Using elastix binary at " + which('elastix'))


        # re-define some default properties that were originally defined in LasagnaPlugin
        self.pluginShortName = 'Transformix'  # Appears on the menu
        self.pluginLongName = 'registration of images'  # Can be used for other purposes (e.g. tool-tip)
        self.pluginAuthor = 'Rob Campbell'

        # This is the file name we monitor during running
        self.elastixLogName = 'elastix.log'
        self.transformixLogName = 'transformix.log'
        self.transformixCommand = ''  # the command we will run

        # Create widgets defined in the designer file
        self.setupUi(self)
        self.show()

        # A dictionary for storing location of temporary parameter files
        # Temporary parameter files are created as the user edits them and are
        # removed when the registration starts
        self.tmpParamFiles = {}

        # Create some properties which we will need
        self.inputImagePath = ''  # absolute path to the image we will transform
        self.transformPath = ''  # absolute path to the tranform file we will use
        self.outputDirPath = ''
        self.transformixCommand = ''

        # Link signals to slots
        self.chooseStack_pushButton.released.connect(self.chooseStack_slot)
        self.chooseTransform_pushButton.released.connect(self.chooseTransform_slot)
        self.outputDirSelect_pushButton.released.connect(self.selectOutputDir_slot)

        self.run_pushButton.released.connect(self.run_slot)
        self.loadResult_pushButton.released.connect(self.loadResult_slot)

        # Disable UI elements that won't be available until the user has completed all actions
        self.run_pushButton.setEnabled(False)
        self.loadResult_pushButton.setEnabled(False)

        # -------------------------------------------------------------------------------------
        # The following will either be hugely changed or deleted when the plugin is no longer
        # under heavy development
        debug = False  # runs certain things quickly to help development
        if debug and os.path.expanduser("~") == '/home/rob':  # Ensure only I can trigger this. Ensures that it doesn't activate if I accidently push with debug enabled
            self.inputImagePath = '' # absolute path to the image we will transform
            self.transformPath = ''  # absolute path to the tranform file we will use
Ejemplo n.º 4
0
 def warnAndQuit(self, msg):
     """
     Display alert and (maybe) quit the plugin
     """
     self.lasagna.alert = alert(self.lasagna, alertText=msg)
     self.deregister_from_lasagna()