Search in sources :

Example 26 with ROI

use of qupath.lib.roi.interfaces.ROI in project qupath by qupath.

the class AbstractPolyROITool method mouseMoved.

@Override
public void mouseMoved(MouseEvent e) {
    super.mouseMoved(e);
    var viewer = getViewer();
    ROI currentROI = viewer.getCurrentROI();
    RoiEditor editor = viewer.getROIEditor();
    if (isPolyROI(currentROI) && editor.getROI() == currentROI) {
        Point2D p = mouseLocationToImage(e, true, requestPixelSnapping());
        ROI roiUpdated = editor.setActiveHandlePosition(p.getX(), p.getY(), viewer.getDownsampleFactor(), e.isShiftDown());
        PathObject pathObject = viewer.getSelectedObject();
        if (roiUpdated != currentROI && pathObject instanceof PathROIObject) {
            ((PathROIObject) pathObject).setROI(roiUpdated);
            viewer.getHierarchy().fireObjectsChangedEvent(this, Collections.singleton(pathObject), true);
        }
    }
}
Also used : PathObject(qupath.lib.objects.PathObject) RoiEditor(qupath.lib.roi.RoiEditor) Point2D(java.awt.geom.Point2D) PathROIObject(qupath.lib.objects.PathROIObject) PolylineROI(qupath.lib.roi.PolylineROI) ROI(qupath.lib.roi.interfaces.ROI) PolygonROI(qupath.lib.roi.PolygonROI)

Example 27 with ROI

use of qupath.lib.roi.interfaces.ROI in project qupath by qupath.

the class AbstractPolyROITool method mouseReleased.

@Override
public void mouseReleased(MouseEvent e) {
    super.mouseReleased(e);
    if (isFreehandPolyROI) {
        var viewer = getViewer();
        PathObject currentObject = viewer.getSelectedObject();
        ROI currentROI = currentObject == null ? null : currentObject.getROI();
        if (isPolyROI(currentROI) && currentROI.isEmpty()) {
            isFreehandPolyROI = false;
        } else if (PathPrefs.enableFreehandToolsProperty().get()) {
            RoiEditor editor = viewer.getROIEditor();
            Point2D p2 = mouseLocationToImage(e, true, requestPixelSnapping());
            ROI roiUpdated = editor.setActiveHandlePosition(p2.getX(), p2.getY(), viewer.getDownsampleFactor(), e.isShiftDown());
            if (currentObject != null && currentObject.getROI() != roiUpdated && currentObject instanceof PathROIObject) {
                ((PathROIObject) currentObject).setROI(roiUpdated);
            }
            commitObjectToHierarchy(e, currentObject);
        // completePolygon(e);
        }
    }
}
Also used : PathObject(qupath.lib.objects.PathObject) RoiEditor(qupath.lib.roi.RoiEditor) Point2D(java.awt.geom.Point2D) PathROIObject(qupath.lib.objects.PathROIObject) PolylineROI(qupath.lib.roi.PolylineROI) ROI(qupath.lib.roi.interfaces.ROI) PolygonROI(qupath.lib.roi.PolygonROI)

Example 28 with ROI

use of qupath.lib.roi.interfaces.ROI in project qupath by qupath.

the class AbstractPolyROITool method mousePressed.

@Override
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    // If we double-clicked a polygon, we're done with it
    var viewer = getViewer();
    PathObject currentObject = viewer == null ? null : viewer.getSelectedObject();
    if (currentObject != null && e.getClickCount() == 1) {
        RoiEditor editor = viewer.getROIEditor();
        logger.trace("Adjusting polygon {}", e);
        Point2D p2 = mouseLocationToImage(e, true, requestPixelSnapping());
        ROI roiUpdated = editor.requestNewHandle(p2.getX(), p2.getY());
        if (currentObject != null && currentObject.getROI() != roiUpdated && currentObject instanceof PathROIObject) {
            ((PathROIObject) currentObject).setROI(roiUpdated);
        }
        isFreehandPolyROI = false;
        viewer.repaint();
    } else {
        commitObjectToHierarchy(e, currentObject);
    }
    ROI currentROI = currentObject == null ? null : currentObject.getROI();
    if (isPolyROI(currentROI) && currentROI.isEmpty() && (currentROI.getNumPoints() == 1 || new HashSet<>(currentROI.getAllPoints()).size() == 1))
        isFreehandPolyROI = true;
}
Also used : PathObject(qupath.lib.objects.PathObject) RoiEditor(qupath.lib.roi.RoiEditor) Point2D(java.awt.geom.Point2D) PathROIObject(qupath.lib.objects.PathROIObject) PolylineROI(qupath.lib.roi.PolylineROI) ROI(qupath.lib.roi.interfaces.ROI) PolygonROI(qupath.lib.roi.PolygonROI)

