Example usage for java.lang Float MAX_VALUE

List of usage examples for java.lang Float MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Float MAX_VALUE.

Prototype

float MAX_VALUE

To view the source code for java.lang Float MAX_VALUE.

Click Source Link

Document

A constant holding the largest positive finite value of type float , (2-2-23)·2127.

Usage

From source file:net.semanticmetadata.lire.imageanalysis.sift.FloatArray2DScaleOctaveDoGDetector.java

private void detectCandidates() {
    FloatArray2D[] d = octave.getD();/*  w  w w  .  j  a v a  2 s  .c o m*/

    for (int i = d.length - 2; i >= 1; --i) {
        int ia = i - 1;
        int ib = i + 1;
        for (int y = d[i].height - 2; y >= 1; --y) {
            int r = y * d[i].width;
            int ra = r - d[i].width;
            int rb = r + d[i].width;

            X: for (int x = d[i].width - 2; x >= 1; --x) {
                int ic = i;
                int iac = ia;
                int ibc = ib;
                int yc = y;
                int rc = r;
                int rac = ra;
                int rbc = rb;
                int xc = x;
                int xa = xc - 1;
                int xb = xc + 1;
                float e111 = d[ic].data[r + xc];

                // check if d(x, y, i) is an extremum
                // do it pipeline-friendly ;)

                float e000 = d[iac].data[rac + xa];
                boolean isMax = e000 < e111;
                boolean isMin = e000 > e111;
                if (!(isMax || isMin))
                    continue;
                float e100 = d[iac].data[rac + xc];
                isMax &= e100 < e111;
                isMin &= e100 > e111;
                if (!(isMax || isMin))
                    continue;
                float e200 = d[iac].data[rac + xb];
                isMax &= e200 < e111;
                isMin &= e200 > e111;
                if (!(isMax || isMin))
                    continue;

                float e010 = d[iac].data[rc + xa];
                isMax &= e010 < e111;
                isMin &= e010 > e111;
                if (!(isMax || isMin))
                    continue;
                float e110 = d[iac].data[rc + xc];
                isMax &= e110 < e111;
                isMin &= e110 > e111;
                if (!(isMax || isMin))
                    continue;
                float e210 = d[iac].data[rc + xb];
                isMax &= e210 < e111;
                isMin &= e210 > e111;
                if (!(isMax || isMin))
                    continue;

                float e020 = d[iac].data[rbc + xa];
                isMax &= e020 < e111;
                isMin &= e020 > e111;
                if (!(isMax || isMin))
                    continue;
                float e120 = d[iac].data[rbc + xc];
                isMax &= e120 < e111;
                isMin &= e120 > e111;
                if (!(isMax || isMin))
                    continue;
                float e220 = d[iac].data[rbc + xb];
                isMax &= e220 < e111;
                isMin &= e220 > e111;
                if (!(isMax || isMin))
                    continue;

                float e001 = d[ic].data[rac + xa];
                isMax &= e001 < e111;
                isMin &= e001 > e111;
                if (!(isMax || isMin))
                    continue;
                float e101 = d[ic].data[rac + xc];
                isMax &= e101 < e111;
                isMin &= e101 > e111;
                if (!(isMax || isMin))
                    continue;
                float e201 = d[ic].data[rac + xb];
                isMax &= e201 < e111;
                isMin &= e201 > e111;
                if (!(isMax || isMin))
                    continue;

                float e011 = d[ic].data[rc + xa];
                isMax &= e011 < e111;
                isMin &= e011 > e111;
                if (!(isMax || isMin))
                    continue;
                float e211 = d[ic].data[rc + xb];
                isMax &= e211 < e111;
                isMin &= e211 > e111;
                if (!(isMax || isMin))
                    continue;

                float e021 = d[ic].data[rbc + xa];
                isMax &= e021 < e111;
                isMin &= e021 > e111;
                if (!(isMax || isMin))
                    continue;
                float e121 = d[ic].data[rbc + xc];
                isMax &= e121 < e111;
                isMin &= e121 > e111;
                if (!(isMax || isMin))
                    continue;
                float e221 = d[ic].data[rbc + xb];
                isMax &= e221 < e111;
                isMin &= e221 > e111;
                if (!(isMax || isMin))
                    continue;

                float e002 = d[ibc].data[rac + xa];
                isMax &= e002 < e111;
                isMin &= e002 > e111;
                if (!(isMax || isMin))
                    continue;
                float e102 = d[ibc].data[rac + xc];
                isMax &= e102 < e111;
                isMin &= e102 > e111;
                if (!(isMax || isMin))
                    continue;
                float e202 = d[ibc].data[rac + xb];
                isMax &= e202 < e111;
                isMin &= e202 > e111;
                if (!(isMax || isMin))
                    continue;

                float e012 = d[ibc].data[rc + xa];
                isMax &= e012 < e111;
                isMin &= e012 > e111;
                if (!(isMax || isMin))
                    continue;
                float e112 = d[ibc].data[rc + xc];
                isMax &= e112 < e111;
                isMin &= e112 > e111;
                if (!(isMax || isMin))
                    continue;
                float e212 = d[ibc].data[rc + xb];
                isMax &= e212 < e111;
                isMin &= e212 > e111;
                if (!(isMax || isMin))
                    continue;

                float e022 = d[ibc].data[rbc + xa];
                isMax &= e022 < e111;
                isMin &= e022 > e111;
                if (!(isMax || isMin))
                    continue;
                float e122 = d[ibc].data[rbc + xc];
                isMax &= e122 < e111;
                isMin &= e122 > e111;
                if (!(isMax || isMin))
                    continue;
                float e222 = d[ibc].data[rbc + xb];
                isMax &= e222 < e111;
                isMin &= e222 > e111;
                if (!(isMax || isMin))
                    continue;

                // so it is an extremum, try to localize it with subpixel
                // accuracy, if it has to be moved for more than 0.5 in at
                // least one direction, try it again there but maximally 5
                // times

                boolean isLocalized = false;
                boolean isLocalizable = true;

                float dx;
                float dy;
                float di;

                float dxx;
                float dyy;
                float dii;

                float dxy;
                float dxi;
                float dyi;

                float ox;
                float oy;
                float oi;

                float od = Float.MAX_VALUE; // offset square distance

                float fx = 0;
                float fy = 0;
                float fi = 0;

                int t = 5; // maximal number of re-localizations
                do {
                    --t;

                    // derive at (x, y, i) by center of difference
                    dx = (e211 - e011) / 2.0f;
                    dy = (e121 - e101) / 2.0f;
                    di = (e112 - e110) / 2.0f;

                    // create hessian at (x, y, i) by laplace
                    float e111_2 = 2.0f * e111;
                    dxx = e011 - e111_2 + e211;
                    dyy = e101 - e111_2 + e121;
                    dii = e110 - e111_2 + e112;

                    dxy = (e221 - e021 - e201 + e001) / 4.0f;
                    dxi = (e212 - e012 - e210 + e010) / 4.0f;
                    dyi = (e122 - e102 - e120 + e100) / 4.0f;

                    // invert hessian
                    Array2DRowRealMatrix H = new Array2DRowRealMatrix(
                            new double[][] { { (double) dxx, (double) dxy, (double) dxi },
                                    { (double) dxy, (double) dyy, (double) dyi },
                                    { (double) dxi, (double) dyi, (double) dii } });
                    RealMatrix H_inv;
                    try {
                        H_inv = new LUDecompositionImpl(H).getSolver().getInverse();
                    } catch (RuntimeException e) {
                        continue X;
                    }
                    double[][] h_inv = H_inv.getData();

                    // estimate the location of zero crossing being the offset of the extremum

                    ox = -(float) h_inv[0][0] * dx - (float) h_inv[0][1] * dy - (float) h_inv[0][0] * di;
                    oy = -(float) h_inv[1][0] * dx - (float) h_inv[1][1] * dy - (float) h_inv[1][0] * di;
                    oi = -(float) h_inv[2][0] * dx - (float) h_inv[2][1] * dy - (float) h_inv[2][0] * di;

                    float odc = ox * ox + oy * oy + oi * oi;

                    if (odc < 2.0f) {
                        if ((Math.abs(ox) > 0.5 || Math.abs(oy) > 0.5 || Math.abs(oi) > 0.5) && odc < od) {
                            od = odc;

                            xc = (int) Math.round((float) xc + ox);
                            yc = (int) Math.round((float) yc + oy);
                            ic = (int) Math.round((float) ic + oi);

                            if (xc < 1 || yc < 1 || ic < 1 || xc > d[0].width - 2 || yc > d[0].height - 2
                                    || ic > d.length - 2)
                                isLocalizable = false;
                            else {
                                xa = xc - 1;
                                xb = xc + 1;
                                rc = yc * d[ic].width;
                                rac = rc - d[ic].width;
                                rbc = rc + d[ic].width;
                                iac = ic - 1;
                                ibc = ic + 1;

                                e000 = d[iac].data[rac + xa];
                                e100 = d[iac].data[rac + xc];
                                e200 = d[iac].data[rac + xb];

                                e010 = d[iac].data[rc + xa];
                                e110 = d[iac].data[rc + xc];
                                e210 = d[iac].data[rc + xb];

                                e020 = d[iac].data[rbc + xa];
                                e120 = d[iac].data[rbc + xc];
                                e220 = d[iac].data[rbc + xb];

                                e001 = d[ic].data[rac + xa];
                                e101 = d[ic].data[rac + xc];
                                e201 = d[ic].data[rac + xb];

                                e011 = d[ic].data[rc + xa];
                                e111 = d[ic].data[rc + xc];
                                e211 = d[ic].data[rc + xb];

                                e021 = d[ic].data[rbc + xa];
                                e121 = d[ic].data[rbc + xc];
                                e221 = d[ic].data[rbc + xb];

                                e002 = d[ibc].data[rac + xa];
                                e102 = d[ibc].data[rac + xc];
                                e202 = d[ibc].data[rac + xb];

                                e012 = d[ibc].data[rc + xa];
                                e112 = d[ibc].data[rc + xc];
                                e212 = d[ibc].data[rc + xb];

                                e022 = d[ibc].data[rbc + xa];
                                e122 = d[ibc].data[rbc + xc];
                                e222 = d[ibc].data[rbc + xb];
                            }
                        } else {
                            fx = (float) xc + ox;
                            fy = (float) yc + oy;
                            fi = (float) ic + oi;

                            if (fx < 0 || fy < 0 || fi < 0 || fx > d[0].width - 1 || fy > d[0].height - 1
                                    || fi > d.length - 1)
                                isLocalizable = false;
                            else
                                isLocalized = true;
                        }
                    } else
                        isLocalizable = false;
                } while (!isLocalized && isLocalizable && t >= 0);
                // reject detections that could not be localized properly

                if (!isLocalized) {
                    //                  System.err.println( "Localization failed (x: " + xc + ", y: " + yc + ", i: " + ic + ") => (ox: " + ox + ", oy: " + oy + ", oi: " + oi + ")" );
                    //                  if ( ic < 1 || ic > d.length - 2 )
                    //                     System.err.println( "  Detection outside octave." );                  
                    continue;
                }

                // reject detections with very low contrast

                if (Math.abs(e111 + 0.5f * (dx * ox + dy * oy + di * oi)) < MIN_CONTRAST)
                    continue;

                // reject edge responses

                float det = dxx * dyy - dxy * dxy;
                float trace = dxx + dyy;
                if (trace * trace / det > MAX_CURVATURE_RATIO)
                    continue;

                candidates.addElement(new float[] { fx, fy, fi });
                //candidates.addElement( new float[]{ x, y, i } );
            }
        }
    }
}

