Commit 99ace3657104bd1793b7d0b35f4e2e9323902e6f
1 parent
d1963727
Exists in
master
and in
6 other branches
STYLE: Cosmetical changes:
* Using underscore (_) instead of CamelCase to methods and variables * Removed duplicated blank lines * Lines smaller than 69 * space after commas
Showing
1 changed file
with
44 additions
and
34 deletions
Show diff stats
invesalius/data/viewer_slice.py
@@ -37,12 +37,14 @@ class Viewer(wx.Panel): | @@ -37,12 +37,14 @@ class Viewer(wx.Panel): | ||
37 | colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]] | 37 | colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]] |
38 | self.SetBackgroundColour(colour) | 38 | self.SetBackgroundColour(colour) |
39 | 39 | ||
40 | - # Interactor aditional style | 40 | + # Interactor additional style |
41 | self.modes = []#['DEFAULT'] | 41 | self.modes = []#['DEFAULT'] |
42 | self.mouse_pressed = 0 | 42 | self.mouse_pressed = 0 |
43 | 43 | ||
44 | # All renderers and image actors in this viewer | 44 | # All renderers and image actors in this viewer |
45 | self.image_windows = [] | 45 | self.image_windows = [] |
46 | + # The layout from image_window, the first is number of cols, the second | ||
47 | + # is the number of rows | ||
46 | self.layout = (2, 2) | 48 | self.layout = (2, 2) |
47 | 49 | ||
48 | self.__init_gui() | 50 | self.__init_gui() |
@@ -95,7 +97,7 @@ class Viewer(wx.Panel): | @@ -95,7 +97,7 @@ class Viewer(wx.Panel): | ||
95 | self.ren = ren | 97 | self.ren = ren |
96 | 98 | ||
97 | 99 | ||
98 | - def AppendMode(self, mode): | 100 | + def append_mode(self, mode): |
99 | 101 | ||
100 | # Retrieve currently set modes | 102 | # Retrieve currently set modes |
101 | self.modes.append(mode) | 103 | self.modes.append(mode) |
@@ -159,7 +161,7 @@ class Viewer(wx.Panel): | @@ -159,7 +161,7 @@ class Viewer(wx.Panel): | ||
159 | cursor = ca.CursorCircle() | 161 | cursor = ca.CursorCircle() |
160 | self.cursor = cursor | 162 | self.cursor = cursor |
161 | 163 | ||
162 | - cursor.SetOrientation(self.orientation) | 164 | + cursor.set_orientation(self.orientation) |
163 | coordinates = {"SAGITAL": [self.slice_number, 0, 0], | 165 | coordinates = {"SAGITAL": [self.slice_number, 0, 0], |
164 | "CORONAL": [0, self.slice_number, 0], | 166 | "CORONAL": [0, self.slice_number, 0], |
165 | "AXIAL": [0, 0, self.slice_number]} | 167 | "AXIAL": [0, 0, self.slice_number]} |
@@ -187,9 +189,10 @@ class Viewer(wx.Panel): | @@ -187,9 +189,10 @@ class Viewer(wx.Panel): | ||
187 | image_window = self.get_image_window(render) | 189 | image_window = self.get_image_window(render) |
188 | self.pick.Pick(mouse_x, mouse_y, 0, render) | 190 | self.pick.Pick(mouse_x, mouse_y, 0, render) |
189 | 191 | ||
190 | - coord = self.GetCoordinateCursor() | 192 | + coord = self.get_coordinate_cursor() |
191 | self.cursor.SetPosition(coord) | 193 | self.cursor.SetPosition(coord) |
192 | - self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition(image_window)) | 194 | + self.cursor.SetEditionPosition( |
195 | + self.get_coordinate_cursor_edition(image_window)) | ||
193 | self.__update_cursor_position(coord) | 196 | self.__update_cursor_position(coord) |
194 | #render.Render() | 197 | #render.Render() |
195 | 198 | ||
@@ -198,7 +201,7 @@ class Viewer(wx.Panel): | @@ -198,7 +201,7 @@ class Viewer(wx.Panel): | ||
198 | const.BRUSH_THRESH: 'Edit mask pixel'} | 201 | const.BRUSH_THRESH: 'Edit mask pixel'} |
199 | msg = evt_msg[self._brush_cursor_op] | 202 | msg = evt_msg[self._brush_cursor_op] |
200 | 203 | ||
201 | - pixels = itertools.ifilter(self.TestOperationPosition, | 204 | + pixels = itertools.ifilter(self.test_operation_position, |
202 | self.cursor.GetPixels()) | 205 | self.cursor.GetPixels()) |
203 | ps.Publisher().sendMessage(msg, pixels) | 206 | ps.Publisher().sendMessage(msg, pixels) |
204 | 207 | ||
@@ -212,9 +215,10 @@ class Viewer(wx.Panel): | @@ -212,9 +215,10 @@ class Viewer(wx.Panel): | ||
212 | render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) | 215 | render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) |
213 | image_window = self.get_image_window(render) | 216 | image_window = self.get_image_window(render) |
214 | self.pick.Pick(mouse_x, mouse_y, 0, render) | 217 | self.pick.Pick(mouse_x, mouse_y, 0, render) |
215 | - coord = self.GetCoordinateCursor() | 218 | + coord = self.get_coordinate_cursor() |
216 | self.cursor.SetPosition(coord) | 219 | self.cursor.SetPosition(coord) |
217 | - self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition(image_window)) | 220 | + self.cursor.SetEditionPosition( |
221 | + self.get_coordinate_cursor_edition(image_window)) | ||
218 | self.__update_cursor_position(coord) | 222 | self.__update_cursor_position(coord) |
219 | 223 | ||
220 | if self._brush_cursor_op == const.BRUSH_ERASE: | 224 | if self._brush_cursor_op == const.BRUSH_ERASE: |
@@ -225,7 +229,7 @@ class Viewer(wx.Panel): | @@ -225,7 +229,7 @@ class Viewer(wx.Panel): | ||
225 | evt_msg = 'Edit mask pixel' | 229 | evt_msg = 'Edit mask pixel' |
226 | 230 | ||
227 | if self.mouse_pressed: | 231 | if self.mouse_pressed: |
228 | - pixels = itertools.ifilter(self.TestOperationPosition, | 232 | + pixels = itertools.ifilter(self.test_operation_position, |
229 | self.cursor.GetPixels()) | 233 | self.cursor.GetPixels()) |
230 | ps.Publisher().sendMessage(evt_msg, pixels) | 234 | ps.Publisher().sendMessage(evt_msg, pixels) |
231 | ps.Publisher().sendMessage('Update slice viewer') | 235 | ps.Publisher().sendMessage('Update slice viewer') |
@@ -233,7 +237,7 @@ class Viewer(wx.Panel): | @@ -233,7 +237,7 @@ class Viewer(wx.Panel): | ||
233 | self.interactor.Render() | 237 | self.interactor.Render() |
234 | 238 | ||
235 | def OnCrossMove(self, obj, evt_vtk): | 239 | def OnCrossMove(self, obj, evt_vtk): |
236 | - coord = self.GetCoordinate() | 240 | + coord = self.get_coordinate() |
237 | # Update position in other slices | 241 | # Update position in other slices |
238 | if self.mouse_pressed: | 242 | if self.mouse_pressed: |
239 | ps.Publisher().sendMessage('Update cursor position in slice', | 243 | ps.Publisher().sendMessage('Update cursor position in slice', |
@@ -250,7 +254,7 @@ class Viewer(wx.Panel): | @@ -250,7 +254,7 @@ class Viewer(wx.Panel): | ||
250 | if i[0] is render: | 254 | if i[0] is render: |
251 | return i | 255 | return i |
252 | 256 | ||
253 | - def GetCoordinate(self): | 257 | + def get_coordinate(self): |
254 | # Find position | 258 | # Find position |
255 | x, y, z = self.pick.GetPickPosition() | 259 | x, y, z = self.pick.GetPickPosition() |
256 | 260 | ||
@@ -288,12 +292,12 @@ class Viewer(wx.Panel): | @@ -288,12 +292,12 @@ class Viewer(wx.Panel): | ||
288 | 292 | ||
289 | return coord | 293 | return coord |
290 | 294 | ||
291 | - def GetCoordinateCursor(self): | 295 | + def get_coordinate_cursor(self): |
292 | # Find position | 296 | # Find position |
293 | x, y, z = self.pick.GetPickPosition() | 297 | x, y, z = self.pick.GetPickPosition() |
294 | return x, y, z | 298 | return x, y, z |
295 | 299 | ||
296 | - def GetCoordinateCursorEdition(self, image_window): | 300 | + def get_coordinate_cursor_edition(self, image_window): |
297 | # Find position | 301 | # Find position |
298 | actor, slice_number = image_window[1::] | 302 | actor, slice_number = image_window[1::] |
299 | x, y, z = self.pick.GetPickPosition() | 303 | x, y, z = self.pick.GetPickPosition() |
@@ -305,7 +309,7 @@ class Viewer(wx.Panel): | @@ -305,7 +309,7 @@ class Viewer(wx.Panel): | ||
305 | y = float(y - bound_yi) | 309 | y = float(y - bound_yi) |
306 | z = float(z - bound_zi) | 310 | z = float(z - bound_zi) |
307 | 311 | ||
308 | - dx = bound_xf - bound_xi; | 312 | + dx = bound_xf - bound_xi |
309 | dy = bound_yf - bound_yi | 313 | dy = bound_yf - bound_yi |
310 | dz = bound_zf - bound_zi | 314 | dz = bound_zf - bound_zi |
311 | 315 | ||
@@ -324,21 +328,27 @@ class Viewer(wx.Panel): | @@ -324,21 +328,27 @@ class Viewer(wx.Panel): | ||
324 | except ZeroDivisionError: | 328 | except ZeroDivisionError: |
325 | z = slice_number | 329 | z = slice_number |
326 | 330 | ||
327 | - return x,y,z | 331 | + return x, y, z |
328 | 332 | ||
329 | def __bind_events(self): | 333 | def __bind_events(self): |
330 | - ps.Publisher().subscribe(self.LoadImagedata, 'Load slice to viewer') | ||
331 | - ps.Publisher().subscribe(self.SetBrushColour, 'Change mask colour') | ||
332 | - ps.Publisher().subscribe(self.UpdateRender, 'Update slice viewer') | ||
333 | - ps.Publisher().subscribe(self.ChangeSliceNumber, ('Set scroll position', | ||
334 | - self.orientation)) | ||
335 | - | 334 | + ps.Publisher().subscribe(self.LoadImagedata, |
335 | + 'Load slice to viewer') | ||
336 | + ps.Publisher().subscribe(self.SetBrushColour, | ||
337 | + 'Change mask colour') | ||
338 | + ps.Publisher().subscribe(self.UpdateRender, | ||
339 | + 'Update slice viewer') | ||
340 | + ps.Publisher().subscribe(self.ChangeSliceNumber, | ||
341 | + ('Set scroll position', | ||
342 | + self.orientation)) | ||
336 | ### | 343 | ### |
337 | - ps.Publisher().subscribe(self.ChangeBrushSize,'Set edition brush size') | ||
338 | - ps.Publisher().subscribe(self.ChangeBrushColour, 'Add mask') | ||
339 | - ps.Publisher().subscribe(self.ChangeBrushActor, 'Set brush format') | ||
340 | - ps.Publisher().subscribe(self.ChangeBrushOperation, 'Set edition operation') | ||
341 | - | 344 | + ps.Publisher().subscribe(self.ChangeBrushSize, |
345 | + 'Set edition brush size') | ||
346 | + ps.Publisher().subscribe(self.ChangeBrushColour, | ||
347 | + 'Add mask') | ||
348 | + ps.Publisher().subscribe(self.ChangeBrushActor, | ||
349 | + 'Set brush format') | ||
350 | + ps.Publisher().subscribe(self.ChangeBrushOperation, | ||
351 | + 'Set edition operation') | ||
342 | 352 | ||
343 | def ChangeBrushOperation(self, pubsub_evt): | 353 | def ChangeBrushOperation(self, pubsub_evt): |
344 | print pubsub_evt.data | 354 | print pubsub_evt.data |
@@ -408,7 +418,7 @@ class Viewer(wx.Panel): | @@ -408,7 +418,7 @@ class Viewer(wx.Panel): | ||
408 | (self.layout[0] * self.layout[1]) | 418 | (self.layout[0] * self.layout[1]) |
409 | self.scroll.SetScrollbar(wx.SB_VERTICAL, 1, max_slice_number, | 419 | self.scroll.SetScrollbar(wx.SB_VERTICAL, 1, max_slice_number, |
410 | max_slice_number) | 420 | max_slice_number) |
411 | - self.SetScrollPosition(0) | 421 | + self.set_scroll_position(0) |
412 | 422 | ||
413 | actor_bound = actor.GetBounds() | 423 | actor_bound = actor.GetBounds() |
414 | 424 | ||
@@ -423,7 +433,7 @@ class Viewer(wx.Panel): | @@ -423,7 +433,7 @@ class Viewer(wx.Panel): | ||
423 | 433 | ||
424 | self.cursor = cursor | 434 | self.cursor = cursor |
425 | 435 | ||
426 | - self.AppendMode('EDITOR') | 436 | + self.append_mode('EDITOR') |
427 | 437 | ||
428 | def __update_cursor_position(self, position): | 438 | def __update_cursor_position(self, position): |
429 | x, y, z = position | 439 | x, y, z = position |
@@ -435,7 +445,7 @@ class Viewer(wx.Panel): | @@ -435,7 +445,7 @@ class Viewer(wx.Panel): | ||
435 | "AXIAL": [x, y, actor_bound[5] + 1 + slice_number]} | 445 | "AXIAL": [x, y, actor_bound[5] + 1 + slice_number]} |
436 | self.cursor.SetPosition(coordinates[self.orientation]) | 446 | self.cursor.SetPosition(coordinates[self.orientation]) |
437 | 447 | ||
438 | - def SetOrientation(self, orientation): | 448 | + def set_orientation(self, orientation): |
439 | self.orientation = orientation | 449 | self.orientation = orientation |
440 | for ren, actor, n in self.image_windows: | 450 | for ren, actor, n in self.image_windows: |
441 | self.__update_camera(ren, actor, n) | 451 | self.__update_camera(ren, actor, n) |
@@ -478,13 +488,13 @@ class Viewer(wx.Panel): | @@ -478,13 +488,13 @@ class Viewer(wx.Panel): | ||
478 | def UpdateRender(self, evt): | 488 | def UpdateRender(self, evt): |
479 | self.interactor.Render() | 489 | self.interactor.Render() |
480 | 490 | ||
481 | - def SetScrollPosition(self, position): | 491 | + def set_scroll_position(self, position): |
482 | self.scroll.SetThumbPosition(position) | 492 | self.scroll.SetThumbPosition(position) |
483 | self.OnScrollBar() | 493 | self.OnScrollBar() |
484 | 494 | ||
485 | def OnScrollBar(self, evt=None): | 495 | def OnScrollBar(self, evt=None): |
486 | pos = self.scroll.GetThumbPosition() | 496 | pos = self.scroll.GetThumbPosition() |
487 | - self.SetSliceNumber(pos) | 497 | + self.set_slice_number(pos) |
488 | self.interactor.Render() | 498 | self.interactor.Render() |
489 | if evt: | 499 | if evt: |
490 | evt.Skip() | 500 | evt.Skip() |
@@ -507,7 +517,7 @@ class Viewer(wx.Panel): | @@ -507,7 +517,7 @@ class Viewer(wx.Panel): | ||
507 | if evt: | 517 | if evt: |
508 | evt.Skip() | 518 | evt.Skip() |
509 | 519 | ||
510 | - def SetSliceNumber(self, index): | 520 | + def set_slice_number(self, index): |
511 | self.text_actor.SetInput(str(index)) | 521 | self.text_actor.SetInput(str(index)) |
512 | self.slice_number = index | 522 | self.slice_number = index |
513 | for n, window in enumerate(self.image_windows): | 523 | for n, window in enumerate(self.image_windows): |
@@ -528,11 +538,11 @@ class Viewer(wx.Panel): | @@ -528,11 +538,11 @@ class Viewer(wx.Panel): | ||
528 | 538 | ||
529 | def ChangeSliceNumber(self, pubsub_evt): | 539 | def ChangeSliceNumber(self, pubsub_evt): |
530 | index = pubsub_evt.data | 540 | index = pubsub_evt.data |
531 | - self.SetSliceNumber(index) | 541 | + self.set_slice_number(index) |
532 | self.scroll.SetThumbPosition(index) | 542 | self.scroll.SetThumbPosition(index) |
533 | self.interactor.Render() | 543 | self.interactor.Render() |
534 | 544 | ||
535 | - def TestOperationPosition(self, coord): | 545 | + def test_operation_position(self, coord): |
536 | """ | 546 | """ |
537 | Test if coord is into the imagedata limits. | 547 | Test if coord is into the imagedata limits. |
538 | """ | 548 | """ |