Example usage for java.lang ArrayIndexOutOfBoundsException getStackTrace

List of usage examples for java.lang ArrayIndexOutOfBoundsException getStackTrace

Introduction

In this page you can find the example usage for java.lang ArrayIndexOutOfBoundsException getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:uk.ac.sanger.mig.xray.trendlinecropper.utils.TrendCropper.java

/**
 * Crop out a region of the image following the trend line.
 * //from   ww  w . j av a  2 s  .c  o m
 * @param inImage
 *            Image that will be cropped. Original image is not modified
 * @param coefs
 *            coeficients that are used to predict points of the trendline
 * @param trendType
 *            the trend type, produced by the Trend Line node
 * @return image with specified region cropped out
 */
public ImgPlus<T> process(ImgPlus<T> inImage, String coefs, String trendType) {
    final ImgPlus<T> image = inImage.copy();

    final long cols = image.dimension(Image.COL);
    final long rows = image.dimension(Image.ROW);

    // if user didn't set the ending row, will use the last row
    final int actualEndRow = (int) ((endRow == -1) ? rows : endRow);

    final OLSTrendLine trend = getTrendType(trendType, convertCoefs(coefs));

    // random access to traverse the image vertically
    final RandomAccess<T> ra = image.randomAccess();
    // random access to travel anywhere in the image to modify the pixel
    // values
    final RandomAccess<T> modRa = ra.copyRandomAccess();

    ra.setPosition(startRow, Image.ROW);
    ra.setPosition(0, Image.COL);

    final int firstY = ra.getIntPosition(Image.ROW);
    final int firstX = (int) trend.predict(firstY);

    try {
        while (ra.getIntPosition(Image.ROW) != actualEndRow) {

            final int y = ra.getIntPosition(Image.ROW);
            final int x = (int) trend.predict(y);

            // set position to predicted x and y
            modRa.setPosition(x, Image.COL);
            modRa.setPosition(y, Image.ROW);

            // delete pixels to the right of the trend line
            setPixelsIn(modRa, Image.COL, (x + rightMargin), 0, FORWARD, (int) cols);

            // delete pixels to the left of the trend line
            setPixelsIn(modRa, Image.COL, (x - leftMargin), 0, BACKWARD, (int) cols);

            ra.fwd(Image.ROW);
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        // shouldn't get here
        logger.debug(e.getStackTrace());
        logger.fatal("Critical error analysing one of the images.");
    }

    if (cropTop)
        cropTop(image, firstY, firstX);

    return image;
}