Commit fb797bab66772bbff87de02371dbb2039766bf4a

Authored by tfmoraes
1 parent 9fb87ccd

ENH: A try to improve the editor performance removing unnecessary updates

invesalius/data/cursor_actors.py
@@ -26,7 +26,6 @@ class CursorCircle: @@ -26,7 +26,6 @@ class CursorCircle:
26 self.__build_actor() 26 self.__build_actor()
27 self.__calculate_area_pixels() 27 self.__calculate_area_pixels()
28 28
29 -  
30 def __build_actor(self): 29 def __build_actor(self):
31 """ 30 """
32 Function to plot the circle 31 Function to plot the circle
@@ -113,15 +112,18 @@ class CursorCircle: @@ -113,15 +112,18 @@ class CursorCircle:
113 px, py, pz = self.edition_position 112 px, py, pz = self.edition_position
114 orient = self.orientation 113 orient = self.orientation
115 xs, ys, zs = self.spacing 114 xs, ys, zs = self.spacing
  115 + abs_pixel = {"AXIAL": lambda x,y: (px + x / xs, py+(y/ys), pz),
  116 + "CORONAL": lambda x,y: (px+(x/xs), py,
  117 + pz+(y/zs)),
  118 + "SAGITAL": lambda x,y: (px, py+(x/ys),
  119 + pz+(y/zs))}
  120 + function_orientation = abs_pixel[orient]
116 for pixel_0,pixel_1 in self.pixel_list: 121 for pixel_0,pixel_1 in self.pixel_list:
117 # The position of the pixels in this list is relative (based only on 122 # The position of the pixels in this list is relative (based only on
118 # the area, and not the cursor position). 123 # the area, and not the cursor position).
119 # Let's calculate the absolute position 124 # Let's calculate the absolute position
120 # TODO: Optimize this!!!! 125 # TODO: Optimize this!!!!
121 - abs_pixel = {"AXIAL": [px+pixel_0/xs, py+(pixel_1/ys), pz],  
122 - "CORONAL": [px+(pixel_0/xs), py, pz+(pixel_1/zs)],  
123 - "SAGITAL": [px, py+(pixel_0/ys), pz+(pixel_1/zs)]}  
124 - yield abs_pixel[orient] 126 + yield function_orientation(pixel_0, pixel_1)
125 127
126 128
127 #------------------------------------------------------------------------------- 129 #-------------------------------------------------------------------------------
invesalius/data/slice_.py
@@ -98,16 +98,19 @@ class Slice(object): @@ -98,16 +98,19 @@ class Slice(object):
98 self.ShowMask(index, value) 98 self.ShowMask(index, value)
99 #--------------------------------------------------------------------------- 99 #---------------------------------------------------------------------------
100 def __erase_mask_pixel(self, pubsub_evt): 100 def __erase_mask_pixel(self, pubsub_evt):
101 - position = pubsub_evt.data  
102 - self.ErasePixel(position) 101 + positions = pubsub_evt.data
  102 + for position in positions:
  103 + self.ErasePixel(position)
103 104
104 def __edit_mask_pixel(self, pubsub_evt): 105 def __edit_mask_pixel(self, pubsub_evt):
105 - position = pubsub_evt.data  
106 - self.EditPixelBasedOnThreshold(position) 106 + positions = pubsub_evt.data
  107 + for position in positions:
  108 + self.EditPixelBasedOnThreshold(position)
107 109
108 def __add_mask_pixel(self, pubsub_evt): 110 def __add_mask_pixel(self, pubsub_evt):
109 - position = pubsub_evt.data  
110 - self.DrawPixel(position) 111 + positions = pubsub_evt.data
  112 + for position in positions:
  113 + self.DrawPixel(position)
111 #--------------------------------------------------------------------------- 114 #---------------------------------------------------------------------------
112 # END PUBSUB_EVT METHODS 115 # END PUBSUB_EVT METHODS
113 #--------------------------------------------------------------------------- 116 #---------------------------------------------------------------------------
@@ -191,7 +194,7 @@ class Slice(object): @@ -191,7 +194,7 @@ class Slice(object):
191 colour = self.imagedata.GetScalarRange()[0]# - 1 # Important to effect erase 194 colour = self.imagedata.GetScalarRange()[0]# - 1 # Important to effect erase
192 imagedata = self.current_mask.imagedata 195 imagedata = self.current_mask.imagedata
193 imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) 196 imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour)
194 - imagedata.Update() 197 + #imagedata.Update()
195 self.current_mask.edited_points[(x, y, z)] = colour 198 self.current_mask.edited_points[(x, y, z)] = colour
196 199
197 def DrawPixel(self, position, colour=None): 200 def DrawPixel(self, position, colour=None):
@@ -201,7 +204,6 @@ class Slice(object): @@ -201,7 +204,6 @@ class Slice(object):
201 colour = self.imagedata.GetScalarRange()[1] 204 colour = self.imagedata.GetScalarRange()[1]
202 imagedata = self.current_mask.imagedata 205 imagedata = self.current_mask.imagedata
203 imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) 206 imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour)
204 - imagedata.Update()  
205 self.current_mask.edited_points[(x, y, z)] = colour 207 self.current_mask.edited_points[(x, y, z)] = colour
206 208
207 def EditPixelBasedOnThreshold(self, position): 209 def EditPixelBasedOnThreshold(self, position):
invesalius/data/viewer_slice.py
@@ -195,8 +195,7 @@ class Viewer(wx.Panel): @@ -195,8 +195,7 @@ class Viewer(wx.Panel):
195 195
196 pixels = itertools.ifilter(self.TestOperationPosition, 196 pixels = itertools.ifilter(self.TestOperationPosition,
197 self.cursor.GetPixels()) 197 self.cursor.GetPixels())
198 - for coord in pixels:  
199 - ps.Publisher().sendMessage(evt_msg, coord) 198 + ps.Publisher().sendMessage(evt_msg, pixels)
200 199
201 # FIXME: This is idiot, but is the only way that brush operations are 200 # FIXME: This is idiot, but is the only way that brush operations are
202 # working when cross is disabled 201 # working when cross is disabled
@@ -219,10 +218,9 @@ class Viewer(wx.Panel): @@ -219,10 +218,9 @@ class Viewer(wx.Panel):
219 if self.mouse_pressed: 218 if self.mouse_pressed:
220 pixels = itertools.ifilter(self.TestOperationPosition, 219 pixels = itertools.ifilter(self.TestOperationPosition,
221 self.cursor.GetPixels()) 220 self.cursor.GetPixels())
222 - for coord in pixels:  
223 - ps.Publisher().sendMessage(evt_msg, coord) 221 + ps.Publisher().sendMessage(evt_msg, pixels)
  222 + ps.Publisher().sendMessage('Update slice viewer')
224 self.interactor.Render() 223 self.interactor.Render()
225 - ps.Publisher().sendMessage('Update slice viewer')  
226 224
227 def OnCrossMove(self, obj, evt_vtk): 225 def OnCrossMove(self, obj, evt_vtk):
228 coord = self.GetCoordinate() 226 coord = self.GetCoordinate()