List of usage examples for java.awt.geom AffineTransform getMatrix
public void getMatrix(double[] flatmatrix)
From source file:org.apache.pdfbox.pdmodel.graphics.pattern.PDShadingPatternResources.java
/** * Sets the optional Matrix entry for the Pattern. * @param transform the transformation matrix */// www.ja va 2 s. com public void setMatrix(AffineTransform transform) { matrix = new COSArray(); double[] values = new double[6]; transform.getMatrix(values); for (double v : values) { matrix.add(new COSFloat((float) v)); } getCOSDictionary().setItem(COSName.MATRIX, matrix); }
From source file:org.apache.pdfbox.pdmodel.PDPageContentStream.java
/** * Writes an AffineTransform to the content stream as an array. *//* ww w . java 2s . c o m*/ private void writeAffineTransform(AffineTransform transform) throws IOException { double[] values = new double[6]; transform.getMatrix(values); for (double v : values) { writeOperand((float) v); } }
From source file:org.apache.xmlgraphics.ps.PSGenerator.java
/** * Formats a transformation matrix./*from w w w . j a va2 s. c o m*/ * @param at the AffineTransform with the matrix * @return the formatted transformation matrix (example: "[1 0 0 1 0 0]") */ public String formatMatrix(AffineTransform at) { double[] matrix = new double[6]; at.getMatrix(matrix); return "[" + formatDouble5(matrix[0]) + " " + formatDouble5(matrix[1]) + " " + formatDouble5(matrix[2]) + " " + formatDouble5(matrix[3]) + " " + formatDouble5(matrix[4]) + " " + formatDouble5(matrix[5]) + "]"; }
From source file:org.jcurl.core.base.CurveTransformedTest.java
public void testAffineTransformMemoryLayout() { Rock r = new RockDouble(1, 2, 3); AffineTransform at = new AffineTransform(); final double[] d = new double[6]; at.getMatrix(d); assertEquals("", 1.0, d[0], 1e-9); assertEquals("", 0.0, d[1], 1e-9); assertEquals("", 0.0, d[2], 1e-9); assertEquals("", 1.0, d[3], 1e-9); assertEquals("", 0.0, d[4], 1e-9); assertEquals("", 0.0, d[5], 1e-9); at.transform(r = new RockDouble(2, 3, 4), r); assertEquals(2, 3, 4, r, 1e-9);//from w ww. ja va 2s. com at = AffineTransform.getScaleInstance(0.5, 0.75); at.getMatrix(d); assertEquals("", 0.5, d[0], 1e-9); assertEquals("", 0.0, d[1], 1e-9); assertEquals("", 0.0, d[2], 1e-9); assertEquals("", 0.75, d[3], 1e-9); assertEquals("", 0.0, d[4], 1e-9); assertEquals("", 0.0, d[5], 1e-9); at.transform(r = new RockDouble(2, 3, 4), r); assertEquals(1, 2.25, 4, r, 1e-9); at = AffineTransform.getTranslateInstance(0.5, 0.75); at.getMatrix(d); assertEquals("", 1.0, d[0], 1e-9); assertEquals("", 0.0, d[1], 1e-9); assertEquals("", 0.0, d[2], 1e-9); assertEquals("", 1.0, d[3], 1e-9); assertEquals("", 0.5, d[4], 1e-9); assertEquals("", 0.75, d[5], 1e-9); at.transform(r = new RockDouble(2, 3, 4), r); assertEquals(2.5, 3.75, 4, r, 1e-9); }
From source file:org.jcurl.core.base.CurveTransformedTest.java
/** * Test the transformation from a Rock Coordinates (rc) System at wc(3,3.5) * with positive y axis along wc(2,4.2) into World Coordinates (wc). Uses a * Point rc(5,1.3) = wc(8,2.5).//from w w w . ja va 2 s . c om * * @see CurveTransformed#createRc2Wc(AffineTransform, Point2D, Point2D) */ public void testCreateRc2Wc() { final Point2D p0_wc = new Point2D.Double(3, 3.5); final Rock v0_wc = new RockDouble(2, 4.2, 0.3); final AffineTransform at = CurveTransformed.createRc2Wc(null, p0_wc, v0_wc); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_TRANSLATION, at.getType()); assertEquals(1.0, at.getDeterminant()); assertEquals(0.9028605188239303, at.getScaleX()); assertEquals(at.getScaleX(), at.getScaleY()); assertEquals(0.42993358039234775, at.getShearX()); assertEquals(-at.getShearX(), at.getShearY()); assertEquals(p0_wc.getX(), at.getTranslateX()); assertEquals(p0_wc.getY(), at.getTranslateY()); final Point2D rc = new Point2D.Double(5, 1.3); final Point2D wc = at.transform(rc, null); assertEquals("Point2D.Double[8.073216248629704, 2.524050772509371]", wc.toString()); // angle in rc: double ang = Math.atan2(rc.getY(), rc.getX()); assertEquals(14.574216198038739, rad2deg(ang)); // wc rotation: ang = Math.atan2(at.getShearY(), at.getScaleY()); assertEquals(-25.463345061871614, rad2deg(ang)); final double[] d = new double[6]; at.getMatrix(d); ang = Math.atan2(-d[2], d[3]); assertEquals(-25.463345061871614, rad2deg(ang)); // angle in wc: ang = Math.atan2(wc.getY(), wc.getX()); assertEquals(17.36159358309492, rad2deg(ang)); }
From source file:org.micromanager.plugins.magellan.propsandcovariants.SurfaceData.java
public double[] curvedSurfacePower(AcquisitionEvent event, double multiplier) { XYStagePosition xyPos = event.xyPosition_; double zPosition = event.zPosition_; Point2D.Double[] corners = xyPos.getFullTileCorners(); //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(surface_.getCurrentPixelSizeConfig(), 0, 0); try {//from w w w . j a va 2 s. c om transform.inverseTransform(new Point2D.Double(xSpan, ySpan), pixelSpan); } catch (NoninvertibleTransformException ex) { Log.log("Problem inverting affine transform"); } double[] relativePower = new double[FOV_LASER_MODULATION_RESOLUTION * FOV_LASER_MODULATION_RESOLUTION]; for (int xInd = 0; xInd < FOV_LASER_MODULATION_RESOLUTION; xInd++) { for (int yInd = 0; yInd < FOV_LASER_MODULATION_RESOLUTION; yInd++) { double x = ((0.5 + pixelSpan.x) / (double) FOV_LASER_MODULATION_RESOLUTION) * xInd; double y = ((0.5 + pixelSpan.y) / (double) FOV_LASER_MODULATION_RESOLUTION) * yInd; //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); //Index in the way Teensy expects data int flatIndex = xInd + FOV_LASER_MODULATION_RESOLUTION * yInd; try { //test point for inclusion of position if (!surface_.waitForCurentInterpolation().isInterpDefined(stageCoords.x, stageCoords.y)) { //if position is outside of convex hull, use minimum laser power relativePower[flatIndex] = basePower_; } else { float interpVal = surface_.waitForCurentInterpolation().getInterpolatedValue(stageCoords.x, stageCoords.y); float normalAngle = surface_.waitForCurentInterpolation() .getNormalAngleToVertical(stageCoords.x, stageCoords.y); relativePower[flatIndex] = basePower_ * CurvedSurfaceCalculations.getRelativePower(meanFreePath_, Math.max(0, zPosition - interpVal), normalAngle, radiusOfCurvature_) * multiplier; } } catch (InterruptedException ex) { Log.log("Couldn't calculate curved surface power"); Log.log(ex); return null; } } } return relativePower; }
From source file:org.micromanager.plugins.magellan.propsandcovariants.SurfaceData.java
/** *//from w ww.j a v a 2s . c o m * @param corners * @param min true to get min, false to get max * @return {minDistance,maxDistance, minNormalAngle, maxNormalAngle) */ private double[] distanceAndNormalCalc(Point2D.Double[] corners, double zVal) throws InterruptedException { //check a grid of points spanning entire 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(surface_.getCurrentPixelSizeConfig(), 0, 0); try { transform.inverseTransform(new Point2D.Double(xSpan, ySpan), pixelSpan); } catch (NoninvertibleTransformException ex) { Log.log("Problem inverting affine transform"); } double minDistance = Integer.MAX_VALUE; double maxDistance = 0; double minNormalAngle = 90; double maxNormalAngle = 0; 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 if (!surface_.waitForCurentInterpolation().isInterpDefined(stageCoords.x, stageCoords.y)) { //if position is outside of convex hull, assume min distance is 0 minDistance = 0; //get extrapolated value for max distance float interpVal = surface_.getExtrapolatedValue(stageCoords.x, stageCoords.y); maxDistance = Math.max(zVal - interpVal, maxDistance); //only take actual values for normals } else { float interpVal = surface_.waitForCurentInterpolation().getInterpolatedValue(stageCoords.x, stageCoords.y); float normalAngle = surface_.waitForCurentInterpolation() .getNormalAngleToVertical(stageCoords.x, stageCoords.y); minDistance = Math.min(Math.max(0, zVal - interpVal), minDistance); maxDistance = Math.max(zVal - interpVal, maxDistance); minNormalAngle = Math.min(minNormalAngle, normalAngle); maxNormalAngle = Math.max(maxNormalAngle, normalAngle); } } } return new double[] { minDistance, maxDistance, minNormalAngle, maxNormalAngle }; }
From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolator.java
/** * test whether XY position is completely abve or completely below surface * @throws InterruptedException /* ww w . j av a2 s . c om*/ */ 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 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 w w w. j a v 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(); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
@Override public void drawString(final String s, final float x, float y) { if (s.length() == 0) { return;/*from w w w . j a v a 2 s .co m*/ } setFillPaint(); setStrokePaint(); final AffineTransform at = getTransform(); final AffineTransform at2 = getTransform(); at2.translate(x, y); at2.concatenate(font.getTransform()); setTransform(at2); final AffineTransform inverse = this.normalizeMatrix(); final AffineTransform flipper = FLIP_TRANSFORM; inverse.concatenate(flipper); final double[] mx = new double[6]; inverse.getMatrix(mx); cb.beginText(); final float fontSize = font.getSize2D(); if (lastBaseFont == null) { final String fontName = font.getName(); final boolean bold = font.isBold(); final boolean italic = font.isItalic(); final BaseFontFontMetrics fontMetrics = metaData.getBaseFontFontMetrics(fontName, fontSize, bold, italic, null, metaData.isFeatureSupported(OutputProcessorFeature.EMBED_ALL_FONTS), false); final FontNativeContext nativeContext = fontMetrics.getNativeContext(); lastBaseFont = fontMetrics.getBaseFont(); cb.setFontAndSize(lastBaseFont, fontSize); if (fontMetrics.isTrueTypeFont() && bold && nativeContext.isNativeBold() == false) { final float strokeWidth = font.getSize2D() / 30.0f; // right from iText ... if (strokeWidth == 1) { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); } else { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE); cb.setLineWidth(strokeWidth); } } else { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); } } else { cb.setFontAndSize(lastBaseFont, fontSize); } cb.setTextMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); double width = 0; if (fontSize > 0) { final float scale = 1000 / fontSize; final Font font = this.font.deriveFont(AffineTransform.getScaleInstance(scale, scale)); final Rectangle2D stringBounds = font.getStringBounds(s, getFontRenderContext()); width = stringBounds.getWidth() / scale; } if (s.length() > 1) { final float adv = ((float) width - lastBaseFont.getWidthPoint(s, fontSize)) / (s.length() - 1); cb.setCharacterSpacing(adv); } cb.showText(s); if (s.length() > 1) { cb.setCharacterSpacing(0); } cb.endText(); setTransform(at); if (underline) { // These two are supposed to be taken from the .AFM file // int UnderlinePosition = -100; final int UnderlineThickness = 50; // final double d = PdfGraphics2D.asPoints(UnderlineThickness, (int) fontSize); setStroke(new BasicStroke((float) d)); y = (float) ((y) + PdfGraphics2D.asPoints((UnderlineThickness), (int) fontSize)); final Line2D line = new Line2D.Double(x, y, (width + x), y); draw(line); } }