Class AbstractPlugin<T>
- Type Parameters:
T
-
- All Implemented Interfaces:
PathPlugin<T>
- Direct Known Subclasses:
AbstractInteractivePlugin
,ImageJMacroRunner
- Author:
- Pete Bankhead
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
addRunnableTasks
(ImageData<T> imageData, PathObject parentObject, List<Runnable> tasks) For a specified parent object, generate a task to run.protected void
addWorkflowStep
(ImageData<T> imageData, String arg) Add a workflow step to the ImageData indicating the argument that this plugin was run with.protected abstract Collection
<? extends PathObject> getParentObjects
(ImageData<T> imageData) Get a collection of objects to process, based on the contents of the PluginRunner.protected Collection
<Runnable> Get a collection of tasks to perform.protected abstract boolean
parseArgument
(ImageData<T> imageData, String arg) Parse the input argument, returning 'true' if the argument is valid and it's possible to run the plugin.protected void
postprocess
(TaskRunner taskRunner, ImageData<T> imageData) Called immediately after running any generated tasks.protected void
preprocess
(TaskRunner taskRunner, ImageData<T> imageData) Called after parsing the argument String, and immediately before creating & running any generated tasks.protected static <T> boolean
rearrangeByStride
(Collection<T> input, T[] output, int stride) Test method for rearranging a collection so that entries are interleaved with a regularity given by stride.protected boolean
Optionally request a hierarchy update after the tasks have run.boolean
runPlugin
(TaskRunner taskRunner, ImageData<T> imageData, String arg) Run the plugin.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface qupath.lib.plugins.PathPlugin
getDescription, getLastResultsDescription, getName
-
Constructor Details
-
AbstractPlugin
public AbstractPlugin()
-
-
Method Details
-
getTasks
Get a collection of tasks to perform. This will be called fromrunPlugin(TaskRunner, ImageData, String)
after a call toparseArgument(ImageData, String)
. The default implementation simply callsgetParentObjects(ImageData)
, thenaddRunnableTasks(ImageData, PathObject, List)
for every parent object that was returned.- Parameters:
imageData
-- Returns:
-
requestHierarchyUpdate
protected boolean requestHierarchyUpdate()Optionally request a hierarchy update after the tasks have run. Default implementation returns true.- Returns:
-
parseArgument
Parse the input argument, returning 'true' if the argument is valid and it's possible to run the plugin.This is called from within runPlugin. If it returns 'true', getTasks will be called and then runTasks will submit these to the plugin runner to run. If it returns 'false', runPlugin will immediately abort and return false as well. Since this could result in some internal variables changed (e.g. a ParameterList), implementing classes can't be assumed to be thread-safe; plugins should be created and called from a single thread, although they may use multiple threads (via a PluginRunner) to complete their tasks.
- Parameters:
imageData
-arg
-- Returns:
-
getParentObjects
Get a collection of objects to process, based on the contents of the PluginRunner. This could (for example) return the selected object, the root object, all detection objects... depending upon what the plugin does. Each object this returns will be passed to addRunnableTasks to create a task to run. In practice, this method can be overridden to return anything/nothing if getTasks is overridden instead.- Parameters:
imageData
-- Returns:
-
addRunnableTasks
protected abstract void addRunnableTasks(ImageData<T> imageData, PathObject parentObject, List<Runnable> tasks) For a specified parent object, generate a task to run. In practice, this method can be overridden to return anything/nothing if getTasks is overridden instead.- Parameters:
imageData
-parentObject
-tasks
-
-
runPlugin
Description copied from interface:PathPlugin
Run the plugin. A PluginRunner may be provided that this plugin can use to update the user on its progress.Note: This command should block until it has completed processing.
- Specified by:
runPlugin
in interfacePathPlugin<T>
- Parameters:
taskRunner
-arg
-- Returns:
-
preprocess
Called after parsing the argument String, and immediately before creating & running any generated tasks. Does nothing by default.- Parameters:
taskRunner
-imageData
-
-
postprocess
Called immediately after running any generated tasks. Does nothing by default.- Parameters:
taskRunner
-imageData
-
-
addWorkflowStep
Add a workflow step to the ImageData indicating the argument that this plugin was run with. Subclasses may override this if a better workflow step should be logged. A subclass may also override this to avoid adding a workflow step at all.- Parameters:
imageData
-arg
-
-
rearrangeByStride
Test method for rearranging a collection so that entries are interleaved with a regularity given by stride.It can be used to rearrange tasks to try to make better use of cached image regions, by helping to ensure that all available processors are operating on distinct parts of the image - rather than all in the same region, where image tile requests could become a bottleneck. Intended use would be something like the following:
int n = tasks.size(); Runnable[] tasks2 = new Runnable[n]; if (rearrangeByStride(tasks, tasks2, Runtime.getRuntime().availableProcessors())) tasks = Arrays.asList(tasks2);
- Parameters:
input
-output
-stride
-- Returns:
-