/** * If {@code false}, returns a category with the original sample values. */ @Override public Category geophysics(final boolean geo) { // Assertion below is for preventing recursive invocation. assert !(inverse instanceof GeophysicsCategory) : inverse; return inverse.geophysics(geo); }
/** * If {@code false}, returns a category with the original sample values. */ public Category geophysics(final boolean toGeophysics) { assert !(inverse instanceof GeophysicsCategory) : inverse; return inverse.geophysics(toGeophysics); }
/** * Verify if all categories are scaled to the specified state. * * @param categories The categories to test. * @param toGeophysics The state to test. * @return {@code true} if all categories are in the specified state. */ static boolean isScaled(final Category[] categories, final boolean toGeophysics) { for (int i=0; i<categories.length; i++) { final Category c = categories[i]; if (c.geophysics(toGeophysics) != c) { return false; } } return true; }
/** * Verifies if all categories are of the specified type. {@code true} is for * {@linkplain org.geotools.coverage.grid.ViewType#GEOPHYSICS geophysics} and {@code false} is * for {@linkplain org.geotools.coverage.grid.ViewType#PACKED packed} data. This method is used * mostly in assertion statements. * * @param categories The categories to test. * @param geo The desired type for every categories. * @return {@code true} if all categories are in the specified type. */ static boolean isGeophysics(final Category[] categories, final boolean geo) { for (int i=0; i<categories.length; i++) { final Category category = categories[i]; if (category.geophysics(geo) != category) { return false; } } return true; }
/** * Computes the smallest number of fraction digits necessary to resolve all * quantitative values. This method assume that geophysics values in the range * {@code Category.geophysics(true).getRange} are stored as integer sample * values in the range {@code Category.geophysics(false).getRange}. */ private static int getFractionDigitCount(final Category[] categories) { int ndigits = 0; final double EPS = 1E-6; final int length=categories.length; for (int i=0; i<length; i++) { final Category category = categories[i]; final Category geophysics = category.geophysics(true); final Category packed = category.geophysics(false); final double ln = Math.log10((geophysics.maximum - geophysics.minimum)/ ( packed.maximum - packed.minimum)); if (!Double.isNaN(ln)) { final int n = -(int)(Math.floor(ln + EPS)); if (n > ndigits) { ndigits = Math.min(n, MAX_DIGITS); } } } return ndigits; }
/** * Computes the smallest number of fraction digits necessary to resolve all * quantitative values. This method assume that geophysics values in the range * {@code Category.geophysics(true).getRange} are stored as integer sample * values in the range {@code Category.geophysics(false).getRange}. */ private static int getFractionDigitCount(final Category[] categories) { int ndigits = 0; final double EPS = 1E-6; final int length=categories.length; for (int i=0; i<length; i++) { final Category geophysics = categories[i].geophysics(true); final Category samples = categories[i].geophysics(false); final double ln = XMath.log10((geophysics.maximum - geophysics.minimum)/ ( samples.maximum - samples.minimum)); if (!Double.isNaN(ln)) { final int n = -(int)(Math.floor(ln + EPS)); if (n>ndigits) { ndigits = Math.min(n, MAX_DIGITS); } } } return ndigits; }
/** * Returns the quantitative category for a single {@linkplain GridSampleDimension sample dimension} * in the target {@linkplain GridCoverage2D grid coverage}. This method is invoked automatically * by the {@link #deriveSampleDimension deriveSampleDimension} method for each band in the * target image. The default implementation creates a default category from the target range * of values returned by {@link #deriveRange deriveRange}. * * @param categories The quantitative categories from every sources. For unary operations * like {@code "GradientMagnitude"}, this array has a length of 1. For binary * operations like {@code "add"} and {@code "multiply"}, this array has a length of 2. * @param parameters Parameters, rendering hints and coordinate reference system to use. * @return The quantitative category to use in the destination image, or {@code null} if unknown. */ protected Category deriveCategory(final Category[] categories, final Parameters parameters) { final NumberRange[] ranges = new NumberRange[categories.length]; for (int i=0; i<ranges.length; i++) { if (categories[i] == null) { continue; } ranges[i] = categories[i].getRange(); } final NumberRange range = deriveRange(ranges, parameters); if (range != null) { final Category category = categories[PRIMARY_SOURCE_INDEX]; return new Category(category.getName(), category.getColors(), category.geophysics(false).getRange(), range).geophysics(true); } return null; }
/** * Returns the quantitative category for a single {@linkplain GridSampleDimension sample dimension} * in the target {@linkplain GridCoverage2D grid coverage}. This method is invoked automatically * by the {@link #deriveSampleDimension deriveSampleDimension} method for each band in the * target image. The default implementation creates a default category from the target range * of values returned by {@link #deriveRange deriveRange}. * * @param categories The quantitative categories from every sources. For unary operations * like {@code "GradientMagnitude"}, this array has a length of 1. For binary * operations like {@code "add"} and {@code "multiply"}, this array has a length of 2. * @param parameters Parameters, rendering hints and coordinate reference system to use. * @return The quantitative category to use in the destination image, or {@code null} if unknown. */ protected Category deriveCategory(final Category[] categories, final Parameters parameters) { final NumberRange[] ranges = new NumberRange[categories.length]; for (int i=0; i<ranges.length; i++) { ranges[i] = categories[i].getRange(); } final NumberRange range = deriveRange(ranges, parameters); if (range != null) { final Category category = categories[PRIMARY_SOURCE_INDEX]; return new Category(category.getName(), category.getColors(), category.geophysics(false).getRange(), range).geophysics(true); } return null; }
/** * Returns a sample dimension using new {@link #getScale scale} and {@link #getOffset offset} * coefficients. Other properties like the {@linkplain #getRange sample value range}, * {@linkplain #getNoDataValues no data values} and {@linkplain #getColorModel colors} * are unchanged. * * @param scale The value which is multiplied to grid values for the new sample dimension. * @param offset The value to add to grid values for the new sample dimension. * * @see #getScale * @see #getOffset * @see Category#rescale */ public GridSampleDimension rescale(final double scale, final double offset) { final MathTransform1D sampleToGeophysics = Category.createLinearTransform(scale, offset); final Category[] categories = (Category[]) getCategories().toArray(); final Category[] reference = (Category[]) categories.clone(); final int length = categories.length; for (int i = 0; i < length; i++) { if (categories[i].isQuantitative()) { categories[i] = categories[i].rescale(sampleToGeophysics); } categories[i] = categories[i].geophysics(isGeophysics); } if (Arrays.equals(categories, reference)) { return this; } return new GridSampleDimension(description, categories, getUnits()); }
this.categories = categories = categories.clone(); for (int i=0; i<categories.length; i++) { categories[i] = categories[i].geophysics(geophysics); for (int i=categories.length; --i>=0;) { final Category candidate = categories[i]; final double value = candidate.geophysics(true).minimum; if (Double.isNaN(value)) { nodata = candidate; final Category candidate = categories[i]; if (candidate.isQuantitative()) { final Category candidatePeer = candidate.geophysics(false); final double candidateRange = candidatePeer.maximum - candidatePeer.minimum; if (candidateRange >= range) {
NumberRange range = null; Category category = categories[0]; final NumberRange samples = category.geophysics(false).getRange(); final boolean isGeophysics = (category == category.geophysics(true)); 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(); return category.geophysics(isGeophysics);
this.categories = categories = (Category[]) categories.clone(); for (int i=0; i<categories.length; i++) { categories[i] = categories[i].geophysics(isGeophysics); for (int i=categories.length; --i>=0;) { final Category candidate = categories[i]; final double value = candidate.geophysics(true).minimum; if (Double.isNaN(value)) { nodata = candidate; final Category candidate = categories[i]; if (candidate.isQuantitative()) { final Category candidatePeer = candidate.geophysics(false); final double candidateRange = candidatePeer.maximum - candidatePeer.minimum; if (candidateRange >= range) {
NumberRange range = null; Category category = categories[0]; final NumberRange samples = category.geophysics(false).getRange(); final boolean isGeophysics = (category == category.geophysics(true)); 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(); return category.geophysics(isGeophysics);
for(Category category:categories){ if(category.getName().equals(NODATA)){ background[i]=category.geophysics(true).getRange().getMinimum(); found=true; break;
category = category.rescale(sampleToGeophysics); category = category.geophysics(isGeophysics); if (!categories[i].equals(category)) { categories[i] = category;
LinearTransform1D.IDENTITY).geophysics(geophysics);
for (int j=0; j<numCategories; j++) { final Category category = (Category) categories.get(j); MathTransform1D transform = category.geophysics(false).getSampleToGeophysics(); if (transform == null) {
for (int j=0; j<numCategories; j++) { final Category sourceCategory = sources.get(j); final Category packedCategory = sourceCategory.geophysics(false); MathTransform1D transform = packedCategory.getSampleToGeophysics(); final double offset, scale; final NumberRange target = sourceCategory.geophysics(true).getRange(); offset = target.getMinimum(); if (Double.doubleToRawLongBits(offset) != Double.doubleToRawLongBits(target.getMaximum())) {