Commit 94e17db75ad08fd522d76c4c7e6e7ccaade50f2c

Authored by Thiago Franco de Moraes
1 parent 39603f52
Exists in rotvol

Starting to show reoriented image

invesalius/constants.py
... ... @@ -494,16 +494,18 @@ SLICE_STATE_CROSS = 3006
494 494 SLICE_STATE_SCROLL = 3007
495 495 SLICE_STATE_EDITOR = 3008
496 496 SLICE_STATE_WATERSHED = 3009
  497 +SLICE_STATE_REORIENT = 3010
497 498  
498 499 VOLUME_STATE_SEED = 2001
499   -#STATE_LINEAR_MEASURE = 3001
500   -#STATE_ANGULAR_MEASURE = 3002
  500 +# STATE_LINEAR_MEASURE = 3001
  501 +# STATE_ANGULAR_MEASURE = 3002
501 502  
502 503 TOOL_STATES = [STATE_WL, STATE_SPIN, STATE_ZOOM,
503 504 STATE_ZOOM_SL, STATE_PAN, STATE_MEASURE_DISTANCE,
504   - STATE_MEASURE_ANGLE]#, STATE_ANNOTATE]
  505 + STATE_MEASURE_ANGLE] #, STATE_ANNOTATE]
505 506  
506   -TOOL_SLICE_STATES = [SLICE_STATE_CROSS, SLICE_STATE_SCROLL]
  507 +TOOL_SLICE_STATES = [SLICE_STATE_CROSS, SLICE_STATE_SCROLL,
  508 + SLICE_STATE_REORIENT]
507 509  
508 510  
509 511 SLICE_STYLES = TOOL_STATES + TOOL_SLICE_STATES
... ... @@ -520,6 +522,7 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1,
520 522 SLICE_STATE_WATERSHED: 1,
521 523 SLICE_STATE_CROSS: 2,
522 524 SLICE_STATE_SCROLL: 2,
  525 + SLICE_STATE_REORIENT: 2,
523 526 STATE_ANNOTATE: 2,
524 527 STATE_DEFAULT: 0,
525 528 STATE_MEASURE_ANGLE: 2,
... ...
invesalius/data/slice_.py
... ... @@ -584,7 +584,7 @@ class Slice(object):
584 584 if orientation == 'AXIAL':
585 585 tmp_array = np.array(self.matrix[slice_number:slice_number + number_slices])
586 586 if np.any(self.rotations):
587   - transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, 1, self.matrix.min(), tmp_array)
  587 + transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, 2, self.matrix.min(), tmp_array)
588 588 if self._type_projection == const.PROJECTION_NORMAL:
589 589 n_image = tmp_array.squeeze()
590 590 else:
... ...
invesalius/data/styles.py
... ... @@ -1405,6 +1405,46 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1405 1405 session.ChangeProject()
1406 1406  
1407 1407  
  1408 +class ReorientImageInteractorStyle(DefaultInteractorStyle):
  1409 + """
  1410 + Interactor style responsible for image reorientation
  1411 + """
  1412 + def __init__(self, viewer):
  1413 + DefaultInteractorStyle.__init__(self, viewer)
  1414 +
  1415 + self.viewer = viewer
  1416 +
  1417 + self.AddObserver("KeyPressEvent", self.OnKeyPress)
  1418 +
  1419 + def SetUp(self):
  1420 + self.viewer.slice_.current_mask.is_shown = False
  1421 + Publisher.sendMessage('Reload actual slice')
  1422 +
  1423 + def OnKeyPress(self, evt, obj):
  1424 + key = self.viewer.interactor.GetKeyCode()
  1425 + if key == '+':
  1426 + delta = 1
  1427 + elif key == '-':
  1428 + delta = -1
  1429 + else:
  1430 + return
  1431 +
  1432 + rx, ry, rz = self.viewer.slice_.rotations
  1433 + orientation = self.viewer.orientation
  1434 + if orientation == 'AXIAL':
  1435 + rz += np.deg2rad(delta)
  1436 + elif orientation == 'CORONAL':
  1437 + ry += np.deg2rad(delta)
  1438 + elif orientation == 'SAGITAL':
  1439 + rx += np.deg2rad(delta)
  1440 +
  1441 + self.viewer.slice_.rotations = (rx, ry, rz)
  1442 +
  1443 + self.viewer.slice_.discard_all_buffers()
  1444 + self.viewer.slice_.current_mask.clear_history()
  1445 + Publisher.sendMessage('Reload actual slice')
  1446 +
  1447 +
1408 1448 def get_style(style):
1409 1449 STYLES = {
1410 1450 const.STATE_DEFAULT: DefaultInteractorStyle,
... ... @@ -1419,5 +1459,6 @@ def get_style(style):
1419 1459 const.SLICE_STATE_SCROLL: ChangeSliceInteractorStyle,
1420 1460 const.SLICE_STATE_EDITOR: EditorInteractorStyle,
1421 1461 const.SLICE_STATE_WATERSHED: WaterShedInteractorStyle,
  1462 + const.SLICE_STATE_REORIENT: ReorientImageInteractorStyle,
1422 1463 }
1423 1464 return STYLES[style]
... ...
invesalius/gui/frame.py
... ... @@ -1278,7 +1278,8 @@ class SliceToolBar(AuiToolBar):
1278 1278  
1279 1279 self.parent = parent
1280 1280 self.enable_items = [const.SLICE_STATE_SCROLL,
1281   - const.SLICE_STATE_CROSS]
  1281 + const.SLICE_STATE_CROSS,
  1282 + const.SLICE_STATE_REORIENT]
1282 1283 self.__init_items()
1283 1284 self.__bind_events()
1284 1285 self.__bind_events_wx()
... ... @@ -1297,6 +1298,9 @@ class SliceToolBar(AuiToolBar):
1297 1298  
1298 1299 path = os.path.join(d,"cross_original.png")
1299 1300 BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
  1301 +
  1302 + path = os.path.join(d, "tool_rotate_original.png")
  1303 + BMP_REORIENT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
1300 1304 else:
1301 1305 path = os.path.join(d, "slice.png")
1302 1306 BMP_SLICE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
... ... @@ -1304,6 +1308,9 @@ class SliceToolBar(AuiToolBar):
1304 1308 path = os.path.join(d,"cross.png")
1305 1309 BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
1306 1310  
  1311 + path = os.path.join(d, "tool_rotate.png")
  1312 + BMP_REORIENT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
  1313 +
1307 1314 self.sst = self.AddToggleTool(const.SLICE_STATE_SCROLL,
1308 1315 BMP_SLICE,#, kind=wx.ITEM_CHECK)
1309 1316 wx.NullBitmap,
... ... @@ -1316,6 +1323,12 @@ class SliceToolBar(AuiToolBar):
1316 1323 toggle=True,
1317 1324 short_help_string=_("Slices' cross intersection"))
1318 1325  
  1326 + self.srt = self.AddToggleTool(const.SLICE_STATE_REORIENT,
  1327 + BMP_REORIENT,#, kind=wx.ITEM_CHECK)
  1328 + wx.NullBitmap,
  1329 + toggle=True,
  1330 + short_help_string=_("Reorient slices"))
  1331 +
1319 1332 def __bind_events(self):
1320 1333 """
1321 1334 Bind events related to pubsub.
... ...