use of qupath.lib.roi.PolylineROI in project qupath by qupath.
the class IJTools method convertToIJRoi.
/**
* Convert a QuPath ROI to an ImageJ Roi.
* @param <T>
* @param pathROI
* @param xOrigin x-origin indicating relationship of ImagePlus to the original image, as stored in ImageJ Calibration object
* @param yOrigin y-origin indicating relationship of ImagePlus to the original image, as stored in ImageJ Calibration object
* @param downsampleFactor downsample factor at which the ImagePlus was extracted from the full-resolution image
* @return
*/
public static <T extends PathImage<ImagePlus>> Roi convertToIJRoi(ROI pathROI, double xOrigin, double yOrigin, double downsampleFactor) {
if (pathROI instanceof PolygonROI)
return ROIConverterIJ.convertToPolygonROI((PolygonROI) pathROI, xOrigin, yOrigin, downsampleFactor);
if (pathROI instanceof RectangleROI)
return ROIConverterIJ.getRectangleROI((RectangleROI) pathROI, xOrigin, yOrigin, downsampleFactor);
if (pathROI instanceof EllipseROI)
return ROIConverterIJ.convertToOvalROI((EllipseROI) pathROI, xOrigin, yOrigin, downsampleFactor);
if (pathROI instanceof LineROI)
return ROIConverterIJ.convertToLineROI((LineROI) pathROI, xOrigin, yOrigin, downsampleFactor);
if (pathROI instanceof PolylineROI)
return ROIConverterIJ.convertToPolygonROI((PolylineROI) pathROI, xOrigin, yOrigin, downsampleFactor);
if (pathROI instanceof PointsROI)
return ROIConverterIJ.convertToPointROI((PointsROI) pathROI, xOrigin, yOrigin, downsampleFactor);
// If we have any other kind of shape, create a general shape roi
if (pathROI != null && pathROI.isArea()) {
// TODO: Deal with non-AWT area ROIs!
Shape shape = RoiTools.getArea(pathROI);
// "scaleX", "shearY", "shearX", "scaleY", "translateX", "translateY"
shape = new AffineTransform(1.0 / downsampleFactor, 0, 0, 1.0 / downsampleFactor, xOrigin, yOrigin).createTransformedShape(shape);
return ROIConverterIJ.setIJRoiProperties(new ShapeRoi(shape), pathROI);
}
// TODO: Integrate ROI not supported exception...?
return null;
}
use of qupath.lib.roi.PolylineROI in project qupath by qupath.
the class AbstractPathROITool method mousePressed.
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
if (!e.isPrimaryButtonDown() || e.isConsumed()) {
return;
}
var viewer = getViewer();
PathObjectHierarchy hierarchy = viewer.getHierarchy();
if (hierarchy == null)
return;
PathObject currentObject = viewer.getSelectedObject();
ROI currentROI = currentObject == null ? null : currentObject.getROI();
RoiEditor editor = viewer.getROIEditor();
boolean adjustingPolygon = (currentROI instanceof PolygonROI || currentROI instanceof PolylineROI) && editor.getROI() == currentROI && (editor.isTranslating() || editor.hasActiveHandle());
// If we're adjusting a polygon/polyline with an appropriate tool, return at leave it up to the tool to handle the custom things
if (adjustingPolygon) {
if (viewer.getActiveTool() == PathTools.POLYGON || viewer.getActiveTool() == PathTools.POLYLINE)
return;
else {
viewer.getHierarchy().getSelectionModel().clearSelection();
viewer.getHierarchy().fireHierarchyChangedEvent(currentObject);
}
}
// Find out the coordinates in the image domain
Point2D p2 = mouseLocationToImage(e, false, requestPixelSnapping());
double xx = p2.getX();
double yy = p2.getY();
if (xx < 0 || yy < 0 || xx >= viewer.getServerWidth() || yy >= viewer.getServerHeight())
return;
// If we are double-clicking & we don't have a polygon, see if we can access a ROI
if (!PathPrefs.selectionModeProperty().get() && e.getClickCount() > 1) {
// Reset parent... for now
resetConstrainedAreaParent();
tryToSelect(xx, yy, e.getClickCount() - 2, false);
e.consume();
return;
}
// Set the current parent object based on the first click
setConstrainedAreaParent(hierarchy, xx, yy, Collections.emptyList());
// Create a new annotation
PathObject pathObject = createNewAnnotation(e, xx, yy);
if (pathObject == null)
return;
// Start editing the ROI immediately
editor.setROI(pathObject.getROI());
editor.grabHandle(xx, yy, viewer.getMaxROIHandleSize() * 1.5, e.isShiftDown());
}
Aggregations