Example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D.

Prototype

public Vector3D(double x, double y, double z) 

Source Link

Document

Simple constructor.

Usage

From source file:ch.epfl.leb.sass.models.fluorophores.commands.internal.FluorophoreReceiverIT.java

@Before
public void setUp() {
    // Camera//from www .jav a 2  s  .  c  om
    DefaultCamera.Builder cameraBuilder = new DefaultCamera.Builder();

    cameraBuilder.nX(32); // Number of pixels in x
    cameraBuilder.nY(32); // Number of pixels in y
    cameraBuilder.readoutNoise(1.6); // Standard deviation, electrons
    cameraBuilder.darkCurrent(0.06);
    cameraBuilder.quantumEfficiency(0.8);
    cameraBuilder.aduPerElectron(2.2);
    cameraBuilder.emGain(0); // Set to zero for CMOS cameras
    cameraBuilder.baseline(100); // ADU
    cameraBuilder.pixelSize(6.45); // microns
    camera = cameraBuilder.build();

    // Illumination profile
    RefractiveIndex n = new UniformRefractiveIndex(new Complex(1.33));
    SquareUniformIllumination.Builder illumBuilder = new SquareUniformIllumination.Builder();
    illumBuilder.height(32 * 6.45 / 60); // microns
    illumBuilder.orientation(new Vector3D(1.0, 0, 0)); // x-polarized
    illumBuilder.power(1.0);
    illumBuilder.refractiveIndex(n);
    illumBuilder.wavelength(0.642);
    illumBuilder.width(32 * 6.45 / 60); // microns
    illumination = illumBuilder.build();

    // PSF, create a 2D Gaussian point-spread function
    psfBuilder = new Gaussian2D.Builder();
    psfBuilder.stageDisplacement(0).NA(1.3).FWHM(0.3).wavelength(0.68).resLateral(0.108);

    // Fluorophore dynamics and properties; rates are in units of 1/frames
    SimpleDynamics.Builder fluorPropBuilder = new SimpleDynamics.Builder();

    fluorPropBuilder.signal(2500); // Photons per fluorophore per frame
    fluorPropBuilder.wavelength(0.68); // Wavelength, microns
    fluorPropBuilder.tOn(3); // Mean on time
    fluorPropBuilder.tOff(100); // Mean off time
    fluorPropBuilder.tBl(10000); // Mean bleaching time
    fluorDynamics = fluorPropBuilder.build();
}

From source file:com.diozero.imu.drivers.invensense.ImuDataFactory.java

public static ImuData newInstance(MPU9150FIFOData fifoData, short[] compassData, double gyroScaleFactor,
        double accelScaleFactor, double compassScaleFactor, double quatScaleFactor, float temperature) {
    Vector3D gyro = createVector(fifoData.getGyro(), gyroScaleFactor);
    Vector3D accel = createVector(fifoData.getAccel(), accelScaleFactor);
    // TODO What is the scale factor for the quaternion data?!
    Quaternion quaternion = createQuaternion(fifoData.getQuat(), quatScaleFactor);
    Vector3D compass = createVector(compassData, compassScaleFactor);

    // From https://github.com/sparkfun/MPU-9150_Breakout/blob/master/firmware/MPU6050/Examples/MPU9150_AHRS.ino
    //  The gyros and accelerometers can in principle be calibrated in addition to any factory calibration but they are generally
    //  pretty accurate. You can check the accelerometer by making sure the reading is +1 g in the positive direction for each axis.
    //  The gyro should read zero for each axis when the sensor is at rest. Small or zero adjustment should be needed for these sensors.
    //  The magnetometer is a different thing. Most magnetometers will be sensitive to circuit currents, computers, and 
    //  other both man-made and natural sources of magnetic field. The rough way to calibrate the magnetometer is to record
    //  the maximum and minimum readings (generally achieved at the North magnetic direction). The average of the sum divided by two
    //  should provide a pretty good calibration offset. Don't forget that for the MPU9150, the magnetometer x- and y-axes are switched 
    //  compared to the gyro and accelerometer!
    // Sensors x (y)-axis of the accelerometer is aligned with the y (x)-axis of the magnetometer;
    // the magnetometer z-axis (+ down) is opposite to z-axis (+ up) of accelerometer and gyro!
    // We have to make some allowance for this orientation mismatch in feeding the output to the quaternion filter.
    // For the MPU-9150, we have chosen a magnetic rotation that keeps the sensor forward along the x-axis just like
    // in the LSM9DS0 sensor. This rotation can be modified to allow any convenient orientation convention.
    // This is ok by aircraft orientation standards!

    // From Richards Tech (not sure if this is needed if the orientation has been set correctly by the DMP driver!)
    // Sort out gyro axes
    //gyro = new Vector3D(gyro.getX(), -gyro.getY(), -gyro.getZ());
    // Sort out accel axes
    //accel = new Vector3D(-accel.getX(), accel.getY(), accel.getZ());
    // Sort out compass axes
    // TODO Can this be handled by a generic transformation matrix?
    compass = new Vector3D(compass.getY(), -compass.getX(), -compass.getZ());

    long timestamp = fifoData.getTimestamp();

    return new ImuData(gyro, accel, quaternion, compass, temperature, timestamp);
}

