use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class Commands method duplicateSelectedAnnotations.
/**
* Duplicate the selected annotations.
* @param imageData
*/
public static void duplicateSelectedAnnotations(ImageData<?> imageData) {
if (imageData == null) {
Dialogs.showNoImageError("Duplicate annotations");
return;
}
PathObjectHierarchy hierarchy = imageData.getHierarchy();
PathObjectTools.duplicateSelectedAnnotations(hierarchy);
imageData.getHistoryWorkflow().addStep(new DefaultScriptableWorkflowStep("Duplicate selected annotations", "duplicateSelectedAnnotations()"));
}
use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class Commands method promptToResolveHierarchy.
/**
* Resolve parent-child relationships within the object hierarchy.
* This means that objects will be arranged hierarchically, rather than as a flat list.
* @param imageData the image data to process
*/
public static void promptToResolveHierarchy(ImageData<?> imageData) {
if (imageData == null) {
Dialogs.showNoImageError("Resolve hierarchy");
return;
}
var hierarchy = imageData == null ? null : imageData.getHierarchy();
if (hierarchy == null)
return;
if (!Dialogs.showConfirmDialog("Resolve hierarchy", "Are you sure you want to resolve object relationships?\n" + "For large object hierarchies this can take a long time.")) {
return;
}
hierarchy.resolveHierarchy();
imageData.getHistoryWorkflow().addStep(new DefaultScriptableWorkflowStep("Resolve hierarchy", "resolveHierarchy()"));
}
use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class ImportObjectsCommand method runObjectImport.
/**
* Import objects or ROIs and adds them to the current hierarchy.
*
* @param qupath
* @return success
* @throws IOException
*/
public static boolean runObjectImport(QuPathGUI qupath) throws IOException {
var imageData = qupath.getImageData();
if (imageData == null)
return false;
var file = Dialogs.promptForFile("Choose file to import", null, "QuPath objects", PathIO.getObjectFileExtensions(true).toArray(String[]::new));
// User cancel
if (file == null)
return false;
List<PathObject> objs;
try {
objs = PathIO.readObjects(file);
} catch (IOException | IllegalArgumentException ex) {
Dialogs.showErrorNotification("Error importing objects", ex.getLocalizedMessage());
return false;
}
if (objs.isEmpty()) {
Dialogs.showWarningNotification("Import objects", "No objects found in " + file.getAbsolutePath());
return false;
}
int nObjects = objs.stream().mapToInt(p -> 1 + PathObjectTools.countDescendants(p)).sum();
String message = nObjects == 1 ? "Add 1 object to the hierarchy?" : String.format("Add %d objects to the hierarchy?", nObjects);
var confirm = Dialogs.showConfirmDialog("Add to hierarchy", message);
if (!confirm)
return false;
var hierarchy = imageData.getHierarchy();
hierarchy.addPathObjects(objs);
Map<String, String> map = new HashMap<>();
map.put("path", file.getPath());
String method = "Import objects";
String methodString = String.format("%s(%s%s%s)", "importObjectsFromFile", "\"", GeneralTools.escapeFilePath(file.getPath()), "\"");
imageData.getHistoryWorkflow().addStep(new DefaultScriptableWorkflowStep(method, map, methodString));
return true;
}
use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class ImageData method addColorDeconvolutionStainsToWorkflow.
// TODO: REINTRODUCE LOGGING!
private static void addColorDeconvolutionStainsToWorkflow(ImageData<?> imageData) {
// logger.warn("Color deconvolution stain logging not currently enabled!");
ColorDeconvolutionStains stains = imageData.getColorDeconvolutionStains();
if (stains == null) {
return;
}
String arg = ColorDeconvolutionStains.getColorDeconvolutionStainsAsString(imageData.getColorDeconvolutionStains(), 5);
Map<String, String> map = GeneralTools.parseArgStringValues(arg);
WorkflowStep lastStep = imageData.getHistoryWorkflow().getLastStep();
String commandName = "Set color deconvolution stains";
WorkflowStep newStep = new DefaultScriptableWorkflowStep(commandName, map, "setColorDeconvolutionStains(\'" + arg + "');");
// else
if (!Objects.equals(newStep, lastStep))
imageData.getHistoryWorkflow().addStep(newStep);
// ColorDeconvolutionStains stains = imageData.getColorDeconvolutionStains();
// if (stains == null)
// return;
//
// String arg = ColorDeconvolutionStains.getColorDeconvolutionStainsAsString(imageData.getColorDeconvolutionStains(), 5);
// Map<String, String> map = GeneralTools.parseArgStringValues(arg);
// WorkflowStep lastStep = imageData.getWorkflow().getLastStep();
// String commandName = "Set color deconvolution stains";
// WorkflowStep newStep = new DefaultScriptableWorkflowStep(commandName,
// map,
// QP.class.getSimpleName() + ".setColorDeconvolutionStains(\'" + arg + "');");
//
// if (lastStep != null && commandName.equals(lastStep.getName()))
// imageData.getWorkflow().replaceLastStep(newStep);
// else
// imageData.getWorkflow().addStep(newStep);
}
use of qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep in project qupath by qupath.
the class PathClassPane method selectObjectsByClassification.
/**
* Select objects by classification, logging the step (if performed) in the history workflow.
* @param imageData the {@link ImageData} containing objects to be selected
* @param pathClasses classifications that will result in an object being selected
* @return true if a selection command was run, false otherwise (e.g. if no pathClasses were specified)
*/
public static boolean selectObjectsByClassification(ImageData<?> imageData, PathClass... pathClasses) {
var hierarchy = imageData.getHierarchy();
if (pathClasses.length == 0) {
logger.warn("Cannot select objects by classification - no classifications selected!");
return false;
}
QP.selectObjectsByPathClass(hierarchy, pathClasses);
var s = Arrays.stream(pathClasses).map(p -> p == null || p == PathClassFactory.getPathClassUnclassified() ? "null" : "\"" + p.toString() + "\"").collect(Collectors.joining(", "));
imageData.getHistoryWorkflow().addStep(new DefaultScriptableWorkflowStep("Select objects by classification", "selectObjectsByClassification(" + s + ");"));
return true;
}
Aggregations