Example usage for org.apache.commons.math3.geometry.euclidean.twod.hull ConvexHull2D getVertices

List of usage examples for org.apache.commons.math3.geometry.euclidean.twod.hull ConvexHull2D getVertices

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.twod.hull ConvexHull2D getVertices.

Prototype

public Vector2D[] getVertices() 

Source Link

Usage

From source file:gdsc.core.utils.ConvexHull.java

/**
 * Create a new convex hull from the given coordinates.
 *
 * @param xbase/*from  www  .ja  v a 2 s .  co m*/
 *            the x base coordinate (origin)
 * @param ybase
 *            the y base coordinate (origin)
 * @param xCoordinates
 *            the x coordinates
 * @param yCoordinates
 *            the y coordinates
 * @param n
 *            the number of coordinates
 * @return the convex hull
 * @throws NullPointerException
 *             if the inputs are null
 * @throws ArrayIndexOutOfBoundsException
 *             if the yCoordinates are smaller than the xCoordinates
 */
public static ConvexHull create(float xbase, float ybase, float[] xCoordinates, float[] yCoordinates, int n) {
    // This algorithm is not suitable for floating point coords
    //return createGiftWrap(xbase, ybase, xCoordinates, yCoordinates, n);

    // Use Apache Math to do this
    MonotoneChain chain = new MonotoneChain();
    TurboList<Vector2D> points = new TurboList<Vector2D>(n);
    for (int i = 0; i < n; i++)
        points.add(new Vector2D(xbase + xCoordinates[i], ybase + yCoordinates[i]));
    ConvexHull2D hull = null;
    try {
        hull = chain.generate(points);
    } catch (ConvergenceException e) {
    }

    if (hull == null)
        return null;

    Vector2D[] v = hull.getVertices();
    if (v.length == 0)
        return null;

    int size = v.length;
    float[] xx = new float[size];
    float[] yy = new float[size];
    int n2 = 0;
    for (int i = 0; i < size; i++) {
        xx[n2] = (float) v[i].getX();
        yy[n2] = (float) v[i].getY();
        n2++;
    }
    return new ConvexHull(0, 0, xx, yy);
}

From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolator.java

private synchronized void updateConvexHullAndInterpolate() {
    //duplicate points for use on caluclation thread
    final LinkedList<Point3d> points = new LinkedList<Point3d>(points_);
    if (currentInterpolationTask_ != null && !currentInterpolationTask_.isDone()) {
        //cancel current interpolation because interpolation points have changed, call does not block
        currentInterpolationTask_.cancel(true);
    }/*from   w  w  w . ja v  a  2s  .com*/
    //don't want one of the get methods returning a null object thinking it has a value
    synchronized (convexHullLock_) {
        convexHullVertices_ = null;
        convexHullRegion_ = null;
    }
    synchronized (interpolationLock_) {
        currentInterpolation_ = null;
    }
    synchronized (xyPositionLock_) {
        xyPositions_ = null;
    }
    numRows_ = 0;
    numCols_ = 0;

    currentInterpolationTask_ = executor_.submit(new Runnable() {
        @Override
        public void run() {
            if (points.size() > 2) {
                try {
                    //convert xyPoints to a vector2d for convex hull calculation
                    LinkedList<Vector2D> xyPoints = new LinkedList<Vector2D>();
                    for (Point3d p : points) {
                        xyPoints.add(new Vector2D(p.x, p.y));
                    }
                    ConvexHull2D hull = null;
                    hull = mChain_.generate(xyPoints);
                    if (Thread.interrupted()) {
                        throw new InterruptedException();
                    }
                    synchronized (convexHullLock_) {
                        convexHullVertices_ = hull.getVertices();
                        convexHullLock_.notifyAll();
                    }
                    if (Thread.interrupted()) {
                        throw new InterruptedException();
                    }
                    convexHullRegion_ = hull.createRegion();
                    if (Thread.interrupted()) {
                        throw new InterruptedException();
                    }
                    calculateConvexHullBounds();
                    if (Thread.interrupted()) {
                        throw new InterruptedException();
                    }
                    //use the most recently set overlap value for display purposes. When it comes time to calc the real thing, 
                    //get it from the acquisition settings
                    fitXYPositionsToConvexHull(FixedAreaAcquisitionSettings.getStoredTileOverlapPercentage());
                    //Interpolate surface as specified by the subclass method
                    interpolateSurface(points);
                    //let manager handle event firing to acquisitions using surface
                    manager_.surfaceUpdated(SurfaceInterpolator.this);
                } catch (InterruptedException e) {
                    return;
                }
            }
        }
    });
}