From source file:com.diozero.imu.drivers.invensense.MPU9150DataFactory.java

public static ImuData newInstance(MPU9150FIFOData fifoData, short[] compassData, double gyroScaleFactor,
        double accelScaleFactor, double compassScaleFactor, double quatScaleFactor, float temperature) {
    Vector3D gyro = ImuDataFactory.createVector(fifoData.getGyro(), gyroScaleFactor);
    Vector3D accel = ImuDataFactory.createVector(fifoData.getAccel(), accelScaleFactor);
    // TODO What is the scale factor for the quaternion data?!
    Quaternion quaternion = ImuDataFactory.createQuaternion(fifoData.getQuat(), quatScaleFactor);
    Vector3D compass = ImuDataFactory.createVector(compassData, compassScaleFactor);

    // From https://github.com/sparkfun/MPU-9150_Breakout/blob/master/firmware/MPU6050/Examples/MPU9150_AHRS.ino
    //  The gyros and accelerometers can in principle be calibrated in addition to any factory calibration but they are generally
    //  pretty accurate. You can check the accelerometer by making sure the reading is +1 g in the positive direction for each axis.
    //  The gyro should read zero for each axis when the sensor is at rest. Small or zero adjustment should be needed for these sensors.
    //  The magnetometer is a different thing. Most magnetometers will be sensitive to circuit currents, computers, and 
    //  other both man-made and natural sources of magnetic field. The rough way to calibrate the magnetometer is to record
    //  the maximum and minimum readings (generally achieved at the North magnetic direction). The average of the sum divided by two
    //  should provide a pretty good calibration offset. Don't forget that for the MPU9150, the magnetometer x- and y-axes are switched 
    //  compared to the gyro and accelerometer!
    // Sensors x (y)-axis of the accelerometer is aligned with the y (x)-axis of the magnetometer;
    // the magnetometer z-axis (+ down) is opposite to z-axis (+ up) of accelerometer and gyro!
    // We have to make some allowance for this orientation mismatch in feeding the output to the quaternion filter.
    // For the MPU-9150, we have chosen a magnetic rotation that keeps the sensor forward along the x-axis just like
    // in the LSM9DS0 sensor. This rotation can be modified to allow any convenient orientation convention.
    // This is ok by aircraft orientation standards!

    // From Richards Tech (not sure if this is needed if the orientation has been set correctly by the DMP driver!)
    // Sort out gyro axes
    //gyro = new Vector3D(gyro.getX(), -gyro.getY(), -gyro.getZ());
    // Sort out accel axes
    //accel = new Vector3D(-accel.getX(), accel.getY(), accel.getZ());
    // Sort out compass axes
    // TODO Can this be handled by a generic transformation matrix?
    compass = new Vector3D(compass.getY(), -compass.getX(), -compass.getZ());

    long timestamp = fifoData.getTimestamp();

    return new ImuData(gyro, accel, quaternion, compass, temperature, timestamp);
}

From source file:edu.stanford.cfuller.imageanalysistools.filter.WatershedFilter.java

/**
 * Applies the WatershedFilter to the specified Image, segmenting it.
 * @param im    The Image to be segmented.
 *///from   w w  w .  j  a  v  a 2s. com
