Example usage for java.lang Float isNaN

List of usage examples for java.lang Float isNaN

Introduction

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

Prototype

public static boolean isNaN(float v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

From source file:services.SimulationService.java

@Override
public void insertOpcodes(Map<Integer, INetworkRemoteEvent> swgOpcodes,
        Map<Integer, INetworkRemoteEvent> objControllerOpcodes) {

    objControllerOpcodes.put(ObjControllerOpcodes.DATA_TRANSFORM, new INetworkRemoteEvent() {

        @Override//from  ww  w  . j  a  v a 2s.com
        public void handlePacket(IoSession session, IoBuffer data) throws Exception {

            data.order(ByteOrder.LITTLE_ENDIAN);

            DataTransform dataTransform = new DataTransform();
            dataTransform.deserialize(data);
            //System.out.println("Movement Counter: " + dataTransform.getMovementCounter());
            Client client = core.getClient(session);

            if (client == null) {
                System.out.println("NULL Client");
                return;
            }

            if (client.getParent() == null) {
                System.out.println("NULL Object");
                return;
            }

            CreatureObject creature = (CreatureObject) client.getParent();
            if (creature.getPosture() == Posture.Dead || creature.getPosture() == Posture.Incapacitated)
                return;

            CreatureObject object = creature;

            if (core.mountService.isMounted(creature)
                    && creature.getObjectID() == ((CreatureObject) creature.getContainer()).getOwnerId()) {
                object = (CreatureObject) object.getContainer();
            }

            Point3D newPos;
            Point3D oldPos;

            synchronized (object.getMutex()) {
                newPos = new Point3D(dataTransform.getXPosition(), dataTransform.getYPosition(),
                        dataTransform.getZPosition());
                if (Float.isNaN(newPos.x) || Float.isNaN(newPos.y) || Float.isNaN(newPos.z))
                    return;
                oldPos = object.getPosition();
            }

            if (object instanceof CreatureObject && object.getOption(Options.MOUNT)) {
                if (!checkLineOfSight(object, newPos)) {
                    newPos = oldPos;
                }
            }

            synchronized (object.getMutex()) {
                //Collection<Client> oldObservers = object.getObservers();
                //Collection<Client> newObservers = new HashSet<Client>();
                if (object.getContainer() == null)
                    move(object, oldPos.x, oldPos.z, newPos.x, newPos.z);
                Quaternion newOrientation = new Quaternion(dataTransform.getWOrientation(),
                        dataTransform.getXOrientation(), dataTransform.getYOrientation(),
                        dataTransform.getZOrientation());
                object.setPosition(newPos);
                creature.setPosition(newPos);
                object.setOrientation(newOrientation);
                creature.setOrientation(newOrientation);
                object.setMovementCounter(dataTransform.getMovementCounter());
                creature.setMovementCounter(dataTransform.getMovementCounter());
            }

            synchronized (creature.getMutex()) {
                if (dataTransform.getSpeed() > 0.0f) {
                    switch (creature.getLocomotion()) {
                    case Locomotion.Prone:
                        creature.setLocomotion(Locomotion.Crawling);
                        break;
                    case Locomotion.ClimbingStationary:
                        creature.setLocomotion(Locomotion.Climbing);
                        break;
                    case Locomotion.Standing:
                    case Locomotion.Running:
                    case Locomotion.Walking:
                        if (dataTransform.getSpeed() >= (creature.getRunSpeed()
                                * (creature.getSpeedMultiplierBase() + creature.getSpeedMultiplierMod()))) {
                            creature.setLocomotion(Locomotion.Running);
                        } else {
                            creature.setLocomotion(Locomotion.Walking);
                        }

                        break;
                    case Locomotion.Sneaking:
                    case Locomotion.CrouchSneaking:
                    case Locomotion.CrouchWalking:
                        if (dataTransform.getSpeed() >= (creature.getRunSpeed()
                                * (creature.getSpeedMultiplierBase() + creature.getSpeedMultiplierMod()))) {
                            creature.setLocomotion(Locomotion.CrouchSneaking);
                        } else {
                            creature.setLocomotion(Locomotion.CrouchWalking);
                        }

                        break;
                    }
                } else {
                    switch (creature.getLocomotion()) {
                    case Locomotion.Crawling:
                        creature.setLocomotion(Locomotion.Prone);
                        break;
                    case Locomotion.Climbing:
                        creature.setLocomotion(Locomotion.ClimbingStationary);
                        break;
                    case Locomotion.Running:
                    case Locomotion.Walking:
                        creature.setLocomotion(Locomotion.Standing);
                        break;
                    case Locomotion.CrouchSneaking:
                    case Locomotion.CrouchWalking:
                        creature.setLocomotion(Locomotion.Sneaking);
                        break;
                    }
                }
            }

            if (object.getContainer() != null) {
                object.getContainer()._remove(object);
                add(object, newPos.x, newPos.z);
            }

            //object.setParentId(0);
            //object.setParent(null);
            //   System.out.println("Parsed Height: " + core.terrainService.getHeight(object.getPlanetId(), dataTransform.getXPosition(), dataTransform.getZPosition())
            //       + " should be: " + dataTransform.getYPosition());
            UpdateTransformMessage utm = new UpdateTransformMessage(object.getObjectID(),
                    dataTransform.getTransformedX(), dataTransform.getTransformedY(),
                    dataTransform.getTransformedZ(), dataTransform.getMovementCounter(),
                    (byte) dataTransform.getMovementAngle(), dataTransform.getSpeed());
            object.notifyObservers(utm, false);

            List<SWGObject> newAwareObjects = get(creature.getPlanet(), newPos.x, newPos.z, 512);
            ArrayList<SWGObject> oldAwareObjects = new ArrayList<SWGObject>(creature.getAwareObjects());
            @SuppressWarnings("unchecked")
            Collection<SWGObject> updateAwareObjects = CollectionUtils.intersection(oldAwareObjects,
                    newAwareObjects);

            for (int i = 0; i < oldAwareObjects.size(); i++) {
                SWGObject obj = oldAwareObjects.get(i);
                if (!updateAwareObjects.contains(obj) && obj != creature
                        && obj.getWorldPosition().getDistance2D(newPos) > 200
                        && obj.isInQuadtree() /*&& obj.getParentId() == 0*/) {
                    if (obj.getAttachment("bigSpawnRange") != null
                            && obj.getWorldPosition().getDistance2D(newPos) < 512)
                        continue;
                    creature.makeUnaware(obj);
                    if (obj.getClient() != null)
                        obj.makeUnaware(creature);
                } else if (obj != creature && obj.getWorldPosition().getDistance2D(newPos) > 200
                        && obj.isInQuadtree() && obj.getAttachment("bigSpawnRange") == null) {
                    creature.makeUnaware(obj);
                    if (obj.getClient() != null)
                        obj.makeUnaware(creature);
                }
            }

            for (int i = 0; i < newAwareObjects.size(); i++) {
                SWGObject obj = newAwareObjects.get(i);
                //System.out.println(obj.getTemplate());
                if (!updateAwareObjects.contains(obj) && obj != creature
                        && !creature.getAwareObjects().contains(obj) && obj.getContainer() != creature
                        && obj.isInQuadtree()) {
                    if (obj.getAttachment("bigSpawnRange") == null
                            && obj.getWorldPosition().getDistance2D(newPos) > 200)
                        continue;
                    creature.makeAware(obj);
                    if (obj.getClient() != null)
                        obj.makeAware(creature);
                }
            }

            checkForCollidables(object);
            object.setAttachment("lastValidPosition", object.getPosition());
            MoveEvent event = new MoveEvent();
            event.object = object;
            object.getEventBus().publish(event);

        }

    });

    objControllerOpcodes.put(ObjControllerOpcodes.DATA_TRANSFORM_WITH_PARENT, new INetworkRemoteEvent() {

        @Override
        public void handlePacket(IoSession session, IoBuffer data) throws Exception {

            data.order(ByteOrder.LITTLE_ENDIAN);

            DataTransformWithParent dataTransform = new DataTransformWithParent();
            dataTransform.deserialize(data);
            Client client = core.getClient(session);

            if (core.objectService.getObject(dataTransform.getCellId()) == null)
                return;

            SWGObject parent = core.objectService.getObject(dataTransform.getCellId());

            if (client == null) {
                System.out.println("NULL Client");
                return;
            }

            if (client.getParent() == null) {
                System.out.println("NULL Object");
                return;
            }

            CreatureObject object = (CreatureObject) client.getParent();
            if (object.getPosture() == Posture.Dead || object.getPosture() == Posture.Incapacitated)
                return;

            if (core.mountService.isMounted(object)) {
                object.sendSystemMessage(OutOfBand.ProsePackage("@pet_menu:cant_mount"), DisplayType.Broadcast);
                core.mountService.dismount(object, (CreatureObject) object.getContainer());
            }

            Point3D newPos = new Point3D(dataTransform.getXPosition(), dataTransform.getYPosition(),
                    dataTransform.getZPosition());
            newPos.setCell((CellObject) parent);
            if (Float.isNaN(newPos.x) || Float.isNaN(newPos.y) || Float.isNaN(newPos.z))
                return;
            Point3D oldPos = object.getPosition();
            Quaternion newOrientation = new Quaternion(dataTransform.getWOrientation(),
                    dataTransform.getXOrientation(), dataTransform.getYOrientation(),
                    dataTransform.getZOrientation());

            UpdateTransformWithParentMessage utm = new UpdateTransformWithParentMessage(object.getObjectID(),
                    dataTransform.getCellId(), dataTransform.getTransformedX(), dataTransform.getTransformedY(),
                    dataTransform.getTransformedZ(), dataTransform.getMovementCounter(),
                    (byte) dataTransform.getMovementAngle(), dataTransform.getSpeed());

            if (object.getContainer() != parent) {
                remove(object, oldPos.x, oldPos.z);
                if (object.getContainer() != null)
                    object.getContainer()._remove(object);
                if (object.getClient() == null)
                    System.err.println("Client is null!  This is a very strange error.");
                //if (object.getClient() != null && object.getClient().isGM() && parent != null && parent instanceof CellObject && parent.getContainer() != null)
                //object.sendSystemMessage("BuildingId - Dec: " + parent.getContainer().getObjectID() + " Hex: " + Long.toHexString(parent.getContainer().getObjectID()) + " CellNumber: " + ((CellObject) parent).getCellNumber(), DisplayType.Broadcast);
                parent._add(object);
            }
            object.setPosition(newPos);
            object.setOrientation(newOrientation);
            object.setMovementCounter(dataTransform.getMovementCounter());
            object.notifyObservers(utm, false);

            checkForCollidables(object);
            object.setAttachment("lastValidPosition", object.getPosition());

            synchronized (object.getMutex()) {
                if (dataTransform.getSpeed() > 0.0f) {
                    switch (object.getLocomotion()) {
                    case Locomotion.Prone:
                        object.setLocomotion(Locomotion.Crawling);
                        break;
                    case Locomotion.ClimbingStationary:
                        object.setLocomotion(Locomotion.Climbing);
                        break;
                    case Locomotion.Standing:
                    case Locomotion.Running:
                    case Locomotion.Walking:
                        if (dataTransform.getSpeed() >= (object.getRunSpeed()
                                * (object.getSpeedMultiplierBase() + object.getSpeedMultiplierMod()))) {
                            object.setLocomotion(Locomotion.Running);
                        } else {
                            object.setLocomotion(Locomotion.Walking);
                        }

                        break;
                    case Locomotion.Sneaking:
                    case Locomotion.CrouchSneaking:
                    case Locomotion.CrouchWalking:
                        if (dataTransform.getSpeed() >= (object.getRunSpeed()
                                * (object.getSpeedMultiplierBase() + object.getSpeedMultiplierMod()))) {
                            object.setLocomotion(Locomotion.CrouchSneaking);
                        } else {
                            object.setLocomotion(Locomotion.CrouchWalking);
                        }

                        break;
                    }
                } else {
                    switch (object.getLocomotion()) {
                    case Locomotion.Crawling:
                        object.setLocomotion(Locomotion.Prone);
                        break;
                    case Locomotion.Climbing:
                        object.setLocomotion(Locomotion.ClimbingStationary);
                        break;
                    case Locomotion.Running:
                    case Locomotion.Walking:
                        object.setLocomotion(Locomotion.Standing);
                        break;
                    case Locomotion.CrouchSneaking:
                    case Locomotion.CrouchWalking:
                        object.setLocomotion(Locomotion.Sneaking);
                        break;
                    }
                }
            }
        }

    });

    swgOpcodes.put(Opcodes.ClientOpenContainerMessage, new INetworkRemoteEvent() {

        @Override
        public void handlePacket(IoSession session, IoBuffer data) throws Exception {
            System.out.println("Open Container Request");
        }

    });

    objControllerOpcodes.put(ObjControllerOpcodes.lookAtTarget, new INetworkRemoteEvent() {

        @Override
        public void handlePacket(IoSession session, IoBuffer data) throws Exception {

            data.order(ByteOrder.LITTLE_ENDIAN);

            Client client = core.getClient(session);

            if (client == null) {
                System.out.println("NULL Client");
                return;
            }

            if (client.getParent() == null) {
                System.out.println("NULL Object");
                return;
            }
            CreatureObject object = (CreatureObject) client.getParent();

            TargetUpdate targetUpdate = new TargetUpdate();
            targetUpdate.deserialize(data);

            object.setLookAtTarget(targetUpdate.getTargetId());

        }

    });

    objControllerOpcodes.put(ObjControllerOpcodes.intendedTarget, new INetworkRemoteEvent() {

        @Override
        public void handlePacket(IoSession session, IoBuffer data) throws Exception {

            data.order(ByteOrder.LITTLE_ENDIAN);

            Client client = core.getClient(session);

            if (client == null) {
                System.out.println("NULL Client");
                return;
            }

            if (client.getParent() == null) {
                System.out.println("NULL Object");
                return;
            }
            CreatureObject object = (CreatureObject) client.getParent();

            TargetUpdate targetUpdate = new TargetUpdate();
            targetUpdate.deserialize(data);

            object.setIntendedTarget(targetUpdate.getTargetId());

        }

    });

}

From source file:org.eclipse.dataset.Stats.java

/**
 * @param a/*from w w w  . j ava  2  s .  c om*/
 * @param dtype
 * @param ignoreNaNs if true, skip NaNs
 * @param axis
 * @return product of items along axis in dataset
 */
public static Dataset typedProduct(final Dataset a, final int dtype, final boolean ignoreNaNs, int axis) {
    axis = a.checkAxis(axis);
    final int[] oshape = a.getShape();
    final int is = a.getElementsPerItem();
    final int alen = oshape[axis];
    oshape[axis] = 1;

    Dataset result = DatasetFactory.zeros(is, oshape, dtype);

    IndexIterator qiter = result.getIterator(true);
    int[] qpos = qiter.getPos();
    int[] spos;

    while (qiter.hasNext()) {
        spos = qpos.clone();

        if (a.isComplex()) {
            double rv = 1, iv = 0;
            switch (dtype) {
            case Dataset.COMPLEX64:
                ComplexFloatDataset af = (ComplexFloatDataset) a;
                if (ignoreNaNs) {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final float r1 = af.getReal(spos);
                        final float i1 = af.getImag(spos);
                        if (Float.isNaN(r1) || Float.isNaN(i1))
                            continue;
                        final double tv = r1 * rv - i1 * iv;
                        iv = r1 * iv + i1 * rv;
                        rv = tv;
                    }
                } else {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final float r1 = af.getReal(spos);
                        final float i1 = af.getImag(spos);
                        final double tv = r1 * rv - i1 * iv;
                        iv = r1 * iv + i1 * rv;
                        rv = tv;
                    }
                }
                break;
            case Dataset.COMPLEX128:
                ComplexDoubleDataset ad = (ComplexDoubleDataset) a;
                if (ignoreNaNs) {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final double r1 = ad.getReal(spos);
                        final double i1 = ad.getImag(spos);
                        if (Double.isNaN(r1) || Double.isNaN(i1))
                            continue;
                        final double tv = r1 * rv - i1 * iv;
                        iv = r1 * iv + i1 * rv;
                        rv = tv;
                    }
                } else {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final double r1 = ad.getReal(spos);
                        final double i1 = ad.getImag(spos);
                        final double tv = r1 * rv - i1 * iv;
                        iv = r1 * iv + i1 * rv;
                        rv = tv;
                    }
                }
                break;
            }

            result.set(new Complex(rv, iv), qpos);
        } else {
            final long[] lresults;
            final double[] dresults;

            switch (dtype) {
            case Dataset.BOOL:
            case Dataset.INT8:
            case Dataset.INT16:
            case Dataset.INT32:
            case Dataset.INT64:
                long lresult = 1;
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    lresult *= a.getInt(spos);
                }
                result.set(lresult, qpos);
                break;
            case Dataset.ARRAYINT8:
                lresults = new long[is];
                for (int k = 0; k < is; k++) {
                    lresults[k] = 1;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final byte[] va = (byte[]) a.getObject(spos);
                    for (int k = 0; k < is; k++) {
                        lresults[k] *= va[k];
                    }
                }
                result.set(lresults, qpos);
                break;
            case Dataset.ARRAYINT16:
                lresults = new long[is];
                for (int k = 0; k < is; k++) {
                    lresults[k] = 1;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final short[] va = (short[]) a.getObject(spos);
                    for (int k = 0; k < is; k++) {
                        lresults[k] *= va[k];
                    }
                }
                result.set(lresults, qpos);
                break;
            case Dataset.ARRAYINT32:
                lresults = new long[is];
                for (int k = 0; k < is; k++) {
                    lresults[k] = 1;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final int[] va = (int[]) a.getObject(spos);
                    for (int k = 0; k < is; k++) {
                        lresults[k] *= va[k];
                    }
                }
                result.set(lresults, qpos);
                break;
            case Dataset.ARRAYINT64:
                lresults = new long[is];
                for (int k = 0; k < is; k++) {
                    lresults[k] = 1;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final long[] va = (long[]) a.getObject(spos);
                    for (int k = 0; k < is; k++) {
                        lresults[k] *= va[k];
                    }
                }
                result.set(lresults, qpos);
                break;
            case Dataset.FLOAT32:
            case Dataset.FLOAT64:
                double dresult = 1.;
                if (ignoreNaNs) {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final double x = a.getDouble(spos);
                        if (Double.isNaN(x))
                            continue;
                        dresult *= x;
                    }
                } else {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        dresult *= a.getDouble(spos);
                    }
                }
                result.set(dresult, qpos);
                break;
            case Dataset.ARRAYFLOAT32:
                dresults = new double[is];
                for (int k = 0; k < is; k++) {
                    dresults[k] = 1.;
                }
                if (ignoreNaNs) {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final float[] va = (float[]) a.getObject(spos);
                        boolean skip = false;
                        for (int k = 0; k < is; k++) {
                            if (Float.isNaN(va[k])) {
                                skip = true;
                                break;
                            }
                        }
                        if (!skip)
                            for (int k = 0; k < is; k++) {
                                dresults[k] *= va[k];
                            }
                    }
                } else {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final float[] va = (float[]) a.getObject(spos);
                        for (int k = 0; k < is; k++) {
                            dresults[k] *= va[k];
                        }
                    }
                }
                result.set(dresults, qpos);
                break;
            case Dataset.ARRAYFLOAT64:
                dresults = new double[is];
                for (int k = 0; k < is; k++) {
                    dresults[k] = 1.;
                }
                if (ignoreNaNs) {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final double[] va = (double[]) a.getObject(spos);
                        boolean skip = false;
                        for (int k = 0; k < is; k++) {
                            if (Double.isNaN(va[k])) {
                                skip = true;
                                break;
                            }
                        }
                        if (!skip)
                            for (int k = 0; k < is; k++) {
                                dresults[k] *= va[k];
                            }
                    }
                } else {
                    for (int j = 0; j < alen; j++) {
                        spos[axis] = j;
                        final double[] va = (double[]) a.getObject(spos);
                        for (int k = 0; k < is; k++) {
                            dresults[k] *= va[k];
                        }
                    }
                }
                result.set(dresults, qpos);
                break;
            }
        }
    }

    result.setShape(AbstractDataset.squeezeShape(oshape, axis));
    return result;
}

