Commit cf6af70c6e705d0320cf410daf5927cef076072f

Authored by Paulo Henrique Junqueira Amorim
1 parent 03258f78

FIX: Crash program if open DICOM with Localization None

invesalius/reader/dicom_grouper.py
@@ -121,6 +121,7 @@ class ivDicomGroups: @@ -121,6 +121,7 @@ class ivDicomGroups:
121 spacing = parser.GetPixelSpacing() 121 spacing = parser.GetPixelSpacing()
122 id_study = parser.GetStudyID() 122 id_study = parser.GetStudyID()
123 tilt = parser.GetAcquisitionGantryTilt() 123 tilt = parser.GetAcquisitionGantryTilt()
  124 + localization = parser.GetImageLocation()
124 125
125 if (parser.GetImageThickness()): 126 if (parser.GetImageThickness()):
126 spacing.append(parser.GetImageThickness()) 127 spacing.append(parser.GetImageThickness())
@@ -135,7 +136,7 @@ class ivDicomGroups: @@ -135,7 +136,7 @@ class ivDicomGroups:
135 image_position, patient_position, 136 image_position, patient_position,
136 image_type,patient_name, 137 image_type,patient_name,
137 image_orientation_label, file, 138 image_orientation_label, file,
138 - series_description, id_study, tilt]) 139 + series_description, id_study, tilt, localization])
139 self.filelist = filelist 140 self.filelist = filelist
140 141
141 def __GetInformations(self, ind): 142 def __GetInformations(self, ind):
@@ -160,12 +161,14 @@ class ivDicomGroups: @@ -160,12 +161,14 @@ class ivDicomGroups:
160 series_description = filelist[ind][9] 161 series_description = filelist[ind][9]
161 id_study = filelist[ind][10] 162 id_study = filelist[ind][10]
162 tilt = filelist[ind][11] 163 tilt = filelist[ind][11]
  164 + localization = filelist[ind][12]
163 165
164 list = [image_number, serie_number, spacing, 166 list = [image_number, serie_number, spacing,
165 image_position, patient_position, 167 image_position, patient_position,
166 image_type,patient_name, 168 image_type,patient_name,
167 image_orientation_label, file, 169 image_orientation_label, file,
168 - series_description, id_study, tilt] 170 + series_description, id_study, tilt,
  171 + localization]
169 172
170 return list 173 return list
171 174
@@ -311,6 +314,7 @@ class ivDicomGroups: @@ -311,6 +314,7 @@ class ivDicomGroups:
311 series_description = groups_dcm[key][0][y][9] 314 series_description = groups_dcm[key][0][y][9]
312 id_study = groups_dcm[key][0][y][10] 315 id_study = groups_dcm[key][0][y][10]
313 tilt = groups_dcm[key][0][y][11] 316 tilt = groups_dcm[key][0][y][11]
  317 + localization = groups_dcm[key][0][y][12]
314 318
315 #Generate new key to dictionary 319 #Generate new key to dictionary
316 key_ = (image_pos[0], image_pos[1], image_pos[2]) 320 key_ = (image_pos[0], image_pos[1], image_pos[2])
@@ -320,7 +324,7 @@ class ivDicomGroups: @@ -320,7 +324,7 @@ class ivDicomGroups:
320 image_position, patient_position, 324 image_position, patient_position,
321 image_type,patient_name, 325 image_type,patient_name,
322 image_orientation_label, file, 326 image_orientation_label, file,
323 - series_description, id_study, tilt] 327 + series_description, id_study, tilt, localization]
324 328
325 #If list Null, create dictionary 329 #If list Null, create dictionary
326 #and add list with information 330 #and add list with information
@@ -379,6 +383,7 @@ class ivDicomGroups: @@ -379,6 +383,7 @@ class ivDicomGroups:
379 series_description = tmp1[key][9] 383 series_description = tmp1[key][9]
380 id_study = tmp1[key][10] 384 id_study = tmp1[key][10]
381 tilt = tmp1[key][11] 385 tilt = tmp1[key][11]
  386 + localization = tmp1[key][12]
382 387
383 new_key = (patient_name, None, x, image_orientation_label) 388 new_key = (patient_name, None, x, image_orientation_label)
384 389
@@ -387,7 +392,8 @@ class ivDicomGroups: @@ -387,7 +392,8 @@ class ivDicomGroups:
387 image_position, patient_position, 392 image_position, patient_position,
388 image_type,patient_name, 393 image_type,patient_name,
389 image_orientation_label, file, 394 image_orientation_label, file,
390 - series_description, id_study, tilt] 395 + series_description, id_study, tilt,
  396 + localization]
391 397
392 398
393 if (new_key in groups_dcm_.keys()): 399 if (new_key in groups_dcm_.keys()):
invesalius/reader/dicom_reader.py
@@ -71,17 +71,20 @@ def LoadImages(dir_): @@ -71,17 +71,20 @@ def LoadImages(dir_):
71 tilt = groups[key][0][x][11] 71 tilt = groups[key][0][x][11]
72 spacing = groups[key][1][14] 72 spacing = groups[key][1][14]
73 spacing_z = groups[key][1][30] 73 spacing_z = groups[key][1][30]
74 -  
75 -  
76 - #Organize reversed image  
77 - sorter = gdcm.IPPSorter()  
78 - sorter.SetComputeZSpacing(True)  
79 - sorter.SetZSpacingTolerance(1e-10)  
80 - sorter.Sort(file_list)  
81 -  
82 - #Getting organized image  
83 - files = sorter.GetFilenames()  
84 - 74 + localization = groups[key][0][x][12]
  75 +
  76 + files = file_list
  77 + #Coronal or Sagital with
  78 + #localization None Crash. necessary verify
  79 + if (localization):
  80 + #Organize reversed image
  81 + sorter = gdcm.IPPSorter()
  82 + sorter.SetComputeZSpacing(True)
  83 + sorter.SetZSpacingTolerance(1e-10)
  84 + sorter.Sort(file_list)
  85 + #Getting organized image
  86 + files = sorter.GetFilenames()
  87 +
85 array = vtk.vtkStringArray() 88 array = vtk.vtkStringArray()
86 89
87 img_app = vtk.vtkImageAppend() 90 img_app = vtk.vtkImageAppend()
@@ -121,7 +124,7 @@ def LoadImages(dir_): @@ -121,7 +124,7 @@ def LoadImages(dir_):
121 124
122 125
123 img_axial.Update() 126 img_axial.Update()
124 - 127 +
125 return img_axial, acquisition_modality, tilt 128 return img_axial, acquisition_modality, tilt
126 129
127 def GetDicomFiles(path, recursive = False): 130 def GetDicomFiles(path, recursive = False):