- 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected float[]
This method defines the steps to be performed for a single image pixel and must be implemented by any concrete sub-class.protected void
initFilter
(PixelPack source, PixelPack target) This method is called once at the start of the filter execution.protected void
This method is called once at the start of each filter pass.static void
Main method for demonstration only.protected int
Returns the necessary number of passes, which may change during execution of the filter.protected double
This method is called asynchonously and may be overridden by the terminal filter class if it does extensive work that should be monitored.Methods inherited from class imagingbook.common.filter.generic.GenericFilterVector
reportProgress, runPass
Methods inherited from class imagingbook.common.filter.generic.GenericFilter
abort, applyTo, applyTo, applyTo, closeFilter, getDepth, getHeight, getPass, getProgress, getWidth
-
Constructor Details
-
FilterProgressExample
public FilterProgressExample()
-
-
Method Details
-
initFilter
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 classGenericFilter
- Parameters:
source
- the image source datatarget
- the image target data
-
initPass
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 classGenericFilter
- Parameters:
source
- the image source datatarget
- the image target data
-
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 alsoGenericFilter.getPass()
.- Overrides:
passesRequired
in classGenericFilter
- Returns:
- the required number of filter passes
-
doPixel
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 aPixelPack
container, which holds the pixel values of all image components. The methodPixelPack.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 classGenericFilterVector
- Parameters:
source
- the vector-valued image datau
- the current x-positionv
- the current y-position- Returns:
- the result of the filter calculation for this pixel
-
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). SeeFilterProgressExample
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 classGenericFilter
- Returns:
- the degree of completion (0,...,1)
-
main
Main method for demonstration only.- Parameters:
args
- ignored
-