Commit 586739ecae59f3604b831e67e7636d16fdbbfb16

Authored by Paulo Henrique Junqueira Amorim
1 parent 661fb4fe

ENH: Removed list of list from dicom_grouper

invesalius/reader/dicom_grouper.py
@@ -282,32 +282,29 @@ class DicomGroups: @@ -282,32 +282,29 @@ class DicomGroups:
282 for x in xrange(size_tmp_list): 282 for x in xrange(size_tmp_list):
283 283
284 tmp1 = tmp_list[x] 284 tmp1 = tmp_list[x]
285 -  
286 -  
287 for m in xrange(len(tmp1.keys())): 285 for m in xrange(len(tmp1.keys())):
288 286
289 key = tmp1.keys()[m] 287 key = tmp1.keys()[m]
290 information = tmp1[key] 288 information = tmp1[key]
  289 +
291 new_key = (information.patient.name, information.image.orientation_label, 290 new_key = (information.patient.name, information.image.orientation_label,
292 information.acquisition.serie_number) 291 information.acquisition.serie_number)
293 -  
294 - 292 +
295 if (new_key in groups_dcm_.keys()): 293 if (new_key in groups_dcm_.keys()):
296 - groups_dcm_[new_key][0].append(information) 294 + groups_dcm_[new_key].append(information)
297 else: 295 else:
298 - groups_dcm_[new_key] = [[information]] 296 + groups_dcm_[new_key] = [information]
299 297
300 #the number of previously existing number is 298 #the number of previously existing number is
301 #greater or equal then the group keeps up, 299 #greater or equal then the group keeps up,
302 #but maintains the same group of positions. 300 #but maintains the same group of positions.
303 - if len(self.groups_dcm.keys()) > len(groups_dcm_.keys()):  
304 - self.groups_dcm = groups_dcm_ 301 + #if len(self.groups_dcm.keys()) > len(groups_dcm_.keys()):
  302 + self.groups_dcm = groups_dcm_
305 303
306 -  
307 for j in xrange(len(self.groups_dcm.keys())): 304 for j in xrange(len(self.groups_dcm.keys())):
308 key = self.groups_dcm.keys()[j] 305 key = self.groups_dcm.keys()[j]
309 - self.groups_dcm[key][0].sort(key=lambda x: x.image.number)  
310 - 306 + self.groups_dcm[key].sort(key=lambda x: x.image.number)
  307 +
311 308
312 def __UpdateZSpacing(self): 309 def __UpdateZSpacing(self):
313 """ 310 """
@@ -315,23 +312,27 @@ class DicomGroups: @@ -315,23 +312,27 @@ class DicomGroups:
315 """ 312 """
316 313
317 for x in xrange(len(self.groups_dcm.keys())): 314 for x in xrange(len(self.groups_dcm.keys())):
318 - 315 + print len(self.groups_dcm.keys())
  316 +
319 key = self.groups_dcm.keys()[x] 317 key = self.groups_dcm.keys()[x]
320 information = self.groups_dcm[key][0] 318 information = self.groups_dcm[key][0]
321 - if (len(self.groups_dcm[key][0]) > 1): 319 + if (len(self.groups_dcm[key]) > 1):
322 #Catch a slice of middle and the next to find the spacing. 320 #Catch a slice of middle and the next to find the spacing.
323 - center = len(self.groups_dcm[key][0])/2 321 + center = len(self.groups_dcm[key])/2
324 if (center == 1): 322 if (center == 1):
325 center = 0 323 center = 0
326 324
327 - information = self.groups_dcm[key][0][center] 325 + information = self.groups_dcm[key][center]
328 current_position = information.image.position 326 current_position = information.image.position
329 327
330 - information = self.groups_dcm[key][0][center + 1] 328 + information = self.groups_dcm[key][center + 1]
331 next_position = information.image.position 329 next_position = information.image.position
332 330
333 try: 331 try:
334 - image_orientation_label = self.groups_dcm.keys()[x][3] 332 + information = self.groups_dcm[self.groups_dcm.keys()[x]][3]
  333 + image_orientation_label = information.image.orientation_label
  334 + print image_orientation_label
  335 +
335 except(IndexError): 336 except(IndexError):
336 image_orientation_label = None 337 image_orientation_label = None
337 338
@@ -347,6 +348,6 @@ class DicomGroups: @@ -347,6 +348,6 @@ class DicomGroups:
347 else: 348 else:
348 spacing = None 349 spacing = None
349 350
350 - for information in self.groups_dcm[key][0]: 351 + for information in self.groups_dcm[key]:
351 if information.image.spacing: 352 if information.image.spacing:
352 information.image.spacing[2] = spacing 353 information.image.spacing[2] = spacing
invesalius/reader/dicom_reader.py
@@ -45,8 +45,8 @@ def LoadImages(dir_): @@ -45,8 +45,8 @@ def LoadImages(dir_):
45 for x in xrange(len(groups.keys())): 45 for x in xrange(len(groups.keys())):
46 key = groups.keys()[x] 46 key = groups.keys()[x]
47 47
48 - for y in xrange(len(groups[key][0])):  
49 - dicom = groups[key][0][y] 48 + for y in xrange(len(groups[key])):
  49 + dicom = groups[key][y]
50 file = dicom.image.file 50 file = dicom.image.file
51 tmp_list.append(file) 51 tmp_list.append(file)
52 52
@@ -59,8 +59,8 @@ def LoadImages(dir_): @@ -59,8 +59,8 @@ def LoadImages(dir_):
59 return None 59 return None
60 60
61 file_list = [] 61 file_list = []
62 - for x in xrange(len(groups[key][0])):  
63 - dicom = groups[key][0][x] 62 + for x in xrange(len(groups[key])):
  63 + dicom = groups[key][x]
64 file_list.append(dicom.image.file) 64 file_list.append(dicom.image.file)
65 65
66 files = file_list 66 files = file_list