org.geotoolkit.coverage
Class TypeMap

Object
  extended by Static
      extended by TypeMap

public final class TypeMap
extends Static

Utility methods for choosing a sample model or a color model on the basis of a range of values. This class provides also some methods for mapping SampleDimensionType to DataBuffer types.

Since:
2.1
Version:
3.10
Author:
Martin Desruisseaux (IRD)
Module:
coverage/geotk-coverage (download)    View source code for this class

Method Summary
static ColorInterpretation getColorInterpretation(ColorModel model, int band)
          Returns the color interpretation code for the specified color model and band number.
static int getDataBufferType(SampleDimensionType type)
          Returns the DataBuffer type.
static InternationalString getName(SampleDimensionType type)
          Returns the sample dimension type name as an international string.
static NumberRange<?> getPositiveRange(SampleDimensionType type)
          Returns the range of positive sample values (excluding 0).
static NumberRange<?> getRange(SampleDimensionType type)
          Returns the full range of sample values for the specified dimension type.
static SampleDimensionType getSampleDimensionType(double min, double max)
          Returns the smallest sample dimension type capable to hold the specified range of values.
static SampleDimensionType getSampleDimensionType(long min, long max)
          Returns the smallest sample dimension type capable to hold the specified range of values.
static SampleDimensionType getSampleDimensionType(NumberSet type, int numBits)
          Returns the sample dimension for the given number of bits.
static SampleDimensionType getSampleDimensionType(Range<? extends Number> range)
          Returns the smallest sample dimension type capable to hold the specified range of values.
static SampleDimensionType getSampleDimensionType(SampleModel model, int band)
          Returns the sample dimension type for the specified sample model and band number.
static int getSize(SampleDimensionType type)
          Returns the size in bits.
static boolean isFloatingPoint(SampleDimensionType type)
          Returns true for floating-point data type.
static boolean isSigned(SampleDimensionType type)
          Returns true for signed sample type.
static Number wrapSample(double value, SampleDimensionType type, boolean allowWidening)
          Wraps the specified value into a number of the specified data type.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSampleDimensionType

public static SampleDimensionType getSampleDimensionType(Range<? extends Number> range)
Returns the smallest sample dimension type capable to hold the specified range of values.

Parameters:
range - The range of values.
Returns:
The smallest sample dimension type for the specified range.

getSampleDimensionType

public static SampleDimensionType getSampleDimensionType(double min,
                                                         double max)
Returns the smallest sample dimension type capable to hold the specified range of values. An heuristic approach is used for non-integer values.

Parameters:
min - The lower value, inclusive.
max - The upper value, inclusive as well.
Returns:
The smallest sample dimension type for the specified range.

getSampleDimensionType

public static SampleDimensionType getSampleDimensionType(long min,
                                                         long max)
Returns the smallest sample dimension type capable to hold the specified range of values.

Parameters:
min - The lower value, inclusive.
max - The upper value, inclusive as well.
Returns:
The smallest sample dimension type for the specified range.

getSampleDimensionType

public static SampleDimensionType getSampleDimensionType(NumberSet type,
                                                         int numBits)
Returns the sample dimension for the given number of bits. This method may return a type having more bits than the requested one. It may also return a signed type even if a unsigned type was requested, provided that the returned type is wide enough for holding all unsigned values expressed using the given number of bits.

Parameters:
type - The number type as one of NATURAL for unsigned integers, INTEGER for signed integers, or READ for floating point values.
numBits - The number of bits.
Returns:
The sample dimension type for the given criterion, or null if none match.
Since:
3.10

getSampleDimensionType

public static SampleDimensionType getSampleDimensionType(SampleModel model,
                                                         int band)
                                                  throws IllegalArgumentException
Returns the sample dimension type for the specified sample model and band number. If the sample model use an undefined data type, then this method returns null.

Parameters:
model - The sample model.
band - The band to query.
Returns:
The sample dimension type for the specified sample model and band number.
Throws:
IllegalArgumentException - if the band number is not in the valid range.

getName

public static InternationalString getName(SampleDimensionType type)
Returns the sample dimension type name as an international string. For example, the localized name for SampleDimensionType.UNSIGNED_16BITS is "16 bits unsigned integer" in English and "Entier non-signé sur 16 bits" in French.

Parameters:
type - The sample dimension type for which to get a localized description.
Returns:
The localized description of the given type.

getDataBufferType

public static int getDataBufferType(SampleDimensionType type)
Returns the DataBuffer type. This is one of the following constants: TYPE_BYTE, TYPE_USHORT, TYPE_SHORT, TYPE_INT, TYPE_FLOAT, TYPE_DOUBLE or DataBuffer.TYPE_UNDEFINED if the type is unrecognized.

Parameters:
type - The sample dimension type for which to get the data buffer type.
Returns:
The data buffer type for the given sample dimension type.

getSize

public static int getSize(SampleDimensionType type)
Returns the size in bits. The value range from 1 to 64. This is similar, but different than DataBuffer.getDataTypeSize(int), which have values ranging from 8 to 64.

Parameters:
type - The sample dimension type for which to get the data size.
Returns:
The data size in bits for the given sample dimension type.

isSigned

public static boolean isSigned(SampleDimensionType type)
Returns true for signed sample type.

Parameters:
type - The sample dimension type for which to get information about its data.
Returns:
true if the data of the given sample dimension type are signed.

isFloatingPoint

public static boolean isFloatingPoint(SampleDimensionType type)
Returns true for floating-point data type.

Parameters:
type - The sample dimension type for which to get information about its data.
Returns:
true if the data of the given sample dimension type are floating points.

getRange

public static NumberRange<?> getRange(SampleDimensionType type)
Returns the full range of sample values for the specified dimension type.

Parameters:
type - The sample dimension type for which to get its data range.
Returns:
The range of values for the given sample dimension type.

getPositiveRange

public static NumberRange<?> getPositiveRange(SampleDimensionType type)
Returns the range of positive sample values (excluding 0). This range is non-null only for unsigned type. A range excluding 0 is sometime useful when the 0 value is reserved for a "no data" category.

Parameters:
type - The sample dimension type for which to get its data range.
Returns:
The range of values for the given sample dimension type.

wrapSample

public static Number wrapSample(double value,
                                SampleDimensionType type,
                                boolean allowWidening)
                         throws IllegalArgumentException
Wraps the specified value into a number of the specified data type. If the value can't fit in the specified type, then a wider type is chosen unless allowWidening is false.

Parameters:
value - The value to wrap in a Number object.
type - A constant from the SampleDimensionType code list.
allowWidening - true if this method is allowed to returns a wider type than the usual one for the specified type.
Returns:
The value as a Number.
Throws:
IllegalArgumentException - if type is not a recognized constant, or if allowWidening is false and the specified value can't fit in the specified sample type.

getColorInterpretation

public static ColorInterpretation getColorInterpretation(ColorModel model,
                                                         int band)
                                                  throws IllegalArgumentException
Returns the color interpretation code for the specified color model and band number.

Parameters:
model - The color model.
band - The band to query.
Returns:
The code for the specified color model and band number.
Throws:
IllegalArgumentException - if the band number is not in the valid range.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.