use of qupath.lib.roi.RoiEditor 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);
}
}
}
use of qupath.lib.roi.RoiEditor 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);
}
}
}
use of qupath.lib.roi.RoiEditor 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;
}
use of qupath.lib.roi.RoiEditor 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);
}
}
}
use of qupath.lib.roi.RoiEditor in project qupath by qupath.
the class AbstractPathDraggingROITool method mouseReleased.
@Override
public void mouseReleased(MouseEvent e) {
if (e.getButton() != MouseButton.PRIMARY) {
return;
}
var viewer = getViewer();
PathObject selectedObject = viewer.getSelectedObject();
if (selectedObject == null)
return;
RoiEditor editor = viewer.getROIEditor();
ROI currentROI = selectedObject.getROI();
if (currentROI != null && editor.getROI() == currentROI && editor.hasActiveHandle()) {
editor.setROI(null);
// Remove empty ROIs
if (currentROI.isEmpty()) {
if (selectedObject.getParent() != null)
viewer.getHierarchy().removeObject(selectedObject, true);
viewer.setSelectedObject(null);
} else {
commitObjectToHierarchy(e, selectedObject);
}
// editor.ensureHandlesUpdated();
// editor.resetActiveHandle();
// if (PathPrefs.getReturnToMoveMode())
// modes.setMode(Modes.MOVE);
}
}
Aggregations