Commit f557693220ba8544478394d49f56b0b6c4bb1c52
1 parent
22aa7bb1
Exists in
master
and in
49 other branches
Added a method into mask to copy the instance mask
Showing
2 changed files
with
44 additions
and
19 deletions
Show diff stats
invesalius/data/mask.py
... | ... | @@ -285,6 +285,26 @@ class Mask(): |
285 | 285 | shape = shape[0] + 1, shape[1] + 1, shape[2] + 1 |
286 | 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 | 308 | def clear_history(self): |
289 | 309 | self.history.clear_history() |
290 | 310 | ... | ... |
invesalius/data/slice_.py
... | ... | @@ -224,14 +224,9 @@ class Slice(object): |
224 | 224 | name = original_mask.name |
225 | 225 | names_list = [mask_dict[i].name for i in mask_dict.keys()] |
226 | 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 | 231 | def OnEnableStyle(self, pubsub_evt): |
237 | 232 | state = pubsub_evt.data |
... | ... | @@ -1090,22 +1085,32 @@ class Slice(object): |
1090 | 1085 | if threshold_range: |
1091 | 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 | 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 | 1103 | ## update gui related to mask |
1099 | 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 | 1115 | def __load_masks(self, imagedata, mask_dict): |
1111 | 1116 | keys = mask_dict.keys() | ... | ... |