@Override
public void apply(WritableImage im) {

    WritableImage imCopy = ImageFactory.createWritable(im);

    InversionFilter invf = new InversionFilter();

    invf.apply(imCopy);

    Histogram h = new Histogram(imCopy);

    java.util.Hashtable<Double, java.util.Vector<Vector3D>> greylevelLookup = new Hashtable<Double, java.util.Vector<Vector3D>>();

    for (ImageCoordinate ic : imCopy) {
        double value = imCopy.getValue(ic);

        if (greylevelLookup.get(value) == null) {
            greylevelLookup.put(value, new java.util.Vector<Vector3D>());
        }

        greylevelLookup.get(value).add(
                new Vector3D(ic.get(ImageCoordinate.X), ic.get(ImageCoordinate.Y), ic.get(ImageCoordinate.Z)));

    }

    WritableImage processing = getSeedImage(greylevelLookup, imCopy, h);

    Histogram hSeed = new Histogram(processing);

    int nextLabel = hSeed.getMaxValue() + 1;

    ImageCoordinate ic = ImageCoordinate.createCoordXYZCT(0, 0, 0, 0, 0);

    for (int i = h.getMinValue() + 1; i < h.getMaxValue(); i++) {

        //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("processing greylevel: " + i);

        if (h.getCounts(i) == 0)
            continue;

        for (Vector3D v : greylevelLookup.get((double) i)) {

            int x = (int) v.getX();
            int y = (int) v.getY();
            int z = (int) v.getZ();

            ic.set(ImageCoordinate.X, x);
            ic.set(ImageCoordinate.Y, y);
            ic.set(ImageCoordinate.Z, z);

            int label = getCorrectLabel(ic, processing, nextLabel);

            processing.setValue(ic, label);

            if (label == nextLabel)
                nextLabel++;

        }

    }

    ic.recycle();

    MaskFilter mf = new MaskFilter();

    mf.setReferenceImage(processing);
    mf.apply(im);

    LabelFilter lf = new LabelFilter();

    lf.apply(im);

}

From source file:edu.stanford.cfuller.imageanalysistools.clustering.Cluster.java

/**
 * Sets the centroid of the Cluster by its individual components.
 * @param x     The centroid x-coordinate.
 * @param y     The centroid y-coordinate.
 * @param z     The centroid z-coordinate.
 *//*w  ww . j a v a 2 s  .  co  m*/
public void setCentroidComponents(double x, double y, double z) {
    this.centroid = new Vector3D(x, y, z);
}

From source file:edu.stanford.cfuller.imageanalysistools.clustering.ObjectClustering.java

/**
 * Sets up a set of ClusterObjects and a set of Clusters from two Image masks, one labeled with individual objects, and one labeled with all objects in a single cluster grouped with a single label.
 *
 * @param labeledByObject       An Image mask with all objects in the Image labeled with an unique greylevel value.  These labels must start with 1 and be consecutive.
 * @param labeledByCluster      An Image mask with all the objects in each cluster labeled with the same unique greylevel value.  These labels must start with 1 and be consecutive.
 * @param clusterObjects        A Vector of ClusterObjects that will contain the initialized ClusterObjects on return; this can be empty, and any contents will be erased.
 * @param clusters              A Vector of Clusters that will contain the initialized Clusters on return; this can be empty, and any contents will be erased.
 * @param k                     The number of clusters in the Image.  This must be the same as the number of unique nonzero greylevels in the labeledByCluster Image.
 * @return                      The number of ClusterObjects in the Image.
 *///from ww w  .ja  va 2  s.c o m
public static int initializeObjectsAndClustersFromClusterImage(Image labeledByObject, Image labeledByCluster,
        Vector<ClusterObject> clusterObjects, Vector<Cluster> clusters, int k) {

    clusters.clear();

    for (int j = 0; j < k; j++) {

        clusters.add(new Cluster());
        clusters.get(j).setID(j + 1);

    }

    Histogram h = new Histogram(labeledByObject);

    int n = h.getMaxValue();

    clusterObjects.clear();

    for (int j = 0; j < n; j++) {
        clusterObjects.add(new ClusterObject());
        clusterObjects.get(j).setCentroidComponents(0, 0, 0);
        clusterObjects.get(j).setnPixels(0);
    }

    for (ImageCoordinate i : labeledByObject) {

        if (labeledByObject.getValue(i) > 0) {

            int value = (int) (labeledByObject.getValue(i));

            clusterObjects.get(value - 1).incrementnPixels();
            clusterObjects.get(value - 1).setCentroid(
                    clusterObjects.get(value - 1).getCentroid().add(new Vector3D(i.get(ImageCoordinate.X),
                            i.get(ImageCoordinate.Y), i.get(ImageCoordinate.Z))));

        }

    }

    for (int j = 0; j < n; j++) {
        ClusterObject current = clusterObjects.get(j);
        current.setCentroid(current.getCentroid().scalarMultiply(1.0 / current.getnPixels()));
    }

    for (ImageCoordinate i : labeledByObject) {

        int clusterValue = (int) labeledByCluster.getValue(i);
        int objectValue = (int) labeledByObject.getValue(i);
        if (clusterValue == 0 || objectValue == 0) {
            continue;
        }

        clusters.get(clusterValue - 1).getObjectSet().add(clusterObjects.get(objectValue - 1));

    }

    for (Cluster c : clusters) {

        int objectCounter = 0;

        c.setCentroidComponents(0, 0, 0);

        for (ClusterObject co : c.getObjectSet()) {

            objectCounter++;
            co.setCurrentCluster(c);

            c.setCentroid(c.getCentroid().add(co.getCentroid()));

        }

        c.setCentroid(c.getCentroid().scalarMultiply(1.0 / objectCounter));

    }

    return n;

}

