Commit a39e606a8dbf1414b4333a0aa64555f8c1dc285a

Authored by Thiago Franco de Moraes
1 parent 5072564a
Exists in rotvol

Showing the cross

Showing 1 changed file with 57 additions and 0 deletions   Show diff stats
invesalius/data/styles.py
... ... @@ -1414,10 +1414,15 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
1414 1414  
1415 1415 self.viewer = viewer
1416 1416  
  1417 + self.line1 = None
  1418 + self.line2 = None
  1419 +
1417 1420 self.AddObserver("KeyPressEvent", self.OnKeyPress)
  1421 + self.viewer.slice_data.renderer.AddObserver("StartEvent", self.OnUpdate)
1418 1422  
1419 1423 def SetUp(self):
1420 1424 self.viewer.slice_.current_mask.is_shown = False
  1425 + self.draw_lines()
1421 1426 Publisher.sendMessage('Reload actual slice')
1422 1427  
1423 1428 def OnKeyPress(self, evt, obj):
... ... @@ -1447,6 +1452,58 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
1447 1452 self.viewer.slice_.current_mask.clear_history()
1448 1453 Publisher.sendMessage('Reload actual slice')
1449 1454  
  1455 + def OnUpdate(self, obj, evt):
  1456 + w, h = self.viewer.slice_data.renderer.GetSize()
  1457 +
  1458 + center = self.viewer.slice_data.actor.GetCenter()
  1459 + coord = vtk.vtkCoordinate()
  1460 + coord.SetValue(center)
  1461 + x, y = coord.GetComputedDisplayValue(self.viewer.slice_data.renderer)
  1462 +
  1463 + self.line1.SetPoint1(0, y, 0)
  1464 + self.line1.SetPoint2(w, y, 0)
  1465 + self.line1.Update()
  1466 +
  1467 + self.line2.SetPoint1(x, 0, 0)
  1468 + self.line2.SetPoint2(x, h, 0)
  1469 + self.line2.Update()
  1470 +
  1471 + def _create_line(self, x0, y0, x1, y1, color):
  1472 + line = vtk.vtkLineSource()
  1473 + line.SetPoint1(x0, y0, 0)
  1474 + line.SetPoint2(x1, y1, 0)
  1475 +
  1476 + coord = vtk.vtkCoordinate()
  1477 + coord.SetCoordinateSystemToDisplay()
  1478 +
  1479 + mapper = vtk.vtkPolyDataMapper2D()
  1480 + mapper.SetTransformCoordinate(coord)
  1481 + mapper.SetInputConnection(line.GetOutputPort())
  1482 + mapper.Update()
  1483 +
  1484 + actor = vtk.vtkActor2D()
  1485 + actor.SetMapper(mapper)
  1486 + actor.GetProperty().SetLineWidth(2.0)
  1487 + actor.GetProperty().SetColor(color)
  1488 +
  1489 + self.viewer.slice_data.renderer.AddActor(actor)
  1490 +
  1491 + return line
  1492 +
  1493 + def draw_lines(self):
  1494 + if self.viewer.orientation == 'AXIAL':
  1495 + color1 = (0, 1, 0)
  1496 + color2 = (0, 0, 1)
  1497 + elif self.viewer.orientation == 'CORONAL':
  1498 + color1 = (1, 0, 0)
  1499 + color2 = (0, 0, 1)
  1500 + elif self.viewer.orientation == 'SAGITAL':
  1501 + color1 = (1, 0, 0)
  1502 + color2 = (0, 1, 0)
  1503 +
  1504 + self.line1 = self._create_line(0, 0.5, 1, 0.5, color1)
  1505 + self.line2 = self._create_line(0.5, 0, 0.5, 1, color2)
  1506 +
1450 1507  
1451 1508 def get_style(style):
1452 1509 STYLES = {
... ...