Class CellGrid


  • public class CellGrid
    extends java.lang.Object
    Defines AbstractCellImg geometry and translates between image, cell, and grid coordinates.
    • Constructor Summary

      Constructors 
      Constructor Description
      CellGrid​(long[] dimensions, int[] cellDimensions)  
      CellGrid​(CellGrid grid)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int cellDimension​(int d)
      Get the number of pixels in a standard cell in dimension d.
      void cellDimensions​(int[] dimensions)
      Write the number of pixels in a standard cell in each dimension into the provided dimensions array.
      CellGrid.CellIntervals cellIntervals()  
      boolean equals​(java.lang.Object obj)  
      (package private) void getCellAndPixelIndices​(long index, long[] indices)
      From a global index (in CellIterationOrder, with flat iteration order of the cells), compute the flattened grid index of the cell containing index, and the flattened pixel index within the cell.
      (package private) int getCellCoordinates​(long[] position, int[] cellSteps, long[] cellMin, long[] cellMax)
      Compute all cell-related coordinates/sizes required by CellRandomAccess.
      int getCellDimension​(int d, long cellGridPosition)
      From the position of a cell in the grid, compute the size of the cell in dimension d.
      int[] getCellDimensions()
      Get the number of pixels in a standard cell in each dimension as a new int[].
      CellGrid.CellDimensionsAndSteps getCellDimensions​(long[] cellGridPosition, long[] cellMin)
      From the position of a cell in the grid, compute the image position of the first pixel of the cell (the offset of the cell in image coordinates) and the dimensions of the cell.
      void getCellDimensions​(long[] cellGridPosition, long[] cellMin, int[] cellDims)
      From the position of a cell in the grid, compute the image position of the first pixel of the cell (the offset of the cell in image coordinates) and the dimensions of the cell.
      CellGrid.CellDimensionsAndSteps getCellDimensions​(long index, long[] cellMin)
      From the index of a cell in the grid, compute the image position of the first pixel of the cell (the offset of the cell in image coordinates) and the dimensions of the cell.
      void getCellDimensions​(long index, long[] cellMin, int[] cellDims)
      From the index of a cell in the grid, compute the image position of the first pixel of the cell (the offset of the cell in image coordinates) and the dimensions of the cell.
      long getCellGridIndexFlat​(long[] cellGridPosition)
      From the position of a cell in the grid, compute the flattened index of the cell in the grid.
      void getCellGridPositionFlat​(long index, long[] cellGridPosition)
      From the flattened index of a cell in the grid, compute the position of a cell in the grid.
      void getCellInterval​(long[] cellGridPosition, long[] cellMin, long[] cellMax)  
      long getCellMin​(int d, long cellGridPosition)
      From the position of a cell in the grid, compute the image position in dimension d of the first pixel of the cell (the offset of the cell in image coordinates).
      void getCellPosition​(long[] position, long[] cellPos)
      Get the grid position of the cell containing the element at position.
      void getCellPosition​(long[] position, Positionable cellPos)
      Get the grid position of the cell containing the element at position.
      long[] getGridDimensions()
      Get the number of cells in each dimension as a new long[].
      long[] getImgDimensions()
      Get the number of pixels in each dimension as a new long[].
      (package private) void getIndicesFromGridPosition​(long[] cellGridPosition, long[] indices)
      From the grid coordinates of a cell, compute the grid index of the cell, and the global index of the first pixel in the cell.
      (package private) void getIndicesFromGridPosition​(Localizable cellGridPosition, long[] indices)
      From the grid coordinates of a cell, compute the grid index of the cell, and the global index of the first pixel in the cell.
      long gridDimension​(int d)
      Get the number of cells in dimension d.
      void gridDimensions​(long[] dimensions)
      Write the number of cells in each dimension into the provided dimensions array.
      int hashCode()  
      long imgDimension​(int d)
      Get the number of pixels in dimension d.
      void imgDimensions​(long[] dimensions)
      Write the number of pixels in each dimension into the provided dimensions array.
      (package private) long indexOfFirstPixelInCell​(long cellGridIndex)
      Get the global index of the first pixel in the cell with the given cellGridIndex.
      (package private) long indexOfFirstPixelInCell​(long[] cellGridPosition)
      Get the global index of the first pixel in the cell with the given grid coordinates.
      (package private) long indexOfFirstPixelInCell​(long cellGridIndex, long[] tmp)
      Get the global index of the first pixel in the cell with the given cellGridIndex.
      (package private) long indexOfFirstPixelInCell​(Localizable cellGridPosition)
      Get the global index of the first pixel in the cell with the given grid coordinates.
      int numDimensions()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • n

        private final int n
      • dimensions

        private final long[] dimensions
      • steps

        private final long[] steps
      • cellDimensions

        private final int[] cellDimensions
      • numCells

        private final long[] numCells
      • borderSize

        private final int[] borderSize
      • hashcode

        private final int hashcode
      • cellDimensionsAndSteps

        private final CellGrid.CellDimensionsAndSteps[] cellDimensionsAndSteps
        Pre-computed dimensions[], steps[], and numPixels for each distinct cell type (inner, X border, Y border, XY border, etc). Indexed by flattened cell type index, where cell type is arranges in a 2^n grid with the inner cell at (0,...,0) etc.
    • Constructor Detail

      • CellGrid

        public CellGrid​(long[] dimensions,
                        int[] cellDimensions)
        Parameters:
        dimensions - the dimensions of the image (in pixels, not in cells).
        cellDimensions - the dimensions of a standard cell (in pixels). Cells on the max border of the image may be cut off and have different dimensions.
      • CellGrid

        public CellGrid​(CellGrid grid)
    • Method Detail

      • numDimensions

        public int numDimensions()
      • getGridDimensions

        public long[] getGridDimensions()
        Get the number of cells in each dimension as a new long[].
      • gridDimensions

        public void gridDimensions​(long[] dimensions)
        Write the number of cells in each dimension into the provided dimensions array.
      • gridDimension

        public long gridDimension​(int d)
        Get the number of cells in dimension d.
      • getImgDimensions

        public long[] getImgDimensions()
        Get the number of pixels in each dimension as a new long[]. Note, that this is the number of pixels in all cells combined, not the number of cells!
      • imgDimensions

        public void imgDimensions​(long[] dimensions)
        Write the number of pixels in each dimension into the provided dimensions array. Note, that this is the number of pixels in all cells combined, not the number of cells!
      • imgDimension

        public long imgDimension​(int d)
        Get the number of pixels in dimension d. Note, that this is the number of pixels in all cells combined, not the number of cells!
      • getCellDimensions

        public int[] getCellDimensions()
        Get the number of pixels in a standard cell in each dimension as a new int[]. Cells on the borders of the image may be cut off and have different dimensions.
      • cellDimensions

        public void cellDimensions​(int[] dimensions)
        Write the number of pixels in a standard cell in each dimension into the provided dimensions array. Cells on the max border of the image may be cut off and have different dimensions.
      • cellDimension

        public int cellDimension​(int d)
        Get the number of pixels in a standard cell in dimension d. Cells on the max border of the image may be cut off and have different dimensions.
      • getCellDimensions

        public void getCellDimensions​(long index,
                                      long[] cellMin,
                                      int[] cellDims)
        From the index of a cell in the grid, compute the image position of the first pixel of the cell (the offset of the cell in image coordinates) and the dimensions of the cell. The dimensions will be the standard cellDimensions unless the cell is at the border of the image in which case it might be truncated.

        Note, that this method assumes that the cell grid has flat iteration order. It this is not the case, use getCellDimensions(long[], long[], int[]).

        Parameters:
        index - flattened grid coordinates of the cell.
        cellMin - offset of the cell in image coordinates are written here.
        cellDims - dimensions of the cell are written here.
      • getCellDimensions

        public void getCellDimensions​(long[] cellGridPosition,
                                      long[] cellMin,
                                      int[] cellDims)
        From the position of a cell in the grid, compute the image position of the first pixel of the cell (the offset of the cell in image coordinates) and the dimensions of the cell. The dimensions will be the standard cellDimensions unless the cell is at the border of the image in which case it might be truncated.
        Parameters:
        cellGridPosition - grid coordinates of the cell.
        cellMin - offset of the cell in image coordinates are written here.
        cellDims - dimensions of the cell are written here.
      • getCellDimensions

        public CellGrid.CellDimensionsAndSteps getCellDimensions​(long index,
                                                                 long[] cellMin)
        From the index of a cell in the grid, compute the image position of the first pixel of the cell (the offset of the cell in image coordinates) and the dimensions of the cell. The dimensions will be the standard cellDimensions unless the cell is at the border of the image in which case it might be truncated.

        Note, that this method assumes that the cell grid has flat iteration order. It this is not the case, use getCellDimensions(long[], long[], int[]).

        Parameters:
        index - flattened grid coordinates of the cell.
        cellMin - offset of the cell in image coordinates are written here.
        Returns:
        the dimensions of the cell and derived strides and number of pixels.
      • getCellDimensions

        public CellGrid.CellDimensionsAndSteps getCellDimensions​(long[] cellGridPosition,
                                                                 long[] cellMin)
        From the position of a cell in the grid, compute the image position of the first pixel of the cell (the offset of the cell in image coordinates) and the dimensions of the cell. The dimensions will be the standard cellDimensions unless the cell is at the border of the image in which case it might be truncated.
        Parameters:
        cellGridPosition - grid coordinates of the cell.
        cellMin - offset of the cell in image coordinates are written here.
        Returns:
        the dimensions of the cell and derived strides and number of pixels.
      • getCellInterval

        public void getCellInterval​(long[] cellGridPosition,
                                    long[] cellMin,
                                    long[] cellMax)
      • getCellDimension

        public int getCellDimension​(int d,
                                    long cellGridPosition)
        From the position of a cell in the grid, compute the size of the cell in dimension d. The size will be the standard cellDimensions unless the cell is at the border of the image in which case it might be truncated.
        Parameters:
        d - dimension index
        cellGridPosition - grid coordinates of the cell in dimension d.
        Returns:
        size of the cell in dimension d.
      • getCellMin

        public long getCellMin​(int d,
                               long cellGridPosition)
        From the position of a cell in the grid, compute the image position in dimension d of the first pixel of the cell (the offset of the cell in image coordinates).
        Parameters:
        d - dimension index
        cellGridPosition - grid coordinates of the cell in dimension d.
        Returns:
        offset of the cell in dimension d (in image coordinates).
      • getCellGridPositionFlat

        public void getCellGridPositionFlat​(long index,
                                            long[] cellGridPosition)
        From the flattened index of a cell in the grid, compute the position of a cell in the grid.
        Parameters:
        index - flattened grid coordinates of the cell.
        cellGridPosition - grid coordinates of the cell are written here.
      • getCellGridIndexFlat

        public long getCellGridIndexFlat​(long[] cellGridPosition)
        From the position of a cell in the grid, compute the flattened index of the cell in the grid.
        Parameters:
        cellGridPosition - grid coordinates of the cell
        Returns:
        flattened grid coordinates of the cell.
      • getCellPosition

        public void getCellPosition​(long[] position,
                                    long[] cellPos)
        Get the grid position of the cell containing the element at position.
        Parameters:
        position - position of an element in the image.
        cellPos - is set to the grid position of the cell containing the element.
      • getCellPosition

        public void getCellPosition​(long[] position,
                                    Positionable cellPos)
        Get the grid position of the cell containing the element at position.
        Parameters:
        position - position of an element in the image.
        cellPos - is set to the grid position of the cell containing the element.
      • getCellAndPixelIndices

        void getCellAndPixelIndices​(long index,
                                    long[] indices)
        From a global index (in CellIterationOrder, with flat iteration order of the cells), compute the flattened grid index of the cell containing index, and the flattened pixel index within the cell.
        Parameters:
        index - pixel index in flat iteration order
        indices - array with 2 elements, which will be set to the flattened cell index (indices[0]), and the flattened pixel index within the cell (indices[1]).
      • getIndicesFromGridPosition

        void getIndicesFromGridPosition​(long[] cellGridPosition,
                                        long[] indices)
        From the grid coordinates of a cell, compute the grid index of the cell, and the global index of the first pixel in the cell.
        Parameters:
        cellGridPosition - grid coordinates of a cell
        indices - array with 2 elements, which will be set to the grid index of the cell (indices[0]), and the global pixel index of the first pixel in the cell (indices[1]).
      • getIndicesFromGridPosition

        void getIndicesFromGridPosition​(Localizable cellGridPosition,
                                        long[] indices)
        From the grid coordinates of a cell, compute the grid index of the cell, and the global index of the first pixel in the cell.
        Parameters:
        cellGridPosition - grid coordinates of a cell
        indices - array with 2 elements, which will be set to the grid index of the cell (indices[0]), and the global pixel index of the first pixel in the cell (indices[1]).
      • indexOfFirstPixelInCell

        long indexOfFirstPixelInCell​(long cellGridIndex)
        Get the global index of the first pixel in the cell with the given cellGridIndex.
        Parameters:
        cellGridIndex - grid index of a cell
        Returns:
        global index of the first pixel in the cell
      • indexOfFirstPixelInCell

        long indexOfFirstPixelInCell​(long cellGridIndex,
                                     long[] tmp)
        Get the global index of the first pixel in the cell with the given cellGridIndex.
        Parameters:
        cellGridIndex - grid index of a cell
        tmp - temporary array used to store the gird coordinates of the cell
        Returns:
        global index of the first pixel in the cell
      • indexOfFirstPixelInCell

        long indexOfFirstPixelInCell​(long[] cellGridPosition)
        Get the global index of the first pixel in the cell with the given grid coordinates.
        Parameters:
        cellGridPosition - grid coordinates of a cell
        Returns:
        global index of the first pixel in the cell
      • indexOfFirstPixelInCell

        long indexOfFirstPixelInCell​(Localizable cellGridPosition)
        Get the global index of the first pixel in the cell with the given grid coordinates.
        Parameters:
        cellGridPosition - grid coordinates of a cell
        Returns:
        global index of the first pixel in the cell
      • getCellCoordinates

        int getCellCoordinates​(long[] position,
                               int[] cellSteps,
                               long[] cellMin,
                               long[] cellMax)
        Compute all cell-related coordinates/sizes required by CellRandomAccess.
        Parameters:
        position - current image position
        cellSteps - allocation steps for cell are written here.
        cellMin - offset of the cell in image coordinates are written here.
        cellMax - is set to the max of the cell in image coordinates are written here.
        Returns:
        index within the cell.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object