Commit 10ef6cb7b59260c1102f086a8f3e5a5f902b0693
1 parent
bcb8814f
Exists in
master
and in
6 other branches
FIX:Edit points is not erased when you use the erase brush. FIX #205
Showing
1 changed file
with
21 additions
and
21 deletions
Show diff stats
invesalius/data/slice_.py
@@ -108,7 +108,7 @@ class Slice(object): | @@ -108,7 +108,7 @@ class Slice(object): | ||
108 | # compute copy name | 108 | # compute copy name |
109 | name = original_mask.name | 109 | name = original_mask.name |
110 | names_list = [mask_dict[i].name for i in mask_dict.keys()] | 110 | names_list = [mask_dict[i].name for i in mask_dict.keys()] |
111 | - new_name = utils.next_copy_name(name, names_list) | 111 | + new_name = utils.next_copy_name(name, names_list) |
112 | # create new mask | 112 | # create new mask |
113 | self.CreateMask(imagedata = original_mask.imagedata, | 113 | self.CreateMask(imagedata = original_mask.imagedata, |
114 | name = new_name, | 114 | name = new_name, |
@@ -131,7 +131,7 @@ class Slice(object): | @@ -131,7 +131,7 @@ class Slice(object): | ||
131 | if (state in const.SLICE_STYLES): | 131 | if (state in const.SLICE_STYLES): |
132 | new_state = self.interaction_style.RemoveState(state) | 132 | new_state = self.interaction_style.RemoveState(state) |
133 | ps.Publisher().sendMessage('Set slice interaction style', new_state) | 133 | ps.Publisher().sendMessage('Set slice interaction style', new_state) |
134 | - | 134 | + |
135 | if (state == const.SLICE_STATE_EDITOR): | 135 | if (state == const.SLICE_STATE_EDITOR): |
136 | ps.Publisher().sendMessage('Set interactor default cursor') | 136 | ps.Publisher().sendMessage('Set interactor default cursor') |
137 | 137 | ||
@@ -190,7 +190,7 @@ class Slice(object): | @@ -190,7 +190,7 @@ class Slice(object): | ||
190 | #Clear edited points | 190 | #Clear edited points |
191 | self.current_mask.edited_points = {} | 191 | self.current_mask.edited_points = {} |
192 | self.num_gradient += 1 | 192 | self.num_gradient += 1 |
193 | - | 193 | + |
194 | def __set_current_mask_colour(self, pubsub_evt): | 194 | def __set_current_mask_colour(self, pubsub_evt): |
195 | # "if" is necessary because wx events are calling this before any mask | 195 | # "if" is necessary because wx events are calling this before any mask |
196 | # has been created | 196 | # has been created |
@@ -298,10 +298,10 @@ class Slice(object): | @@ -298,10 +298,10 @@ class Slice(object): | ||
298 | else: | 298 | else: |
299 | proj = Project() | 299 | proj = Project() |
300 | proj.mask_dict[index].threshold_range = threshold_range | 300 | proj.mask_dict[index].threshold_range = threshold_range |
301 | - | 301 | + |
302 | proj = Project() | 302 | proj = Project() |
303 | proj.mask_dict[self.current_mask.index].threshold_range = threshold_range | 303 | proj.mask_dict[self.current_mask.index].threshold_range = threshold_range |
304 | - | 304 | + |
305 | 305 | ||
306 | def ShowMask(self, index, value): | 306 | def ShowMask(self, index, value): |
307 | "Show a mask given its index and 'show' value (0: hide, other: show)" | 307 | "Show a mask given its index and 'show' value (0: hide, other: show)" |
@@ -317,19 +317,19 @@ class Slice(object): | @@ -317,19 +317,19 @@ class Slice(object): | ||
317 | #--------------------------------------------------------------------------- | 317 | #--------------------------------------------------------------------------- |
318 | def ErasePixel(self, position): | 318 | def ErasePixel(self, position): |
319 | "Delete pixel, based on x, y and z position coordinates." | 319 | "Delete pixel, based on x, y and z position coordinates." |
320 | - x, y, z = position | 320 | + x, y, z = round(position[0],0), round(position[1],0),position[2] |
321 | colour = self.imagedata.GetScalarRange()[0] | 321 | colour = self.imagedata.GetScalarRange()[0] |
322 | imagedata = self.current_mask.imagedata | 322 | imagedata = self.current_mask.imagedata |
323 | imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) | 323 | imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) |
324 | self.current_mask.edited_points[(x, y, z)] = colour | 324 | self.current_mask.edited_points[(x, y, z)] = colour |
325 | - | 325 | + |
326 | session = ses.Session() | 326 | session = ses.Session() |
327 | session.ChangeProject() | 327 | session.ChangeProject() |
328 | 328 | ||
329 | 329 | ||
330 | def DrawPixel(self, position, colour=None): | 330 | def DrawPixel(self, position, colour=None): |
331 | "Draw pixel, based on x, y and z position coordinates." | 331 | "Draw pixel, based on x, y and z position coordinates." |
332 | - x, y, z = position | 332 | + x, y, z = round(position[0],0), round(position[1],0),position[2] |
333 | colour = self.imagedata.GetScalarRange()[1] | 333 | colour = self.imagedata.GetScalarRange()[1] |
334 | imagedata = self.current_mask.imagedata | 334 | imagedata = self.current_mask.imagedata |
335 | imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) | 335 | imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) |
@@ -341,7 +341,7 @@ class Slice(object): | @@ -341,7 +341,7 @@ class Slice(object): | ||
341 | 341 | ||
342 | def EditPixelBasedOnThreshold(self, position): | 342 | def EditPixelBasedOnThreshold(self, position): |
343 | "Erase or draw pixel based on edition threshold range." | 343 | "Erase or draw pixel based on edition threshold range." |
344 | - x, y, z = position | 344 | + x, y, z = round(position[0],0), round(position[1],0),position[2] |
345 | colour = self.imagedata.GetScalarComponentAsDouble(x, y, z, 0) | 345 | colour = self.imagedata.GetScalarComponentAsDouble(x, y, z, 0) |
346 | thresh_min, thresh_max = self.current_mask.edition_threshold_range | 346 | thresh_min, thresh_max = self.current_mask.edition_threshold_range |
347 | if (colour >= thresh_min) and (colour <= thresh_max): | 347 | if (colour >= thresh_min) and (colour <= thresh_max): |
@@ -366,7 +366,7 @@ class Slice(object): | @@ -366,7 +366,7 @@ class Slice(object): | ||
366 | future_mask = proj.GetMask(index) | 366 | future_mask = proj.GetMask(index) |
367 | future_mask.is_shown = True | 367 | future_mask.is_shown = True |
368 | self.current_mask = future_mask | 368 | self.current_mask = future_mask |
369 | - | 369 | + |
370 | colour = future_mask.colour | 370 | colour = future_mask.colour |
371 | #index = future_mask.index | 371 | #index = future_mask.index |
372 | print index | 372 | print index |
@@ -392,7 +392,7 @@ class Slice(object): | @@ -392,7 +392,7 @@ class Slice(object): | ||
392 | 392 | ||
393 | def CreateSurfaceFromIndex(self, pubsub_evt): | 393 | def CreateSurfaceFromIndex(self, pubsub_evt): |
394 | mask_index, overwrite_surface = pubsub_evt.data | 394 | mask_index, overwrite_surface = pubsub_evt.data |
395 | - | 395 | + |
396 | 396 | ||
397 | proj = Project() | 397 | proj = Project() |
398 | mask = proj.mask_dict[mask_index] | 398 | mask = proj.mask_dict[mask_index] |
@@ -496,18 +496,18 @@ class Slice(object): | @@ -496,18 +496,18 @@ class Slice(object): | ||
496 | thresh_min, thresh_max = self.window_level.GetOutput().GetScalarRange() | 496 | thresh_min, thresh_max = self.window_level.GetOutput().GetScalarRange() |
497 | self.lut_bg.SetTableRange(thresh_min, thresh_max) | 497 | self.lut_bg.SetTableRange(thresh_min, thresh_max) |
498 | 498 | ||
499 | - | 499 | + |
500 | def InputImageWidget(self, pubsub_evt): | 500 | def InputImageWidget(self, pubsub_evt): |
501 | widget = pubsub_evt.data | 501 | widget = pubsub_evt.data |
502 | - | 502 | + |
503 | flip = vtk.vtkImageFlip() | 503 | flip = vtk.vtkImageFlip() |
504 | flip.SetInput(self.window_level.GetOutput()) | 504 | flip.SetInput(self.window_level.GetOutput()) |
505 | flip.SetFilteredAxis(1) | 505 | flip.SetFilteredAxis(1) |
506 | flip.FlipAboutOriginOn() | 506 | flip.FlipAboutOriginOn() |
507 | flip.Update() | 507 | flip.Update() |
508 | - | 508 | + |
509 | widget.SetInput(flip.GetOutput()) | 509 | widget.SetInput(flip.GetOutput()) |
510 | - | 510 | + |
511 | 511 | ||
512 | def CreateMask(self, imagedata=None, name=None, colour=None, | 512 | def CreateMask(self, imagedata=None, name=None, colour=None, |
513 | opacity=None, threshold_range=None, | 513 | opacity=None, threshold_range=None, |
@@ -570,7 +570,7 @@ class Slice(object): | @@ -570,7 +570,7 @@ class Slice(object): | ||
570 | keys.sort() | 570 | keys.sort() |
571 | for key in keys: | 571 | for key in keys: |
572 | mask = mask_dict[key] | 572 | mask = mask_dict[key] |
573 | - | 573 | + |
574 | # update gui related to mask | 574 | # update gui related to mask |
575 | utils.debug("__load_masks") | 575 | utils.debug("__load_masks") |
576 | utils.debug('THRESHOLD_RANGE %s'% mask.threshold_range) | 576 | utils.debug('THRESHOLD_RANGE %s'% mask.threshold_range) |
@@ -609,22 +609,22 @@ class Slice(object): | @@ -609,22 +609,22 @@ class Slice(object): | ||
609 | lut_mask.SetRampToLinear() | 609 | lut_mask.SetRampToLinear() |
610 | lut_mask.Build() | 610 | lut_mask.Build() |
611 | self.lut_mask = lut_mask | 611 | self.lut_mask = lut_mask |
612 | - | 612 | + |
613 | mask_thresh_imagedata = self.__create_mask_threshold(imagedata) | 613 | mask_thresh_imagedata = self.__create_mask_threshold(imagedata) |
614 | - | 614 | + |
615 | if create: | 615 | if create: |
616 | # threshold pipeline | 616 | # threshold pipeline |
617 | current_mask.imagedata.DeepCopy(mask_thresh_imagedata) | 617 | current_mask.imagedata.DeepCopy(mask_thresh_imagedata) |
618 | else: | 618 | else: |
619 | mask_thresh_imagedata = self.current_mask.imagedata | 619 | mask_thresh_imagedata = self.current_mask.imagedata |
620 | - | 620 | + |
621 | # map the input image through a lookup table | 621 | # map the input image through a lookup table |
622 | img_colours_mask = vtk.vtkImageMapToColors() | 622 | img_colours_mask = vtk.vtkImageMapToColors() |
623 | img_colours_mask.SetOutputFormatToRGBA() | 623 | img_colours_mask.SetOutputFormatToRGBA() |
624 | img_colours_mask.SetLookupTable(lut_mask) | 624 | img_colours_mask.SetLookupTable(lut_mask) |
625 | - | 625 | + |
626 | img_colours_mask.SetInput(mask_thresh_imagedata) | 626 | img_colours_mask.SetInput(mask_thresh_imagedata) |
627 | - | 627 | + |
628 | self.img_colours_mask = img_colours_mask | 628 | self.img_colours_mask = img_colours_mask |
629 | 629 | ||
630 | return img_colours_mask.GetOutput() | 630 | return img_colours_mask.GetOutput() |