Commit 25ff6f47950a828f254489a58dc66af1c1000280

Authored by tfmoraes
1 parent 95d3e337

FIX: Sorting the dicom list with the image number

Showing 1 changed file with 7 additions and 7 deletions   Show diff stats
invesalius/reader/dicom_grouper.py
@@ -297,15 +297,16 @@ class DicomGroups: @@ -297,15 +297,16 @@ class DicomGroups:
297 else: 297 else:
298 groups_dcm_[new_key] = [[information]] 298 groups_dcm_[new_key] = [[information]]
299 299
300 - for j in xrange(len(groups_dcm_.keys())):  
301 - key = groups_dcm_.keys()[j]  
302 - groups_dcm_[key][0].sort()  
303 #the number of previously existing number is 300 #the number of previously existing number is
304 #greater or equal then the group keeps up, 301 #greater or equal then the group keeps up,
305 #but maintains the same group of positions. 302 #but maintains the same group of positions.
306 if len(self.groups_dcm.keys()) < len(groups_dcm_.keys()): 303 if len(self.groups_dcm.keys()) < len(groups_dcm_.keys()):
307 self.groups_dcm = groups_dcm_ 304 self.groups_dcm = groups_dcm_
308 305
  306 + for j in xrange(len(self.groups_dcm.keys())):
  307 + key = self.groups_dcm.keys()[j]
  308 + self.groups_dcm[key][0].sort(key=lambda x: x.image.number)
  309 +
309 310
310 def __UpdateZSpacing(self): 311 def __UpdateZSpacing(self):
311 """ 312 """
@@ -316,16 +317,15 @@ class DicomGroups: @@ -316,16 +317,15 @@ class DicomGroups:
316 317
317 key = self.groups_dcm.keys()[x] 318 key = self.groups_dcm.keys()[x]
318 information = self.groups_dcm[key][0] 319 information = self.groups_dcm[key][0]
319 -  
320 if (len(self.groups_dcm[key][0]) > 1): 320 if (len(self.groups_dcm[key][0]) > 1):
321 #Catch a slice of middle and the next to find the spacing. 321 #Catch a slice of middle and the next to find the spacing.
322 center = len(self.groups_dcm[key][0])/2 322 center = len(self.groups_dcm[key][0])/2
323 if (center == 1): 323 if (center == 1):
324 center = 0 324 center = 0
325 - 325 +
326 information = self.groups_dcm[key][0][center] 326 information = self.groups_dcm[key][0][center]
327 current_position = information.image.position 327 current_position = information.image.position
328 - 328 +
329 information = self.groups_dcm[key][0][center + 1] 329 information = self.groups_dcm[key][0][center + 1]
330 next_position = information.image.position 330 next_position = information.image.position
331 331
@@ -345,6 +345,6 @@ class DicomGroups: @@ -345,6 +345,6 @@ class DicomGroups:
345 345
346 else: 346 else:
347 spacing = None 347 spacing = None
348 - 348 +
349 for information in self.groups_dcm[key][0]: 349 for information in self.groups_dcm[key][0]:
350 information.image.spacing[2] = spacing 350 information.image.spacing[2] = spacing