Commit 64eec96aa2a3767b7e96b99df4d16f496d8b86b3

Authored by Thiago Franco de Moraes
1 parent 4ad28286
Exists in rotvol

Improvements

Showing 1 changed file with 73 additions and 45 deletions   Show diff stats
invesalius/data/styles.py
@@ -1431,6 +1431,8 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): @@ -1431,6 +1431,8 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
1431 self.AddObserver("MouseMoveEvent", self.OnMouseMove) 1431 self.AddObserver("MouseMoveEvent", self.OnMouseMove)
1432 self.viewer.slice_data.renderer.AddObserver("StartEvent", self.OnUpdate) 1432 self.viewer.slice_data.renderer.AddObserver("StartEvent", self.OnUpdate)
1433 1433
  1434 + self.viewer.interactor.Bind(wx.EVT_LEFT_DCLICK, self.OnDblClick)
  1435 +
1434 def SetUp(self): 1436 def SetUp(self):
1435 self.viewer.slice_.current_mask.is_shown = False 1437 self.viewer.slice_.current_mask.is_shown = False
1436 self.draw_lines() 1438 self.draw_lines()
@@ -1495,55 +1497,22 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): @@ -1495,55 +1497,22 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
1495 """ 1497 """
1496 This event is responsible to reorient image, set mouse cursors 1498 This event is responsible to reorient image, set mouse cursors
1497 """ 1499 """
1498 - # Getting mouse position  
1499 - iren = self.viewer.interactor  
1500 - mx, my = iren.GetEventPosition()  
1501 -  
1502 - # Getting center value  
1503 - center = self.viewer.slice_.center  
1504 - coord = vtk.vtkCoordinate()  
1505 - coord.SetValue(center)  
1506 - cx, cy = coord.GetComputedDisplayValue(self.viewer.slice_data.renderer)  
1507 -  
1508 - self.picker.Pick(mx, my, 0, self.viewer.slice_data.renderer)  
1509 - x, y, z = self.picker.GetPickPosition()  
1510 1500
1511 if self.dragging: 1501 if self.dragging:
1512 - icx, icy, icz = self.viewer.slice_.center  
1513 -  
1514 - if self.viewer.orientation == 'AXIAL':  
1515 - self.viewer.slice_.center = (x, y, icz)  
1516 - elif self.viewer.orientation == 'CORONAL':  
1517 - self.viewer.slice_.center = (x, icy, z)  
1518 - elif self.viewer.orientation == 'SAGITAL':  
1519 - self.viewer.slice_.center = (icx, y, z)  
1520 - Publisher.sendMessage('Update slice viewer')  
1521 - 1502 + self._move_center_rot()
1522 elif self.to_rot: 1503 elif self.to_rot:
1523 - cx, cy, cz = self.viewer.slice_.center  
1524 - # x, y, z = self.picker.GetPickPosition()  
1525 - if self.viewer.orientation == 'AXIAL':  
1526 - p1 = np.array((y-cy, x-cx))  
1527 - elif self.viewer.orientation == 'CORONAL':  
1528 - p1 = np.array((z-cz, x-cx))  
1529 - elif self.viewer.orientation == 'SAGITAL':  
1530 - p1 = np.array((z-cz, y-cy))  
1531 - p0 = self.p0  
1532 -  
1533 - if self.viewer.orientation == 'AXIAL':  
1534 - angle = np.arctan2(p0[0] , p0[1]) - np.arctan2(p1[0], p1[1])  
1535 - self.viewer.slice_.rotations[2] = angle  
1536 - elif self.viewer.orientation == 'CORONAL':  
1537 - angle = np.arctan2(p0[0] , p0[1]) - np.arctan2(p1[0], p1[1])  
1538 - self.viewer.slice_.rotations[1] = angle  
1539 - elif self.viewer.orientation == 'SAGITAL':  
1540 - angle = np.arctan2(p0[0] , p0[1]) - np.arctan2(p1[0], p1[1])  
1541 - self.viewer.slice_.rotations[0] = angle  
1542 - self._discard_buffers()  
1543 - self.viewer.slice_.current_mask.clear_history()  
1544 - Publisher.sendMessage('Reload actual slice')  
1545 - Publisher.sendMessage('Update slice viewer') 1504 + self._rotate()
1546 else: 1505 else:
  1506 + # Getting mouse position
  1507 + iren = self.viewer.interactor
  1508 + mx, my = iren.GetEventPosition()
  1509 +
  1510 + # Getting center value
  1511 + center = self.viewer.slice_.center
  1512 + coord = vtk.vtkCoordinate()
  1513 + coord.SetValue(center)
  1514 + cx, cy = coord.GetComputedDisplayValue(self.viewer.slice_data.renderer)
  1515 +
