From 70dfcbb80bf1d46448582852fa6dabcc958336c3 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Mon, 21 Oct 2019 10:58:17 -0300 Subject: [PATCH] Single slice import (#207) --- invesalius/data/imagedata_utils.py | 15 ++++++++++----- invesalius/data/slice_.py | 24 ++++++++++++++++-------- invesalius/gui/import_panel.py | 9 +++------ invesalius/reader/bitmap_reader.py | 11 +++++------ 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/invesalius/data/imagedata_utils.py b/invesalius/data/imagedata_utils.py index 167d5e5..ea09d75 100644 --- a/invesalius/data/imagedata_utils.py +++ b/invesalius/data/imagedata_utils.py @@ -284,7 +284,8 @@ def bitmap2memmap(files, slice_size, orientation, spacing, resolution_percentage returns it and its related filename. """ message = _("Generating multiplanar visualization...") - update_progress= vtk_utils.ShowProgress(len(files) - 1, dialog_type = "ProgressDialog") + if len(files) > 1: + update_progress= vtk_utils.ShowProgress(len(files) - 1, dialog_type = "ProgressDialog") temp_file = tempfile.mktemp() @@ -368,12 +369,14 @@ def bitmap2memmap(files, slice_size, orientation, spacing, resolution_percentage array.shape = matrix.shape[1], matrix.shape[2] matrix[n] = array - update_progress(cont,message) + if len(files) > 1: + update_progress(cont,message) cont += 1 matrix.flush() scalar_range = min_scalar, max_scalar + print("MATRIX", matrix.shape) return matrix, scalar_range, temp_file @@ -382,8 +385,9 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage): From a list of dicom files it creates memmap file in the temp folder and returns it and its related filename. """ - message = _("Generating multiplanar visualization...") - update_progress= vtk_utils.ShowProgress(len(files) - 1, dialog_type = "ProgressDialog") + if len(files) > 1: + message = _("Generating multiplanar visualization...") + update_progress= vtk_utils.ShowProgress(len(files) - 1, dialog_type = "ProgressDialog") first_slice = read_dcm_slice_as_np2(files[0], resolution_percentage) slice_size = first_slice.shape[::-1] @@ -410,7 +414,8 @@ def dcm2memmap(files, slice_size, orientation, resolution_percentage): matrix[:, :, n] = im_array else: matrix[n] = im_array - update_progress(n, message) + if len(files) > 1: + update_progress(n, message) matrix.flush() scalar_range = matrix.min(), matrix.max() diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index f7aebb2..a6ac533 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -614,12 +614,20 @@ class Slice(with_metaclass(utils.Singleton, object)): final_image = self.do_blend(final_image, aux_image) return final_image - def get_image_slice(self, orientation, slice_number, number_slices=1, - inverted=False, border_size=1.0): - if self.buffer_slices[orientation].index == slice_number \ - and self.buffer_slices[orientation].image is not None: + def get_image_slice( + self, + orientation, + slice_number, + number_slices=1, + inverted=False, + border_size=1.0, + ): + dz, dy, dx = self.matrix.shape + if ( + self.buffer_slices[orientation].index == slice_number + and self.buffer_slices[orientation].image is not None + ): n_image = self.buffer_slices[orientation].image - # print "BUFFER IMAGE" else: if self._type_projection == const.PROJECTION_NORMAL: number_slices = 1 @@ -642,7 +650,7 @@ class Slice(with_metaclass(utils.Singleton, object)): if np.any(self.q_orientation[1::]): transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array) if self._type_projection == const.PROJECTION_NORMAL: - n_image = tmp_array.squeeze() + n_image = tmp_array.reshape(dy, dx) else: if inverted: tmp_array = tmp_array[::-1] @@ -690,7 +698,7 @@ class Slice(with_metaclass(utils.Singleton, object)): transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array) if self._type_projection == const.PROJECTION_NORMAL: - n_image = tmp_array.squeeze() + n_image = tmp_array.reshape(dz, dx) else: #if slice_number == 0: #slice_number = 1 @@ -740,7 +748,7 @@ class Slice(with_metaclass(utils.Singleton, object)): transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, self.interp_method, self.matrix.min(), tmp_array) if self._type_projection == const.PROJECTION_NORMAL: - n_image = tmp_array.squeeze() + n_image = tmp_array.reshape(dz, dy) else: if inverted: tmp_array = tmp_array[:, :, ::-1] diff --git a/invesalius/gui/import_panel.py b/invesalius/gui/import_panel.py index 2c8da54..446b88a 100644 --- a/invesalius/gui/import_panel.py +++ b/invesalius/gui/import_panel.py @@ -185,12 +185,9 @@ class InnerPanel(wx.Panel): slice_amont = group.nslices nslices_result = slice_amont / (interval + 1) - if (nslices_result > 1): - Publisher.sendMessage('Open DICOM group', group=group, - interval=interval, - file_range=(self.first_image_selection, self.last_image_selection)) - else: - dlg.MissingFilesForReconstruction() + Publisher.sendMessage('Open DICOM group', group=group, + interval=interval, + file_range=(self.first_image_selection, self.last_image_selection)) class TextPanel(wx.Panel): def __init__(self, parent): diff --git a/invesalius/reader/bitmap_reader.py b/invesalius/reader/bitmap_reader.py index b8d98f3..c7490b0 100644 --- a/invesalius/reader/bitmap_reader.py +++ b/invesalius/reader/bitmap_reader.py @@ -264,21 +264,20 @@ class ProgressBitmapReader: Publisher.sendMessage("End bitmap load", data=bitmap_list) def GetBitmaps(self, path, recursive): - y = yGetBitmaps(path, recursive) for value_progress in y: + print(">>> YYYYYY", value_progress) if not self.running: break if isinstance(value_progress, tuple): + print("UPDATE PROGRESS") self.UpdateLoadFileProgress(value_progress) else: + print("END PROGRESS") self.EndLoadFile(value_progress) - #Is necessary in the case user cancel - #the load, ensure that dicomdialog is closed - if(self.stoped): - self.UpdateLoadFileProgress(None) - self.stoped = False + self.UpdateLoadFileProgress(None) + self.stoped = False def VtkErrorPNGWriter(obj, f): global vtk_error -- libgit2 0.21.2