From source file:org.knowrob.vis.model.util.algorithm.ACCUM.java

/**
 * Computes a "typical scale" for the mesh as 1% of the reciprocal of the 10-th
 * percentile of the curvature//from w  w w . j  a va 2  s.c o m
 * 
 * @param curvatures
 *            curvature values for each vertex of the model
 * @param m
 *            model analyzed
 * @return the typical scale value for the mesh
 */
private static float typical_scale(HashMap<Vertex, Curvature> curvatures, Model m) {
    float frac = 0.1f;
    float mult = 0.01f;

    int nv = m.getVertices().size();
    int nsamp = Math.min(nv, 500);
    if (nsamp == 0)
        return 0;

    float samples[] = new float[nsamp * 2];
    int idx = 0;
    for (int i = 0; i < nsamp; i++) {
        int ind = (int) (Math.random() * nv);

        samples[idx++] = Math.abs(curvatures.get(m.getVertices().get(ind)).getCurvatureMax());
        samples[idx++] = Math.abs(curvatures.get(m.getVertices().get(ind)).getCurvatureMin());
    }

    int which = (int) (frac * samples.length);
    Arrays.sort(samples);

    float f = 0;
    if (samples[which] == 0.0f || Float.isNaN(samples[which])) {
        f = mult * m.getBoundingSphere().getR();
        // LOGGER.warn("Couldn't determine typical scale. Using bsphere value: " + f + ".");
    } else {
        f = mult / samples[which];
    }
    return f;
}