1547 dist_center = ((mx - cx)**2 + (my - cy)**2)**0.5 1516 dist_center = ((mx - cx)**2 + (my - cy)**2)**0.5
1548 if dist_center <= 15: 1517 if dist_center <= 15:
1549 self._over_center = True 1518 self._over_center = True
@@ -1570,6 +1539,64 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): @@ -1570,6 +1539,64 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
1570 self.line2.SetPoint2(x, h, 0) 1539 self.line2.SetPoint2(x, h, 0)
1571 self.line2.Update() 1540 self.line2.Update()
1572 1541
  1542 + def OnDblClick(self, evt):
  1543 + self.viewer.slice_.rotations = [0, 0, 0]
  1544 + self._discard_buffers()
  1545 + self.viewer.slice_.current_mask.clear_history()
  1546 + Publisher.sendMessage('Reload actual slice')
  1547 +
  1548 + def _move_center_rot(self):
  1549 + iren = self.viewer.interactor
  1550 + mx, my = iren.GetEventPosition()
  1551 +
  1552 + icx, icy, icz = self.viewer.slice_.center
  1553 +
  1554 + self.picker.Pick(mx, my, 0, self.viewer.slice_data.renderer)
  1555 + x, y, z = self.picker.GetPickPosition()
  1556 +
  1557 + if self.viewer.orientation == 'AXIAL':
  1558 + self.viewer.slice_.center = (x, y, icz)
  1559 + elif self.viewer.orientation == 'CORONAL':
  1560 + self.viewer.slice_.center = (x, icy, z)
  1561 + elif self.viewer.orientation == 'SAGITAL':
  1562 + self.viewer.slice_.center = (icx, y, z)
  1563 +
  1564 + self._discard_buffers()
  1565 + self.viewer.slice_.current_mask.clear_history()
  1566 + Publisher.sendMessage('Reload actual slice')
  1567 +
  1568 + def _rotate(self):
  1569 + # Getting mouse position
  1570 + iren = self.viewer.interactor
  1571 + mx, my = iren.GetEventPosition()
  1572 +
  1573 + cx, cy, cz = self.viewer.slice_.center
  1574 +
  1575 + self.picker.Pick(mx, my, 0, self.viewer.slice_data.renderer)
  1576 + x, y, z = self.picker.GetPickPosition()
  1577 +
  1578 + if self.viewer.orientation == 'AXIAL':
  1579 + p1 = np.array((y-cy, x-cx))
  1580 + elif self.viewer.orientation == 'CORONAL':
  1581 + p1 = np.array((z-cz, x-cx))
  1582 + elif self.viewer.orientation == 'SAGITAL':
  1583 + p1 = np.array((z-cz, y-cy))
  1584 + p0 = self.p0
  1585 +
  1586 + if self.viewer.orientation == 'AXIAL':
  1587 + angle = np.arctan2(p0[0] , p0[1]) - np.arctan2(p1[0], p1[1])
  1588 + self.viewer.slice_.rotations[2] = angle
  1589 + elif self.viewer.orientation == 'CORONAL':
  1590 + angle = np.arctan2(p0[0] , p0[1]) - np.arctan2(p1[0], p1[1])
  1591 + self.viewer.slice_.rotations[1] = angle
  1592 + elif self.viewer.orientation == 'SAGITAL':
  1593 + angle = np.arctan2(p0[0] , p0[1]) - np.arctan2(p1[0], p1[1])
  1594 + self.viewer.slice_.rotations[0] = angle
  1595 +
  1596 + self._discard_buffers()
  1597 + self.viewer.slice_.current_mask.clear_history()
  1598 + Publisher.sendMessage('Reload actual slice')
  1599 +
1573 def _create_line(self, x0, y0, x1, y1, color): 1600 def _create_line(self, x0, y0, x1, y1, color):
1574 line = vtk.vtkLineSource() 1601 line = vtk.vtkLineSource()
1575 line.SetPoint1(x0, y0, 0) 1602 line.SetPoint1(x0, y0, 0)
@@ -1587,6 +1614,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): @@ -1587,6 +1614,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
1587 actor.SetMapper(mapper) 1614 actor.SetMapper(mapper)
1588 actor.GetProperty().SetLineWidth(2.0) 1615 actor.GetProperty().SetLineWidth(2.0)
1589 actor.GetProperty().SetColor(color) 1616 actor.GetProperty().SetColor(color)
  1617 + actor.GetProperty().SetOpacity(0.5)
1590 1618
1591 self.viewer.slice_data.renderer.AddActor(actor) 1619 self.viewer.slice_data.renderer.AddActor(actor)
1592 1620