Commit 70dfcbb80bf1d46448582852fa6dabcc958336c3

Authored by Thiago Franco de Moraes
Committed by GitHub
1 parent 4ed4823b
Exists in master

Single slice import (#207)

* Importing just one bitmap slice

* Importing just one dicom slice
invesalius/data/imagedata_utils.py
@@ -284,7 +284,8 @@ def bitmap2memmap(files, slice_size, orientation, spacing, resolution_percentage @@ -284,7 +284,8 @@ def bitmap2memmap(files, slice_size, orientation, spacing, resolution_percentage
284 returns it and its related filename. 284 returns it and its related filename.
285 """ 285 """
286 message = _("Generating multiplanar visualization...") 286 message = _("Generating multiplanar visualization...")
287 - update_progress= vtk_utils.ShowProgress(len(files) - 1, dialog_type = "ProgressDialog") 287 + if len(files) > 1:
  288 + update_progress= vtk_utils.ShowProgress(len(files) - 1, dialog_type = "ProgressDialog")
288 289
289 temp_file = tempfile.mktemp() 290 temp_file = tempfile.mktemp()
290 291
@@ -368,12 +369,14 @@ def bitmap2memmap(files, slice_size, orientation, spacing, resolution_percentage @@ -368,12 +369,14 @@ def bitmap2memmap(files, slice_size, orientation, spacing, resolution_percentage
368 array.shape = matrix.shape[1], matrix.shape[2] 369 array.shape = matrix.shape[1], matrix.shape[2]
369 matrix[n] = array 370 matrix[n] = array
370 371
371 - update_progress(cont,message) 372 + if len(files) > 1:
  373 + update_progress(cont,message)
372 cont += 1 374 cont += 1
373 375
374 matrix.flush() 376 matrix.flush()
375 scalar_range = min_scalar, max_scalar 377 scalar_range = min_scalar, max_scalar
376 378
  379 + print("MATRIX", matrix.shape)
377 return matrix, scalar_range, temp_file 380 return matrix, scalar_range, temp_file
378 381
379 382
@@ -382,8 +385,9 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage): @@ -382,8 +385,9 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage):
382 From a list of dicom files it creates memmap file in the temp folder and 385 From a list of dicom files it creates memmap file in the temp folder and
383 returns it and its related filename. 386 returns it and its related filename.
384 """ 387 """
385 - message = _("Generating multiplanar visualization...")  
386 - update_progress= vtk_utils.ShowProgress(len(files) - 1, dialog_type = "ProgressDialog") 388 + if len(files) > 1:
  389 + message = _("Generating multiplanar visualization...")
  390 + update_progress= vtk_utils.ShowProgress(len(files) - 1, dialog_type = "ProgressDialog")
387 391
388 first_slice = read_dcm_slice_as_np2(files[0], resolution_percentage) 392 first_slice = read_dcm_slice_as_np2(files[0], resolution_percentage)
389 slice_size = first_slice.shape[::-1] 393 slice_size = first_slice.shape[::-1]
@@ -410,7 +414,8 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage): @@ -410,7 +414,8 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage):
410 matrix[:, :, n] = im_array 414 matrix[:, :, n] = im_array
411 else: 415 else:
412 matrix[n] = im_array 416 matrix[n] = im_array
413 - update_progress(n, message) 417 + if len(files) > 1:
  418 + update_progress(n, message)
414 419
415 matrix.flush() 420 matrix.flush()
416 scalar_range = matrix.min(), matrix.max() 421 scalar_range = matrix.min(), matrix.max()
invesalius/data/slice_.py
@@ -614,12 +614,20 @@ class Slice(with_metaclass(utils.Singleton, object)): @@ -614,12 +614,20 @@ class Slice(with_metaclass(utils.Singleton, object)):
614 final_image = self.do_blend(final_image, aux_image) 614 final_image = self.do_blend(final_image, aux_image)
615 return final_image 615 return final_image
616 616
617 - def get_image_slice(self, orientation, slice_number, number_slices=1,  
618 - inverted=False, border_size=1.0):  
619 - if self.buffer_slices[orientation].index == slice_number \  
620 - and self.buffer_slices[orientation].image is not None: 617 + def get_image_slice(
  618 + self,
  619 + orientation,
  620 + slice_number,
  621 + number_slices=1,
  622 + inverted=False,
  623 + border_size=1.0,
  624 + ):
  625 + dz, dy, dx = self.matrix.shape
  626 + if (
  627 + self.buffer_slices[orientation].index == slice_number
  628 + and self.buffer_slices[orientation].image is not None
  629 + ):
621 n_image = self.buffer_slices[orientation].image 630 n_image = self.buffer_slices[orientation].image
622 - # print "BUFFER IMAGE"  
623 else: 631 else:
624 if self._type_projection == const.PROJECTION_NORMAL: 632 if self._type_projection == const.PROJECTION_NORMAL:
625 number_slices = 1 633 number_slices = 1
@@ -642,7 +650,7 @@ class Slice(with_metaclass(utils.Singleton, object)): @@ -642,7 +650,7 @@ class Slice(with_metaclass(utils.Singleton, object)):
642 if np.any(self.q_orientation[1::]): 650 if np.any(self.q_orientation[1::]):
643 transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array) 651 transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array)
644 if self._type_projection == const.PROJECTION_NORMAL: 652 if self._type_projection == const.PROJECTION_NORMAL:
645 - n_image = tmp_array.squeeze() 653 + n_image = tmp_array.reshape(dy, dx)
646 else: 654 else:
647 if inverted: 655 if inverted:
648 tmp_array = tmp_array[::-1] 656 tmp_array = tmp_array[::-1]
@@ -690,7 +698,7 @@ class Slice(with_metaclass(utils.Singleton, object)): @@ -690,7 +698,7 @@ class Slice(with_metaclass(utils.Singleton, object)):
690 transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array) 698 transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array)
691 699
692 if self._type_projection == const.PROJECTION_NORMAL: 700 if self._type_projection == const.PROJECTION_NORMAL:
693 - n_image = tmp_array.squeeze() 701 + n_image = tmp_array.reshape(dz, dx)
694 else: 702 else:
695 #if slice_number == 0: 703 #if slice_number == 0:
696 #slice_number = 1 704 #slice_number = 1
@@ -740,7 +748,7 @@ class Slice(with_metaclass(utils.Singleton, object)): @@ -740,7 +748,7 @@ class Slice(with_metaclass(utils.Singleton, object)):
740 transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array) 748 transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array)
741 749
742 if self._type_projection == const.PROJECTION_NORMAL: 750 if self._type_projection == const.PROJECTION_NORMAL:
743 - n_image = tmp_array.squeeze() 751 + n_image = tmp_array.reshape(dz, dy)
744 else: 752 else:
745 if inverted: 753 if inverted:
746 tmp_array = tmp_array[:, :, ::-1] 754 tmp_array = tmp_array[:, :, ::-1]
invesalius/gui/import_panel.py
@@ -185,12 +185,9 @@ class InnerPanel(wx.Panel): @@ -185,12 +185,9 @@ class InnerPanel(wx.Panel):
185 slice_amont = group.nslices 185 slice_amont = group.nslices
186 186
187 nslices_result = slice_amont / (interval + 1) 187 nslices_result = slice_amont / (interval + 1)
188 - if (nslices_result > 1):  
189 - Publisher.sendMessage('Open DICOM group', group=group,  
190 - interval=interval,  
191 - file_range=(self.first_image_selection, self.last_image_selection))  
192 - else:  
193 - dlg.MissingFilesForReconstruction() 188 + Publisher.sendMessage('Open DICOM group', group=group,
  189 + interval=interval,
  190 + file_range=(self.first_image_selection, self.last_image_selection))
