Search in sources :

Example 11 with WorkflowStep

use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.

the class MeasurementManager method promptToRemoveMeasurements.

private boolean promptToRemoveMeasurements() {
    var selectedItems = new ArrayList<>(listView.getSelectionModel().getSelectedItems());
    if (selectedItems.isEmpty()) {
        Dialogs.showErrorMessage("Remove measurements", "No measurements selected!");
        return false;
    }
    String number = selectedItems.size() == 1 ? String.format("'%s'", selectedItems.iterator().next()) : selectedItems.size() + " measurements";
    if (!Dialogs.showConfirmDialog("Remove measurements", "Are you sure you want to permanently remove " + number + "?"))
        return false;
    String removeString = selectedItems.stream().map(m -> "\"" + m + "\"").collect(Collectors.joining(", "));
    logger.info("Removing measurements: {}", removeString);
    Class<? extends PathObject> cls = comboBox.getSelectionModel().getSelectedItem();
    QP.removeMeasurements(imageData.getHierarchy(), cls, selectedItems.toArray(String[]::new));
    // Keep for scripting
    WorkflowStep step = new DefaultScriptableWorkflowStep("Remove measurements", String.format("removeMeasurements(%s, %s);", cls.getName(), removeString));
    imageData.getHistoryWorkflow().addStep(step);
    // Update
    refreshMeasurements();
    updateCurrentList();
    filterText.set("");
    return true;
}
Also used : Button(javafx.scene.control.Button) Arrays(java.util.Arrays) PathTileObject(qupath.lib.objects.PathTileObject) ListView(javafx.scene.control.ListView) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ButtonType(javafx.scene.control.ButtonType) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Bindings(javafx.beans.binding.Bindings) ArrayList(java.util.ArrayList) PathRootObject(qupath.lib.objects.PathRootObject) Dialogs(qupath.lib.gui.dialogs.Dialogs) Insets(javafx.geometry.Insets) ComboBox(javafx.scene.control.ComboBox) Map(java.util.Map) Tooltip(javafx.scene.control.Tooltip) LinkedHashSet(java.util.LinkedHashSet) QuPathGUI(qupath.lib.gui.QuPathGUI) Pane(javafx.scene.layout.Pane) ImageData(qupath.lib.images.ImageData) KeyCode(javafx.scene.input.KeyCode) TextField(javafx.scene.control.TextField) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) TitledPane(javafx.scene.control.TitledPane) FilteredList(javafx.collections.transformation.FilteredList) Set(java.util.Set) TMACoreObject(qupath.lib.objects.TMACoreObject) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) Collectors(java.util.stream.Collectors) PathObjectTools(qupath.lib.objects.PathObjectTools) PathAnnotationObject(qupath.lib.objects.PathAnnotationObject) PathDetectionObject(qupath.lib.objects.PathDetectionObject) PathObject(qupath.lib.objects.PathObject) Dimension(java.awt.Dimension) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) GuiTools(qupath.lib.gui.tools.GuiTools) QP(qupath.lib.scripting.QP) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) PathCellObject(qupath.lib.objects.PathCellObject) Collections(java.util.Collections) Toolkit(java.awt.Toolkit) PaneTools(qupath.lib.gui.tools.PaneTools) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) ArrayList(java.util.ArrayList)

Example 12 with WorkflowStep

use of qupath.lib.plugins.workflow.WorkflowStep 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 13 with WorkflowStep

use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.

the class ImageDetailsPane method promptToSetPixelSize.

