* This implementation computes the expected gradient range from the two
* masks and the value range in the source grid coverage.
*/
protected Category deriveCategory(final Category[] categories, final Parameters parameters) {
NumberRange range = null;
Category category = categories[0];
final NumberRange samples = category.geophysics(false).getRange();
final boolean isGeophysics = (category == category.geophysics(true));
/*
* Computes a default range of output values one from the normalized kernels.
* The normalization has been done by 'deriveGridCoverage' before this method
* is invoked. The algorithm is as below:
*
* - Computes the value produced by the kernels for an artificial gradient of 1 unit/pixel.
* - Transforms into a lower gradient of 1 unit/(kernel size).
* - Transforms into a gradient of (maximal range)/(kernel size).
* - Applies an arbitrary correction factor for more convenient range in most cases.
*/
final ParameterList block = parameters.parameters;
final KernelJAI mask1 = (KernelJAI) block.getObjectParameter("Mask1");
final KernelJAI mask2 = (KernelJAI) block.getObjectParameter("Mask2");
final double size = (mask1.getWidth() + mask1.getHeight() +
mask2.getWidth() + mask2.getHeight()) / 4.0;
double factor = getNormalizationFactor(mask1, mask2) / (size-1);
if (factor>0 && !Double.isInfinite(factor)) {
range = category.geophysics(true).getRange();
final double minimum = range.getMinimum();
final double maximum = range.getMaximum();
factor *= (maximum - minimum) * DEFAULT_RANGE_SCALE;
range = NumberRange.create(0, factor);
}
if (range != null) {
category = new Category(category.getName(), DEFAULT_COLOR_PALETTE, samples, range);
return category.geophysics(isGeophysics);
}
return super.deriveCategory(categories, parameters);
}