From source file:au.org.ala.layers.intersect.Grid.java

private void updatesStats(Map<Float, float[]> info, long i, float v) {
    float[] stats;
    if ((stats = info.get(v)) != null) {
        int row = (int) (i / ncols);
        float lng = (float) (xmin + xres * (i % ncols));
        float lat = (float) (ymax - yres * row);

        stats[0] += SpatialUtil.cellArea(yres, ymin + yres * row);
        if (Float.isNaN(stats[1]) || stats[1] > lng)
            stats[1] = lng;/*w  w  w .j av  a 2  s  .  com*/
        if (Float.isNaN(stats[2]) || stats[2] > lat)
            stats[2] = lat;
        if (Float.isNaN(stats[3]) || stats[3] < lng + xres)
            stats[3] = (float) (lng + xres);
        if (Float.isNaN(stats[4]) || stats[4] < lat + yres)
            stats[4] = (float) (lat + yres);
    }
}

From source file:net.pms.util.Rational.java

/**
 * Returns a {@link Rational} whose value is {@code (this + value)}.
 *
 * @param value the value to be added to this {@link Rational}.
 * @return The addition result./*from  w ww  .  jav a 2 s  .c o m*/
 */
@Nonnull
public Rational add(float value) {
    if (isNaN() || Float.isNaN(value)) {
        return NaN;
    }

    if (value == 0f) {
        return this;
    }

    if (isInfinite()) {
        if (Float.isInfinite(value) && signum() != Math.signum(value)) {
            return NaN; // Infinity minus infinity
        }
        return this;
    }

    return add(valueOf(value));
}

