Commit d8df5d576e393f5c8db03d2308e5e6c2d2e3c49e

Authored by Paulo Henrique Junqueira Amorim
1 parent 77023ee3

FIX: Bug in CursorRectangle, if movimented cursor balanced

Showing 1 changed file with 72 additions and 109 deletions   Show diff stats
invesalius/data/cursor_actors.py
@@ -110,7 +110,6 @@ class CursorCircle: @@ -110,7 +110,6 @@ class CursorCircle:
110 def SetOrientation(self, orientation): 110 def SetOrientation(self, orientation):
111 self.orientation = orientation 111 self.orientation = orientation
112 proj = Project() 112 proj = Project()
113 -  
114 orig_orien = proj.original_orientation 113 orig_orien = proj.original_orientation
115 if (orig_orien == const.SAGITAL): 114 if (orig_orien == const.SAGITAL):
116 if orientation == "CORONAL": 115 if orientation == "CORONAL":
@@ -151,7 +150,6 @@ class CursorCircle: @@ -151,7 +150,6 @@ class CursorCircle:
151 xs, ys, zs = self.spacing 150 xs, ys, zs = self.spacing
152 proj = Project() 151 proj = Project()
153 orig_orien = proj.original_orientation 152 orig_orien = proj.original_orientation
154 -  
155 xy1 = lambda x,y: (px + x / xs, py+(y/ys), pz) 153 xy1 = lambda x,y: (px + x / xs, py+(y/ys), pz)
156 xy2 = lambda x,y: (px+(x/xs), py, pz+(y/zs)) 154 xy2 = lambda x,y: (px+(x/xs), py, pz+(y/zs))
157 xy3 = lambda x,y: (px, py+(x/ys), pz+(y/zs)) 155 xy3 = lambda x,y: (px, py+(x/ys), pz+(y/zs))
@@ -178,21 +176,8 @@ class CursorCircle: @@ -178,21 +176,8 @@ class CursorCircle:
178 # TODO: Optimize this!!!! 176 # TODO: Optimize this!!!!
179 yield function_orientation(pixel_0, pixel_1) 177 yield function_orientation(pixel_0, pixel_1)
180 178
181 -  
182 -#-------------------------------------------------------------------------------  
183 -#-------------------------------------------------------------------------------  
184 -#-------------------------------------------------------------------------------  
185 -#-------------------------------------------------------------------------------  
186 -#-------------------------------------------------------------------------------  
187 -#-------------------------------------------------------------------------------  
188 -#-------------------------------------------------------------------------------  
189 -#-------------------------------------------------------------------------------  
190 -#-------------------------------------------------------------------------------  
191 -#-------------------------------------------------------------------------------  
192 -#-------------------------------------------------------------------------------  
193 -#-------------------------------------------------------------------------------  
194 -#-------------------------------------------------------------------------------  
195 -#------------------------------------------------------------------------------- 179 +
  180 +