194 191
195 class TextPanel(wx.Panel): 192 class TextPanel(wx.Panel):
196 def __init__(self, parent): 193 def __init__(self, parent):
invesalius/reader/bitmap_reader.py
@@ -264,21 +264,20 @@ class ProgressBitmapReader: @@ -264,21 +264,20 @@ class ProgressBitmapReader:
264 Publisher.sendMessage("End bitmap load", data=bitmap_list) 264 Publisher.sendMessage("End bitmap load", data=bitmap_list)
265 265
266 def GetBitmaps(self, path, recursive): 266 def GetBitmaps(self, path, recursive):
267 -  
268 y = yGetBitmaps(path, recursive) 267 y = yGetBitmaps(path, recursive)
269 for value_progress in y: 268 for value_progress in y:
  269 + print(">>> YYYYYY", value_progress)
270 if not self.running: 270 if not self.running:
271 break 271 break
272 if isinstance(value_progress, tuple): 272 if isinstance(value_progress, tuple):
  273 + print("UPDATE PROGRESS")
273 self.UpdateLoadFileProgress(value_progress) 274 self.UpdateLoadFileProgress(value_progress)
274 else: 275 else:
  276 + print("END PROGRESS")
275 self.EndLoadFile(value_progress) 277 self.EndLoadFile(value_progress)
276 278
277 - #Is necessary in the case user cancel  
278 - #the load, ensure that dicomdialog is closed  
279 - if(self.stoped):  
280 - self.UpdateLoadFileProgress(None)  
281 - self.stoped = False 279 + self.UpdateLoadFileProgress(None)
  280 + self.stoped = False
282 281
283 def VtkErrorPNGWriter(obj, f): 282 def VtkErrorPNGWriter(obj, f):
284 global vtk_error 283 global vtk_error