From source file:net.semanticmetadata.lire.imageanalysis.features.local.sift.FloatArray2DScaleOctaveDoGDetector.java

private void detectCandidates() {
    FloatArray2D[] d = octave.getD();//  w  w  w.j  ava 2  s.com

    for (int i = d.length - 2; i >= 1; --i) {
        int ia = i - 1;
        int ib = i + 1;
        for (int y = d[i].height - 2; y >= 1; --y) {
            int r = y * d[i].width;
            int ra = r - d[i].width;
            int rb = r + d[i].width;

            X: for (int x = d[i].width - 2; x >= 1; --x) {
                int ic = i;
                int iac = ia;
                int ibc = ib;
                int yc = y;
                int rc = r;
                int rac = ra;
                int rbc = rb;
                int xc = x;
                int xa = xc - 1;
                int xb = xc + 1;
                float e111 = d[ic].data[r + xc];

                // check if d(x, y, i) is an extremum
                // do it pipeline-friendly ;)

                float e000 = d[iac].data[rac + xa];
                boolean isMax = e000 < e111;
                boolean isMin = e000 > e111;
                if (!(isMax || isMin))
                    continue;
                float e100 = d[iac].data[rac + xc];
                isMax &= e100 < e111;
                isMin &= e100 > e111;
                if (!(isMax || isMin))
                    continue;
                float e200 = d[iac].data[rac + xb];
                isMax &= e200 < e111;
                isMin &= e200 > e111;
                if (!(isMax || isMin))
                    continue;

                float e010 = d[iac].data[rc + xa];
                isMax &= e010 < e111;
                isMin &= e010 > e111;
                if (!(isMax || isMin))
                    continue;
                float e110 = d[iac].data[rc + xc];
                isMax &= e110 < e111;
                isMin &= e110 > e111;
                if (!(isMax || isMin))
                    continue;
                float e210 = d[iac].data[rc + xb];
                isMax &= e210 < e111;
                isMin &= e210 > e111;
                if (!(isMax || isMin))
                    continue;

                float e020 = d[iac].data[rbc + xa];
                isMax &= e020 < e111;
                isMin &= e020 > e111;
                if (!(isMax || isMin))
                    continue;
                float e120 = d[iac].data[rbc + xc];
                isMax &= e120 < e111;
                isMin &= e120 > e111;
                if (!(isMax || isMin))
                    continue;
                float e220 = d[iac].data[rbc + xb];
                isMax &= e220 < e111;
                isMin &= e220 > e111;
                if (!(isMax || isMin))
                    continue;

                float e001 = d[ic].data[rac + xa];
                isMax &= e001 < e111;
                isMin &= e001 > e111;
                if (!(isMax || isMin))
                    continue;
                float e101 = d[ic].data[rac + xc];
                isMax &= e101 < e111;
                isMin &= e101 > e111;
                if (!(isMax || isMin))
                    continue;
                float e201 = d[ic].data[rac + xb];
                isMax &= e201 < e111;
                isMin &= e201 > e111;
                if (!(isMax || isMin))
                    continue;

                float e011 = d[ic].data[rc + xa];
                isMax &= e011 < e111;
                isMin &= e011 > e111;
                if (!(isMax || isMin))
                    continue;
                float e211 = d[ic].data[rc + xb];
                isMax &= e211 < e111;
                isMin &= e211 > e111;
                if (!(isMax || isMin))
                    continue;

                float e021 = d[ic].data[rbc + xa];
                isMax &= e021 < e111;
                isMin &= e021 > e111;
                if (!(isMax || isMin))
                    continue;
                float e121 = d[ic].data[rbc + xc];
                isMax &= e121 < e111;
                isMin &= e121 > e111;
                if (!(isMax || isMin))
                    continue;
                float e221 = d[ic].data[rbc + xb];
                isMax &= e221 < e111;
                isMin &= e221 > e111;
                if (!(isMax || isMin))
                    continue;

                float e002 = d[ibc].data[rac + xa];
                isMax &= e002 < e111;
                isMin &= e002 > e111;
                if (!(isMax || isMin))
                    continue;
                float e102 = d[ibc].data[rac + xc];
                isMax &= e102 < e111;
                isMin &= e102 > e111;
                if (!(isMax || isMin))
                    continue;
                float e202 = d[ibc].data[rac + xb];
                isMax &= e202 < e111;
                isMin &= e202 > e111;
                if (!(isMax || isMin))
                    continue;

                float e012 = d[ibc].data[rc + xa];
                isMax &= e012 < e111;
                isMin &= e012 > e111;
                if (!(isMax || isMin))
                    continue;
                float e112 = d[ibc].data[rc + xc];
                isMax &= e112 < e111;
                isMin &= e112 > e111;
                if (!(isMax || isMin))
                    continue;
                float e212 = d[ibc].data[rc + xb];
                isMax &= e212 < e111;
                isMin &= e212 > e111;
                if (!(isMax || isMin))
                    continue;

                float e022 = d[ibc].data[rbc + xa];
                isMax &= e022 < e111;
                isMin &= e022 > e111;
                if (!(isMax || isMin))
                    continue;
                float e122 = d[ibc].data[rbc + xc];
                isMax &= e122 < e111;
                isMin &= e122 > e111;
                if (!(isMax || isMin))
                    continue;
                float e222 = d[ibc].data[rbc + xb];
                isMax &= e222 < e111;
                isMin &= e222 > e111;
                if (!(isMax || isMin))
                    continue;

                // so it is an extremum, try to localize it with subpixel
                // accuracy, if it has to be moved for more than 0.5 in at
                // least one direction, try it again there but maximally 5
                // times

                boolean isLocalized = false;
                boolean isLocalizable = true;

                float dx;
                float dy;
                float di;

                float dxx;
                float dyy;
                float dii;

                float dxy;
                float dxi;
                float dyi;

                float ox;
                float oy;
                float oi;

                float od = Float.MAX_VALUE; // offset square distance

                float fx = 0;
                float fy = 0;
                float fi = 0;

                int t = 5; // maximal number of re-localizations
                do {
                    --t;

                    // derive at (x, y, i) by center of difference
                    dx = (e211 - e011) / 2.0f;
                    dy = (e121 - e101) / 2.0f;
                    di = (e112 - e110) / 2.0f;

                    // create hessian at (x, y, i) by laplace
                    float e111_2 = 2.0f * e111;
                    dxx = e011 - e111_2 + e211;
                    dyy = e101 - e111_2 + e121;
                    dii = e110 - e111_2 + e112;

                    dxy = (e221 - e021 - e201 + e001) / 4.0f;
                    dxi = (e212 - e012 - e210 + e010) / 4.0f;
                    dyi = (e122 - e102 - e120 + e100) / 4.0f;

                    // invert hessian
                    Array2DRowRealMatrix H = new Array2DRowRealMatrix(
                            new double[][] { { (double) dxx, (double) dxy, (double) dxi },
                                    { (double) dxy, (double) dyy, (double) dyi },
                                    { (double) dxi, (double) dyi, (double) dii } });
                    RealMatrix H_inv;
                    try {
                        H_inv = new LUDecomposition(H).getSolver().getInverse();
                    } catch (RuntimeException e) {
                        continue X;
                    }
                    double[][] h_inv = H_inv.getData();

                    // estimate the location of zero crossing being the offset of the extremum

                    ox = -(float) h_inv[0][0] * dx - (float) h_inv[0][1] * dy - (float) h_inv[0][0] * di;
                    oy = -(float) h_inv[1][0] * dx - (float) h_inv[1][1] * dy - (float) h_inv[1][0] * di;
                    oi = -(float) h_inv[2][0] * dx - (float) h_inv[2][1] * dy - (float) h_inv[2][0] * di;

                    float odc = ox * ox + oy * oy + oi * oi;

                    if (odc < 2.0f) {
                        if ((Math.abs(ox) > 0.5 || Math.abs(oy) > 0.5 || Math.abs(oi) > 0.5) && odc < od) {
                            od = odc;

                            xc = (int) Math.round((float) xc + ox);
                            yc = (int) Math.round((float) yc + oy);
                            ic = (int) Math.round((float) ic + oi);

                            if (xc < 1 || yc < 1 || ic < 1 || xc > d[0].width - 2 || yc > d[0].height - 2
                                    || ic > d.length - 2)
                                isLocalizable = false;
                            else {
                                xa = xc - 1;
                                xb = xc + 1;
                                rc = yc * d[ic].width;
                                rac = rc - d[ic].width;
                                rbc = rc + d[ic].width;
                                iac = ic - 1;
                                ibc = ic + 1;

                                e000 = d[iac].data[rac + xa];
                                e100 = d[iac].data[rac + xc];
                                e200 = d[iac].data[rac + xb];

                                e010 = d[iac].data[rc + xa];
                                e110 = d[iac].data[rc + xc];
                                e210 = d[iac].data[rc + xb];

                                e020 = d[iac].data[rbc + xa];
                                e120 = d[iac].data[rbc + xc];
                                e220 = d[iac].data[rbc + xb];

                                e001 = d[ic].data[rac + xa];
                                e101 = d[ic].data[rac + xc];
                                e201 = d[ic].data[rac + xb];

                                e011 = d[ic].data[rc + xa];
                                e111 = d[ic].data[rc + xc];
                                e211 = d[ic].data[rc + xb];

                                e021 = d[ic].data[rbc + xa];
                                e121 = d[ic].data[rbc + xc];
                                e221 = d[ic].data[rbc + xb];

                                e002 = d[ibc].data[rac + xa];
                                e102 = d[ibc].data[rac + xc];
                                e202 = d[ibc].data[rac + xb];

                                e012 = d[ibc].data[rc + xa];
                                e112 = d[ibc].data[rc + xc];
                                e212 = d[ibc].data[rc + xb];

                                e022 = d[ibc].data[rbc + xa];
                                e122 = d[ibc].data[rbc + xc];
                                e222 = d[ibc].data[rbc + xb];
                            }
                        } else {
                            fx = (float) xc + ox;
                            fy = (float) yc + oy;
                            fi = (float) ic + oi;

                            if (fx < 0 || fy < 0 || fi < 0 || fx > d[0].width - 1 || fy > d[0].height - 1
                                    || fi > d.length - 1)
                                isLocalizable = false;
                            else
                                isLocalized = true;
                        }
                    } else
                        isLocalizable = false;
                } while (!isLocalized && isLocalizable && t >= 0);
                // reject detections that could not be localized properly

                if (!isLocalized) {
                    //                  System.err.println( "Localization failed (x: " + xc + ", y: " + yc + ", i: " + ic + ") => (ox: " + ox + ", oy: " + oy + ", oi: " + oi + ")" );
                    //                  if ( ic < 1 || ic > d.length - 2 )
                    //                     System.err.println( "  Detection outside octave." );                  
                    continue;
                }

                // reject detections with very low contrast

                if (Math.abs(e111 + 0.5f * (dx * ox + dy * oy + di * oi)) < MIN_CONTRAST)
                    continue;

                // reject edge responses

                float det = dxx * dyy - dxy * dxy;
                float trace = dxx + dyy;
                if (trace * trace / det > MAX_CURVATURE_RATIO)
                    continue;

                candidates.addElement(new float[] { fx, fy, fi });
                //candidates.addElement( new float[]{ x, y, i } );
            }
        }
    }
}

