Example usage for org.apache.commons.math3.geometry.partitioning Region getBoundarySize

List of usage examples for org.apache.commons.math3.geometry.partitioning Region getBoundarySize

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.partitioning Region getBoundarySize.

Prototype

double getBoundarySize();

Source Link

Document

Get the size of the boundary.

Usage

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

private void fitXYPositionsToConvexHull(double overlap) throws InterruptedException {
    int fullTileWidth = JavaLayerImageConstructor.getInstance().getImageWidth();
    int fullTileHeight = JavaLayerImageConstructor.getInstance().getImageHeight();
    int overlapX = (int) (JavaLayerImageConstructor.getInstance().getImageWidth() * overlap / 100);
    int overlapY = (int) (JavaLayerImageConstructor.getInstance().getImageHeight() * overlap / 100);
    int tileWidthMinusOverlap = fullTileWidth - overlapX;
    int tileHeightMinusOverlap = fullTileHeight - overlapY;
    int pixelPadding = (int) (xyPadding_um_ / Magellan.getCore().getPixelSizeUm());
    numRows_ = (int) Math
            .ceil((boundYPixelMax_ - boundYPixelMin_ + pixelPadding) / (double) tileHeightMinusOverlap);
    numCols_ = (int) Math
            .ceil((boundXPixelMax_ - boundXPixelMin_ + pixelPadding) / (double) tileWidthMinusOverlap);

    //take center of bounding box and create grid
    int pixelCenterX = boundXPixelMin_ + (boundXPixelMax_ - boundXPixelMin_) / 2;
    int pixelCenterY = boundYPixelMin_ + (boundYPixelMax_ - boundYPixelMin_) / 2;

    AffineTransform transform = AffineUtils.getAffineTransform(getCurrentPixelSizeConfig(), 0, 0);
    ArrayList<XYStagePosition> positions = new ArrayList<XYStagePosition>();
    Point2D.Double gridCenterStageCoords = new Point2D.Double();
    transform.transform(new Point2D.Double(pixelCenterX, pixelCenterY), gridCenterStageCoords);
    gridCenterStageCoords.x += convexHullVertices_[0].getX();
    gridCenterStageCoords.y += convexHullVertices_[0].getY();
    //set affine transform translation relative to grid center
    double[] transformMaxtrix = new double[6];
    transform.getMatrix(transformMaxtrix);
    transformMaxtrix[4] = gridCenterStageCoords.x;
    transformMaxtrix[5] = gridCenterStageCoords.y;
    //create new transform with translation applied
    transform = new AffineTransform(transformMaxtrix);
    //add all positions of rectangle around convex hull
    for (int col = 0; col < numCols_; col++) {
        double xPixelOffset = (col - (numCols_ - 1) / 2.0) * (tileWidthMinusOverlap);
        for (int row = 0; row < numRows_; row++) {
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }/*from ww  w .  j  av a 2  s .co  m*/
            double yPixelOffset = (row - (numRows_ - 1) / 2.0) * (tileHeightMinusOverlap);
            Point2D.Double pixelPos = new Point2D.Double(xPixelOffset, yPixelOffset);
            Point2D.Double stagePos = new Point2D.Double();
            transform.transform(pixelPos, stagePos);
            AffineTransform posTransform = AffineUtils.getAffineTransform(getCurrentPixelSizeConfig(),
                    stagePos.x, stagePos.y);
            positions.add(new XYStagePosition(stagePos, tileWidthMinusOverlap, tileHeightMinusOverlap,
                    fullTileWidth, fullTileHeight, row, col, posTransform));
        }
    }
    //delete positions squares (+padding) that do not overlap convex hull
    for (int i = positions.size() - 1; i >= 0; i--) {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        XYStagePosition pos = positions.get(i);
        //create square region correpsonding to stage pos
        Region<Euclidean2D> square = getStagePositionRegion(pos);
        //if convex hull and position have no intersection, delete
        Region<Euclidean2D> intersection = regionFacotry_.intersection(square, convexHullRegion_);
        if (intersection.isEmpty()) {
            positions.remove(i);
        }
        square.getBoundarySize();
    }
    if (Thread.interrupted()) {
        throw new InterruptedException();
    }
    synchronized (xyPositionLock_) {
        xyPositions_ = positions;
        xyPositionLock_.notifyAll();
    }

    //let manger know new parmas caluclated
    manager_.updateSurfaceTableAndCombos();
}