Class AbstractPlugin<T>

java.lang.Object
qupath.lib.plugins.AbstractPlugin<T>
Type Parameters:
T -
All Implemented Interfaces:
PathPlugin<T>
Direct Known Subclasses:
AbstractInteractivePlugin, ImageJMacroRunner

public abstract class AbstractPlugin<T> extends Object implements PathPlugin<T>
General abstract plugin implementation, which defines some methods to facilitate creating plugins that do parallel processing.
Author:
Pete Bankhead
  • Constructor Details

    • AbstractPlugin

      public AbstractPlugin()
  • Method Details

    • getTasks

      protected Collection<Runnable> getTasks(ImageData<T> imageData)
      Get a collection of tasks to perform. This will be called from runPlugin(TaskRunner, ImageData, String) after a call to parseArgument(ImageData, String). The default implementation simply calls getParentObjects(ImageData), then addRunnableTasks(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

      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.

      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

      protected abstract Collection<? extends PathObject> getParentObjects(ImageData<T> imageData)
      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

      public boolean runPlugin(TaskRunner taskRunner, ImageData<T> imageData, String arg)
      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 interface PathPlugin<T>
      Parameters:
      taskRunner -
      arg -
      Returns:
    • preprocess

      protected void preprocess(TaskRunner taskRunner, ImageData<T> imageData)
      Called after parsing the argument String, and immediately before creating & running any generated tasks. Does nothing by default.
      Parameters:
      taskRunner -
      imageData -
    • postprocess

      protected void postprocess(TaskRunner taskRunner, ImageData<T> imageData)
      Called immediately after running any generated tasks. Does nothing by default.
      Parameters:
      taskRunner -
      imageData -
    • addWorkflowStep

      protected void addWorkflowStep(ImageData<T> imageData, String arg)
      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

      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.

      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: