use of qupath.lib.roi.RoiEditor in project qupath by qupath.
the class AbstractPathDraggingROITool method mouseDragged.
@Override
public void mouseDragged(MouseEvent e) {
super.mouseDragged(e);
if (!e.isPrimaryButtonDown()) {
return;
}
var viewer = getViewer();
ROI currentROI = viewer.getCurrentROI() instanceof ROI ? (ROI) viewer.getCurrentROI() : null;
RoiEditor editor = viewer.getROIEditor();
if (currentROI != null && editor.getROI() == currentROI && editor.hasActiveHandle()) {
PathObject pathObject = viewer.getSelectedObject();
Point2D p = mouseLocationToImage(e, true, requestPixelSnapping());
ROI roiUpdated = editor.setActiveHandlePosition(p.getX(), p.getY(), 0.25, e.isShiftDown());
if (roiUpdated != currentROI) {
((PathROIObject) pathObject).setROI(roiUpdated);
viewer.repaint();
}
viewer.getHierarchy().fireObjectsChangedEvent(this, Collections.singleton(pathObject), true);
// editor.setActiveHandlePosition(x, y, minDisplacement, shiftDown)
// currentROI.updateAdjustment(p.getX(), p.getY(), e.isShiftDown());
viewer.repaint();
}
}
use of qupath.lib.roi.RoiEditor in project qupath by qupath.
the class PointsTool method mouseDragged.
@Override
public void mouseDragged(MouseEvent e) {
super.mouseDragged(e);
if (!e.isPrimaryButtonDown() || e.isConsumed()) {
return;
}
var viewer = getViewer();
RoiEditor editor = viewer.getROIEditor();
if (!(editor.getROI() instanceof PointsROI) || !editor.hasActiveHandle())
return;
PointsROI points = getCurrentPoints();
// Find out the coordinates in the image domain & update the adjustment
Point2D pAdjusting = mouseLocationToImage(e, true, requestPixelSnapping());
// double radius = PointsROI.defaultPointRadiusProperty().get();
PointsROI points2 = (PointsROI) editor.setActiveHandlePosition(pAdjusting.getX(), pAdjusting.getY(), 0.25, e.isShiftDown());
if (points2 == points)
return;
PathROIObject currentObject = (PathROIObject) viewer.getSelectedObject();
currentObject.setROI(points2);
viewer.repaint();
// viewer.getHierarchy().fireHierarchyChangedEvent(this, currentObject);
// // points.updateAdjustment(pAdjusting.getX(), pAdjusting.getY(), e.isShiftDown());
//
// // Point2 p = points.getNearest(pAdjusting.getX(), pAdjusting.getY(), radius);
// if (p == null) {
// } else {
// p.setLocation(pAdjusting.getX(), pAdjusting.getY());
// // points.resetMeasurements();
// viewer.repaint();
// }
}
use of qupath.lib.roi.RoiEditor in project qupath by qupath.
the class PointsTool method mousePressed.
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
if (!e.isPrimaryButtonDown() || e.isConsumed()) {
return;
}
// Get a server, if we can
var viewer = getViewer();
ImageServer<?> server = viewer.getServer();
if (server == null)
return;
var viewerPlane = viewer.getImagePlane();
// Find out the coordinates in the image domain
Point2D p = mouseLocationToImage(e, false, requestPixelSnapping());
double xx = p.getX();
double yy = p.getY();
// If we are outside the image, ignore click
if (xx < 0 || yy < 0 || xx >= server.getWidth() || yy >= server.getHeight())
return;
// See if we have a selected ROI
PathObject currentObjectTemp = viewer.getSelectedObject();
if (!(currentObjectTemp == null || currentObjectTemp instanceof PathROIObject))
return;
PathROIObject currentObject = (PathROIObject) currentObjectTemp;
ROI currentROI = currentObject == null ? null : currentObject.getROI();
RoiEditor editor = viewer.getROIEditor();
double radius = PathPrefs.pointRadiusProperty().get();
ROI points = null;
if (currentROI != null && currentROI.isPoint() && (currentROI.isEmpty() || currentROI.getImagePlane().equals(viewerPlane)))
points = currentROI;
// If Alt is pressed, try to delete a point
if (e.isAltDown()) {
handleAltClick(xx, yy, currentObject);
} else // Create a new ROI if we've got Alt & Shift pressed - or we just don't have a point ROI
if (points == null || (!PathPrefs.multipointToolProperty().get() && !editor.grabHandle(xx, yy, radius, e.isShiftDown())) || (e.isShiftDown() && e.getClickCount() > 1)) {
// PathPoints is effectively ready from the start - don't need to finalize
points = ROIs.createPointsROI(xx, yy, viewerPlane);
currentObject = (PathROIObject) PathObjects.createAnnotationObject(points, PathPrefs.autoSetAnnotationClassProperty().get());
viewer.getHierarchy().addPathObject(currentObject);
viewer.setSelectedObject(currentObject);
// viewer.createAnnotationObject(points);
editor.setROI(points);
editor.grabHandle(xx, yy, radius, e.isShiftDown());
} else if (points != null) {
// Add point to current ROI, or adjust the position of a nearby point
ImagePlane plane = points == null || points.isEmpty() ? viewerPlane : points.getImagePlane();
ROI points2 = addPoint(points, xx, yy, radius, plane);
if (points2 == points) {
// If we didn't add a point, try to grab a handle
if (!editor.grabHandle(xx, yy, radius, e.isShiftDown()))
return;
points2 = (PointsROI) editor.setActiveHandlePosition(xx, yy, 0.25, e.isShiftDown());
} else {
editor.setROI(points2);
editor.grabHandle(xx, yy, radius, e.isShiftDown());
}
if (points2 != points) {
currentObject.setROI(points2);
viewer.getHierarchy().updateObject(currentObject, true);
// viewer.getHierarchy().fireHierarchyChangedEvent(this, currentObject);
}
}
viewer.repaint();
}
Aggregations