Class FilterProgressExample

All Implemented Interfaces:
ProgressReporter

This class defines a custom filter implementing GenericFilterVector that reports its progress, which is queried by a ProgressMonitor in the main(String[]) method.

In this example the work required for processing each SINGLE pixel is assumed to be substantial and progress reporting thus goes all the way down to the single pixel level. Method GenericFilter.getProgress() in this case reports how much of the work for the current pixel is already completed. Note that this is for demonstration only and such fine granularity is usually not needed. Typically method GenericFilter.getProgress() needs not to be overridden or may be defined to return always 1.

The OVERALL filter progress (which depends on the image size and the number of required filter passes) is calculated automatically by the associated super classes.

See Also:
  • Constructor Details

  • Method Details

    • initFilter

      protected void initFilter(PixelPack source, PixelPack target)
      Description copied from class: GenericFilter
      This method is called once at the start of the filter execution. It does nothing by default. Concrete filter classes should override this method, e.g., for setting up temporary data structures.
      Overrides:
      initFilter in class GenericFilter
      Parameters:
      source - the image source data
      target - the image target data
    • initPass

      protected void initPass(PixelPack source, PixelPack target)
      Description copied from class: GenericFilter
      This method is called once at the start of each filter pass. It does nothing by default. Concrete filter classes should override this method if needed.
      Overrides:
      initPass in class GenericFilter
      Parameters:
      source - the image source data
      target - the image target data
    • passesRequired

      protected int passesRequired()
      Description copied from class: GenericFilter
      Returns the necessary number of passes, which may change during execution of the filter. The value 1 is returned by default. Multi-pass filters must override this method. The filter terminates as soon as the requested number of passes is reached. This this method can be used to terminate filter execution once some desired state has been reached (e.g., convergence). See also GenericFilter.getPass().
      Overrides:
      passesRequired in class GenericFilter
      Returns:
      the required number of filter passes
    • doPixel

      protected float[] doPixel(PixelPack source, int u, int v)
      Description copied from class: GenericFilterVector
      This method defines the steps to be performed for a single image pixel and must be implemented by any concrete sub-class. The source data are passed as a PixelPack container, which holds the pixel values of all image components. The method PixelPack.getPix(int, int) should be used to read individual pixel vectors. These data should not be modified but the (float[]) result of the single-pixel calculation must be returned. Implementations are free to return the same float-array at each invocation, i.e., there is no need to allocate a new array every time.
      Specified by:
      doPixel in class GenericFilterVector
      Parameters:
      source - the vector-valued image data
      u - the current x-position
      v - the current y-position
      Returns:
      the result of the filter calculation for this pixel
    • reportProgress

      protected double reportProgress()
      This method is called asynchonously and may be overridden by the terminal filter class if it does extensive work that should be monitored. In this case the method must return a value between 0 and 1, reflecting the degree of completion (only of the final class's subtask) at the time of invocation. Normally this is not necessary, since the intermediate classes return their own progress state (for the less granular tasks) anyways. The default implementations returns 0 (progress). See FilterProgressExample for an example.

      Note: This method returns the filter's progress (degree of completion) for the current pixel (see doPixel(PixelPack, int, int)). Typically this fine granularity is not relevant and the method should either return 1 or not be overridden at all (removed).

      Overrides:
      reportProgress in class GenericFilter
      Returns:
      the degree of completion (0,...,1)
    • main

      public static void main(String[] args)
      Main method for demonstration only.
      Parameters:
      args - ignored