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;
}
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;
}
}
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
}
}
Aggregations