Class DomainMapper<T>

  • All Implemented Interfaces:
    Iterable<DomainMapper.DomainMapperEntry<T>>
    Direct Known Subclasses:
    Domain1DMapper, Domain2DMapper

    public abstract class DomainMapper<T>
    extends Object
    implements Iterable<DomainMapper.DomainMapperEntry<T>>

    Maps real-world points to i and j indices of corresponding points within the source data. A DomainMapper is constructed using the following general algorithm:

     For each point in the given targetDomain:
        1. Find the grid cell in the source grid that contains this point
        2. Let i and j be the coordinates of this grid cell
        3. Let p be the index of this point in the target domain
        4. Add the mapping (p to i,j) to the pixel map
     

    The resulting DomainMapper is then used by DataReadingStrategys to work out what data to read from the source data files. A variety of strategies are possible for reading these data points, each of which may be optimal in a certain situation.

    Author:
    Jon Blower, Guy
    See Also:
    DataReadingStrategy
    • Field Detail

      • log

        protected static org.slf4j.Logger log
    • Constructor Detail

      • DomainMapper

        protected DomainMapper​(HorizontalGrid sourceGrid,
                               long targetDomainSize)
    • Method Detail

      • sortIndices

        protected void sortIndices()
        Sorts the arrays of source and target indices so that the arrays are in order of increasing source grid index, then increasing target grid index. Uses an in-place quicksort algorithm adapted from http://www.vogella.de/articles/JavaAlgorithmsQuicksort/article.html.
      • put

        protected void put​(int i,
                           int j,
                           int targetGridIndex)
        Adds a new pixel index to this map. Does nothing if either i or j is negative.
        Parameters:
        i - The i index of the point in the source data
        j - The j index of the point in the source data
        targetGridIndex - The index of the corresponding point in the target domain
      • isEmpty

        public boolean isEmpty()
        Returns true if this DomainMapper does not contain any data: this will happen if there is no intersection between the requested data and the data on disk.
      • getTargetDomainSize

        public int getTargetDomainSize()
        Returns the size of the target domain
      • getMinIIndex

        public int getMinIIndex()
        Gets the minimum i index in the whole domain mapper
      • getMinJIndex

        public int getMinJIndex()
        Gets the minimum j index in the whole domain mapper
      • getMaxIIndex

        public int getMaxIIndex()
        Gets the maximum i index in the whole domain mapper
      • getMaxJIndex

        public int getMaxJIndex()
        Gets the maximum j index in the whole domain mapper
      • getNumUniqueIJPairs

        public int getNumUniqueIJPairs()

        Gets the number of unique i-j pairs in this pixel map. When combined with the size of the resulting image we can quantify the under- or over-sampling. This is the number of data points that will be extracted by the DataReadingStrategy.PIXEL_BY_PIXEL data reading strategy.

        This implementation counts the number of unique pairs by cycling through the iterator() and so is not a cheap operation. Use sparingly, e.g. for debugging.

        Returns:
        the number of unique i-j pairs in this pixel map.
      • getBoundingBoxSize

        public long getBoundingBoxSize()
        Gets the size of the i-j bounding box that encompasses all data. This is the number of data points that will be extracted using the BOUNDING_BOX data reading strategy.
        Returns:
        the size of the i-j bounding box that encompasses all data.
      • convertIndexToCoordType

        protected abstract T convertIndexToCoordType​(int index)
        This performs the conversion from a single long index into whatever coordinate type is required. The simplest example would be to simply return the index for a 1D array (see Domain1DMapper for this). TODO This currently takes an int. Do we want to support target domains which are bigger than Integer.MAX_VALUE?
        Parameters:
        index - The index to convert to a co-ordinate
        Returns:
        The co-ordinate represented by the index
      • scanlineIterator

        public Iterator<DomainMapper.Scanline<T>> scanlineIterator()
        Returns an unmodifiable iterator over all the Scanlines in this pixel map
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object