/** * Constructs a qualitative or quantitative category for samples in the specified range. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param colors A set of colors for this category. This array may have any length; colors will * be interpolated as needed. An array of length 1 means that an uniform color should be * used for all sample values. An array of length 0 or a {@code null} array means that some * default colors should be used (usually a gradient from opaque black to opaque white). * @param sampleValueRange The range of sample values for this category. Element class is * usually {@link Integer}, but {@link Float} and {@link Double} are accepted as well. * @throws ClassCastException if the range element class is not a {@link Number} subclass. * @throws IllegalArgumentException if the range is invalid. */ public Category( final CharSequence name, final Color[] colors, final NumberRange sampleValueRange, final boolean isQuantitative) throws IllegalArgumentException { this(name, toARGB(colors), sampleValueRange, isQuantitative); }
/** * Constructs a qualitative category for sample value {@code sample}. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param color The category color, or {@code null} for a default color. * @param sample The sample value as an integer, usually in the range 0 to 255. */ public Category(final CharSequence name, final Color color, final int sample) { this(name, toARGB(color, sample), Integer.valueOf(sample), false); assert minimum == sample : minimum; assert maximum == sample : maximum; }
/** * Constructs a qualitative category for sample value {@code sample}. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param color The category color, or {@code null} for a default color. * @param sample The sample value as an integer, usually in the range 0 to 255. */ public Category( final CharSequence name, final Color color, final int sample, final boolean isQuantitative) { this(name, toARGB(color, sample), Integer.valueOf(sample), isQuantitative); assert minimum == sample : minimum; assert maximum == sample : maximum; }
/** * Constructs a qualitative category for sample value {@code sample}. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param color The category color, or {@code null} for a default color. * @param sample The sample value as a double. May be one of {@code NaN} values. */ public Category(final CharSequence name, final Color color, final double sample) { this(name, toARGB(color, (int) sample), Double.valueOf(sample), false); assert Double.doubleToRawLongBits(minimum) == Double.doubleToRawLongBits(sample) : minimum; assert Double.doubleToRawLongBits(maximum) == Double.doubleToRawLongBits(sample) : maximum; }
/** * Returns a category for the same range of sample values but a different color palette. The * array given in argument may have any length; colors will be interpolated as needed. An array * of length 1 means that an uniform color should be used for all sample values. An array of * length 0 or a {@code null} array means that some default colors should be used (usually a * gradient from opaque black to opaque white). * * @param colors A set of colors for the new category. * @return A category with the new color palette, or {@code this} if the new colors are * identical to the current ones. * @see org.geotools.coverage.processing.ColorMap#recolor */ public Category recolor(final Color[] colors) { final int[] newARGB = toARGB(colors); if (Arrays.equals(ARGB, newARGB)) { return this; } assert range != null : this; final Category newCategory = new Category(name, newARGB, range, isQuantitative); return newCategory; }
/** * Returns ARGB values for the specified color. If {@code color} * is null, a default ARGB code will be returned. */ private static int[] toARGB(Color color, final int sample) { if (color==null) { color = CYCLE[Math.abs(sample) % CYCLE.length]; } return toARGB(new Color[] {color}); }
/** * Constructs a qualitative or quantitative category for samples in the specified range. * Sample values (usually integers) will be converted into geophysics values (usually * floating-point) through the {@code sampleToGeophysics} transform. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param colors A set of colors for this category. This array may have any length; * colors will be interpolated as needed. An array of length 1 means * that an uniform color should be used for all sample values. An array * of length 0 or a {@code null} array means that some default colors * should be used (usually a gradient from opaque black to opaque white). * @param sampleValueRange The range of sample values for this category. Element class * is usually {@link Integer}, but {@link Float} and {@link Double} are * accepted as well. * @param sampleToGeophysics A transform from sample values to geophysics values, * or {@code null} if this category is not a quantitative one. * * @throws ClassCastException if the range element class is not a {@link Number} subclass. * @throws IllegalArgumentException if the range is invalid. */ public Category(final CharSequence name, final Color[] colors, final NumberRange sampleValueRange, final MathTransform1D sampleToGeophysics) throws IllegalArgumentException { this(name, toARGB(colors), sampleValueRange, sampleToGeophysics); }
/** * Constructs a qualitative or quantitative category for samples in the specified range. * Sample values (usually integers) will be converted into geophysics values (usually * floating-point) through the {@code sampleToGeophysics} transform. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param colors A set of colors for this category. This array may have any length; * colors will be interpolated as needed. An array of length 1 means * that an uniform color should be used for all sample values. An array * of length 0 or a {@code null} array means that some default colors * should be used (usually a gradient from opaque black to opaque white). * @param sampleValueRange The range of sample values for this category. Element class * is usually {@link Integer}, but {@link Float} and {@link Double} are * accepted as well. * @param sampleToGeophysics A transform from sample values to geophysics values, * or {@code null} if this category is not a quantitative one. * * @throws ClassCastException if the range element class is not a {@link Number} subclass. * @throws IllegalArgumentException if the range is invalid. */ public Category(final CharSequence name, final Color[] colors, final NumberRange sampleValueRange, final MathTransform1D sampleToGeophysics) throws IllegalArgumentException { this(name, toARGB(colors), sampleValueRange, sampleToGeophysics); }
/** * Constructs a qualitative category for sample value {@code sample}. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param color The category color, or {@code null} for a default color. * @param sample The sample value as an integer, usually in the range 0 to 255. */ public Category(final CharSequence name, final Color color, final int sample) { this(name, toARGB(color, sample), Integer.valueOf(sample)); assert minimum == sample : minimum; assert maximum == sample : maximum; }
/** * Constructs a qualitative category for sample value {@code sample}. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param color The category color, or {@code null} for a default color. * @param sample The sample value as an integer, usually in the range 0 to 255. */ public Category(final CharSequence name, final Color color, final int sample) { this(name, toARGB(color, sample), new Integer(sample)); assert minimum == sample : minimum; assert maximum == sample : maximum; }
/** * Constructs a qualitative category for sample value {@code sample}. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param color The category color, or {@code null} for a default color. * @param sample The sample value as a double. May be one of {@code NaN} values. */ public Category(final CharSequence name, final Color color, final double sample) { this(name, toARGB(color, (int) sample), Double.valueOf(sample)); assert Double.doubleToRawLongBits(minimum) == Double.doubleToRawLongBits(sample) : minimum; assert Double.doubleToRawLongBits(maximum) == Double.doubleToRawLongBits(sample) : maximum; }
/** * Constructs a qualitative category for sample value {@code sample}. * * @param name The category name as a {@link String} or {@link InternationalString} object. * @param color The category color, or {@code null} for a default color. * @param sample The sample value as a double. May be one of {@code NaN} values. */ public Category(final CharSequence name, final Color color, final double sample) { this(name, toARGB(color, (int)sample), new Double(sample)); assert Double.doubleToRawLongBits(minimum) == Double.doubleToRawLongBits(sample) : minimum; assert Double.doubleToRawLongBits(maximum) == Double.doubleToRawLongBits(sample) : maximum; }
/** * Returns a category for the same range of sample values but a different color palette. * The array given in argument may have any length; colors will be interpolated as needed. * An array of length 1 means that an uniform color should be used for all sample values. * An array of length 0 or a {@code null} array means that some default colors should be * used (usually a gradient from opaque black to opaque white). * * @param colors A set of colors for the new category. * @return A category with the new color palette, or {@code this} * if the new colors are identical to the current ones. * * @see org.geotools.coverage.processing.ColorMap#recolor */ public Category recolor(final Color[] colors) { // GeophysicsCategory overrides this method in such // a way that the case below should never occurs. assert !(this instanceof GeophysicsCategory) : this; final int[] newARGB = toARGB(colors); if (Arrays.equals(ARGB, newARGB)) { return this; } // The range can be null only for GeophysicsCategory cases. Because // the later override this method, the case below should never occurs. assert range != null : this; final Category newCategory = new Category(name, newARGB, range, getSampleToGeophysics()); newCategory.inverse.range = inverse.range; // Share a common instance. return newCategory; }
/** * Returns a category for the same range of sample values but a different color palette. * The array given in argument may have any length; colors will be interpolated as needed. * An array of length 1 means that an uniform color should be used for all sample values. * An array of length 0 or a {@code null} array means that some default colors should be * used (usually a gradient from opaque black to opaque white). * * @param colors A set of colors for the new category. * @return A category with the new color palette, or {@code this} * if the new colors are identical to the current ones. * * @see org.geotools.coverage.processing.ColorMap#recolor */ public Category recolor(final Color[] colors) { // GeophysicsCategory overrides this method in such // a way that the case below should never occurs. assert !(this instanceof GeophysicsCategory) : this; final int[] newARGB = toARGB(colors); if (Arrays.equals(ARGB, newARGB)) { return this; } // The range can be null only for GeophysicsCategory cases. Because // the later override this method, the case below should never occurs. assert range != null : this; final Category newCategory = new Category(name, newARGB, range, getSampleToGeophysics()); newCategory.inverse.range = inverse.range; // Share a common instance. return newCategory; }