* * PURPOSE: * This class represents a generic MDD in the sense that it * is independent of the cell base type. The only information * available is the length in bytes of the base type. ************************************************************ */ public class RasGMArray extends RasObject implements RasGlobalDefs { static final String rcsid = "@(#)Package rasj, class RasGMArray: $Header: /home/rasdev/CVS-repository/rasdaman/java/rasj/RasGMArray.java,v 1.26 2003/12/10 21:04:23 rasdev Exp $"; /** spatial domain */ protected RasMInterval domain; /** internal array representation in bytes*/ protected byte[] data; /** internal array representation as Object for use in special marrays*/ protected Object objectData; /** internal object for accessing one cell of the array */ protected byte[] currentCell; /** size of internal array representation in bytes */ protected long dataSize; /** length of the cell base type in bytes */ protected long typeLength; /** store current data format */ protected int currentFormat; //RasDataFormat -> RasGlobalDefs /** storage layout object */ protected RasStorageLayout storageLayout; /** * Default constructor. **/ public RasGMArray() { super(RAS_MARRAY); data = null; objectData = null; currentCell = null; dataSize = 0; domain = null; typeLength = 0; currentFormat = RAS_ARRAY; storageLayout = new RasStorageLayout(); } /** * Constructor for uninitialized MDD objects * @param initDomain The initial Domain of the GMArray * @param cellTypeLength The length of the cell type used */ public RasGMArray(final RasMInterval initDomain, long cellTypeLength) { super(RAS_MARRAY); data = null; objectData = null; dataSize = 0; domain = initDomain; typeLength = cellTypeLength; currentFormat = RAS_ARRAY; storageLayout = new RasStorageLayout(); // If dimensionality is zero, just one scalar value is stored. dataSize = ((domain.dimension() != 0) ? domain.cellCount() : 1) * typeLength; data = new byte[(int)dataSize]; currentCell = new byte[(int)cellTypeLength]; } /** * Constructor for uninitialized MDD objects with Storage Layout * @param initDomain The initial Domain of the GMArray * @param cellTypeLength The length of the cell type used * @param RasStorageLayout The storage layout to be used */ public RasGMArray(final RasMInterval initDomain, long cellTypeLength, RasStorageLayout stl) { super(RAS_MARRAY); data = null; objectData = null; dataSize = 0; domain = initDomain; typeLength = cellTypeLength; currentFormat = RAS_ARRAY; storageLayout = stl; // If dimensionality is zero, just one scalar value is stored. dataSize = ((domain.dimension() != 0) ? domain.cellCount() : 1) * typeLength; data = new byte[(int)dataSize]; currentCell = new byte[(int)cellTypeLength]; } /** * Copy constructor. * @param obj a copy of this object will be created **/ public RasGMArray(final RasGMArray obj) { super(obj, RAS_MARRAY); if(data!=null) { System.arraycopy(obj.getArray(), 0, data, 0, (int)obj.dataSize); objectData = null; } dataSize = obj.getArraySize(); domain = obj.spatialDomain(); typeLength = obj.typeLength; currentFormat = obj.currentFormat; storageLayout = new RasStorageLayout(obj.storageLayout); if(obj.typeLength != 0) currentCell = new byte[(int)obj.typeLength]; } /** * This method copies the values of mArray to itself. * @param mArray the values of this MArray will be copied * @return itself (after having copied the values from mArray) **/ public RasGMArray setTo(final RasGMArray mArray) { if(this != mArray) { if(data != null) { data = null; } if (mArray.data != null) { dataSize = mArray.dataSize; data = mArray.data; } if (mArray.objectData != null) { dataSize = mArray.dataSize; objectData = mArray.objectData; } if(storageLayout != null) { storageLayout = null; } // this has to be changed to a clone() function in future if(mArray.storageLayout != null) storageLayout = new RasStorageLayout(mArray.storageLayout); domain = mArray.domain; typeLength = mArray.typeLength; currentFormat = mArray.currentFormat; } return this; } /** * Reads a cell of the MDD. The cell's value is returned * as a byte array, the length of which depends on the size of the base type. * If you want to get the cell value as a primitive type (like integer or byte), * you either have to do a cast or use the type-specific MArrays * that are derived from this class. * @param point the coordinates of the requested cell * @return a byte array representing the value of the requested cell. **/ public byte[] getCell(RasPoint point) throws RasDimensionMismatchException, RasIndexOutOfBoundsException { // first test dimensionality if(point.dimension() != domain.dimension()) throw new RasDimensionMismatchException(point.dimension(), domain.dimension()); if(typeLength == 0) return null; System.arraycopy(data, (int)(domain.cellOffset(point)*typeLength), currentCell, 0, (int)typeLength); return currentCell; } /** * Returns the storage layout object of this MDD. * @return the storage layout object **/ public final RasStorageLayout getStorageLayout() { return storageLayout; } /** * Sets the storage layout object and checks compatibility with the domain. * @param stl the new storage layout */ public void setStorageLayout(RasStorageLayout stl) throws RasDimensionMismatchException { if (!stl.isCompatible(domain)) throw new RasDimensionMismatchException(domain.dimension(),stl.getSpatialDomain().dimension()); else storageLayout = stl; } /** * Returns a RasGMArray that is the intersection of the current domain * with the specified interval. * @param where the interval that is used for the intersection * @return the result of the intersection of this GMArray with the parameter interval */ public RasGMArray intersectionWith(RasMInterval where) { RasGMArray tile = new RasGMArray(); try { RasMInterval objDomain = spatialDomain(); int numDims = objDomain.dimension(); long tlength = getTypeLength(); byte[] objData = new byte[(int)(where.cellCount() * tlength)]; tile.setSpatialDomain(where); tile.setTypeLength(tlength); tile.setArray(objData); tile.setArraySize(where.cellCount() * tlength); long blockLength = where.item(numDims-1).high() - where.item(numDims-1).low() + 1; long total = where.cellCount()/blockLength; byte[] dest = objData; byte[] source = getArray(); int blength = (int)(blockLength * tlength); for (long cell=0; cellMore specific MDDs including base type information for more * type safety are represented by a set of typed subclasses. * @version $Revision: 1.26 $ * * * COMMENTS: * *