From source file:Engine.WorldMap.java

public double GetGroundPosition(double[] position, WorldMap worldMap) {
    double retX = 0;
    double retY = 0;
    double x = (int) position[0] / GenerateTerrain.Size;
    double y = (int) position[1] / GenerateTerrain.Size;

    double[] p11 = { x, y, (double) worldMap.Map[(int) x][(int) y] };
    double[] p12 = { x, y + 1, (double) worldMap.Map[(int) x][(int) y + 1] };
    double[] p21 = { x + 1, y, (double) worldMap.Map[(int) x + 1][(int) y] };
    double[] p22 = { x + 1, y + 1, (double) worldMap.Map[(int) x + 1][(int) y + 1] };
    if (PointInTriangle(position, p11, p12, p22)) {
        Vector3D v1 = new Vector3D(p12[0] - p11[0], p12[1] - p11[1], p12[2] - p11[2]);
        Vector3D v2 = new Vector3D(p22[0] - p11[0], p22[1] - p11[1], p22[2] - p11[2]);
        Vector3D n = Vector3D.crossProduct(v1, v2);
        double z = ((n.getX() * x) + (n.getY() * y)
                + ((-n.getX() * p11[0]) + (-n.getY() * p11[1]) + (-n.getZ() * p11[2]))) / (-n.getZ());
        return z;
        //return (z3(x-x1)(y-y2) + z1(x-x2)(y-y3) + z2(x-x3)(y-y1) - z2(x-x1)(y-y3) - z3(x-x2)(y-y1) - z1(x-x3)(y-y2))
        //  / (  (x-x1)(y-y2) +   (x-x2)(y-y3) +   (x-x3)(y-y1) -   (x-x1)(y-y3) -   (x-x2)(y-y1) -   (x-x3)(y-y2));
    } else {/*from   w ww  .j a va 2  s .com*/
        Vector3D v1 = new Vector3D(p21[0] - p11[0], p21[1] - p11[1], p21[2] - p11[2]);
        Vector3D v2 = new Vector3D(p22[0] - p11[0], p22[1] - p11[1], p22[2] - p11[2]);
        Vector3D n = Vector3D.crossProduct(v1, v2);
        double z = ((n.getX() * x) + (n.getY() * y)
                + ((-n.getX() * p11[0]) + (-n.getY() * p11[1]) + (-n.getZ() * p11[2]))) / (-n.getZ());
        return z;
    }
    //screen.worldMap.Map[x][y];
}

From source file:ch.epfl.leb.sass.models.MicroscopeIT.java

/**
 * Sets up a basic Microscope for an acquisition simulation.
 *///w w  w. jav  a2s .c  o m