From source file:org.kaaproject.kaa.demo.powerplant.fragment.DashboardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_dashboard, container, false);

    androidKaaPlatformContext = new AndroidKaaPlatformContext(getActivity());
    kaaClient = Kaa.newClient(androidKaaPlatformContext);

    endpoint = DataEndpointFactory.createEndpoint(kaaClient.getConfiguration(), getActivity());
    Log.i(TAG, "Default configuration: " + kaaClient.getConfiguration().toString());

    kaaClient.addConfigurationListener(new ConfigurationListener() {
        @Override//from w  w  w.j a v  a 2s.c o m
        public void onConfigurationUpdate(PowerPlantEndpointConfiguration config) {
            endpoint.stop();
            endpoint = DataEndpointFactory.createEndpoint(config, getActivity());
            Log.i(TAG, "Updating configuration: " + config.toString());
        }
    });

    kaaClient.start();

    gaugeCharts.add((GaugeChart) rootView.findViewById(R.id.gaugeChart11));
    gaugeCharts.add((GaugeChart) rootView.findViewById(R.id.gaugeChart12));
    gaugeCharts.add((GaugeChart) rootView.findViewById(R.id.gaugeChart13));
    gaugeCharts.add((GaugeChart) rootView.findViewById(R.id.gaugeChart21));
    gaugeCharts.add((GaugeChart) rootView.findViewById(R.id.gaugeChart22));
    gaugeCharts.add((GaugeChart) rootView.findViewById(R.id.gaugeChart23));
    logBox = (TextView) rootView.findViewById(R.id.logBox);
    logBox.setMovementMethod(new ScrollingMovementMethod());

    updateThread = new Thread(new Runnable() {

        @Override
        public void run() {

            Log.i(TAG, "generating history data ");

            final List<DataReport> reports = endpoint.getHistoryData(0);
            if (reports == null) {
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mActivity, "No Data!", Toast.LENGTH_LONG).show();
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e) {
                        }
                        mActivity.finish();
                    }
                });
            } else {
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.i(TAG, "populating charts with data " + reports.size());
                        prepareLineChart(rootView, reports);
                        Log.i(TAG, "populated line chart with data ");
                        if (!reports.isEmpty()) {
                            preparePieChart(rootView, reports.get(reports.size() - 1));
                        } else {
                            preparePieChart(rootView, INITIAL_REPORT);
                        }
                        Log.i(TAG, "populated pie chart with data ");
                    }
                });

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }

                DataReport previousReport = INITIAL_REPORT;
                long previousUpdate = 0l;
                while (true) {
                    try {
                        Thread.sleep(UPDATE_CHECK_PERIOD);
                        long updateDelta = System.currentTimeMillis() - previousUpdate;
                        if (updateDelta < UPDATE_PERIOD) {
                            continue;
                        } else {
                            Log.i(TAG, "Updating since -" + (updateDelta / 1000.) + " s.");
                        }
                        DataReport latestDataCandidate = endpoint.getLatestData();
                        latestDataCandidate = (latestDataCandidate == null ? previousReport
                                : latestDataCandidate);
                        Log.i(TAG, "Latest data: " + latestDataCandidate.toString());
                        Log.i(TAG, "Previous data: " + previousReport.toString());
                        previousReport = latestDataCandidate;
                        previousUpdate = System.currentTimeMillis();
                    } catch (InterruptedException e) {
                        Log.e(TAG, "Failed to fetch data", e);
                    }

                    final DataReport latestData = previousReport;
                    Log.i(TAG, "latest data: " + latestData.toString());

                    mActivity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            float maxValue = Float.MIN_VALUE;
                            float minValue = Float.MAX_VALUE;

                            PieChartData data = pieChart.getPieChartData();
                            float plantVoltage = 0.0f;

                            int counter = 0;
                            for (DataPoint dp : latestData.getDataPoints()) {
                                float curVoltage = convertVoltage(dp.getVoltage());
                                plantVoltage += curVoltage;
                                SliceValue sliceValue = data.getValues().get(dp.getPanelId());
                                sliceValue.setTarget(curVoltage);
                                gaugeCharts.get(counter).setValue(dp.getAverageVoltage());
                                showLogIfNeeded(counter, curVoltage * 1000);
                                counter++;
                                Log.i(TAG, dp.toString());
                            }

                            float gridVoltage = (latestData.getPowerConsumption() - plantVoltage * 1000) / 1000;
                            pieChart.startDataAnimation(UPDATE_PERIOD / 2);
                            updateLabels(plantVoltage * 1000, gridVoltage);

                            // Actual point update
                            int curPointIndex = line.getValues().size() - FUTURE_POINTS_COUNT;
                            PointValue curPoint = line.getValues().get(curPointIndex);
                            curPoint.set(curPoint.getX(), plantVoltage);
                            for (PointValue point : line.getValues()) {
                                point.setTarget(point.getX() - 1, point.getY());
                                minValue = Math.min(minValue, point.getY());
                                maxValue = Math.max(maxValue, point.getY());
                            }
                            if (line.getValues()
                                    .size() == (POINTS_COUNT + PAST_POINTS_COUNT + FUTURE_POINTS_COUNT)) {
                                line.getValues().remove(0);
                            }
                            // Adding one dot to the end;
                            line.getValues()
                                    .add(new PointValue(POINTS_COUNT + FUTURE_POINTS_COUNT, plantVoltage));

                            lineChart.startDataAnimation(UPDATE_PERIOD / 2);

                            lineChart.getChartRenderer().setMinViewportYValue(MIN_VOLTAGE);
                            lineChart.getChartRenderer().setMaxViewportYValue(
                                    (MAX_VOLTAGE * MAX_PANEL_PER_ZONE * NUM_ZONES) / 1000);
                        }
                    });
                }
            }
        }
    });

    updateThread.start();

    return rootView;
}

