Search in sources :

Example 11 with RoiEditor

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

Example 12 with RoiEditor

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

Example 13 with RoiEditor

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();
}
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)

Aggregations

RoiEditor (qupath.lib.roi.RoiEditor)13 PathObject (qupath.lib.objects.PathObject)11 ROI (qupath.lib.roi.interfaces.ROI)11 Point2D (java.awt.geom.Point2D)10 PathROIObject (qupath.lib.objects.PathROIObject)9 PolygonROI (qupath.lib.roi.PolygonROI)5 PolylineROI (qupath.lib.roi.PolylineROI)5 PointsROI (qupath.lib.roi.PointsROI)3 PathObjectHierarchy (qupath.lib.objects.hierarchy.PathObjectHierarchy)2 Rectangle2D (java.awt.geom.Rectangle2D)1 PathAnnotationObject (qupath.lib.objects.PathAnnotationObject)1 TMACoreObject (qupath.lib.objects.TMACoreObject)1 ImagePlane (qupath.lib.regions.ImagePlane)1