예제 #1
0
    def load_mri(self, *args):
        print "loc3djr_maintoolbar.load_mri()"
        if self.niftiFilename is not None:
            fname=self.niftiFilename
        else:
            dialog = gtk.FileSelection('Choose nifti file')
            dialog.set_transient_for(widgets['dlgReader'])
            dialog.set_filename(shared.get_last_dir())
            response = dialog.run()
            fname = dialog.get_filename()
            dialog.destroy()
            if response == gtk.RESPONSE_OK:
                print fname
            else:
                return
        #reader = vtkNiftiImageReader()
        #reader.SetFileName(fname)
        #reader.Update()

        pars = Params()
        
        if fname.endswith(".nii.gz"):
            pars.extension=".".join(fname.split(".")[-2:])
            pars.pattern=".".join(fname.split(os.path.sep)[-1].split(".")[:-2])
        #elif fname.endswith(".nii"):
        #    pars.extension=".nii"
        else: 
            pars.extension=".".join(fname.split(".")[-1:])
            pars.pattern=".".join(fname.split(os.path.sep)[-1].split(".")[:-1])
        print "pars.extension", pars.extension
        
        print "pars.pattern", pars.pattern
        pars.dir=os.path.dirname(fname)#sep.join(fname.split(os.path.sep)[:-1])
        print "pars.dir", pars.dir

        pars.readerClass='vtkNiftiImageReader'
        reader=widgets.get_reader(pars)
        pars.first=1
        pars.last=reader.GetDepth()

        print "reader=", reader
        if not reader:
            print "hit cancel, see if we can survive"
        else:
            pars=widgets.get_params()
            pars=widgets.validate(pars)

            imageData = reader.GetOutput()

            #stupid workaround, somehow imageData.Extent is not written. dunno why
            #maybe its in vtkImageImportFromArray
            imageData.SetExtent(reader.GetDataExtent())
          
            print "loc3djr_maintoolbar.load_mri(): reader.GetOutput() is " , imageData
            print "load_mri(): imageData.SetSpacing(", reader.GetDataSpacing(), " )"
            imageData.SetSpacing(reader.GetDataSpacing())
            print "calling EventHandler().notify('set image data', imageData)"
            EventHandler().notify('set image data', imageData)
            print "calling EventHandler().setNifti()"
            EventHandler().setNifti(reader.GetQForm(),reader.GetDataSpacing())
예제 #2
0
    def load_image(self, *args):
        if debug:
            print "loc3djr_maintoolbar.load_image()"
        debug = False
        reader = None

        pars = None
        
        if debug:
            reader = vtk.vtkImageReader2()
            reader.SetDataScalarTypeToUnsignedShort()
            reader.SetDataByteOrderToLittleEndian()
            reader.SetFileNameSliceOffset(120)
            reader.SetDataExtent(0, 511, 0, 511, 0, 106)
            reader.SetFilePrefix('/home/jdhunter/seizure/data/ThompsonK/CT/raw/1.2.840.113619.2.55.1.1762864819.1957.1074338393.')
            reader.SetFilePattern( '%s%d.raw')
            reader.SetDataSpacing(25.0/512, 25.0/512, 0.125 )

            reader.Update()
        else:
    
            dlg = widgets['dlgReader']

            response = dlg.run()

            if response == gtk.RESPONSE_OK:
                try: reader = widgets.reader
                except AttributeError: 
                    pars = widgets.get_params()
                    pars = widgets.validate(pars)
                    if pars is None:
                        error_msg('Could not validate the parameters', dlg)
                        return
                    reader = widgets.get_reader(pars)
                pars = widgets.get_params()
                pars = widgets.validate(pars)
                
            dlg.hide()


        if debug:
            print "reader=", reader
        if not reader:
            if debug:
                print "hit cancel, see if we can survive"
        else:
            imageData = reader.GetOutput()
            if debug:
                print "pars=", pars
                print "loc3djr_maintoolbar.load_image(): reader.GetOutput() is " , imageData
                print "load_image(): imageData.SetSpacing(", reader.GetDataSpacing(), " )"
            imageData.SetSpacing(reader.GetDataSpacing())
            if debug:
                print "calling EventHandler().notify('set image data', imageData)"
            EventHandler().notify('set image data', imageData)
            if type(reader) == vtkNiftiImageReader:
                if debug:
                    print "calling EventHandler().setNifti()"
                #XXX EventHandler().setNifti(reader.GetFilename())
                EventHandler().setNifti(reader.GetQForm())
예제 #3
0
    def load_image(self, *args):
        print "loc3djr_maintoolbar.load_image()"
        debug = False
        reader = None

        pars = None

        if debug:
            reader = vtk.vtkImageReader2()
            reader.SetDataScalarTypeToUnsignedShort()
            reader.SetDataByteOrderToLittleEndian()
            reader.SetFileNameSliceOffset(120)
            reader.SetDataExtent(0, 511, 0, 511, 0, 106)
            reader.SetFilePrefix(
                '/home/jdhunter/seizure/data/ThompsonK/CT/raw/1.2.840.113619.2.55.1.1762864819.1957.1074338393.'
            )
            reader.SetFilePattern('%s%d.raw')
            reader.SetDataSpacing(25.0 / 512, 25.0 / 512, 0.125)

            reader.Update()
        else:

            dlg = widgets['dlgReader']

            response = dlg.run()

            if response == gtk.RESPONSE_OK:
                try:
                    reader = widgets.reader
                except AttributeError:
                    pars = widgets.get_params()
                    pars = widgets.validate(pars)
                    if pars is None:
                        error_msg('Could not validate the parameters', dlg)
                        return
                    reader = widgets.get_reader(pars)
                pars = widgets.get_params()
                pars = widgets.validate(pars)

            dlg.hide()

        print "reader=", reader
        if not reader:
            print "hit cancel, see if we can survive"
        else:
            imageData = reader.GetOutput()
            print "pars=", pars
            print "loc3djr_maintoolbar.load_image(): reader.GetOutput() is ", imageData
            print "load_image(): imageData.SetSpacing(", reader.GetDataSpacing(
            ), " )"
            imageData.SetSpacing(reader.GetDataSpacing())
            print "calling EventHandler().notify('set image data', imageData)"
            EventHandler().notify('set image data', imageData)
            if type(reader) == vtkNiftiImageReader:
                print "calling EventHandler().setNifti()"
                #XXX EventHandler().setNifti(reader.GetFilename())
                EventHandler().setNifti(reader.GetQForm())