Search in sources :

Example 21 with DefaultScriptableWorkflowStep

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()"));
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy)

Example 22 with DefaultScriptableWorkflowStep

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()"));
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)

Example 23 with DefaultScriptableWorkflowStep

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;
}
Also used : Dialogs(qupath.lib.gui.dialogs.Dialogs) List(java.util.List) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) GeneralTools(qupath.lib.common.GeneralTools) Map(java.util.Map) IOException(java.io.IOException) HashMap(java.util.HashMap) QuPathGUI(qupath.lib.gui.QuPathGUI) PathObjectTools(qupath.lib.objects.PathObjectTools) PathIO(qupath.lib.io.PathIO) PathObject(qupath.lib.objects.PathObject) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) PathObject(qupath.lib.objects.PathObject) HashMap(java.util.HashMap) IOException(java.io.IOException)

Example 24 with DefaultScriptableWorkflowStep

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);
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) DefaultColorDeconvolutionStains(qupath.lib.color.ColorDeconvolutionStains.DefaultColorDeconvolutionStains) ColorDeconvolutionStains(qupath.lib.color.ColorDeconvolutionStains)

Example 25 with DefaultScriptableWorkflowStep

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;
}
Also used : Button(javafx.scene.control.Button) Arrays(java.util.Arrays) ImageServer(qupath.lib.images.servers.ImageServer) ListCell(javafx.scene.control.ListCell) ActionUtils(org.controlsfx.control.action.ActionUtils) LoggerFactory(org.slf4j.LoggerFactory) Side(javafx.geometry.Side) ContextMenu(javafx.scene.control.ContextMenu) Map(java.util.Map) StandardPathClasses(qupath.lib.objects.classes.PathClassFactory.StandardPathClasses) QuPathGUI(qupath.lib.gui.QuPathGUI) Pane(javafx.scene.layout.Pane) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) BufferedImage(java.awt.image.BufferedImage) Predicate(java.util.function.Predicate) Set(java.util.Set) Rectangle(javafx.scene.shape.Rectangle) KeyEvent(javafx.scene.input.KeyEvent) Collectors(java.util.stream.Collectors) PathObject(qupath.lib.objects.PathObject) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) QuPathViewer(qupath.lib.gui.viewer.QuPathViewer) Priority(javafx.scene.layout.Priority) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Project(qupath.lib.projects.Project) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) ProjectIO(qupath.lib.projects.ProjectIO) ToggleButton(javafx.scene.control.ToggleButton) Clipboard(javafx.scene.input.Clipboard) DataFormat(javafx.scene.input.DataFormat) GuiTools(qupath.lib.gui.tools.GuiTools) ColorToolsFX(qupath.lib.gui.tools.ColorToolsFX) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) ListView(javafx.scene.control.ListView) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Action(org.controlsfx.control.action.Action) PathClassFactory(qupath.lib.objects.classes.PathClassFactory) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) Bindings(javafx.beans.binding.Bindings) ArrayList(java.util.ArrayList) Dialogs(qupath.lib.gui.dialogs.Dialogs) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) ColorPicker(javafx.scene.control.ColorPicker) ImageData(qupath.lib.images.ImageData) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) PathClass(qupath.lib.objects.classes.PathClass) MenuTools(qupath.lib.gui.tools.MenuTools) File(java.io.File) OverlayOptions(qupath.lib.gui.viewer.OverlayOptions) Menu(javafx.scene.control.Menu) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SelectionMode(javafx.scene.control.SelectionMode) QP(qupath.lib.scripting.QP) Collections(java.util.Collections) PathPrefs(qupath.lib.gui.prefs.PathPrefs) DialogButton(qupath.lib.gui.dialogs.Dialogs.DialogButton) PaneTools(qupath.lib.gui.tools.PaneTools) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)

Aggregations

DefaultScriptableWorkflowStep (qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)31 PathObject (qupath.lib.objects.PathObject)12 PathObjectHierarchy (qupath.lib.objects.hierarchy.PathObjectHierarchy)12 WorkflowStep (qupath.lib.plugins.workflow.WorkflowStep)12 ArrayList (java.util.ArrayList)10 List (java.util.List)10 Map (java.util.Map)10 Dialogs (qupath.lib.gui.dialogs.Dialogs)10 Collectors (java.util.stream.Collectors)9 QuPathGUI (qupath.lib.gui.QuPathGUI)9 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)8 Arrays (java.util.Arrays)8 ImageData (qupath.lib.images.ImageData)8 File (java.io.File)7 StringProperty (javafx.beans.property.StringProperty)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 GeneralTools (qupath.lib.common.GeneralTools)7 Collections (java.util.Collections)6