From source file:hits.HitTools.java

public static Float computeRmsdBackboneAtomBetweenHitPeptideAndQueryLigandDefinigQuery(
        ShapeContainerIfc targetShape, ResultsFromEvaluateCost result, ShapeContainerIfc queryShape,
        AlgoParameters algoParameters) {

    boolean isQueryShapeContainerHasPeptideIfc = queryShape instanceof HasPeptideIfc;
    boolean isHitShapeContainerHasPeptideIfc = targetShape instanceof HasPeptideIfc;

    boolean canBeComputed = isQueryShapeContainerHasPeptideIfc && isHitShapeContainerHasPeptideIfc;
    if (!canBeComputed) {
        return null;
    }/*from   w w  w  . j a  v a 2s. c o  m*/

    HasPeptideIfc queryShapeWithPeptide = (HasPeptideIfc) queryShape;
    MyChainIfc peptideUsedToBuiltTheQuery = queryShapeWithPeptide.getPeptide();

    HasPeptideIfc currentBestHitWithPeptide = (HasPeptideIfc) targetShape;
    MyChainIfc peptideCurrentBestHit = currentBestHitWithPeptide.getPeptide();

    if (peptideUsedToBuiltTheQuery != null) {

        List<MyAtomIfc> backboneAtomPeptideQuery = extractBackBoneAtoms(peptideUsedToBuiltTheQuery,
                algoParameters);
        List<MyAtomIfc> backboneAtomPeptideHit = extractBackBoneAtoms(peptideCurrentBestHit, algoParameters);
        // put hit in ref frame of query
        List<double[]> coordinatesHit = new ArrayList<>();
        for (MyAtomIfc atomHit : backboneAtomPeptideHit) {
            RealVector newPointCoords = PairingTools.alignPointFromShape2toShape1(result,
                    new ArrayRealVector(MathTools.convertToDoubleArray(atomHit.getCoords())));
            coordinatesHit.add(newPointCoords.toArray());
        }
        List<double[]> coordinatesQuery = new ArrayList<>();
        for (MyAtomIfc atomQuery : backboneAtomPeptideQuery) {
            coordinatesQuery.add(MathTools.convertToDoubleArray(atomQuery.getCoords()));
        }

        List<double[]> smallestChainCoords = coordinatesHit;
        List<double[]> longestChainCoords = coordinatesQuery;
        List<MyAtomIfc> smallestChain = backboneAtomPeptideHit;
        List<MyAtomIfc> longestChain = backboneAtomPeptideQuery;

        if (backboneAtomPeptideHit.size() > backboneAtomPeptideQuery.size()) {
            smallestChain = backboneAtomPeptideQuery;
            longestChain = backboneAtomPeptideHit;
            smallestChainCoords = coordinatesQuery;
            longestChainCoords = coordinatesHit;
        }
        // 10
        // 6
        // pos 0 to pos 4 as start

        List<Integer> posibleStart = new ArrayList<>();

        int countPossibleOverlays = longestChain.size() - smallestChain.size() + 1;
        A: for (int j = 0; j <= countPossibleOverlays; j++) {

            for (int k = 0; k < smallestChain.size(); k++) {
                MyAtomIfc currentAtomLongestchain = longestChain.get(k + j);
                // if any mismatch in atom name I skip the current comparaison
                //System.out.println(String.valueOf(smallestChain.get(k).getAtomName()) + " compared to " + String.valueOf(currentAtomLongestchain.getAtomName()));
                if (!String.valueOf(smallestChain.get(k).getAtomName())
                        .equals(String.valueOf(currentAtomLongestchain.getAtomName()))) {
                    continue A;
                }
            }
            posibleStart.add(j);
        }
        //System.out.println("posibleStart : " + posibleStart);

        // for each possible start I compute the rmsd
        float minRmsd = Float.MAX_VALUE;
        for (int j = 0; j < posibleStart.size(); j++) {

            double rmsd = 0.0;
            for (int k = 0; k < smallestChain.size(); k++) {
                double[] currentAtomSmallestchain = smallestChainCoords.get(k);
                double[] currentAtomLongestchain = longestChainCoords.get(k + posibleStart.get(j));
                double contribRmsd = MathTools.computeDistance(currentAtomSmallestchain,
                        currentAtomLongestchain);
                rmsd += contribRmsd * contribRmsd;
            }
            rmsd = rmsd / smallestChain.size();
            float finalRmsd = (float) Math.sqrt(rmsd);
            if (finalRmsd < minRmsd) {
                minRmsd = finalRmsd;
            }
        }

        return minRmsd;
    }
    return null;
}

