Search in sources :

Example 6 with PointsROI

use of qupath.lib.roi.PointsROI in project qupath by qupath.

the class CountingPane method copyCoordinatesToClipboard.

public static void copyCoordinatesToClipboard(PathObject pathObject) {
    // PathObject pathObject = viewer.getPathObjectHierarchy().getSelectionModel().getSelectedPathObject();
    if (pathObject == null || !pathObject.hasROI() || !(pathObject.getROI() instanceof PointsROI)) {
        Dialogs.showErrorMessage("Copy points to clipboard", "No points selected!");
        return;
    }
    StringBuilder sb = new StringBuilder();
    String name = pathObject.getDisplayedName();
    PointsROI points = (PointsROI) pathObject.getROI();
    for (Point2 p : points.getAllPoints()) sb.append(name).append("\t").append(p.getX()).append("\t").append(p.getY()).append("\n");
    StringSelection stringSelection = new StringSelection(sb.toString());
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, null);
}
Also used : Point2(qupath.lib.geom.Point2) PointsROI(qupath.lib.roi.PointsROI) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 7 with PointsROI

use of qupath.lib.roi.PointsROI in project qupath by qupath.

the class PointsTool method handleAltClick.

/**
 * Alt-clicks remove the selected point, or selects a new 'family' of points (i.e. a different object) if
 * a point from the current object isn't clicked.
 *
 * @param x
 * @param y
 * @param currentObject
 * @return
 */
private boolean handleAltClick(double x, double y, PathObject currentObject) {
    var viewer = getViewer();
    var viewerPlane = viewer.getImagePlane();
    PathObjectHierarchy hierarchy = viewer.getHierarchy();
    double distance = PathPrefs.pointRadiusProperty().get();
    // Remove a point if the current selection has one
    if (currentObject != null && PathObjectTools.hasPointROI(currentObject)) {
        PointsROI points = (PointsROI) currentObject.getROI();
        if (points.getImagePlane().equals(viewerPlane)) {
            ROI points2 = removeNearbyPoint(points, x, y, distance);
            if (points != points2) {
                ((PathROIObject) currentObject).setROI(points2);
                hierarchy.updateObject(currentObject, false);
                // hierarchy.fireHierarchyChangedEvent(this, currentObject);
                return true;
            }
        }
    }
    // Activate a points object if there is one
    for (PathObject pathObject : hierarchy.getPointObjects(PathObject.class)) {
        // Don't check the current object again
        if (pathObject == currentObject || !pathObject.getROI().getImagePlane().equals(viewerPlane))
            continue;
        // See if we've almost clicked on a point
        if (((PointsROI) pathObject.getROI()).getNearest(x, y, distance) != null) {
            viewer.setSelectedObject(pathObject);
            // hierarchy.getSelectionModel().setSelectedPathObject(pathObject);
            return true;
        }
    }
    // Select nothing
    viewer.setSelectedObject(null);
    return true;
}
Also used : PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) PathObject(qupath.lib.objects.PathObject) PointsROI(qupath.lib.roi.PointsROI) PathROIObject(qupath.lib.objects.PathROIObject) ROI(qupath.lib.roi.interfaces.ROI) PointsROI(qupath.lib.roi.PointsROI)

Example 8 with PointsROI

use of qupath.lib.roi.PointsROI 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();
// }
}
Also used : RoiEditor(qupath.lib.roi.RoiEditor) Point2D(java.awt.geom.Point2D) PointsROI(qupath.lib.roi.PointsROI) PathROIObject(qupath.lib.objects.PathROIObject)

Example 9 with PointsROI

use of qupath.lib.roi.PointsROI 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();
}
Also used : PathObject(qupath.lib.objects.PathObject) RoiEditor(qupath.lib.roi.RoiEditor) Point2D(java.awt.geom.Point2D) ImagePlane(qupath.lib.regions.ImagePlane) PathROIObject(qupath.lib.objects.PathROIObject) ROI(qupath.lib.roi.interfaces.ROI) PointsROI(qupath.lib.roi.PointsROI)

Example 10 with PointsROI

use of qupath.lib.roi.PointsROI in project qupath by qupath.

the class PointsTool method getCurrentPoints.

private PointsROI getCurrentPoints() {
    var viewer = getViewer();
    PathObject currentObject = viewer.getSelectedObject();
    if (currentObject == null)
        return null;
    return (currentObject.getROI() instanceof PointsROI) ? (PointsROI) currentObject.getROI() : null;
}
Also used : PathObject(qupath.lib.objects.PathObject) PointsROI(qupath.lib.roi.PointsROI)

Aggregations

PointsROI (qupath.lib.roi.PointsROI)10 PathObject (qupath.lib.objects.PathObject)5 Point2 (qupath.lib.geom.Point2)4 PathROIObject (qupath.lib.objects.PathROIObject)3 RoiEditor (qupath.lib.roi.RoiEditor)3 ROI (qupath.lib.roi.interfaces.ROI)3 Point2D (java.awt.geom.Point2D)2 ArrayList (java.util.ArrayList)2 ImagePlane (qupath.lib.regions.ImagePlane)2 EllipseROI (qupath.lib.roi.EllipseROI)2 LineROI (qupath.lib.roi.LineROI)2 RectangleROI (qupath.lib.roi.RectangleROI)2 ShapeRoi (ij.gui.ShapeRoi)1 AlphaComposite (java.awt.AlphaComposite)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Shape (java.awt.Shape)1 Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 AffineTransform (java.awt.geom.AffineTransform)1