Commit 4ad282869a0fb3ce665f68e81367fd6e31403b55
1 parent
be359ec4
Exists in
rotvol
It's already rotating
Showing
2 changed files
with
55 additions
and
8 deletions
Show diff stats
invesalius/data/slice_.py
invesalius/data/styles.py
... | ... | @@ -1421,6 +1421,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
1421 | 1421 | |
1422 | 1422 | self._over_center = False |
1423 | 1423 | self.dragging = False |
1424 | + self.to_rot = False | |
1424 | 1425 | |
1425 | 1426 | self.picker = vtk.vtkWorldPointPicker() |
1426 | 1427 | |
... | ... | @@ -1458,10 +1459,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
1458 | 1459 | rx += np.deg2rad(delta) |
1459 | 1460 | |
1460 | 1461 | self.viewer.slice_.rotations = (rx, ry, rz) |
1461 | - | |
1462 | - for buffer_ in self.viewer.slice_.buffer_slices.values(): | |
1463 | - buffer_.discard_vtk_image() | |
1464 | - buffer_.discard_image() | |
1462 | + self._discard_buffers() | |
1465 | 1463 | |
1466 | 1464 | self.viewer.slice_.current_mask.clear_history() |
1467 | 1465 | Publisher.sendMessage('Reload actual slice') |
... | ... | @@ -1469,9 +1467,29 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
1469 | 1467 | def OnLeftClick(self, obj, evt): |
1470 | 1468 | if self._over_center: |
1471 | 1469 | self.dragging = True |
1470 | + else: | |
1471 | + x, y = self.viewer.interactor.GetEventPosition() | |
1472 | + w, h = self.viewer.interactor.GetSize() | |
1473 | + | |
1474 | + self.picker.Pick(h/2.0, w/2.0, 0, self.viewer.slice_data.renderer) | |
1475 | + cx, cy, cz = self.viewer.slice_.center | |
1476 | + | |
1477 | + self.picker.Pick(x, y, 0, self.viewer.slice_data.renderer) | |
1478 | + x, y, z = self.picker.GetPickPosition() | |
1479 | + | |
1480 | + if self.viewer.orientation == 'AXIAL': | |
1481 | + self.p0 = np.array((y-cy, x-cx)) | |
1482 | + elif self.viewer.orientation == 'CORONAL': | |
1483 | + self.p0 = np.array((z-cz, x-cx)) | |
1484 | + elif self.viewer.orientation == 'SAGITAL': | |
1485 | + self.p0 = np.array((z-cz, y-cy)) | |
1486 | + | |
1487 | + self.to_rot = True | |
1488 | + | |
1472 | 1489 | |
1473 | 1490 | def OnLeftRelease(self, obj, evt): |
1474 | 1491 | self.dragging = False |
1492 | + self.to_rot = False | |
1475 | 1493 | |
1476 | 1494 | def OnMouseMove(self, obj, evt): |
1477 | 1495 | """ |
... | ... | @@ -1487,11 +1505,10 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
1487 | 1505 | coord.SetValue(center) |
1488 | 1506 | cx, cy = coord.GetComputedDisplayValue(self.viewer.slice_data.renderer) |
1489 | 1507 | |
1490 | - dist_center = ((mx - cx)**2 + (my - cy)**2)**0.5 | |
1508 | + self.picker.Pick(mx, my, 0, self.viewer.slice_data.renderer) | |
1509 | + x, y, z = self.picker.GetPickPosition() | |
1491 | 1510 | |
1492 | 1511 | if self.dragging: |
1493 | - self.picker.Pick(mx, my, 0, self.viewer.slice_data.renderer) | |
1494 | - x, y, z = self.picker.GetPickPosition() | |
1495 | 1512 | icx, icy, icz = self.viewer.slice_.center |
1496 | 1513 | |
1497 | 1514 | if self.viewer.orientation == 'AXIAL': |
... | ... | @@ -1502,7 +1519,32 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
1502 | 1519 | self.viewer.slice_.center = (icx, y, z) |
1503 | 1520 | Publisher.sendMessage('Update slice viewer') |
1504 | 1521 | |
1522 | + 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') | |
1505 | 1546 | else: |
1547 | + dist_center = ((mx - cx)**2 + (my - cy)**2)**0.5 | |
1506 | 1548 | if dist_center <= 15: |
1507 | 1549 | self._over_center = True |
1508 | 1550 | cursor = wx.StockCursor(wx.CURSOR_SIZENESW) |
... | ... | @@ -1567,6 +1609,11 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
1567 | 1609 | self.line2 = self._create_line(0.5, 0, 0.5, 1, color2) |
1568 | 1610 | |
1569 | 1611 | |
1612 | + def _discard_buffers(self): | |
1613 | + for buffer_ in self.viewer.slice_.buffer_slices.values(): | |
1614 | + buffer_.discard_vtk_image() | |
1615 | + buffer_.discard_image() | |
1616 | + | |
1570 | 1617 | def get_style(style): |
1571 | 1618 | STYLES = { |
1572 | 1619 | const.STATE_DEFAULT: DefaultInteractorStyle, | ... | ... |