static boolean promptToSetPixelSize(ImageData<BufferedImage> imageData, boolean requestZSpacing) {
    var server = imageData.getServer();
    var hierarchy = imageData.getHierarchy();
    var selected = hierarchy.getSelectionModel().getSelectedObject();
    var roi = selected == null ? null : selected.getROI();
    PixelCalibration cal = server.getPixelCalibration();
    double pixelWidthMicrons = cal.getPixelWidthMicrons();
    double pixelHeightMicrons = cal.getPixelHeightMicrons();
    double zSpacingMicrons = cal.getZSpacingMicrons();
    // Use line or area ROI if possible
    if (!requestZSpacing && roi != null && !roi.isEmpty() && (roi.isArea() || roi.isLine())) {
        boolean setPixelHeight = true;
        boolean setPixelWidth = true;
        String message;
        String units = GeneralTools.micrometerSymbol();
        double pixelWidth = cal.getPixelWidthMicrons();
        double pixelHeight = cal.getPixelHeightMicrons();
        if (!Double.isFinite(pixelWidth))
            pixelWidth = 1;
        if (!Double.isFinite(pixelHeight))
            pixelHeight = 1;
        Double defaultValue = null;
        if (roi.isLine()) {
            setPixelHeight = roi.getBoundsHeight() != 0;
            setPixelWidth = roi.getBoundsWidth() != 0;
            message = "Enter selected line length";
            defaultValue = roi.getScaledLength(pixelWidth, pixelHeight);
        } else {
            message = "Enter selected ROI area";
            units = units + "^2";
            defaultValue = roi.getScaledArea(pixelWidth, pixelHeight);
        }
        // }
        if (Double.isNaN(defaultValue))
            defaultValue = 1.0;
        var params = new ParameterList().addDoubleParameter("inputValue", message, defaultValue, units, "Enter calibrated value in " + units + " for the selected ROI to calculate the pixel size").addBooleanParameter("squarePixels", "Assume square pixels", true, "Set the pixel width to match the pixel height");
        params.setHiddenParameters(setPixelHeight && setPixelWidth, "squarePixels");
        if (!Dialogs.showParameterDialog("Set pixel size", params))
            return false;
        Double result = params.getDoubleParameterValue("inputValue");
        setPixelHeight = setPixelHeight || params.getBooleanParameterValue("squarePixels");
        setPixelWidth = setPixelWidth || params.getBooleanParameterValue("squarePixels");
        // Double result = Dialogs.showInputDialog("Set pixel size", message, defaultValue);
        // if (result == null)
        // return false;
        double sizeMicrons;
        if (roi.isLine())
            sizeMicrons = result.doubleValue() / roi.getLength();
        else
            sizeMicrons = Math.sqrt(result.doubleValue() / roi.getArea());
        if (setPixelHeight)
            pixelHeightMicrons = sizeMicrons;
        if (setPixelWidth)
            pixelWidthMicrons = sizeMicrons;
    } else {
        // Prompt for all required values
        ParameterList params = new ParameterList().addDoubleParameter("pixelWidth", "Pixel width", pixelWidthMicrons, GeneralTools.micrometerSymbol(), "Enter the pixel width").addDoubleParameter("pixelHeight", "Pixel height", pixelHeightMicrons, GeneralTools.micrometerSymbol(), "Entry the pixel height").addDoubleParameter("zSpacing", "Z-spacing", zSpacingMicrons, GeneralTools.micrometerSymbol(), "Enter the spacing between slices of a z-stack");
        params.setHiddenParameters(server.nZSlices() == 1, "zSpacing");
        if (!Dialogs.showParameterDialog("Set pixel size", params))
            return false;
        if (server.nZSlices() != 1) {
            zSpacingMicrons = params.getDoubleParameterValue("zSpacing");
        }
        pixelWidthMicrons = params.getDoubleParameterValue("pixelWidth");
        pixelHeightMicrons = params.getDoubleParameterValue("pixelHeight");
    }
    if ((pixelWidthMicrons <= 0 || pixelHeightMicrons <= 0) || (server.nZSlices() > 1 && zSpacingMicrons <= 0)) {
        if (!Dialogs.showConfirmDialog("Set pixel size", "You entered values <= 0, do you really want to remove this pixel calibration information?")) {
            return false;
        }
        zSpacingMicrons = server.nZSlices() > 1 && zSpacingMicrons > 0 ? zSpacingMicrons : Double.NaN;
        if (pixelWidthMicrons <= 0 || pixelHeightMicrons <= 0) {
            pixelWidthMicrons = Double.NaN;
            pixelHeightMicrons = Double.NaN;
        }
    }
    if (QP.setPixelSizeMicrons(imageData, pixelWidthMicrons, pixelHeightMicrons, zSpacingMicrons)) {
        // Log for scripts
        WorkflowStep step;
        if (server.nZSlices() == 1) {
            var map = Map.of("pixelWidthMicrons", pixelWidthMicrons, "pixelHeightMicrons", pixelHeightMicrons);
            String script = String.format("setPixelSizeMicrons(%f, %f)", pixelWidthMicrons, pixelHeightMicrons);
            step = new DefaultScriptableWorkflowStep("Set pixel size " + GeneralTools.micrometerSymbol(), map, script);
        } else {
            var map = Map.of("pixelWidthMicrons", pixelWidthMicrons, "pixelHeightMicrons", pixelHeightMicrons, "zSpacingMicrons", zSpacingMicrons);
            String script = String.format("setPixelSizeMicrons(%f, %f, %f)", pixelWidthMicrons, pixelHeightMicrons, zSpacingMicrons);
            step = new DefaultScriptableWorkflowStep("Set pixel size " + GeneralTools.micrometerSymbol(), map, script);
        }
        imageData.getHistoryWorkflow().addStep(step);
        return true;
    } else
        return false;
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) ParameterList(qupath.lib.plugins.parameters.ParameterList) PixelCalibration(qupath.lib.images.servers.PixelCalibration)

