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 284 returns it and its related filename.
285 285 """
286 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 290 temp_file = tempfile.mktemp()
290 291  
... ... @@ -368,12 +369,14 @@ def bitmap2memmap(files, slice_size, orientation, spacing, resolution_percentage
368 369 array.shape = matrix.shape[1], matrix.shape[2]
369 370 matrix[n] = array
370 371  
371   - update_progress(cont,message)
  372 + if len(files) > 1:
  373 + update_progress(cont,message)
372 374 cont += 1
373 375  
374 376 matrix.flush()
375 377 scalar_range = min_scalar, max_scalar
376 378  
  379 + print("MATRIX", matrix.shape)
377 380 return matrix, scalar_range, temp_file
378 381  
379 382  
... ... @@ -382,8 +385,9 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage):
382 385 From a list of dicom files it creates memmap file in the temp folder and
383 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 392 first_slice = read_dcm_slice_as_np2(files[0], resolution_percentage)
389 393 slice_size = first_slice.shape[::-1]
... ... @@ -410,7 +414,8 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage):
410 414 matrix[:, :, n] = im_array
411 415 else:
412 416 matrix[n] = im_array
413   - update_progress(n, message)
  417 + if len(files) > 1:
  418 + update_progress(n, message)
414 419  
415 420 matrix.flush()
416 421 scalar_range = matrix.min(), matrix.max()
... ...
invesalius/data/slice_.py
... ... @@ -614,12 +614,20 @@ class Slice(with_metaclass(utils.Singleton, object)):
614 614 final_image = self.do_blend(final_image, aux_image)
615 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 630 n_image = self.buffer_slices[orientation].image
622   - # print "BUFFER IMAGE"
623 631 else:
624 632 if self._type_projection == const.PROJECTION_NORMAL:
625 633 number_slices = 1
... ... @@ -642,7 +650,7 @@ class Slice(with_metaclass(utils.Singleton, object)):
642 650 if np.any(self.q_orientation[1::]):
643 651 transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array)
644 652 if self._type_projection == const.PROJECTION_NORMAL:
645   - n_image = tmp_array.squeeze()
  653 + n_image = tmp_array.reshape(dy, dx)
646 654 else:
647 655 if inverted:
648 656 tmp_array = tmp_array[::-1]
... ... @@ -690,7 +698,7 @@ class Slice(with_metaclass(utils.Singleton, object)):
690 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 700 if self._type_projection == const.PROJECTION_NORMAL:
693   - n_image = tmp_array.squeeze()
  701 + n_image = tmp_array.reshape(dz, dx)
694 702 else:
695 703 #if slice_number == 0:
696 704 #slice_number = 1
... ... @@ -740,7 +748,7 @@ class Slice(with_metaclass(utils.Singleton, object)):
740 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 750 if self._type_projection == const.PROJECTION_NORMAL:
743   - n_image = tmp_array.squeeze()
  751 + n_image = tmp_array.reshape(dz, dy)
744 752 else:
745 753 if inverted:
746 754 tmp_array = tmp_array[:, :, ::-1]
... ...
invesalius/gui/import_panel.py
... ... @@ -185,12 +185,9 @@ class InnerPanel(wx.Panel):
185 185 slice_amont = group.nslices
186 186  
187 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 192 class TextPanel(wx.Panel):
196 193 def __init__(self, parent):
... ...
invesalius/reader/bitmap_reader.py
... ... @@ -264,21 +264,20 @@ class ProgressBitmapReader:
264 264 Publisher.sendMessage("End bitmap load", data=bitmap_list)
265 265  
266 266 def GetBitmaps(self, path, recursive):
267   -
268 267 y = yGetBitmaps(path, recursive)
269 268 for value_progress in y:
  269 + print(">>> YYYYYY", value_progress)
270 270 if not self.running:
271 271 break
272 272 if isinstance(value_progress, tuple):
  273 + print("UPDATE PROGRESS")
273 274 self.UpdateLoadFileProgress(value_progress)
274 275 else:
  276 + print("END PROGRESS")
275 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 282 def VtkErrorPNGWriter(obj, f):
284 283 global vtk_error
... ...