From source file:com.actelion.research.table.view.JVisualization.java

private void updateTreeViewGraph() {
    boolean oldWasNull = (mTreeNodeList == null);
    mTreeNodeList = null;/*from ww w  .  ja  va2s. c  om*/

    if (isTreeViewGraph()) {
        int referencedColumn = mTableModel.findColumn(mTableModel.getColumnProperty(mConnectionColumn,
                CompoundTableConstants.cColumnPropertyReferencedColumn));
        int strengthColumn = mTableModel.findColumn(mTableModel.getColumnProperty(mConnectionColumn,
                CompoundTableConstants.cColumnPropertyReferenceStrengthColumn));
        float min = 0;
        float max = 0;
        float dif = 0;
        if (strengthColumn != -1) {
            min = mTableModel.getMinimumValue(strengthColumn);
            max = mTableModel.getMaximumValue(strengthColumn);
            if (max == min) {
                strengthColumn = -1;
            } else {
                min -= 0.2 * (max - min);
                dif = max - min;
            }
        }

        if (mConnectionLineMap == null)
            mConnectionLineMap = createReferenceMap(mConnectionColumn, referencedColumn);

        for (int i = 0; i < mDataPoints; i++)
            mPoint[i].exclusionFlags |= EXCLUSION_FLAG_DETAIL_GRAPH;

        if (mActivePoint == null || (mTreeViewIsDynamic && !mTableModel.isVisible(mActivePoint.record))) {
            mTreeNodeList = new VisualizationNode[0][];
        } else {
            mActivePoint.exclusionFlags &= ~EXCLUSION_FLAG_DETAIL_GRAPH;

            VisualizationNode[] rootShell = new VisualizationNode[1];
            rootShell[0] = createVisualizationNode(mActivePoint, null, 1.0f);

            ArrayList<VisualizationNode[]> shellList = new ArrayList<VisualizationNode[]>();
            shellList.add(rootShell);

            // create array lists for every shell
            for (int shell = 1; shell <= mTreeViewRadius; shell++) {
                ArrayList<VisualizationNode> vpList = new ArrayList<VisualizationNode>();
                for (VisualizationNode parent : shellList.get(shell - 1)) {
                    byte[] data = (byte[]) parent.getVisualizationPoint().record.getData(mConnectionColumn);
                    if (data != null) {
                        String[] entry = mTableModel.separateEntries(new String(data));
                        String[] strength = null;
                        if (strengthColumn != cColumnUnassigned) {
                            byte[] strengthData = (byte[]) parent.getVisualizationPoint().record
                                    .getData(strengthColumn);
                            if (strengthData != null) {
                                strength = mTableModel.separateEntries(new String(strengthData));
                                if (strength.length != entry.length)
                                    strength = null;
                            }
                        }
                        int firstChildIndex = vpList.size();
                        for (int i = 0; i < entry.length; i++) {
                            String ref = entry[i];
                            VisualizationPoint vp = mConnectionLineMap.get(ref.getBytes());
                            if (vp != null && (!mTreeViewIsDynamic || mTableModel.isVisible(vp.record))) {
                                // if we don't have connection strength information and the child is already connected to another parent
                                if (strengthColumn == cColumnUnassigned
                                        && (vp.exclusionFlags & EXCLUSION_FLAG_DETAIL_GRAPH) == 0)
                                    continue;

                                float strengthValue = 1.0f;
                                if (strength != null) {
                                    try {
                                        float value = Math.min(max, Math.max(min,
                                                mTableModel.tryParseEntry(strength[i], strengthColumn)));
                                        strengthValue = Float.isNaN(value) ? 0.0f
                                                : (float) ((value - min) / dif);
                                    } catch (NumberFormatException nfe) {
                                    }
                                }

                                VisualizationNode childNode = null;

                                // if we have a strength value and the child is already connected compare strength values
                                if ((vp.exclusionFlags & EXCLUSION_FLAG_DETAIL_GRAPH) == 0) {
                                    for (int j = 0; j < firstChildIndex; j++) {
                                        if (vpList.get(j).getVisualizationPoint() == vp) {
                                            if (vpList.get(j).getStrength() < strengthValue) {
                                                childNode = vpList.get(j);
                                                vpList.remove(childNode);
                                                firstChildIndex--;
                                                childNode.setParentNode(parent);
                                                childNode.setStrength(strengthValue);
                                            }
                                            break;
                                        }
                                    }
                                    if (childNode == null)
                                        continue;
                                } else {
                                    vp.exclusionFlags &= ~EXCLUSION_FLAG_DETAIL_GRAPH;
                                    childNode = createVisualizationNode(vp, parent, strengthValue);
                                }

                                int insertIndex = firstChildIndex;
                                while (insertIndex < vpList.size()
                                        && childNode.getStrength() <= vpList.get(insertIndex).getStrength())
                                    insertIndex++;

                                vpList.add(insertIndex, childNode);
                            }
                        }
                    }
                }

                if (vpList.size() == 0)
                    break;

                shellList.add(vpList.toArray(new VisualizationNode[0]));
            }

            mTreeNodeList = shellList.toArray(new VisualizationNode[0][]);
        }
    }

    if (!oldWasNull && mTreeNodeList == null) {
        for (int i = 0; i < mDataPoints; i++)
            mPoint[i].exclusionFlags &= ~EXCLUSION_FLAG_DETAIL_GRAPH;
    }

    if (!oldWasNull || mTreeNodeList != null) {
        // if we have a tree without any nodes (no chosen root) we don't want to hide invisible rows from other views
        mActiveExclusionFlags = (mTreeNodeList != null && mTreeNodeList.length == 0) ? 0
                : EXCLUSION_FLAG_DETAIL_GRAPH;
        applyLocalExclusion(false);
        invalidateOffImage(true);
    }
}

