Search in sources :

Example 1 with PathROIObject

use of qupath.lib.objects.PathROIObject 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 2 with PathROIObject

use of qupath.lib.objects.PathROIObject 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 3 with PathROIObject

use of qupath.lib.objects.PathROIObject 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 4 with PathROIObject

use of qupath.lib.objects.PathROIObject 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 5 with PathROIObject

use of qupath.lib.objects.PathROIObject in project qupath by qupath.

the class MoveTool method mouseReleased.

@Override
public void mouseReleased(MouseEvent e) {
    super.mouseReleased(e);
    if (e.isConsumed())
        return;
    var viewer = getViewer();
    RoiEditor editor = viewer.getROIEditor();
    if (editor != null && (editor.hasActiveHandle() || editor.isTranslating())) {
        boolean roiChanged = (editor.isTranslating() && editor.finishTranslation()) || editor.hasActiveHandle();
        editor.resetActiveHandle();
        // if (editor.isTranslating())
        // editor.finishTranslation();
        e.consume();
        PathObject pathObject = viewer.getSelectedObject();
        if (requestParentClipping(e) && pathObject instanceof PathAnnotationObject) {
            ROI roiNew = refineROIByParent(pathObject.getROI());
            ((PathAnnotationObject) pathObject).setROI(roiNew);
        }
        if (pathObject != null && pathObject.hasROI() && pathObject.getROI().isEmpty()) {
            if (pathObject.getParent() != null)
                viewer.getHierarchy().removeObject(pathObject, true);
            viewer.setSelectedObject(null);
        } else {
            PathObjectHierarchy hierarchy = viewer.getHierarchy();
            if (pathObject instanceof TMACoreObject) {
                hierarchy.fireHierarchyChangedEvent(pathObject);
            } else if (pathObject != null) {
                // Handle ROI changes only if required
                if (roiChanged) {
                    var updatedROI = editor.getROI();
                    if (pathObject.getROI() != updatedROI && pathObject instanceof PathROIObject)
                        ((PathROIObject) pathObject).setROI(updatedROI);
                    // PathObject parentPrevious = pathObject.getParent();
                    hierarchy.removeObjectWithoutUpdate(pathObject, true);
                    if (getCurrentParent() == null || !PathPrefs.clipROIsForHierarchyProperty().get() || e.isShiftDown())
                        hierarchy.addPathObject(pathObject);
                    else
                        hierarchy.addPathObjectBelowParent(getCurrentParent(), pathObject, true);
                // PathObject parentNew = pathObject.getParent();
                // if (parentPrevious == parentNew)
                // hierarchy.fireHierarchyChangedEvent(this, parentPrevious);
                // else
                // hierarchy.fireHierarchyChangedEvent(this);
                }
            }
            viewer.setSelectedObject(pathObject);
        }
    }
    // Optionally continue a dragging movement until the canvas comes to a standstill
    if (pDragging != null && requestDynamicDragging && System.currentTimeMillis() - lastDragTimestamp < 100 && (dx * dx + dy * dy > viewer.getDownsampleFactor())) {
        mover = new ViewerMover(viewer);
        mover.startMoving(dx, dy, false);
    } else
        viewer.setDoFasterRepaint(false);
    // Make sure we don't have a previous point (to prevent weird dragging artefacts)
    pDragging = null;
// // If we were translating, stop
// if (editor.isTranslating()) {
// editor.finishTranslation();
// // TODO: Make this more efficient!
// viewer.getPathObjectHierarchy().fireHierarchyChangedEvent();
// return;
// }
}
Also used : PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) PathAnnotationObject(qupath.lib.objects.PathAnnotationObject) PathObject(qupath.lib.objects.PathObject) RoiEditor(qupath.lib.roi.RoiEditor) TMACoreObject(qupath.lib.objects.TMACoreObject) PathROIObject(qupath.lib.objects.PathROIObject) ROI(qupath.lib.roi.interfaces.ROI)

Aggregations

PathROIObject (qupath.lib.objects.PathROIObject)13 PathObject (qupath.lib.objects.PathObject)12 ROI (qupath.lib.roi.interfaces.ROI)12 RoiEditor (qupath.lib.roi.RoiEditor)9 Point2D (java.awt.geom.Point2D)8 PolylineROI (qupath.lib.roi.PolylineROI)5 PathObjectHierarchy (qupath.lib.objects.hierarchy.PathObjectHierarchy)4 PolygonROI (qupath.lib.roi.PolygonROI)4 PointsROI (qupath.lib.roi.PointsROI)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Rectangle2D (java.awt.geom.Rectangle2D)1 DialogButton (qupath.lib.gui.dialogs.Dialogs.DialogButton)1 PixelCalibration (qupath.lib.images.servers.PixelCalibration)1 PathAnnotationObject (qupath.lib.objects.PathAnnotationObject)1 TMACoreObject (qupath.lib.objects.TMACoreObject)1 ImagePlane (qupath.lib.regions.ImagePlane)1