Example usage for org.apache.commons.collections.primitives FloatCollection add

List of usage examples for org.apache.commons.collections.primitives FloatCollection add

Introduction

In this page you can find the example usage for org.apache.commons.collections.primitives FloatCollection add.

Prototype

boolean add(float element);

Source Link

Document

Ensures that I contain the specified element (optional operation).

Usage

From source file:pipeline.plugins.cell_manipulation.CellBallQuantify.java

IProjector getProjector(ClickedPoint p, IPluginIOList<ClickedPoint> allInputPoints, IPluginIOStack input) {

    IProjector projector = getProjector();

    double radius = diameter / 2;
    double radiusSq = radius * radius;
    if (useEmbeddedDiameter) {
        if (!p.hasQuantifiedProperty("localDiameter")) {
            throw new IllegalArgumentException("localDiameter field is missing");
        }//  w w w.  ja  v a2  s  .  c  o  m
        radius = p.getQuantifiedProperty("localDiameter") * 0.5;
        radiusSq = radius * radius;
    }

    final int width = input.getWidth();
    final int height = input.getHeight();
    final int depth = input.getDepth();

    double xCenter = p.x;
    double yCenter = p.y;
    double zCenter = p.z;

    int xCenterInt = (int) xCenter;
    int yCenterInt = (int) yCenter;
    int zCenterInt = (int) zCenter;

    double xyCalib = diameterInPixels || p.xyCalibration == 0 ? 1 : p.xyCalibration;
    double zCalib = diameterInPixels || p.zCalibration == 0 ? 1 : p.zCalibration;

    boolean noPixels = false;

    final FloatCollection pixelValues;
    if (computeOverallPercentiles) {
        pixelValues = new ArrayFloatList(500);
    } else {
        pixelValues = null;
    }

    if (!useSegmentation) {
        int x0, x1, y0, y1, z0, z1;

        z0 = (int) (diskOnly ? 0 : Math.min(zCenter, radius / xyCalib));
        z1 = (int) (diskOnly ? 0 : Math.min(depth - 1 - zCenter, radius / xyCalib));

        y0 = (int) Math.min(yCenter, radius / xyCalib);
        y1 = (int) Math.min(height - 1 - (yCenter), radius / xyCalib);

        x0 = (int) Math.min(xCenter, radius / zCalib);
        x1 = (int) Math.min(width - 1 - xCenter, radius / zCalib);

        for (int k = -z0; k <= z1; k++) {
            double kSq = k * k * zCalib * zCalib;
            for (int j = -y0; j <= y1; j++) {
                double jSq = j * j * xyCalib;
                for (int i = -x0; i <= x1; i++) {
                    double iSq = i * i * xyCalib;
                    if ((!useRectangularShape) && kSq + jSq + iSq > radiusSq)
                        continue;
                    float f = input.getFloat(xCenterInt + i, yCenterInt + j, zCenterInt + k);
                    if (ignoreZero && f == 0)
                        continue;
                    projector.add(f);
                    if (pixelValues != null) {
                        pixelValues.add(f);
                    }
                }
            }
        }
    } else { // use segmentation
        int[] xCoord = usePerimSeg ? p.imagePerimsegCoordsX : p.imageFullSegCoordsX;
        int[] yCoord = usePerimSeg ? p.imagePerimsegCoordsY : p.imageFullSegCoordsY;
        int[] zCoord = usePerimSeg ? p.imagePerimsegCoordsZ : p.imageFullSegCoordsZ;

        if (xCoord == null)
            throw new IllegalArgumentException("Missing segmentation");

        if (xCoord.length == 0) {
            noPixels = true;
        }
        float f;

        for (int i = 0; i < xCoord.length; i++) {
            if (applyRadiusToSegmentation && !useRectangularShape) {
                double distanceSq = Math.pow((xCoord[i] - xCenter) * xyCalib, 2)
                        + Math.pow((yCoord[i] - yCenter) * xyCalib, 2)
                        + Math.pow((zCoord[i] - zCenter) * zCalib, 2);
                if (distanceSq > radiusSq)
                    continue;
            }
            if (diskOnly && zCoord[i] != zCenter)
                continue;
            f = input.getFloat(xCoord[i], yCoord[i], zCoord[i]);
            if (ignoreZero && f == 0)
                continue;
            projector.add(f);
            if (pixelValues != null) {
                pixelValues.add(f);
            }
        }
    }

    if (computeOverallPercentiles) {
        synchronized (allPixelValues) {
            allPixelValues.addAll(pixelValues);
        }
    }

    if (noPixels)
        return null;
    else
        return projector;
}