Search in sources :

Example 6 with QuPathGUI

use of qupath.lib.gui.QuPathGUI 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 7 with QuPathGUI

use of qupath.lib.gui.QuPathGUI in project qupath by qupath.

the class TMASummaryViewer method setTMAEntriesFromOpenImage.

private void setTMAEntriesFromOpenImage() {
    QuPathGUI qupath = QuPathGUI.getInstance();
    if (qupath == null || qupath.getImageData() == null || qupath.getImageData().getHierarchy().getTMAGrid() == null) {
        Dialogs.showErrorMessage("Show TMA summary", "No TMA data available!");
        return;
    }
    ImageData<BufferedImage> imageData = qupath.getImageData();
    setTMAEntriesFromImageData(imageData);
}
Also used : QuPathGUI(qupath.lib.gui.QuPathGUI) BufferedImage(java.awt.image.BufferedImage)

Example 8 with QuPathGUI

use of qupath.lib.gui.QuPathGUI in project qupath by qupath.

the class GuiTools method createAnnotationsMenuImpl.

private static void createAnnotationsMenuImpl(QuPathGUI qupath, Object menu) {
    // Add annotation options
    CheckMenuItem miLockAnnotations = new CheckMenuItem("Lock");
    CheckMenuItem miUnlockAnnotations = new CheckMenuItem("Unlock");
    miLockAnnotations.setOnAction(e -> setSelectedAnnotationLock(qupath.getImageData(), true));
    miUnlockAnnotations.setOnAction(e -> setSelectedAnnotationLock(qupath.getImageData(), false));
    MenuItem miSetProperties = new MenuItem("Set properties");
    miSetProperties.setOnAction(e -> {
        var hierarchy = qupath.getViewer().getHierarchy();
        if (hierarchy != null)
            GuiTools.promptToSetActiveAnnotationProperties(hierarchy);
    });
    var actionInsertInHierarchy = qupath.createImageDataAction(imageData -> Commands.insertSelectedObjectsInHierarchy(imageData));
    actionInsertInHierarchy.setText("Insert in hierarchy");
    var miInsertHierarchy = ActionTools.createMenuItem(actionInsertInHierarchy);
    var actionMerge = qupath.createImageDataAction(imageData -> Commands.mergeSelectedAnnotations(imageData));
    actionMerge.setText("Merge selected");
    var actionSubtract = qupath.createImageDataAction(imageData -> Commands.combineSelectedAnnotations(imageData, CombineOp.SUBTRACT));
    actionSubtract.setText("Subtract selected");
    var actionIntersect = qupath.createImageDataAction(imageData -> Commands.combineSelectedAnnotations(imageData, CombineOp.INTERSECT));
    actionIntersect.setText("Intersect selected");
    var actionInverse = qupath.createImageDataAction(imageData -> Commands.makeInverseAnnotation(imageData));
    actionInverse.setText("Make inverse");
    Menu menuCombine = MenuTools.createMenu("Edit multiple", actionMerge, // TODO: Make this less ambiguous!
    actionSubtract, actionIntersect);
    Menu menuEdit = MenuTools.createMenu("Edit single", actionInverse, qupath.createPluginAction("Split", SplitAnnotationsPlugin.class, null));
    // Menu menuPoints = MenuTools.createMenu(
    // "Points",
    // QuPathGUI.createCommandAction(new MergePointsCommand(qupath, true), "Merge all points for class"),
    // QuPathGUI.createCommandAction(new MergePointsCommand(qupath, true), "Merge selected points for class")
    // );
    MenuItem separator = new SeparatorMenuItem();
    Runnable validator = () -> {
        var imageData = qupath.getImageData();
        PathObject selected = null;
        Collection<PathObject> allSelected = Collections.emptyList();
        boolean allSelectedAnnotations = false;
        boolean hasSelectedAnnotation = false;
        if (imageData != null) {
            selected = imageData.getHierarchy().getSelectionModel().getSelectedObject();
            allSelected = new ArrayList<>(imageData.getHierarchy().getSelectionModel().getSelectedObjects());
            hasSelectedAnnotation = selected != null && selected.isAnnotation();
            allSelectedAnnotations = allSelected.stream().allMatch(p -> p.isAnnotation());
        }
        miLockAnnotations.setDisable(!hasSelectedAnnotation);
        miUnlockAnnotations.setDisable(!hasSelectedAnnotation);
        if (hasSelectedAnnotation) {
            boolean isLocked = selected.isLocked();
            miLockAnnotations.setSelected(isLocked);
            miUnlockAnnotations.setSelected(!isLocked);
        }
        miSetProperties.setDisable(!hasSelectedAnnotation);
        miInsertHierarchy.setVisible(selected != null);
        menuEdit.setVisible(hasSelectedAnnotation);
        menuCombine.setVisible(allSelectedAnnotations && allSelected.size() > 1);
        separator.setVisible(menuEdit.isVisible() || menuCombine.isVisible());
    };
    List<MenuItem> items;
    if (menu instanceof Menu) {
        Menu m = (Menu) menu;
        items = m.getItems();
        m.setOnMenuValidation(e -> validator.run());
    } else if (menu instanceof ContextMenu) {
        ContextMenu m = (ContextMenu) menu;
        items = m.getItems();
        m.setOnShowing(e -> validator.run());
    } else
        throw new IllegalArgumentException("Menu must be either a standard Menu or a ContextMenu!");
    MenuTools.addMenuItems(items, miLockAnnotations, miUnlockAnnotations, miSetProperties, miInsertHierarchy, separator, menuEdit, menuCombine);
}
Also used : CheckComboBox(org.controlsfx.control.CheckComboBox) UnaryOperator(java.util.function.UnaryOperator) TextFormatter(javafx.scene.control.TextFormatter) PathRootObject(qupath.lib.objects.PathRootObject) ParameterList(qupath.lib.plugins.parameters.ParameterList) PointsROI(qupath.lib.roi.PointsROI) Matcher(java.util.regex.Matcher) Action(java.awt.Desktop.Action) ColorTools(qupath.lib.common.ColorTools) GraphicsContext(javafx.scene.canvas.GraphicsContext) Canvas(javafx.scene.canvas.Canvas) Screen(javafx.stage.Screen) PathAnnotationObject(qupath.lib.objects.PathAnnotationObject) Platform(javafx.application.Platform) CountDownLatch(java.util.concurrent.CountDownLatch) Transparency(java.awt.Transparency) Clipboard(javafx.scene.input.Clipboard) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) StringProperty(javafx.beans.property.StringProperty) Callable(java.util.concurrent.Callable) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) DefaultColorDeconvolutionStains(qupath.lib.color.ColorDeconvolutionStains.DefaultColorDeconvolutionStains) Bindings(javafx.beans.binding.Bindings) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Slider(javafx.scene.control.Slider) SplitAnnotationsPlugin(qupath.lib.plugins.objects.SplitAnnotationsPlugin) GridPane(javafx.scene.layout.GridPane) Color(javafx.scene.paint.Color) GeneralTools(qupath.lib.common.GeneralTools) Commands(qupath.lib.gui.commands.Commands) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) IOException(java.io.IOException) File(java.io.File) PathObjectTools(qupath.lib.objects.PathObjectTools) Menu(javafx.scene.control.Menu) ROI(qupath.lib.roi.interfaces.ROI) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ObservableValue(javafx.beans.value.ObservableValue) Image(javafx.scene.image.Image) Button(javafx.scene.control.Button) ImageServer(qupath.lib.images.servers.ImageServer) CombineOp(qupath.lib.roi.RoiTools.CombineOp) DoubleBinding(javafx.beans.binding.DoubleBinding) ListCell(javafx.scene.control.ListCell) CheckMenuItem(javafx.scene.control.CheckMenuItem) LoggerFactory(org.slf4j.LoggerFactory) RenderingHints(java.awt.RenderingHints) Side(javafx.geometry.Side) ContextMenu(javafx.scene.control.ContextMenu) URI(java.net.URI) QuPathGUI(qupath.lib.gui.QuPathGUI) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) Spinner(javafx.scene.control.Spinner) Collectors(java.util.stream.Collectors) StainVector(qupath.lib.color.StainVector) PathObject(qupath.lib.objects.PathObject) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) QuPathViewer(qupath.lib.gui.viewer.QuPathViewer) List(java.util.List) Robot(javafx.scene.robot.Robot) DefaultScriptableWorkflowStep(qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep) Pattern(java.util.regex.Pattern) ClipboardContent(javafx.scene.input.ClipboardContent) Scene(javafx.scene.Scene) ListView(javafx.scene.control.ListView) TextArea(javafx.scene.control.TextArea) ParsePosition(java.text.ParsePosition) DoubleProperty(javafx.beans.property.DoubleProperty) ColorDeconvolutionHelper(qupath.lib.color.ColorDeconvolutionHelper) Function(java.util.function.Function) Dialogs(qupath.lib.gui.dialogs.Dialogs) ColorDeconvolutionStains(qupath.lib.color.ColorDeconvolutionStains) SwingUtilities(javax.swing.SwingUtilities) Graphics2D(java.awt.Graphics2D) ActionTools(qupath.lib.gui.ActionTools) Tooltip(javafx.scene.control.Tooltip) ColorPicker(javafx.scene.control.ColorPicker) ImageData(qupath.lib.images.ImageData) Desktop(java.awt.Desktop) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) WritableImage(javafx.scene.image.WritableImage) TMACoreObject(qupath.lib.objects.TMACoreObject) DoubleSpinnerValueFactory(javafx.scene.control.SpinnerValueFactory.DoubleSpinnerValueFactory) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Stage(javafx.stage.Stage) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) SwingFXUtils(javafx.embed.swing.SwingFXUtils) Window(javafx.stage.Window) Collections(java.util.Collections) ArrayList(java.util.ArrayList) CheckMenuItem(javafx.scene.control.CheckMenuItem) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ContextMenu(javafx.scene.control.ContextMenu) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) CheckMenuItem(javafx.scene.control.CheckMenuItem) PathObject(qupath.lib.objects.PathObject) Collection(java.util.Collection) Menu(javafx.scene.control.Menu) ContextMenu(javafx.scene.control.ContextMenu) SplitAnnotationsPlugin(qupath.lib.plugins.objects.SplitAnnotationsPlugin)

Aggregations

QuPathGUI (qupath.lib.gui.QuPathGUI)8 BufferedImage (java.awt.image.BufferedImage)6 PathObject (qupath.lib.objects.PathObject)6 File (java.io.File)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 GeneralTools (qupath.lib.common.GeneralTools)5 Dialogs (qupath.lib.gui.dialogs.Dialogs)5 Collection (java.util.Collection)4 Collectors (java.util.stream.Collectors)4 DefaultScriptableWorkflowStep (qupath.lib.plugins.workflow.DefaultScriptableWorkflowStep)4 Map (java.util.Map)3 Graphics2D (java.awt.Graphics2D)2 RenderingHints (java.awt.RenderingHints)2 URI (java.net.URI)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 LinkedHashMap (java.util.LinkedHashMap)2 BooleanProperty (javafx.beans.property.BooleanProperty)2