Commit 4c7751d280081c845900237669b1fea332219a7c

Authored by Paulo Henrique Junqueira Amorim
1 parent b6e85870
Exists in master

FIX: Fixed problem to open hdr nifti file format

invesalius/control.py
@@ -207,21 +207,8 @@ class Controller(): @@ -207,21 +207,8 @@ class Controller():
207 if id_type == const.ID_ANALYZE_IMPORT: 207 if id_type == const.ID_ANALYZE_IMPORT:
208 dialog.ImportAnalyzeWarning() 208 dialog.ImportAnalyzeWarning()
209 209
210 - # Import project treating compressed nifti exception  
211 - suptype = ('hdr', 'nii', 'nii.gz', 'par')  
212 filepath = dialog.ShowImportOtherFilesDialog(id_type) 210 filepath = dialog.ShowImportOtherFilesDialog(id_type)
213 - if filepath is not None:  
214 - name = filepath.rpartition('\\')[-1].split('.')  
215 -  
216 - if name[-1] == 'gz':  
217 - name[1] = 'nii.gz'  
218 -  
219 - filetype = name[1].lower()  
220 -  
221 - if filetype in suptype:  
222 - Publisher.sendMessage("Open other files", filepath)  
223 - else:  
224 - dialog.ImportInvalidFiles() 211 + Publisher.sendMessage("Open other files", filepath)
225 212
226 def ShowDialogOpenProject(self): 213 def ShowDialogOpenProject(self):
227 # Offer to save current project if necessary 214 # Offer to save current project if necessary
@@ -749,23 +736,18 @@ class Controller(): @@ -749,23 +736,18 @@ class Controller():
749 736
750 def OnOpenOtherFiles(self, pubsub_evt): 737 def OnOpenOtherFiles(self, pubsub_evt):
751 filepath = pubsub_evt.data 738 filepath = pubsub_evt.data
752 - name = filepath.rpartition('\\')[-1].split('.')  
753 -  
754 - if name[-1] == 'gz':  
755 - name[1] = 'nii.gz'  
756 -  
757 - suptype = ('hdr', 'nii', 'nii.gz', 'par')  
758 - filetype = name[1].lower() 739 + if not(filepath) == None:
  740 + name = filepath.rpartition('\\')[-1].split('.')
759 741
760 - if filetype in suptype:  
761 group = oth.ReadOthers(filepath) 742 group = oth.ReadOthers(filepath)
762 - else:  
763 - dialog.ImportInvalidFiles()  
764 -  
765 - matrix, matrix_filename = self.OpenOtherFiles(group)  
766 - self.CreateOtherProject(str(name[0]), matrix, matrix_filename)  
767 - self.LoadProject()  
768 - Publisher.sendMessage("Enable state project", True) 743 +
  744 + if group:
  745 + matrix, matrix_filename = self.OpenOtherFiles(group)
  746 + self.CreateOtherProject(str(name[0]), matrix, matrix_filename)
  747 + self.LoadProject()
  748 + Publisher.sendMessage("Enable state project", True)
  749 + else:
  750 + dialog.ImportInvalidFiles(ftype="Others")
769 751
770 def OpenDicomGroup(self, dicom_group, interval, file_range, gui=True): 752 def OpenDicomGroup(self, dicom_group, interval, file_range, gui=True):
771 # Retrieve general DICOM headers 753 # Retrieve general DICOM headers
invesalius/gui/dialogs.py
@@ -213,14 +213,15 @@ class ProgressDialog(object): @@ -213,14 +213,15 @@ class ProgressDialog(object):
213 WILDCARD_OPEN = "InVesalius 3 project (*.inv3)|*.inv3|" \ 213 WILDCARD_OPEN = "InVesalius 3 project (*.inv3)|*.inv3|" \
214 "All files (*.*)|*.*" 214 "All files (*.*)|*.*"
215 215
216 -WILDCARD_ANALYZE = "Analyze 7.5 (*.hdr)|*.hdr|" \ 216 +WILDCARD_ANALYZE = "Analyze 7.5 (*.hdr)|*.[hH][dD][rR]|" \
217 "All files (*.*)|*.*" 217 "All files (*.*)|*.*"
218 218
219 WILDCARD_NIFTI = "NIfTI 1 (*.nii)|*.nii|" \ 219 WILDCARD_NIFTI = "NIfTI 1 (*.nii)|*.nii|" \
220 "Compressed NIfTI (*.nii.gz)|*.nii.gz|" \ 220 "Compressed NIfTI (*.nii.gz)|*.nii.gz|" \
  221 + "HDR NIfTI (*.hdr)|*.[hH][dD][rR]|" \
221 "All files (*.*)|*.*" 222 "All files (*.*)|*.*"
222 -  
223 -WILDCARD_PARREC = "PAR/REC (*.par)|*.par|" \ 223 +#".[jJ][pP][gG]"
  224 +WILDCARD_PARREC = "PAR/REC (*.par)|*.[pP][aA][rR]|" \
224 "All files (*.*)|*.*" 225 "All files (*.*)|*.*"
225 226
226 WILDCARD_MESH_FILES = "STL File format (*.stl)|*.stl|" \ 227 WILDCARD_MESH_FILES = "STL File format (*.stl)|*.stl|" \
@@ -636,8 +637,10 @@ def ImportEmptyDirectory(dirpath): @@ -636,8 +637,10 @@ def ImportEmptyDirectory(dirpath):
636 def ImportInvalidFiles(ftype="DICOM"): 637 def ImportInvalidFiles(ftype="DICOM"):
637 if ftype == "Bitmap": 638 if ftype == "Bitmap":
638 msg = _("There are no Bitmap, JPEG, PNG or TIFF files in the selected folder.") 639 msg = _("There are no Bitmap, JPEG, PNG or TIFF files in the selected folder.")
639 - else: 640 + elif ftype == "DICOM":
640 msg = _("There are no DICOM files in the selected folder.") 641 msg = _("There are no DICOM files in the selected folder.")
  642 + else:
  643 + msg = _("Invalid file.")
641 644
642 if sys.platform == 'darwin': 645 if sys.platform == 'darwin':
643 dlg = wx.MessageDialog(None, "", msg, 646 dlg = wx.MessageDialog(None, "", msg,
invesalius/reader/others_reader.py
@@ -44,8 +44,11 @@ def ReadOthers(dir_): @@ -44,8 +44,11 @@ def ReadOthers(dir_):
44 ow = vtk.vtkOutputWindow() 44 ow = vtk.vtkOutputWindow()
45 ow.SetInstance(fow) 45 ow.SetInstance(fow)
46 46
47 - imagedata = nib.squeeze_image(nib.load(dir_))  
48 - imagedata = nib.as_closest_canonical(imagedata)  
49 - imagedata.update_header()  
50 -  
51 - return imagedata  
52 \ No newline at end of file 47 \ No newline at end of file
  48 + try:
  49 + imagedata = nib.squeeze_image(nib.load(dir_))
  50 + imagedata = nib.as_closest_canonical(imagedata)
  51 + imagedata.update_header()
  52 + except(nib.filebasedimages.ImageFileError):
  53 + return False
  54 +
  55 + return imagedata