From source file:eu.udig.catalog.jgrass.utils.JGrassCatalogUtilities.java

public static GridCoverage2D removeNovalues(GridCoverage2D geodata) {
    // need to adapt it, for now do it dirty
    HashMap<String, Double> params = getRegionParamsFromGridCoverage(geodata);
    int height = params.get(ROWS).intValue();
    int width = params.get(COLS).intValue();
    WritableRaster tmpWR = createDoubleWritableRaster(width, height, null, null, null);
    WritableRandomIter tmpIter = RandomIterFactory.createWritable(tmpWR, null);
    RenderedImage readRI = geodata.getRenderedImage();
    RandomIter readIter = RandomIterFactory.create(readRI, null);
    for (int r = 0; r < height; r++) {
        for (int c = 0; c < width; c++) {
            double value = readIter.getSampleDouble(c, r, 0);

            if (Double.isNaN(value) || Float.isNaN((float) value) || Math.abs(value - -9999.0) < .0000001) {
                tmpIter.setSample(c, r, 0, Double.NaN);
            } else {
                tmpIter.setSample(c, r, 0, value);
            }//  w  w  w.j a  va  2 s.  co m
        }
    }
    geodata = buildCoverage("newcoverage", tmpWR, params, geodata.getCoordinateReferenceSystem());
    return geodata;
}

