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