Example 29 with ROI

use of qupath.lib.roi.interfaces.ROI in project qupath by qupath.

the class AbstractPolyROITool method mouseDragged.

@Override
public void mouseDragged(MouseEvent e) {
    // Note: if the 'freehand' part of the polygon creation isn't desired, just comment out this whole method
    super.mouseDragged(e);
    if (!e.isPrimaryButtonDown()) {
        return;
    }
    var viewer = getViewer();
    ROI currentROI = viewer.getCurrentROI();
    RoiEditor editor = viewer.getROIEditor();
    if (isPolyROI(currentROI) && editor.getROI() == currentROI) {
        Point2D p = mouseLocationToImage(e, true, requestPixelSnapping());
        ROI roiUpdated = editor.requestNewHandle(p.getX(), p.getY());
        PathObject pathObject = viewer.getSelectedObject();
        if (roiUpdated != currentROI && pathObject instanceof PathROIObject) {
            ((PathROIObject) pathObject).setROI(roiUpdated);
            viewer.getHierarchy().fireObjectsChangedEvent(this, Collections.singleton(pathObject), true);
        }
    }
}
Also used : PathObject(qupath.lib.objects.PathObject) RoiEditor(qupath.lib.roi.RoiEditor) Point2D(java.awt.geom.Point2D) PathROIObject(qupath.lib.objects.PathROIObject) PolylineROI(qupath.lib.roi.PolylineROI) ROI(qupath.lib.roi.interfaces.ROI) PolygonROI(qupath.lib.roi.PolygonROI)

Example 30 with ROI

use of qupath.lib.roi.interfaces.ROI in project qupath by qupath.

the class BrushTool method mouseDragged.

@Override
public void mouseDragged(MouseEvent e) {
    // Note: if the 'freehand' part of the polygon creation isn't desired, just comment out this whole method
    super.mouseDragged(e);
    ensureCursorType(getRequestedCursor());
    if (!e.isPrimaryButtonDown()) {
        return;
    }
    // Can only modify annotations
    var viewer = getViewer();
    PathObject pathObject = viewer.getSelectedObject();
    if (pathObject == null || !pathObject.isAnnotation() || !pathObject.isEditable())
        return;
    if (pathObject != currentObject) {
        logger.warn("Selected object has changed from {} to {}", currentObject, pathObject);
        return;
    }
    ROI currentROI = pathObject.getROI();
    if (!(currentROI instanceof ROI))
        return;
    ROI shapeROI = currentROI;
    PathObject pathObjectUpdated = getUpdatedObject(e, shapeROI, pathObject, -1);
    if (pathObject != pathObjectUpdated) {
        viewer.setSelectedObject(pathObjectUpdated, PathPrefs.selectionModeProperty().get());
    } else {
        viewer.repaint();
    }
}
Also used : PathObject(qupath.lib.objects.PathObject) RectangleROI(qupath.lib.roi.RectangleROI) ROI(qupath.lib.roi.interfaces.ROI)

Aggregations

ROI (qupath.lib.roi.interfaces.ROI)87 PathObject (qupath.lib.objects.PathObject)61 ArrayList (java.util.ArrayList)31 BufferedImage (java.awt.image.BufferedImage)24 PathObjectHierarchy (qupath.lib.objects.hierarchy.PathObjectHierarchy)24 IOException (java.io.IOException)20 RegionRequest (qupath.lib.regions.RegionRequest)19 List (java.util.List)17 Collectors (java.util.stream.Collectors)17 RectangleROI (qupath.lib.roi.RectangleROI)17 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 PolygonROI (qupath.lib.roi.PolygonROI)16 PathAnnotationObject (qupath.lib.objects.PathAnnotationObject)15 Point2D (java.awt.geom.Point2D)14 Collection (java.util.Collection)14 Collections (java.util.Collections)14 Geometry (org.locationtech.jts.geom.Geometry)14 PathClass (qupath.lib.objects.classes.PathClass)14 ImagePlane (qupath.lib.regions.ImagePlane)13