From source file:net.pms.util.Rational.java

/**
 * Returns a {@link Rational} whose value is {@code (this / value)}.
 *
 * @param value the value by which this {@link Rational} is to be divided.
 * @return The division result.//from  ww w .  ja  v  a  2 s.  c om
 */
@Nonnull
public Rational divide(float value) {
    if (isNaN() || Float.isNaN(value) || isInfinite() && Float.isInfinite(value)) {
        return NaN;
    }

    if (value == 0f) {
        if (signum() == 0) {
            return NaN;
        }
        return signum() > 0 ? POSITIVE_INFINITY : NEGATIVE_INFINITY;
    }

    if (Float.isInfinite(value)) {
        return ZERO;
    }
    if (signum() == 0 || isInfinite() || 1f == Math.abs(value)) {
        return value < 0f ? negate() : this;
    }

    return divide(valueOf(value));
}

From source file:org.eclipse.january.dataset.Stats.java

/**
 * @param a dataset/*from  w ww. ja v  a2  s.  c o m*/
 * @param dtype
 * @param axis
 * @param ignoreInvalids see {@link IDataset#max(boolean...)}
 * @return typed product of items along axis in dataset
 * @since 2.0
 */
public static Dataset typedProduct(final Dataset a, final int dtype, int axis,
        final boolean... ignoreInvalids) {
    axis = a.checkAxis(axis);
    final int[] oshape = a.getShape();
    final int is = a.getElementsPerItem();
    final int alen = oshape[axis];
    oshape[axis] = 1;

    final boolean ignoreNaNs;
    final boolean ignoreInfs;
    if (a.hasFloatingPointElements()) {
        ignoreNaNs = ignoreInvalids != null && ignoreInvalids.length > 0 ? ignoreInvalids[0] : false;
        ignoreInfs = ignoreInvalids != null && ignoreInvalids.length > 1 ? ignoreInvalids[1] : ignoreNaNs;
    } else {
        ignoreNaNs = false;
        ignoreInfs = false;
    }
    @SuppressWarnings("deprecation")
    Dataset result = DatasetFactory.zeros(is, oshape, dtype);

    IndexIterator qiter = result.getIterator(true);
    int[] qpos = qiter.getPos();
    int[] spos;

    // TODO add getLongArray(long[], int...) to CompoundDataset
    while (qiter.hasNext()) {
        spos = qpos.clone();

        if (a.isComplex()) {
            double rv = 1, iv = 0;
            switch (dtype) {
            case Dataset.COMPLEX64:
                ComplexFloatDataset af = (ComplexFloatDataset) a;
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final float r1 = af.getReal(spos);
                    final float i1 = af.getImag(spos);
                    if (ignoreNaNs && (Float.isNaN(r1) || Float.isNaN(i1))) {
                        continue;
                    }
                    if (ignoreInfs && (Float.isInfinite(r1) || Float.isInfinite(i1))) {
                        continue;
                    }
                    final double tv = r1 * rv - i1 * iv;
                    iv = r1 * iv + i1 * rv;
                    rv = tv;
                    if (Double.isNaN(rv) && Double.isNaN(iv)) {
                        break;
                    }
                }
                break;
            case Dataset.COMPLEX128:
                ComplexDoubleDataset ad = (ComplexDoubleDataset) a;
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final double r1 = ad.getReal(spos);
                    final double i1 = ad.getImag(spos);
                    if (ignoreNaNs && (Double.isNaN(r1) || Double.isNaN(i1))) {
                        continue;
                    }
                    if (ignoreInfs && (Double.isInfinite(r1) || Double.isInfinite(i1))) {
                        continue;
                    }
                    final double tv = r1 * rv - i1 * iv;
                    iv = r1 * iv + i1 * rv;
                    rv = tv;
                    if (Double.isNaN(rv) && Double.isNaN(iv)) {
                        break;
                    }
                }
                break;
            }

            result.set(new Complex(rv, iv), qpos);
        } else {
            final long[] lresults;
            final double[] dresults;

            switch (dtype) {
            case Dataset.BOOL:
            case Dataset.INT8:
            case Dataset.INT16:
            case Dataset.INT32:
            case Dataset.INT64:
                long lresult = 1;
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    lresult *= a.getInt(spos);
                }
                result.set(lresult, qpos);
                break;
            case Dataset.ARRAYINT8:
                lresults = new long[is];
                for (int k = 0; k < is; k++) {
                    lresults[k] = 1;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final byte[] va = (byte[]) a.getObject(spos);
                    for (int k = 0; k < is; k++) {
                        lresults[k] *= va[k];
                    }
                }
                result.set(lresults, qpos);
                break;
            case Dataset.ARRAYINT16:
                lresults = new long[is];
                for (int k = 0; k < is; k++) {
                    lresults[k] = 1;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final short[] va = (short[]) a.getObject(spos);
                    for (int k = 0; k < is; k++) {
                        lresults[k] *= va[k];
                    }
                }
                result.set(lresults, qpos);
                break;
            case Dataset.ARRAYINT32:
                lresults = new long[is];
                for (int k = 0; k < is; k++) {
                    lresults[k] = 1;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final int[] va = (int[]) a.getObject(spos);
                    for (int k = 0; k < is; k++) {
                        lresults[k] *= va[k];
                    }
                }
                result.set(lresults, qpos);
                break;
            case Dataset.ARRAYINT64:
                lresults = new long[is];
                for (int k = 0; k < is; k++) {
                    lresults[k] = 1;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final long[] va = (long[]) a.getObject(spos);
                    for (int k = 0; k < is; k++) {
                        lresults[k] *= va[k];
                    }
                }
                result.set(lresults, qpos);
                break;
            case Dataset.FLOAT32:
            case Dataset.FLOAT64:
                double dresult = 1.;
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final double x = a.getDouble(spos);
                    if (ignoreNaNs && Double.isNaN(x)) {
                        continue;
                    }
                    if (ignoreInfs && Double.isInfinite(x)) {
                        continue;
                    }
                    dresult *= x;
                    if (Double.isNaN(dresult)) {
                        break;
                    }
                }
                result.set(dresult, qpos);
                break;
            case Dataset.ARRAYFLOAT32:
            case Dataset.ARRAYFLOAT64:
                CompoundDataset da = (CompoundDataset) a;
                double[] dvalues = new double[is];
                dresults = new double[is];
                for (int k = 0; k < is; k++) {
                    dresults[k] = 1.;
                }
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    da.getDoubleArray(dvalues, spos);
                    boolean okay = true;
                    for (int k = 0; k < is; k++) {
                        final double val = dvalues[k];
                        if (ignoreNaNs && Double.isNaN(val)) {
                            okay = false;
                            break;
                        }
                        if (ignoreInfs && Double.isInfinite(val)) {
                            okay = false;
                            break;
                        }
                    }
                    if (okay) {
                        for (int k = 0; k < is; k++) {
                            dresults[k] *= dvalues[k];
                        }
                    }
                }
                result.set(dresults, qpos);
                break;
            }
        }
    }

    result.setShape(ShapeUtils.squeezeShape(oshape, axis));
    return result;
}