196 181
197 class CursorRectangle: 182 class CursorRectangle:
198 183
@@ -208,51 +193,16 @@ class CursorRectangle: @@ -208,51 +193,16 @@ class CursorRectangle:
208 self.position = (0 ,0) 193 self.position = (0 ,0)
209 self.orientation = "AXIAL" 194 self.orientation = "AXIAL"
210 self.spacing = (1, 1, 1) 195 self.spacing = (1, 1, 1)
211 -  
212 - self.mapper = vtk.vtkPolyDataMapper()  
213 -  
214 - self.retangle = vtk.vtkCubeSource()  
215 - self.actor = vtk.vtkActor()  
216 -  
217 - self.seeds_yi = vtk.vtkLineSource()  
218 - self.seeds_yf = vtk.vtkLineSource()  
219 - self.seeds_xi = vtk.vtkLineSource()  
220 - self.seeds_xf = vtk.vtkLineSource()  
221 - self.join_lines = vtk.vtkAppendPolyData()  
222 - 196 +
223 self.__build_actor() 197 self.__build_actor()
224 self.__calculate_area_pixels() 198 self.__calculate_area_pixels()
225 199
226 def SetSize(self, size): 200 def SetSize(self, size):
227 - print "SetSize", size  
228 self.x_length = size 201 self.x_length = size
229 self.y_length = size 202 self.y_length = size
230 retangle = self.retangle 203 retangle = self.retangle
231 retangle.SetXLength(size) 204 retangle.SetXLength(size)
232 - retangle.SetYLength(size)  
233 -  
234 - seeds_yi = self.seeds_yi  
235 - seeds_yi.SetPoint1(0, 0, 0)  
236 - seeds_yi.SetPoint2(0, self.y_length, 0)  
237 -  
238 - seeds_yf = self.seeds_yf  
239 - seeds_yf.SetPoint1(self.x_length, self.y_length, 0)  
240 - seeds_yf.SetPoint2(self.x_length, 0, 0)  
241 -  
242 - seeds_xi = self.seeds_xi  
243 - seeds_xi.SetPoint1(0, self.y_length, 0)  
244 - seeds_xi.SetPoint2(self.x_length, self.y_length, 0)  
245 -  
246 - seeds_xf = self.seeds_xf  
247 - seeds_xf.SetPoint1(0, 0, 0)  
248 - seeds_xf.SetPoint2(self.x_length, 0, 0)  
249 -  
250 - #join_lines = self.join_lines  
251 - #join_lines.AddInput(seeds_yi.GetOutput())  
252 - #join_lines.AddInput(seeds_yf.GetOutput())  
253 - #join_lines.AddInput(seeds_xi.GetOutput())  
254 - #join_lines.AddInput(seeds_xf.GetOutput())  
255 - 205 + retangle.SetYLength(size)
256 self.__calculate_area_pixels() 206 self.__calculate_area_pixels()
257 207
258 def SetOrientation(self, orientation): 208 def SetOrientation(self, orientation):
@@ -264,24 +214,29 @@ class CursorRectangle: @@ -264,24 +214,29 @@ class CursorRectangle:
264 214
265 def SetOrientation(self, orientation): 215 def SetOrientation(self, orientation):
266 self.orientation = orientation 216 self.orientation = orientation
267 -  
268 - if orientation == "CORONAL":  
269 - self.actor.RotateX(90)  
270 -  
271 - if orientation == "SAGITAL":  
272 - self.actor.RotateY(90) 217 + proj = Project()
  218 + orig_orien = proj.original_orientation
  219 + if (orig_orien == const.SAGITAL):
  220 + if orientation == "CORONAL":
  221 + self.actor.RotateY(90)
  222 + if orientation == "AXIAL":
  223 + self.actor.RotateX(90)
  224 + elif(orig_orien == const.CORONAL):
  225 + if orientation == "AXIAL":
  226 + self.actor.RotateX(270)
  227 + if orientation == "SAGITAL":
  228 + self.actor.RotateY(90)
  229 + else:
  230 + if orientation == "CORONAL":
  231 + self.actor.RotateX(90)
  232 + if orientation == "SAGITAL":
  233 + self.actor.RotateY(90)
273 234
274 def SetPosition(self, position): 235 def SetPosition(self, position):
275 x,y,z = position 236 x,y,z = position
276 - x_half = self.x_length / 2.0  
277 - y_half = self.y_length / 2.0  
278 - orientation_position_based = {"AXIAL" : (x - x_half,y - y_half, z),  
279 - "CORONAL" : (x - x_half, y, z - y_half),  
280 - "SAGITAL" : (x, y - y_half, z + x_half)}  
281 - xc,yc,zc = orientation_position_based[self.orientation]  
282 - self.position = (xc,yc,zc)  
283 - self.actor.SetPosition(xc,yc,zc)  
284 - 237 + self.position = position
  238 + self.actor.SetPosition(x,y,z)
  239 +
285 def SetEditionPosition(self, position): 240 def SetEditionPosition(self, position):
286 self.edition_position = position 241 self.edition_position = position
287 242
@@ -298,40 +253,17 @@ class CursorRectangle: @@ -298,40 +253,17 @@ class CursorRectangle:
298 """ 253 """
299 Function to plot the Retangle 254 Function to plot the Retangle
300 """ 255 """
301 - retangle = self.retangle  
302 - retangle.SetXLength(self.x_length)  
303 - retangle.SetYLength(self.y_length)  
304 -  
305 - seeds_yi = self.seeds_yi  
306 - seeds_yi.SetPoint1(0, 0, 0)  
307 - seeds_yi.SetPoint2(0, self.y_length, 0)  
308 -  
309 - seeds_yf = self.seeds_yf  
310 - seeds_yf.SetPoint1(self.x_length, self.y_length, 0)  
311 - seeds_yf.SetPoint2(self.x_length, 0, 0)  
312 -  
313 - seeds_xi = self.seeds_xi  
314 - seeds_xi.SetPoint1(0, self.y_length, 0)  
315 - seeds_xi.SetPoint2(self.x_length, self.y_length, 0)  
316 -  
317 - seeds_xf = self.seeds_xf  
318 - seeds_xf.SetPoint1(0, 0, 0)  
319 - seeds_xf.SetPoint2(self.x_length, 0, 0) 256 + mapper = vtk.vtkPolyDataMapper()
  257 + self.retangle = vtk.vtkCubeSource()
  258 + self.actor = actor = vtk.vtkActor()