Example 14 with WorkflowStep

use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.

the class Commands method selectObjectsByClass.

/**
 * Select objects that are instances of a specified class, logging an appropriate method in the workflow.
 *
 * @param imageData
 * @param cls
 */
public static void selectObjectsByClass(final ImageData<?> imageData, final Class<? extends PathObject> cls) {
    if (cls == TMACoreObject.class)
        QP.selectTMACores(imageData.getHierarchy());
    else
        QP.selectObjectsByClass(imageData.getHierarchy(), cls);
    Map<String, String> params = Collections.singletonMap("Type", PathObjectTools.getSuitableName(cls, false));
    String method;
    if (cls == PathAnnotationObject.class)
        method = "selectAnnotations();";
    else if (cls == PathDetectionObject.class)
        method = "selectDetections();";
    else if (cls == TMACoreObject.class)
        method = "selectTMACores();";
    else if (cls == PathCellObject.class)
        method = "selectCells();";
    else if (cls == PathTileObject.class)
        method = "selectTiles();";
    else
        // TODO: Get a suitable name to disguise Java classes
        method = "selectObjectsByClass(" + cls.getName() + ");";
    WorkflowStep newStep = new DefaultScriptableWorkflowStep("Select objects by class", params, method);
    WorkflowStep lastStep = imageData.getHistoryWorkflow().getLastStep();
    if (newStep.equals(lastStep))
        imageData.getHistoryWorkflow().replaceLastStep(newStep);
    else
        imageData.getHistoryWorkflow().addStep(newStep);
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) PathDetectionObject(qupath.lib.objects.PathDetectionObject) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) PathCellObject(qupath.lib.objects.PathCellObject)

Example 15 with WorkflowStep

use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.

the class Commands method selectAllObjects.

/**
 * Select all objects (excluding the root object) in the imageData.
 *
 * @param imageData
 */
public static void selectAllObjects(final ImageData<?> imageData) {
    // Select all objects
    QP.selectAllObjects(imageData.getHierarchy(), false);
    // Add this step to the history workflow
    Map<String, String> map = new HashMap<>();
    map.put("includeRootObject", "false");
    WorkflowStep newStep = new DefaultScriptableWorkflowStep("Select all objects", map, "selectAllObjects(false)");
    imageData.getHistoryWorkflow().addStep(newStep);
}
Also used : DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) WorkflowStep(qupath.lib.plugins.workflow.WorkflowStep) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)

Aggregations

WorkflowStep (qupath.lib.plugins.workflow.WorkflowStep)15 DefaultScriptableWorkflowStep (qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)11 ArrayList (java.util.ArrayList)6 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 QuPathGUI (qupath.lib.gui.QuPathGUI)5 Dialogs (qupath.lib.gui.dialogs.Dialogs)5 ImageData (qupath.lib.images.ImageData)5 PathObject (qupath.lib.objects.PathObject)5 BufferedImage (java.awt.image.BufferedImage)4 Arrays (java.util.Arrays)4 StringProperty (javafx.beans.property.StringProperty)4 Scene (javafx.scene.Scene)4 Button (javafx.scene.control.Button)4 BorderPane (javafx.scene.layout.BorderPane)4 File (java.io.File)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3