@Before
public void setUp() {
    if (setupIsDone) {
        // Skip setup if it has already run.
        return;
    }

    // The seed determines the outputs of the random number generator.
    RNG.setSeed(42);

    DefaultCamera.Builder cameraBuilder = new DefaultCamera.Builder();

    cameraBuilder.nX(32); // Number of pixels in x
    cameraBuilder.nY(32); // Number of pixels in y
    cameraBuilder.readoutNoise(1.6); // Standard deviation, electrons
    cameraBuilder.darkCurrent(0.06);
    cameraBuilder.quantumEfficiency(0.8);
    cameraBuilder.aduPerElectron(2.2);
    cameraBuilder.emGain(0); // Set to zero for CMOS cameras
    cameraBuilder.baseline(100); // ADU
    cameraBuilder.pixelSize(6.45); // microns
    cameraBuilder.thermalNoise(0.05); // electrons/frame/pixel

    // DefaultObjective
    DefaultObjective.Builder objectiveBuilder = new DefaultObjective.Builder();

    objectiveBuilder.NA(1.3); // Numerical aperture
    objectiveBuilder.mag(60); // Magnification

    // DefaultLaser
    DefaultLaser.Builder laserBuilder = new DefaultLaser.Builder();

    laserBuilder.currentPower(0.0);
    laserBuilder.minPower(0.0);
    laserBuilder.maxPower(500.0);
    laserBuilder.wavelength(0.642);

    // Illumination profile
    // TODO: Add illumination setup to the GUI
    RefractiveIndex n = new UniformRefractiveIndex(new Complex(1.33));
    SquareUniformIllumination.Builder illumBuilder = new SquareUniformIllumination.Builder();
    illumBuilder.height(32 * 6.45 / 60);
    illumBuilder.orientation(new Vector3D(1.0, 0, 0)); // x-polarized
    illumBuilder.refractiveIndex(n);
    illumBuilder.width(32 * 6.45 / 60);

    // DefaultStage
    DefaultStage.Builder stageBuilder = new DefaultStage.Builder();

    stageBuilder.x(0);
    stageBuilder.y(0);
    stageBuilder.z(0); // Coverslip surface is at z = 0

    // PSF, create a 2D Gaussian point-spread function
    Gaussian2D.Builder psfBuilder = new Gaussian2D.Builder();

    // Fluorophore dynamics and properties; rates are in units of 1/frames
    PalmDynamics.Builder fluorPropBuilder = new PalmDynamics.Builder();

    fluorPropBuilder.signal(2500); // Photons per fluorophore per frame
    fluorPropBuilder.wavelength(0.6); // Wavelength, microns
    fluorPropBuilder.kA(100); // Activation rate
    fluorPropBuilder.kB(0); // Bleaching rate
    fluorPropBuilder.kD1(0.065); // Transition rate to first dark state
    fluorPropBuilder.kD2(0.013); // Transition rate to second dark state
    fluorPropBuilder.kR1(0.004); // Return rate from first dark state
    fluorPropBuilder.kR2(0.157); // Return rate from second dark state

    // Fluorophore positions on a square grid
    GenerateFluorophoresGrid2D.Builder fluorPosBuilder = new GenerateFluorophoresGrid2D.Builder();
    fluorPosBuilder.spacing(4); // pixels

    // Add fiducials to the field of view at a random location
    GenerateFiducialsRandom2D.Builder fidBuilder = new GenerateFiducialsRandom2D.Builder();
    fidBuilder.numFiducials(2);
    fidBuilder.brightness(3000); // photons per frame

    // Add a constant background
    GenerateUniformBackground.Builder backgroundBuilder = new GenerateUniformBackground.Builder();
    backgroundBuilder.backgroundSignal(10); // photons

    // Assemble the microscope.
    microscope = new Microscope(cameraBuilder, laserBuilder, objectiveBuilder, psfBuilder, stageBuilder,
            fluorPosBuilder, fluorPropBuilder, fidBuilder, backgroundBuilder, illumBuilder);

    setupIsDone = true;
}

From source file:com.rvantwisk.cnctools.controls.opengl.ArrowsActor.java

@Override
public void endBlock(GCodeParser parser, MachineStatus machineStatus, Map<String, ParsedWord> block)
        throws SimException {

    switch (machine.getMotionMode()) {
    case G0:/*from w w w  .  j ava2s  .  com*/
    case G1:
        double rX = machine.getX();
        double rY = machine.getY();
        double rZ = machine.getZ();
        double rA = machine.getA();

        if (rX - lastX != 0.0 || rY - lastY != 0.0 || rZ - lastZ != 0.0) {

            addArrow(arrow, new double[] { rX, rY, rZ }, rA, new Vector3D(lastX, lastY, lastZ),
                    new Vector3D(rX, rY, rZ));
        }
        break;
    case G2:
    case G3:
        //   drawArc(parser, machineStatus, currentBlock);
        break;
    }

    lastX = machine.getX();
    lastY = machine.getY();
    lastZ = machine.getZ();
    lastA = machine.getA();
}

From source file:com.mapr.synth.drive.DriveTest.java

static Vector3D project(Vector3D east, Vector3D north, Vector3D step) {
    return new Vector3D(step.dotProduct(east) * Constants.EARTH_RADIUS_KM,
            step.dotProduct(north) * Constants.EARTH_RADIUS_KM, 0);
}