use of qupath.lib.roi.interfaces.ROI in project qupath by qupath.
the class Commands method promptToSimplifySelectedAnnotations.
/**
* Show a prompt to selected annotations in a hierarchy.
* @param imageData the current image data
* @param altitudeThreshold default altitude value for simplification
*/
public static void promptToSimplifySelectedAnnotations(ImageData<?> imageData, double altitudeThreshold) {
PathObjectHierarchy hierarchy = imageData.getHierarchy();
List<PathObject> pathObjects = hierarchy.getSelectionModel().getSelectedObjects().stream().filter(p -> p.isAnnotation() && p.hasROI() && p.isEditable() && !p.getROI().isPoint()).collect(Collectors.toList());
if (pathObjects.isEmpty()) {
Dialogs.showErrorMessage("Simplify annotations", "No unlocked shape annotations selected!");
return;
}
String input = Dialogs.showInputDialog("Simplify shape", "Set altitude threshold in pixels.\nHigher values give simpler shapes.", Double.toString(altitudeThreshold));
if (input == null || !(input instanceof String) || ((String) input).trim().length() == 0)
return;
try {
altitudeThreshold = Double.parseDouble(((String) input).trim());
} catch (NumberFormatException e) {
logger.error("Could not parse altitude threshold from {}", input);
return;
}
if (altitudeThreshold <= 0) {
Dialogs.showErrorMessage("Simplify shape", "Amplitude threshold should be greater than zero!");
return;
}
long startTime = System.currentTimeMillis();
for (var pathObject : pathObjects) {
ROI pathROI = pathObject.getROI();
if (pathROI instanceof PolygonROI) {
PolygonROI polygonROI = (PolygonROI) pathROI;
pathROI = ShapeSimplifier.simplifyPolygon(polygonROI, altitudeThreshold);
} else {
pathROI = ShapeSimplifier.simplifyShape(pathROI, altitudeThreshold);
}
((PathAnnotationObject) pathObject).setROI(pathROI);
}
long endTime = System.currentTimeMillis();
logger.debug("Shapes simplified in " + (endTime - startTime) + " ms");
hierarchy.fireObjectsChangedEvent(hierarchy, pathObjects);
}
use of qupath.lib.roi.interfaces.ROI in project qupath by qupath.
the class TMAGridView method createRegionRequest.
private RegionRequest createRegionRequest(final PathObject core) {
ROI roi = core.getROI();
double downsample = Math.max(roi.getBoundsWidth(), roi.getBoundsHeight()) / CoreDisplaySize.LARGE.getSize();
// downsample = Math.round(downsample);
return RegionRequest.createInstance(getServerPath(), downsample, roi);
}
Aggregations