From source file:pipeline.misc_util.Utils.java

public static int indexOfMax(float[] a) {
    float max = -Float.MAX_VALUE;
    int max_index = -1;
    for (int i = 0; i < a.length; i++) {
        if (a[i] > max) {
            max = a[i];//ww w .  j av a2 s .  co  m
            max_index = i;
        }
    }
    return max_index;
}

From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java

/**
 * Convert any Number object to the specified type for this
 * <i>Converter</i>./*from   www  .j a  v  a 2 s .  co  m*/
 * <p>
 * This method handles conversion to the following types:
 * <ul>
 *     <li><code>java.lang.Byte</code></li>
 *     <li><code>java.lang.Short</code></li>
 *     <li><code>java.lang.Integer</code></li>
 *     <li><code>java.lang.Long</code></li>
 *     <li><code>java.lang.Float</code></li>
 *     <li><code>java.lang.Double</code></li>
 *     <li><code>java.math.BigDecimal</code></li>
 *     <li><code>java.math.BigInteger</code></li>
 * </ul>
 * @param sourceType The type being converted from
 * @param targetType The Number type to convert to
 * @param value The Number to convert.
 *
 * @return The converted value.
 */
private Number toNumber(Class sourceType, Class targetType, Number value) {

    // Correct Number type already
    if (targetType.equals(value.getClass())) {
        return value;
    }

    // Byte
    if (targetType.equals(Byte.class)) {
        long longValue = value.longValue();
        if (longValue > Byte.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Byte.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Byte(value.byteValue());
    }

    // Short
    if (targetType.equals(Short.class)) {
        long longValue = value.longValue();
        if (longValue > Short.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Short.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Short(value.shortValue());
    }

    // Integer
    if (targetType.equals(Integer.class)) {
        long longValue = value.longValue();
        if (longValue > Integer.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Integer.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Integer(value.intValue());
    }

    // Long
    if (targetType.equals(Long.class)) {
        return new Long(value.longValue());
    }

    // Float
    if (targetType.equals(Float.class)) {
        if (value.doubleValue() > Float.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        return new Float(value.floatValue());
    }

    // Double
    if (targetType.equals(Double.class)) {
        return new Double(value.doubleValue());
    }

    // BigDecimal
    if (targetType.equals(BigDecimal.class)) {
        if (value instanceof Float || value instanceof Double) {
            return new BigDecimal(value.toString());
        } else if (value instanceof BigInteger) {
            return new BigDecimal((BigInteger) value);
        } else {
            return BigDecimal.valueOf(value.longValue());
        }
    }

    // BigInteger
    if (targetType.equals(BigInteger.class)) {
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).toBigInteger();
        } else {
            return BigInteger.valueOf(value.longValue());
        }
    }

    String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'";
    throw new ConversionException(msg);

}

From source file:com.davidmiguel.gobees.recording.RecordingFragment.java

/**
 * Configure temperature chart and the data.
 *
 * @param meteo meteo records.//from   w w  w.  ja v a2s . co  m
 */
private void setupTempChart(List<MeteoRecord> meteo) {
    // Setup data
    List<Entry> entries = new ArrayList<>();
    // Add as first entry a copy of the first temperature record
    // First relative timestamp is 0
    entries.add(new Entry(0, (float) meteo.get(0).getTemperature()));
    // Add all temperature records
    float maxTemp = Float.MIN_VALUE;
    float minTemp = Float.MAX_VALUE;
    for (MeteoRecord meteoRecord : meteo) {
        // Convert timestamp to seconds and relative to first timestamp
        long timestamp = meteoRecord.getTimestamp().getTime() / 1000 - referenceTimestamp;
        float temperature = (float) meteoRecord.getTemperature();
        entries.add(new Entry(timestamp, temperature));
        // Get max and min temperature
        if (temperature > maxTemp) {
            maxTemp = temperature;
        }
        if (temperature < minTemp) {
            minTemp = temperature;
        }
    }
    // Add as last entry a copy of the last temperature record
    entries.add(new Entry(lastTimestamp, (float) meteo.get(meteo.size() - 1).getTemperature()));
    // Style char lines (type, color, etc.)
    TempValueFormatter tempValueFormatter = new TempValueFormatter(
            GoBeesPreferences.isMetric(getContext()) ? TempValueFormatter.Unit.CELSIUS
                    : TempValueFormatter.Unit.FAHRENHEIT);
    tempChart.setData(
            new LineData(configureWeatherChart(tempChart, R.string.temperature, R.color.colorLineTempChart,
                    R.color.colorFillTempChart, entries, tempValueFormatter, minTemp - 5, maxTemp + 5)));
}

From source file:com.example.jesse.barscan.BarcodeCaptureActivity.java

/**
 * onTap returns the tapped barcode result to the calling Activity.
 *//*from w  ww . ja  v  a 2  s .  com*/
public boolean onTap(float rawX, float rawY) {
    // Find tap point in preview frame coordinates.
    int[] location = new int[2];
    mGraphicOverlay.getLocationOnScreen(location);
    float x = (rawX - location[0]) / mGraphicOverlay.getWidthScaleFactor();
    float y = (rawY - location[1]) / mGraphicOverlay.getHeightScaleFactor();

    // Find the barcode whose center is closest to the tapped point.
    Barcode best = null;
    float bestDistance = Float.MAX_VALUE;
    for (BarcodeGraphic graphic : mGraphicOverlay.getGraphics()) {
        Barcode barcode = graphic.getBarcode();
        if (barcode.getBoundingBox().contains((int) x, (int) y)) {
            // Exact hit, no need to keep looking.
            best = barcode;
            break;
        }
        float dx = x - barcode.getBoundingBox().centerX();
        float dy = y - barcode.getBoundingBox().centerY();
        float distance = (dx * dx) + (dy * dy); // actually squared distance
        if (distance < bestDistance) {
            best = barcode;
            bestDistance = distance;
        }
    }

    if (best != null) {
        Intent data = new Intent();
        data.putExtra(BarcodeObject, best);
        setResult(CommonStatusCodes.SUCCESS, data);

        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.barcode_toast,
                (ViewGroup) findViewById(R.id.custom_toast_container));

        Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
        //Barcode.DriverLicense dlBarcode = barcode.driverLicense;

        Barcode.DriverLicense sample = barcode.driverLicense;

        TextView name = (TextView) layout.findViewById(R.id.name);
        TextView address = (TextView) layout.findViewById(R.id.address);
        TextView cityStateZip = (TextView) layout.findViewById(R.id.cityStateZip);
        TextView gender = (TextView) layout.findViewById(R.id.gender);
        TextView dob = (TextView) layout.findViewById(R.id.dob);
        TableLayout tbl = (TableLayout) layout.findViewById(R.id.tableLayout);

        try {
            int age = DateDifference.generateAge(sample.birthDate);
            if (age < minAge)
                tbl.setBackgroundColor(Color.parseColor("#980517"));
            else
                tbl.setBackgroundColor(Color.parseColor("#617C17"));

        } catch (ParseException e) {
            e.printStackTrace();
        }

        String cityContent = new String(
                sample.addressCity + ", " + sample.addressState + " " + (sample.addressZip).substring(0, 5));

        address.setText(sample.addressStreet);
        cityStateZip.setText(cityContent);

        String genderString;
        if ((sample.gender).equals("1"))
            genderString = "Male";
        else if ((sample.gender).equals("2"))
            genderString = "Female";
        else
            genderString = "Other";

        gender.setText(genderString);

        dob.setText((sample.birthDate).substring(0, 2) + "/" + (sample.birthDate).substring(2, 4) + "/"
                + (sample.birthDate).substring(4, 8));

        String nameString = new String(sample.firstName + " " + sample.middleName + " " + sample.lastName);

        name.setText(nameString);

        Toast toast = new Toast(getApplicationContext());
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(layout);
        toast.show();

        Date today = Calendar.getInstance().getTime();
        String reportDate = df.format(today);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues row = new ContentValues();
        row.put("dateVar", reportDate);
        row.put("dobVar", sample.birthDate);
        row.put("zipVar", sample.addressZip);
        row.put("genderVar", genderString);
        db.insert("test", null, row);
        db.close();

        return true;
    }
    return false;
}

From source file:com.stromberglabs.jopensurf.Surf.java

public static Map<SURFInterestPoint, SURFInterestPoint> getMatchingPoints(List<SURFInterestPoint> set1,
        List<SURFInterestPoint> set2, double smallestOverSecondSmallestThreshold) {
    //System.out.println("Finding matching points..");
    Map<SURFInterestPoint, SURFInterestPoint> matchingPoints = new HashMap<SURFInterestPoint, SURFInterestPoint>();
    List<SURFInterestPoint> points = set1;

    for (SURFInterestPoint a : points) {
        double smallestDistance = Float.MAX_VALUE;
        double nextSmallestDistance = Float.MAX_VALUE;
        SURFInterestPoint possibleMatch = null;

        for (SURFInterestPoint b : set2) {
            double distance = a.getDistance(b);
            //System.out.println("Distance = " + distance);
            if (distance < smallestDistance) {
                nextSmallestDistance = smallestDistance;
                smallestDistance = distance;
                possibleMatch = b;/*from ww w.jav a 2  s.  com*/
            } else if (distance < nextSmallestDistance) {
                nextSmallestDistance = distance;
            }
        }

        // If match has a d1:d2 ratio < 0.65 ipoints are a match
        //if ( smallestDistance/nextSmallestDistance < 0.65d ){
        if (smallestDistance / nextSmallestDistance < smallestOverSecondSmallestThreshold) {
            //not storing change in position
            matchingPoints.put(a, possibleMatch);
        }
    }
    //System.out.println("Done finding matching points");
    return matchingPoints;
}

From source file:javadz.beanutils.converters.NumberConverter.java

/**
 * Convert any Number object to the specified type for this
 * <i>Converter</i>.// w ww .  ja  v  a 2  s.  c o  m
 * <p>
 * This method handles conversion to the following types:
 * <ul>
 *     <li><code>java.lang.Byte</code></li>
 *     <li><code>java.lang.Short</code></li>
 *     <li><code>java.lang.Integer</code></li>
 *     <li><code>java.lang.Long</code></li>
 *     <li><code>java.lang.Float</code></li>
 *     <li><code>java.lang.Double</code></li>
 *     <li><code>java.math.BigDecimal</code></li>
 *     <li><code>java.math.BigInteger</code></li>
 * </ul>
 * @param sourceType The type being converted from
 * @param targetType The Number type to convert to
 * @param value The Number to convert.
 *
 * @return The converted value.
 */
private Number toNumber(Class sourceType, Class targetType, Number value) {

    // Correct Number type already
    if (targetType.equals(value.getClass())) {
        return value;
    }

    // Byte
    if (targetType.equals(Byte.class)) {
        long longValue = value.longValue();
        if (longValue > Byte.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Byte.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Byte(value.byteValue());
    }

    // Short
    if (targetType.equals(Short.class)) {
        long longValue = value.longValue();
        if (longValue > Short.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Short.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Short(value.shortValue());
    }

    // Integer
    if (targetType.equals(Integer.class)) {
        long longValue = value.longValue();
        if (longValue > Integer.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Integer.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Integer(value.intValue());
    }

    // Long
    if (targetType.equals(Long.class)) {
        return new Long(value.longValue());
    }

    // Float
    if (targetType.equals(Float.class)) {
        if (value.doubleValue() > Float.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        return new Float(value.floatValue());
    }

    // Double
    if (targetType.equals(Double.class)) {
        return new Double(value.doubleValue());
    }

    // BigDecimal
    if (targetType.equals(BigDecimal.class)) {
        if (value instanceof Float || value instanceof Double) {
            return new BigDecimal(value.toString());
        } else if (value instanceof BigInteger) {
            return new BigDecimal((BigInteger) value);
        } else {
            return BigDecimal.valueOf(value.longValue());
        }
    }

    // BigInteger
    if (targetType.equals(BigInteger.class)) {
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).toBigInteger();
        } else {
            return BigInteger.valueOf(value.longValue());
        }
    }

    String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'";
    if (log().isWarnEnabled()) {
        log().warn("    " + msg);
    }
    throw new ConversionException(msg);

}