Search in sources :

Example 1 with PluginRunner

use of qupath.lib.plugins.PluginRunner in project qupath by qupath.

the class QPEx method runPlugin.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static boolean runPlugin(final String className, final ImageData<?> imageData, final String args) throws InterruptedException {
    if (imageData == null)
        return false;
    boolean completed = false;
    String pluginName = className;
    boolean cancelled = false;
    try {
        Class<?> cPlugin = QP.class.getClassLoader().loadClass(className);
        Constructor<?> cons = cPlugin.getConstructor();
        final PathPlugin plugin = (PathPlugin) cons.newInstance();
        pluginName = plugin.getName();
        PluginRunner runner;
        // TODO: Give potential of passing a plugin runner
        var qupath = getQuPath();
        if (isBatchMode() || imageData != qupath.getImageData()) {
            runner = new CommandLinePluginRunner(imageData);
            completed = plugin.runPlugin(runner, args);
            cancelled = runner.isCancelled();
        } else {
            completed = qupath.runPlugin(plugin, args, false);
            cancelled = !completed;
        // runner = new PluginRunnerFX(qupath);
        }
    } catch (Exception e) {
        logger.error("Error running plugin {}: {}", className, e.getLocalizedMessage());
        logger.error("", e);
    }
    // Notify caller that this failed
    if (cancelled)
        throw new InterruptedException(pluginName + " cancelled!");
    // }
    return completed;
}
Also used : CommandLinePluginRunner(qupath.lib.plugins.CommandLinePluginRunner) PluginRunner(qupath.lib.plugins.PluginRunner) CommandLinePluginRunner(qupath.lib.plugins.CommandLinePluginRunner) PathPlugin(qupath.lib.plugins.PathPlugin) IOException(java.io.IOException) QP(qupath.lib.scripting.QP)

Example 2 with PluginRunner

use of qupath.lib.plugins.PluginRunner in project qupath by qupath.

the class ImageJMacroRunner method getParentObjects.

@Override
protected Collection<? extends PathObject> getParentObjects(final PluginRunner<BufferedImage> runner) {
    // Try to get currently-selected objects
    PathObjectHierarchy hierarchy = getHierarchy(runner);
    List<PathObject> pathObjects = hierarchy.getSelectionModel().getSelectedObjects().stream().filter(p -> p.isAnnotation() || p.isTMACore()).collect(Collectors.toList());
    if (pathObjects.isEmpty()) {
        if (GuiTools.promptForParentObjects(this.getName(), runner.getImageData(), false, getSupportedParentObjectClasses()))
            pathObjects = new ArrayList<>(hierarchy.getSelectionModel().getSelectedObjects());
    }
    return pathObjects;
// // TODO: Give option to analyse annotations, even when TMA grid is present
// ImageData<BufferedImage> imageData = runner.getImageData();
// TMAGrid tmaGrid = imageData.getHierarchy().getTMAGrid();
// if (tmaGrid != null && tmaGrid.nCores() > 0)
// return PathObjectTools.getTMACoreObjects(imageData.getHierarchy(), false);
// else
// return imageData.getHierarchy().getObjects(null, PathAnnotationObject.class);
}
Also used : Button(javafx.scene.control.Button) Arrays(java.util.Arrays) ImageServer(qupath.lib.images.servers.ImageServer) CombineOp(qupath.lib.roi.RoiTools.CombineOp) IJTools(qupath.imagej.tools.IJTools) LoggerFactory(org.slf4j.LoggerFactory) PathImage(qupath.lib.images.PathImage) ParameterList(qupath.lib.plugins.parameters.ParameterList) PluginRunner(qupath.lib.plugins.PluginRunner) QuPathGUI(qupath.lib.gui.QuPathGUI) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) Font(javafx.scene.text.Font) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) PathAnnotationObject(qupath.lib.objects.PathAnnotationObject) PathObject(qupath.lib.objects.PathObject) Platform(javafx.application.Platform) ImagePlus(ij.ImagePlus) List(java.util.List) GuiTools(qupath.lib.gui.tools.GuiTools) BorderPane(javafx.scene.layout.BorderPane) Roi(ij.gui.Roi) RectangleROI(qupath.lib.roi.RectangleROI) Scene(javafx.scene.Scene) TextArea(javafx.scene.control.TextArea) WindowManager(ij.WindowManager) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) ImageDisplay(qupath.lib.display.ImageDisplay) ArrayList(java.util.ArrayList) Dialogs(qupath.lib.gui.dialogs.Dialogs) SwingUtilities(javax.swing.SwingUtilities) Insets(javafx.geometry.Insets) AbstractPlugin(qupath.lib.plugins.AbstractPlugin) GridPane(javafx.scene.layout.GridPane) LineROI(qupath.lib.roi.LineROI) ImageData(qupath.lib.images.ImageData) RoiTools(qupath.lib.roi.RoiTools) Logger(org.slf4j.Logger) Interpreter(ij.macro.Interpreter) RegionRequest(qupath.lib.regions.RegionRequest) Calibration(ij.measure.Calibration) ChannelDisplayTransformServer(qupath.lib.gui.images.servers.ChannelDisplayTransformServer) IOException(java.io.IOException) TMACoreObject(qupath.lib.objects.TMACoreObject) ROI(qupath.lib.roi.interfaces.ROI) Stage(javafx.stage.Stage) ParameterPanelFX(qupath.lib.gui.dialogs.ParameterPanelFX) QuPath_Send_Overlay_to_QuPath(qupathj.QuPath_Send_Overlay_to_QuPath) IJ(ij.IJ) PaneTools(qupath.lib.gui.tools.PaneTools) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) PathObject(qupath.lib.objects.PathObject) ArrayList(java.util.ArrayList)

Aggregations

IOException (java.io.IOException)2 PluginRunner (qupath.lib.plugins.PluginRunner)2 IJ (ij.IJ)1 ImagePlus (ij.ImagePlus)1 WindowManager (ij.WindowManager)1 Roi (ij.gui.Roi)1 Interpreter (ij.macro.Interpreter)1 Calibration (ij.measure.Calibration)1 BufferedImage (java.awt.image.BufferedImage)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Platform (javafx.application.Platform)1 Insets (javafx.geometry.Insets)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 TextArea (javafx.scene.control.TextArea)1