From source file:gdsc.core.ij.AlignImagesFFT.java

/**
 * Perform an interpolated Gaussian fit.
 * <p>// w  w  w. j  a v  a2  s .c om
 * The following functions for peak finding using Gaussian fitting have been extracted from Jpiv:
 * http://www.jpiv.vennemann-online.de/
 * 
 * @param fp
 *            Float processor containing a peak surface
 * @param i
 *            The peak x position
 * @param j
 *            The peak y position
 * @return The peak location with sub-pixel accuracy
 */
public static double[] performGaussianFit(FloatProcessor fp, int i, int j) {
    // Extract Pixel block
    float[][] pixelBlock = new float[fp.getWidth()][fp.getHeight()];
    for (int x = pixelBlock.length; x-- > 0;) {
        for (int y = pixelBlock[0].length; y-- > 0;) {
            if (Float.isNaN(fp.getf(x, y))) {
                pixelBlock[x][y] = -1;
            } else {
                pixelBlock[x][y] = fp.getf(x, y);
            }
        }
    }

    // Extracted as per the code in Jpiv2.PivUtils:
    int x = 0, y = 0, w = fp.getWidth(), h = fp.getHeight();
    int[] iCoord = new int[2];
    double[] dCoord = new double[2];
    // This will weight the function more towards the centre of the correlation pixels.
    // I am not sure if this is necessary.
    //pixelBlock = divideByWeightingFunction(pixelBlock, x, y, w, h);
    iCoord = getPeak(pixelBlock);
    dCoord = gaussianPeakFit(pixelBlock, iCoord[0], iCoord[1]);
    double[] ret = null;
    // more or less acceptable peak fit
    if (Math.abs(dCoord[0] - iCoord[0]) < w / 2 && Math.abs(dCoord[1] - iCoord[1]) < h / 2) {
        dCoord[0] += x;
        dCoord[1] += y;
        // Jpiv block is in [Y,X] format (not [X,Y])
        ret = new double[] { dCoord[1], dCoord[0] };

        //          IJ.log(String.format("Fitted x %d -> %g   y %d -> %g",  
        //                i, ret[0],
        //                j, ret[1]));
    }
    return (ret);
}