320 259
321 - join_lines = self.join_lines  
322 - join_lines.AddInput(seeds_yi.GetOutput())  
323 - join_lines.AddInput(seeds_yf.GetOutput())  
324 - join_lines.AddInput(seeds_xi.GetOutput())  
325 - join_lines.AddInput(seeds_xf.GetOutput())  
326 -  
327 - mapper = self.mapper  
328 - mapper.SetScalarRange(0, 360) 260 + prop = vtk.vtkProperty()
  261 + prop.SetRepresentationToWireframe()
  262 + self.actor.SetProperty(prop)
329 263
330 - actor = self.actor  
331 -  
332 - mapper.SetInput(join_lines.GetOutput())  
333 - actor.SetPosition(self.position[0]-self.x_length/2, # if filled remov -  
334 - self.position[1]-self.y_length/2, 1) # idem 264 + mapper.SetInput(self.retangle.GetOutput())
  265 + actor.SetPosition(self.position[0] - self.x_length,\
  266 + self.position[1] - self.y_length, 1)
335 267
336 actor.SetMapper(mapper) 268 actor.SetMapper(mapper)
337 actor.GetProperty().SetOpacity(self.opacity) 269 actor.GetProperty().SetOpacity(self.opacity)
@@ -343,9 +275,27 @@ class CursorRectangle: @@ -343,9 +275,27 @@ class CursorRectangle:
343 yc = 0 275 yc = 0
344 z = 0 276 z = 0
345 xs, ys, zs = self.spacing 277 xs, ys, zs = self.spacing
346 - orientation_based_spacing = {"AXIAL" : (xs, ys),  
347 - "SAGITAL" : (ys, zs),  
348 - "CORONAL" : (xs, zs)} 278 +
  279 + proj = Project()
  280 + orig_orien = proj.original_orientation
  281 +
  282 + xy = (xs, ys)
  283 + yz = (ys, zs)
  284 + xz = (xs, zs)
  285 +
  286 + if (orig_orien == const.SAGITAL):
  287 + orientation_based_spacing = {"SAGITAL" : xy,
  288 + "AXIAL" : yz,
  289 + "CORONAL" : xz}
  290 + elif(orig_orien == const.CORONAL):
  291 + orientation_based_spacing = {"CORONAL" : xy,
  292 + "AXIAL" : xz,
  293 + "SAGITAL" : yz}
  294 + else:
  295 + orientation_based_spacing = {"AXIAL" : xy,
  296 + "SAGITAL" : yz,
  297 + "CORONAL" : xz}
  298 +
349 xs, ys = orientation_based_spacing[self.orientation] 299 xs, ys = orientation_based_spacing[self.orientation]
350 self.pixel_list = [] 300 self.pixel_list = []
351 for i in utils.frange(yc - self.y_length/2, yc + self.y_length/2, ys): 301 for i in utils.frange(yc - self.y_length/2, yc + self.y_length/2, ys):
@@ -360,11 +310,24 @@ class CursorRectangle: @@ -360,11 +310,24 @@ class CursorRectangle:
360 px, py, pz = self.edition_position 310 px, py, pz = self.edition_position
361 orient = self.orientation 311 orient = self.orientation
362 xs, ys, zs = self.spacing 312 xs, ys, zs = self.spacing
363 - abs_pixel = {"AXIAL": lambda x,y: (px + x / xs, py+(y/ys), pz),  
364 - "CORONAL": lambda x,y: (px+(x/xs), py,  
365 - pz+(y/zs)),  
366 - "SAGITAL": lambda x,y: (px, py+(x/ys),  
367 - pz+(y/zs))} 313 + proj = Project()
  314 + orig_orien = proj.original_orientation
  315 + xy1 = lambda x,y: (px + x / xs, py+(y/ys), pz)
  316 + xy2 = lambda x,y: (px+(x/xs), py, pz+(y/zs))
  317 + xy3 = lambda x,y: (px, py+(x/ys), pz+(y/zs))
  318 +
  319 + if (orig_orien == const.SAGITAL):
  320 + abs_pixel = {"SAGITAL": xy1,
  321 + "AXIAL": xy2,
  322 + "CORONAL": xy3}
  323 + elif(orig_orien == const.CORONAL):
  324 + abs_pixel = {"CORONAL": xy1,
  325 + "SAGITAL": xy3,
  326 + "AXIAL": xy2}
  327 + else:
  328 + abs_pixel = {"AXIAL": xy1,
  329 + "CORONAL": xy2,
  330 + "SAGITAL": xy3}
368 function_orientation = abs_pixel[orient] 331 function_orientation = abs_pixel[orient]
369 for pixel_0,pixel_1 in self.pixel_list: 332 for pixel_0,pixel_1 in self.pixel_list:
370 # The position of the pixels in this list is relative (based only on 333 # The position of the pixels in this list is relative (based only on