List of usage examples for java.awt.geom AffineTransform inverseTransform
@SuppressWarnings("fallthrough") public Point2D inverseTransform(Point2D ptSrc, Point2D ptDst) throws NoninvertibleTransformException
From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolator.java
/** * test whether XY position is completely abve or completely below surface * @throws InterruptedException //from w w w . j a va2s . co m */ public boolean testPositionRelativeToSurface(XYStagePosition pos, SurfaceInterpolator surface, double zPos, int mode, boolean extrapolate) throws InterruptedException { //get the corners with padding added in Point2D.Double[] corners = getPositionCornersWithPadding(pos, surface.xyPadding_um_); //First check position corners before going into a more detailed set of test points for (Point2D.Double point : corners) { float interpVal; if (!surface.waitForCurentInterpolation().isInterpDefined(point.x, point.y)) { if (extrapolate) { interpVal = surface.getExtrapolatedValue(point.x, point.y); } else { continue; } } else { interpVal = surface.waitForCurentInterpolation().getInterpolatedValue(point.x, point.y); } if ((towardsSampleIsPositive_ && mode == ABOVE_SURFACE && zPos >= interpVal) || (towardsSampleIsPositive_ && mode == BELOW_SURFACE && zPos <= interpVal) || (!towardsSampleIsPositive_ && mode == ABOVE_SURFACE && zPos <= interpVal) || (!towardsSampleIsPositive_ && mode == BELOW_SURFACE) && zPos >= interpVal) { return false; } } //then check a grid of points spanning entire position //9x9 square of points to check for each position //square is aligned with axes in pixel space, so convert to pixel space to generate test points double xSpan = corners[2].getX() - corners[0].getX(); double ySpan = corners[2].getY() - corners[0].getY(); Point2D.Double pixelSpan = new Point2D.Double(); AffineTransform transform = AffineUtils.getAffineTransform(getCurrentPixelSizeConfig(), 0, 0); try { transform.inverseTransform(new Point2D.Double(xSpan, ySpan), pixelSpan); } catch (NoninvertibleTransformException ex) { Log.log("Problem inverting affine transform"); } outerloop: for (double x = 0; x <= pixelSpan.x; x += pixelSpan.x / (double) NUM_XY_TEST_POINTS) { for (double y = 0; y <= pixelSpan.y; y += pixelSpan.y / (double) NUM_XY_TEST_POINTS) { //convert these abritray pixel coordinates back to stage coordinates double[] transformMaxtrix = new double[6]; transform.getMatrix(transformMaxtrix); transformMaxtrix[4] = corners[0].getX(); transformMaxtrix[5] = corners[0].getY(); //create new transform with translation applied transform = new AffineTransform(transformMaxtrix); Point2D.Double stageCoords = new Point2D.Double(); transform.transform(new Point2D.Double(x, y), stageCoords); //test point for inclusion of position float interpVal; if (!surface.waitForCurentInterpolation().isInterpDefined(stageCoords.x, stageCoords.y)) { if (extrapolate) { interpVal = surface.getExtrapolatedValue(stageCoords.x, stageCoords.y); } else { continue; } } else { interpVal = surface.waitForCurentInterpolation().getInterpolatedValue(stageCoords.x, stageCoords.y); } if ((towardsSampleIsPositive_ && mode == ABOVE_SURFACE && zPos >= interpVal) || (towardsSampleIsPositive_ && mode == BELOW_SURFACE && zPos <= interpVal) || (!towardsSampleIsPositive_ && mode == ABOVE_SURFACE && zPos <= interpVal) || (!towardsSampleIsPositive_ && mode == BELOW_SURFACE) && zPos >= interpVal) { return false; } } } return true; }
From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolator.java
private void calculateConvexHullBounds() { //convert convex hull vertices to pixel offsets in an arbitrary pixel space AffineTransform transform = AffineUtils.getAffineTransform(getCurrentPixelSizeConfig(), 0, 0); boundYPixelMin_ = Integer.MAX_VALUE; boundYPixelMax_ = Integer.MIN_VALUE; boundXPixelMin_ = Integer.MAX_VALUE; boundXPixelMax_ = Integer.MIN_VALUE; boundXMin_ = Double.MAX_VALUE; boundXMax_ = Double.MIN_VALUE; boundYMin_ = Double.MAX_VALUE; boundYMax_ = Double.MIN_VALUE; for (int i = 0; i < convexHullVertices_.length; i++) { //calculate edges of interpolation bounding box //for later use by interpolating function boundXMin_ = Math.min(boundXMin_, convexHullVertices_[i].getX()); boundXMax_ = Math.max(boundXMax_, convexHullVertices_[i].getX()); boundYMin_ = Math.min(boundYMin_, convexHullVertices_[i].getY()); boundYMax_ = Math.max(boundYMax_, convexHullVertices_[i].getY()); //also get pixel bounds of convex hull for fitting of XY positions double dx = convexHullVertices_[i].getX() - convexHullVertices_[0].getX(); double dy = convexHullVertices_[i].getY() - convexHullVertices_[0].getY(); Point2D.Double pixelOffset = new Point2D.Double(); // pixel offset from convex hull vertex 0; try {/*from w w w . j ava2 s .c om*/ transform.inverseTransform(new Point2D.Double(dx, dy), pixelOffset); } catch (NoninvertibleTransformException ex) { Log.log("Problem inverting affine transform"); } boundYPixelMin_ = (int) Math.min(boundYPixelMin_, pixelOffset.y); boundYPixelMax_ = (int) Math.max(boundYPixelMax_, pixelOffset.y); boundXPixelMin_ = (int) Math.min(boundXPixelMin_, pixelOffset.x); boundXPixelMax_ = (int) Math.max(boundXPixelMax_, pixelOffset.x); } }