Skip to content

Commit

Permalink
feat(eyelab): add redo/undo framework for layer editing
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli4 committed Jun 3, 2022
1 parent ffe7148 commit 6436e4d
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 102 deletions.
3 changes: 2 additions & 1 deletion eyelab/commands/layeritem.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __init__(self, knot: QGraphicsItem, new_pos: QPointF, optimize_neighbours=Tr
left_neighbours,
right_neighbours,
) = self.bspline.layer_item.get_neighbour_polygons(self.bspline)

if self.knot is self.bspline.knots[-1] and right_neighbours:
for n in right_neighbours:
# Find the closest neighbour that is not covered after the move
Expand Down Expand Up @@ -620,7 +621,7 @@ def mergeWith(self, other: QUndoCommand) -> bool:
return True


class NewCurve(QUndoCommand):
class AddCurve(QUndoCommand):
def __init__(self, layer_item: "layeritem.LayerItem", pos: QPointF):
self.layeritem = layer_item

Expand Down
3 changes: 2 additions & 1 deletion eyelab/models/treeview/areaitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(

self.setFlag(QtWidgets.QGraphicsItem.ItemIsPanel)

def sync_with_volume(self):
def update(self):
self.setVisible(self.annotation_data.meta["visible"])
self.setZValue(self.annotation_data.meta["z_value"])

Expand All @@ -42,6 +42,7 @@ def sync_with_volume(self):
[color.red(), color.green(), color.blue()]
)
self.update_pixmap()
super().update()

def shape(self) -> QtGui.QPainterPath:
path = QtGui.QPainterPath()
Expand Down
2 changes: 1 addition & 1 deletion eyelab/models/treeview/itemmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def __init__(self, data: ep.EyeVolume, parent):

self._scenes = {}

def duplicate(self, index: QtCore.QModelIndex):
def duplicate_volume(self, index: QtCore.QModelIndex):
annotation = index.internalPointer().annotation
name = annotation.name
data = annotation.data
Expand Down
22 changes: 20 additions & 2 deletions eyelab/models/treeview/layeritem.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,28 @@ def _get_points(self):
points.append(self._start)

if self._end is None:
end_index = len(self.heights) - 1
end_index = len(self.heights)
else:
end_index = int(np.ceil(self._end.x()))

# Make sure there are no Nans between start and stop - interpolate
if any(np.isnan(self.heights[start_index:end_index])):
x = np.arange(start_index, end_index, dtype=int)
x_full = x[~np.isnan(self.heights[x])]
x_empty = x[np.isnan(self.heights[x])]
if len(x_full) > 1:
f = interp1d(
x_full,
self.heights[x_full],
assume_sorted=True,
copy=False,
bounds_error=False,
fill_value="extrapolate",
)
# Get height for the middle of each pixel
y = f(x_empty + 0.5)
self.heights[x_empty] = y

for i in range(start_index, end_index):
# +0.5 for points to sit in the middle and not start of each pixel (in x direction)
points.append(QPointF(i + 0.5, self.heights[i]))
Expand Down Expand Up @@ -840,7 +858,7 @@ def mouseDoubleClickEvent(self, event):
if cs:
command = layer_commands.AddKnot(cs[0], pos)
elif type(self.focusItem()) == LayerItem or self.focusItem() is None:
command = layer_commands.NewCurve(self, event.scenePos())
command = layer_commands.AddCurve(self, event.scenePos())
# else if there is a focusitem add the knot to this items curve
else:
if type(self.focusItem()) is CubicSpline:
Expand Down
9 changes: 5 additions & 4 deletions eyelab/models/viewtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ def configure_imageTreeView(self):

self.imageTreeView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
duplicate_action = QtGui.QAction(self)
duplicate_action.setText("Duplicate")
duplicate_action.triggered.connect(self.duplicate)
duplicate_action.setText("Duplicate All")
duplicate_action.triggered.connect(self.duplicate_volume)

self.imageTreeView.addAction(duplicate_action)

def duplicate(self):
self.model.duplicate(self.imageTreeView.selectionModel().currentIndex())
def duplicate_volume(self):
self.model.duplicate_volume(self.imageTreeView.selectionModel().currentIndex())

def tools(self):
return self._tools
Expand Down
4 changes: 3 additions & 1 deletion eyelab/views/enface_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)

self.setContextMenuPolicy(Qt.ActionsContextMenu)

bscan_overlay_action = QtGui.QAction()
bscan_overlay_action.setCheckable(True)
bscan_overlay_action.setChecked(True)
bscan_overlay_action.setText("B-scan positions")
bscan_overlay_action.toggled.connect(self.test)
bscan_overlay_action.triggered.connect(self.test)
self.addAction(bscan_overlay_action)

def test(self):
Expand Down
Loading

0 comments on commit 6436e4d

Please sign in to comment.