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 26 self.__build_actor()
27 27 self.__calculate_area_pixels()
28 28  
29   -
30 29 def __build_actor(self):
31 30 """
32 31 Function to plot the circle
... ... @@ -113,15 +112,18 @@ class CursorCircle:
113 112 px, py, pz = self.edition_position
114 113 orient = self.orientation
115 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 121 for pixel_0,pixel_1 in self.pixel_list:
117 122 # The position of the pixels in this list is relative (based only on
118 123 # the area, and not the cursor position).
119 124 # Let's calculate the absolute position
120 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 98 self.ShowMask(index, value)
99 99 #---------------------------------------------------------------------------
100 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 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 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 115 # END PUBSUB_EVT METHODS
113 116 #---------------------------------------------------------------------------
... ... @@ -191,7 +194,7 @@ class Slice(object):
191 194 colour = self.imagedata.GetScalarRange()[0]# - 1 # Important to effect erase
192 195 imagedata = self.current_mask.imagedata
193 196 imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour)
194   - imagedata.Update()
  197 + #imagedata.Update()
195 198 self.current_mask.edited_points[(x, y, z)] = colour
196 199  
197 200 def DrawPixel(self, position, colour=None):
... ... @@ -201,7 +204,6 @@ class Slice(object):
201 204 colour = self.imagedata.GetScalarRange()[1]
202 205 imagedata = self.current_mask.imagedata
203 206 imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour)
204   - imagedata.Update()
205 207 self.current_mask.edited_points[(x, y, z)] = colour
206 208  
207 209 def EditPixelBasedOnThreshold(self, position):
... ...
invesalius/data/viewer_slice.py
... ... @@ -195,8 +195,7 @@ class Viewer(wx.Panel):
195 195  
196 196 pixels = itertools.ifilter(self.TestOperationPosition,
197 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 200 # FIXME: This is idiot, but is the only way that brush operations are
202 201 # working when cross is disabled
... ... @@ -219,10 +218,9 @@ class Viewer(wx.Panel):
219 218 if self.mouse_pressed:
220 219 pixels = itertools.ifilter(self.TestOperationPosition,
221 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 223 self.interactor.Render()
225   - ps.Publisher().sendMessage('Update slice viewer')
226 224  
227 225 def OnCrossMove(self, obj, evt_vtk):
228 226 coord = self.GetCoordinate()
... ...