Commit 3867177c65d07ecf02eca6a607c28716aadf014b
Exists in
master
and in
48 other branches
Merge pull request #23 from tfmoraes/mask_copy
Mask copy
Showing
3 changed files
with
46 additions
and
19 deletions
Show diff stats
invesalius/control.py
@@ -572,6 +572,8 @@ class Controller(): | @@ -572,6 +572,8 @@ class Controller(): | ||
572 | self.Slice.window_level = wl | 572 | self.Slice.window_level = wl |
573 | self.Slice.window_width = ww | 573 | self.Slice.window_width = ww |
574 | 574 | ||
575 | + scalar_range = self.matrix.min(), self.matrix.max() | ||
576 | + | ||
575 | Publisher.sendMessage('Update threshold limits list', scalar_range) | 577 | Publisher.sendMessage('Update threshold limits list', scalar_range) |
576 | 578 | ||
577 | return self.matrix, self.filename, dicom | 579 | return self.matrix, self.filename, dicom |
invesalius/data/mask.py
@@ -285,6 +285,26 @@ class Mask(): | @@ -285,6 +285,26 @@ class Mask(): | ||
285 | shape = shape[0] + 1, shape[1] + 1, shape[2] + 1 | 285 | shape = shape[0] + 1, shape[1] + 1, shape[2] + 1 |
286 | self.matrix = numpy.memmap(self.temp_file, mode='w+', dtype='uint8', shape=shape) | 286 | self.matrix = numpy.memmap(self.temp_file, mode='w+', dtype='uint8', shape=shape) |
287 | 287 | ||
288 | + def copy(self, copy_name): | ||
289 | + """ | ||
290 | + creates and return a copy from the mask instance. | ||
291 | + | ||
292 | + params: | ||
293 | + copy_name: the name from the copy | ||
294 | + """ | ||
295 | + new_mask = Mask() | ||
296 | + new_mask.name = copy_name | ||
297 | + new_mask.colour = self.colour | ||
298 | + new_mask.opacity = self.opacity | ||
299 | + new_mask.threshold_range = self.threshold_range | ||
300 | + new_mask.edition_threshold_range = self.edition_threshold_range | ||
301 | + new_mask.is_shown = self.is_shown | ||
302 | + | ||
303 | + new_mask.create_mask(shape=[i-1 for i in self.matrix.shape]) | ||
304 | + new_mask.matrix[:] = self.matrix[:] | ||
305 | + | ||
306 | + return new_mask | ||
307 | + | ||
288 | def clear_history(self): | 308 | def clear_history(self): |
289 | self.history.clear_history() | 309 | self.history.clear_history() |
290 | 310 |
invesalius/data/slice_.py
@@ -224,14 +224,9 @@ class Slice(object): | @@ -224,14 +224,9 @@ class Slice(object): | ||
224 | name = original_mask.name | 224 | name = original_mask.name |
225 | names_list = [mask_dict[i].name for i in mask_dict.keys()] | 225 | names_list = [mask_dict[i].name for i in mask_dict.keys()] |
226 | new_name = utils.next_copy_name(name, names_list) | 226 | new_name = utils.next_copy_name(name, names_list) |
227 | - # create new mask | ||
228 | - self.CreateMask(imagedata = original_mask.imagedata, | ||
229 | - name = new_name, | ||
230 | - colour = original_mask.colour, | ||
231 | - opacity = original_mask.opacity, | ||
232 | - threshold_range = original_mask.threshold_range, | ||
233 | - edition_threshold_range = original_mask.edition_threshold_range, | ||
234 | - edited_points = original_mask.edited_points) | 227 | + |
228 | + copy_mask = original_mask.copy(new_name) | ||
229 | + self._add_mask_into_proj(copy_mask) | ||
235 | 230 | ||
236 | def OnEnableStyle(self, pubsub_evt): | 231 | def OnEnableStyle(self, pubsub_evt): |
237 | state = pubsub_evt.data | 232 | state = pubsub_evt.data |
@@ -1090,22 +1085,32 @@ class Slice(object): | @@ -1090,22 +1085,32 @@ class Slice(object): | ||
1090 | if threshold_range: | 1085 | if threshold_range: |
1091 | future_mask.threshold_range = threshold_range | 1086 | future_mask.threshold_range = threshold_range |
1092 | 1087 | ||
1093 | - # insert new mask into project and retrieve its index | 1088 | + self._add_mask_into_proj(future_mask) |
1089 | + | ||
1090 | + | ||
1091 | + def _add_mask_into_proj(self, mask, show=True): | ||
1092 | + """ | ||
1093 | + Insert a new mask into project and retrieve its index. | ||
1094 | + | ||
1095 | + Params: | ||
1096 | + mask: A mask object. | ||
1097 | + show: indicate if the mask will be shown. | ||
1098 | + """ | ||
1094 | proj = Project() | 1099 | proj = Project() |
1095 | - index = proj.AddMask(future_mask) | ||
1096 | - future_mask.index = index | 1100 | + index = proj.AddMask(mask) |
1101 | + mask.index = index | ||
1097 | 1102 | ||
1098 | ## update gui related to mask | 1103 | ## update gui related to mask |
1099 | Publisher.sendMessage('Add mask', | 1104 | Publisher.sendMessage('Add mask', |
1100 | - (future_mask.index, | ||
1101 | - future_mask.name, | ||
1102 | - future_mask.threshold_range, | ||
1103 | - future_mask.colour)) | ||
1104 | - | ||
1105 | - self.current_mask = future_mask | 1105 | + (mask.index, |
1106 | + mask.name, | ||
1107 | + mask.threshold_range, | ||
1108 | + mask.colour)) | ||
1106 | 1109 | ||
1107 | - Publisher.sendMessage('Change mask selected', future_mask.index) | ||
1108 | - Publisher.sendMessage('Update slice viewer') | 1110 | + if show: |
1111 | + self.current_mask = mask | ||
1112 | + Publisher.sendMessage('Change mask selected', mask.index) | ||
1113 | + Publisher.sendMessage('Update slice viewer') | ||
1109 | 1114 | ||
1110 | def __load_masks(self, imagedata, mask_dict): | 1115 | def __load_masks(self, imagedata, mask_dict): |
1111 | keys = mask_dict.keys() | 1116 | keys = mask_dict.keys() |