コード例 #1
0
    def __onLoadFlirt(self, ev):
        """Called when the user clicks the *Load FLIRT transform* button.
        Prompts the user to choose a FLIRT transformation matrix and reference
        image, and then applies the transformation.
        """

        overlay = self.__overlay

        if overlay is None:
            return

        overlayList = self.overlayList
        displayCtx = self.displayCtx
        affType, matFile, refFile = applyflirtxfm.promptForFlirtFiles(
            self, overlay, overlayList, displayCtx)

        if all((affType is None, matFile is None, refFile is None)):
            return

        if affType == 'flirt':
            xform = applyflirtxfm.calculateTransform(overlay, overlayList,
                                                     displayCtx, matFile,
                                                     refFile)

        elif affType == 'v2w':
            xform = np.loadtxt(matFile)

        self.__extraXform = xform
        self.__xformChanged()
コード例 #2
0
def _test_promptForFlirtFiles(panel, overlayList, displayCtx):

    ovl = random_image()
    overlayList.append(ovl)
    realYield()

    with mock.patch('fsleyes.actions.applyflirtxfm.FlirtFileDialog',
                    MockFlirtFileDialog):
        MockFlirtFileDialog.ShowModalRet = wx.ID_CANCEL
        got = applyflirtxfm.promptForFlirtFiles(panel, ovl, overlayList,
                                                displayCtx)
        assert got == (None, None, None)

        MockFlirtFileDialog.ShowModalRet = wx.ID_OK
        MockFlirtFileDialog.GetAffineTypeRet = 'flirt'
        MockFlirtFileDialog.GetMatFileRet = 'mat.mat'
        MockFlirtFileDialog.GetRefFileRet = 'ref.nii'
        got = applyflirtxfm.promptForFlirtFiles(panel, ovl, overlayList,
                                                displayCtx)
        assert got == ('flirt', 'mat.mat', 'ref.nii')
コード例 #3
0
    def __onSaveFlirt(self, ev):
        """Called when the user clicks the *Save FLIRT* button. Saves the
        current transformation to a FLIRT matrix file.
        """

        overlay = self.__overlay

        if overlay is None:
            return

        overlayList = self.overlayList
        displayCtx = self.displayCtx
        matFile, refFile = applyflirtxfm.promptForFlirtFiles(self,
                                                             overlay,
                                                             overlayList,
                                                             displayCtx,
                                                             save=True)

        if matFile is None or refFile is None:
            return

        if self.__extraXform is None: v2wXform = overlay.voxToWorldMat
        else: v2wXform = self.__extraXform

        newXform = self.__getCurrentXform()
        v2wXform = transform.concat(newXform, v2wXform)

        xform = saveflirtxfm.calculateTransform(overlay,
                                                overlayList,
                                                displayCtx,
                                                refFile,
                                                srcXform=v2wXform)

        try:
            np.savetxt(matFile, xform, fmt='%0.10f')

        except Exception as e:

            log.warn('Error saving FLIRT matrix: {}'.format(e))

            wx.MessageDialog(self,
                             strings.messages[self, 'saveFlirt.error'].format(
                                 str(e)),
                             style=wx.ICON_ERROR).ShowModal()