Search in sources :

Example 1 with PathPlugin

use of qupath.lib.plugins.PathPlugin 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 PathPlugin

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

the class QP method runPlugin.

/**
 * Run the specified plugin on the specified {@code ImageData}.
 *
 * @param className
 * @param imageData
 * @param args
 * @return
 * @throws InterruptedException
 */
@SuppressWarnings("unchecked")
public static boolean runPlugin(final String className, final ImageData<?> imageData, final String args) throws InterruptedException {
    if (imageData == null)
        return false;
    try {
        Class<?> cPlugin = QP.class.getClassLoader().loadClass(className);
        Constructor<?> cons = cPlugin.getConstructor();
        final PathPlugin plugin = (PathPlugin) cons.newInstance();
        return plugin.runPlugin(new CommandLinePluginRunner<>(imageData), args);
    } catch (Exception e) {
        logger.error("Unable to run plugin " + className, e);
        return false;
    }
}
Also used : PathPlugin(qupath.lib.plugins.PathPlugin) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with PathPlugin

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

the class WorkflowCommandLogView method runWorkflowStepInteractively.

/**
 * Launch a plugin dialog for a specified WorkflowStep.
 *
 * TODO: Run any scriptable step
 *
 * @param qupath
 * @param step
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void runWorkflowStepInteractively(final QuPathGUI qupath, final WorkflowStep step) {
    ImageData<BufferedImage> imageData = qupath.getImageData();
    if (imageData == null) {
        Dialogs.showNoImageError("Run workflow step");
        return;
    }
    if (step instanceof SimplePluginWorkflowStep) {
        if (step instanceof SimplePluginWorkflowStep) {
            SimplePluginWorkflowStep pluginStep = (SimplePluginWorkflowStep) step;
            String pluginClassName = pluginStep.getPluginClass();
            PathPlugin<BufferedImage> plugin = null;
            try {
                Class<? extends PathPlugin> cls = (Class<? extends PathPlugin>) Class.forName(pluginClassName);
                plugin = qupath.createPlugin(cls);
                Map<String, ?> parameterMap = pluginStep.getParameterMap();
                String arg = null;
                if (parameterMap != null && !parameterMap.isEmpty()) {
                    arg = ParameterList.getParameterListJSON(parameterMap, " ");
                }
                qupath.runPlugin(plugin, arg, true);
            } catch (ClassNotFoundException e1) {
                Dialogs.showErrorNotification("Plugin class not found", "No plugin class found with name " + pluginClassName);
            } catch (Exception e1) {
                Dialogs.showErrorNotification("Plugin error", "Error running plugin " + plugin.getName() + " - see log for details");
                logger.error(e1.getLocalizedMessage(), e1);
            }
        }
    } else if (step instanceof ScriptableWorkflowStep) {
    // TODO: Run command script
    }
}
Also used : PathPlugin(qupath.lib.plugins.PathPlugin) ScriptableWorkflowStep(qupath.lib.plugins.workflow.ScriptableWorkflowStep) SimplePluginWorkflowStep(qupath.lib.plugins.workflow.SimplePluginWorkflowStep) BufferedImage(java.awt.image.BufferedImage)

Aggregations

PathPlugin (qupath.lib.plugins.PathPlugin)3 IOException (java.io.IOException)2 BufferedImage (java.awt.image.BufferedImage)1 FileNotFoundException (java.io.FileNotFoundException)1 NoSuchElementException (java.util.NoSuchElementException)1 CommandLinePluginRunner (qupath.lib.plugins.CommandLinePluginRunner)1 PluginRunner (qupath.lib.plugins.PluginRunner)1 ScriptableWorkflowStep (qupath.lib.plugins.workflow.ScriptableWorkflowStep)1 SimplePluginWorkflowStep (qupath.lib.plugins.workflow.SimplePluginWorkflowStep)1 QP (qupath.lib.scripting.QP)1