Example usage for org.apache.commons.math.util FastMath round

List of usage examples for org.apache.commons.math.util FastMath round

Introduction

In this page you can find the example usage for org.apache.commons.math.util FastMath round.

Prototype

public static int round(final float x) 

Source Link

Document

Get the closest int to x.

Usage

From source file:org.esa.nest.gpf.ALOSDeskewingOp.java

/**
 * Called by the framework in order to compute the stack of tiles for the given target bands.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetTiles     The current tiles to be computed for each target band.
 * @param targetRectangle The area in pixel coordinates to be computed (same for all rasters in <code>targetRasters</code>).
 * @param pm              A progress monitor which should be used to determine computation cancelation requests.
 * @throws OperatorException if an error occurs during computation of the target rasters.
 *//*from   w  w w . j  a v  a 2  s.c  o  m*/
@Override
public void computeTileStack(Map<Band, Tile> targetTiles, Rectangle targetRectangle, ProgressMonitor pm)
        throws OperatorException {

    try {
        final int tx0 = targetRectangle.x;
        final int ty0 = targetRectangle.y;
        final int tw = targetRectangle.width;
        final int th = targetRectangle.height;
        final int tyMax = ty0 + th;
        final int txMax = tx0 + tw;
        //System.out.println("x0 = " + tx0 + ", y0 = " + ty0 + ", w = " + tw + ", h = " + th);

        final int maxShift = (int) computeMaxShift(txMax, ty0);

        final Rectangle sourceRectangle = getSourceRectangle(tx0, ty0, tw, th, maxShift);
        final int sx0 = sourceRectangle.x;
        final int sy0 = sourceRectangle.y;
        final int sw = sourceRectangle.width;
        final int sh = sourceRectangle.height;
        final int syMax = sy0 + sh;
        final int sxMax = sx0 + sw;

        final Set<Band> keySet = targetTiles.keySet();
        double totalShift;
        for (Band targetBand : keySet) {

            final Tile targetTile = targetTiles.get(targetBand);
            final String srcBandName = targetBandNameToSourceBandName.get(targetBand.getName())[0];
            final Tile sourceTile = getSourceTile(sourceProduct.getBand(srcBandName), sourceRectangle);
            final ProductData trgDataBuffer = targetTile.getDataBuffer();
            final ProductData srcDataBuffer = sourceTile.getDataBuffer();
            final TileIndex srcIndex = new TileIndex(sourceTile);

            for (int y = sy0; y < syMax; y++) {
                srcIndex.calculateStride(y);
                final stateVector v = getOrbitStateVector(firstLineTime + y * lineTimeInterval);
                for (int x = sx0; x < sxMax; x++) {

                    if (useMapreadyShiftOnly) {
                        totalShift = FastMath.round(fracShift * x);
                    } else if (useFAQShiftOnly) {
                        totalShift = computeFAQShift(v, x);
                    } else if (useBoth) {
                        totalShift = computeFAQShift(v, x) + FastMath.round(fracShift * x);
                    } else if (useHybrid) {
                        totalShift = absShift + FastMath.round(fracShift * x);
                    } else {
                        throw new OperatorException("No method was selected for shift calculation");
                    }

                    final int newy = y + (int) totalShift;
                    if (newy >= ty0 && newy < tyMax) {
                        final int trgIdx = targetTile.getDataBufferIndex(x, newy);
                        trgDataBuffer.setElemFloatAt(trgIdx,
                                srcDataBuffer.getElemFloatAt(srcIndex.getIndex(x)));
                    }
                }
            }
        }

    } catch (Throwable e) {
        OperatorUtils.catchOperatorException(getId(), e);
    }
}

From source file:org.esa.nest.gpf.ALOSDeskewingOp.java

private double computeMaxShift(final int txMax, final int ty0) throws Exception {

    if (useMapreadyShiftOnly) {
        return FastMath.round(txMax * fracShift);
    } else if (useFAQShiftOnly) {
        final stateVector v = getOrbitStateVector(firstLineTime + ty0 * lineTimeInterval);
        return computeFAQShift(v, txMax) + FastMath.round(txMax * fracShift);
    } else { // hybrid
        return absShift + FastMath.round(txMax * fracShift);
    }/*from   w  w  w .j a  v  a2  s . c om*/
}