List of usage examples for java.awt.geom AffineTransform AffineTransform
public AffineTransform(double[] flatmatrix)
From source file:org.geoserver.wms.topojson.TopologyBuilder.java
public TopologyBuilder(Rectangle mapSize, ReferencedEnvelope mapArea) { this.worldToScreen = RendererUtilities.worldToScreenTransform(mapArea, mapSize); this.screenToWorld = new AffineTransform(this.worldToScreen); try {/*w w w . j av a 2 s .c om*/ this.screenToWorld.invert(); } catch (NoninvertibleTransformException e) { throw Throwables.propagate(e); } PrecisionModel precisionModel = new PrecisionModel(10.0); fixedGeometryFactory = new GeometryFactory(precisionModel); }
From source file:com.jakemadethis.graphite.visualization.renderers.HyperedgeLabelRenderer.java
public void labelEdge(RenderContext<V, E> rc, Layout<V, E> layout, E e, String label) { if (label == null || label.length() == 0) return;/*w w w . jav a2 s . c om*/ Graph<V, E> g = layout.getGraph(); EdgeLayout<E> edgeLayout = EdgeLayout$.MODULE$.apply(layout); Hypergraph<V, E> hg = g; if (!drawPredicate.evaluate(Context.<Hypergraph<V, E>, E>getInstance(hg, e))) return; if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E>getInstance(g, e))) return; Point2D edgePos = edgeLayout.getEdgeLocation(e); edgePos = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, edgePos); GraphicsDecorator gd = rc.getGraphicsContext(); Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e); Dimension d = component.getPreferredSize(); AffineTransform old = gd.getTransform(); AffineTransform xform = new AffineTransform(old); xform.translate(edgePos.getX(), edgePos.getY()); gd.setTransform(xform); gd.setStroke(new BasicStroke(1)); Rectangle rect = new Rectangle(-10, -10, 20, 20); gd.setPaint(Color.WHITE); gd.fill(rect); gd.setPaint(Color.GRAY); gd.draw(rect); xform.translate(-d.width / 2, -d.height / 2); gd.setTransform(xform); gd.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true); gd.setTransform(old); }
From source file:org.jcurl.core.base.CurveTransformedTest.java
public void testAffineTransformRotate() { final Rock v0 = new RockDouble(1, 1.5, 0.3); final double[] d = { v0.getY(), -v0.getX(), v0.getX(), v0.getY(), 0, 0 }; final AffineTransform at = new AffineTransform(d); final double v = v0.distance(0, 0); at.scale(1 / v, 1 / v);//from ww w . jav a2 s .com assertEquals(AffineTransform.TYPE_GENERAL_ROTATION, at.getType()); assertEquals("", 1.0, at.getDeterminant(), 1e-9); assertEquals("", 0.8320502943378437, at.getScaleX(), 1e-9); assertEquals("", at.getScaleX(), at.getScaleY(), 1e-9); assertEquals("", 0.5547001962252291, at.getShearX(), 1e-9); assertEquals("", -at.getShearX(), at.getShearY(), 1e-9); assertEquals("", 0.0, at.getTranslateX(), 1e-9); assertEquals("", 0.0, at.getTranslateY(), 1e-9); Point2D p = null; p = at.transform(new Point2D.Double(1, 0), null); assertEquals("Point2D.Double[0.8320502943378437, -0.5547001962252291]", p.toString()); assertEquals("", 1.0, p.distanceSq(0, 0), 1e-9); p = at.transform(new Point2D.Double(0, 1), null); assertEquals("Point2D.Double[0.5547001962252291, 0.8320502943378437]", p.toString()); assertEquals("", 1.0, p.distanceSq(0, 0), 1e-9); p = at.transform(new Point2D.Double(0.75, 1.5), null); assertEquals("Point2D.Double[1.4560880150912265, 0.8320502943378438]", p.toString()); p = at.transform(new Point2D.Double(1.5, 3.0), null); assertEquals("Point2D.Double[2.912176030182453, 1.6641005886756877]", p.toString()); }
From source file:VASSAL.tools.image.svg.SVGRenderer.java
public BufferedImage render(double angle, double scale) { // The renderer needs the bounds unscaled---scaling comes from the // width and height hints. AffineTransform px = AffineTransform.getRotateInstance(angle * DEGTORAD, defaultW / 2.0, defaultH / 2.0); r.setTransform(px);/*from w ww . j a va 2s.c om*/ px = new AffineTransform(px); px.scale(scale, scale); final Rectangle2D rect = new Rectangle2D.Float(0, 0, defaultW, defaultH); final Rectangle2D b = px.createTransformedShape(rect).getBounds2D(); r.addTranscodingHint(Rasterizer.KEY_WIDTH, (float) b.getWidth()); r.addTranscodingHint(Rasterizer.KEY_HEIGHT, (float) b.getHeight()); try { r.transcode(new TranscoderInput(doc), null); return r.getBufferedImage(); } // FIXME: review error message catch (BridgeException e) { logger.error("", e); } catch (TranscoderException e) { logger.error("", e); } return null; }
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 ww w . j a va2 s . c o m*/ */ public void testAffineTransformRotateShift() { final Point2D p0_wc = new Point2D.Double(3, 3.5); final Rock v0_wc = new RockDouble(2, 4.2, 0.3); final double v = v0_wc.distance(0, 0); final double[] d = { v0_wc.getY(), -v0_wc.getX(), v0_wc.getX(), v0_wc.getY(), 0, 0 }; final AffineTransform at = new AffineTransform(d); at.scale(1 / v, 1 / v); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_UNIFORM_SCALE, 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(0, at.getTranslateX()); assertEquals(0, at.getTranslateY()); Point2D p = null; p = at.transform(new Point2D.Double(5, 1.3), null); assertEquals("Point2D.Double[5.073216248629703, -0.9759492274906292]", p.toString()); at.preConcatenate(AffineTransform.getTranslateInstance(p0_wc.getX(), p0_wc.getY())); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_TRANSLATION + AffineTransform.TYPE_UNIFORM_SCALE, 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()); p = at.transform(new Point2D.Double(5, 1.3), null); assertEquals("Point2D.Double[8.073216248629702, 2.524050772509371]", p.toString()); }
From source file:VASSAL.tools.image.svg.SVGRenderer.java
public BufferedImage render(double angle, double scale, Rectangle2D aoi) { // The renderer needs the bounds unscaled---scaling comes from the // width and height hints. AffineTransform px = AffineTransform.getRotateInstance(angle * DEGTORAD, defaultW / 2.0, defaultH / 2.0); r.setTransform(px);/* w w w . jav a 2s .com*/ px = new AffineTransform(px); px.scale(scale, scale); final Rectangle2D rect = new Rectangle2D.Float(0, 0, defaultW, defaultH); r.addTranscodingHint(Rasterizer.KEY_WIDTH, (float) aoi.getWidth()); r.addTranscodingHint(Rasterizer.KEY_HEIGHT, (float) aoi.getHeight()); r.addTranscodingHint(Rasterizer.KEY_AOI, aoi); try { r.transcode(new TranscoderInput(doc), null); return r.getBufferedImage(); } // FIXME: review error message catch (BridgeException e) { logger.error("", e); } catch (TranscoderException e) { logger.error("", e); } return null; }
From source file:ddf.catalog.transformer.input.pdf.GeoPdfParser.java
/** * Parses a given NeatLine and Transformation matrix into a WKT String * * @param lgidict - The PDF's LGIDict object * @param neatLineArray - The NeatLine array of points for the PDF * @param toDoubleVisitor - A visitor that converts PDF Strings / Ints / Longs into doubles. * @return the generated WKT Lat/Lon set * @throws IOException/*w w w.j a v a 2 s . co m*/ */ private String getWktFromNeatLine(COSDictionary lgidict, COSArray neatLineArray, ICOSVisitor toDoubleVisitor) throws IOException { List<Double> neatline = new LinkedList<>(); List<String> coordinateList = new LinkedList<>(); String firstCoordinate = null; double[] points = new double[CTM_SIZE]; for (int i = 0; i < CTM_SIZE; i++) { points[i] = (Double) lgidict.getObjectFromPath(CTM + "/[" + i + "]").accept(toDoubleVisitor); } AffineTransform affineTransform = new AffineTransform(points); for (int i = 0; i < neatLineArray.size(); i++) { neatline.add((Double) neatLineArray.get(i).accept(toDoubleVisitor)); } for (int i = 0; i < neatline.size(); i += 2) { double x = neatline.get(i); double y = neatline.get(i + 1); Point2D p = new Point2D.Double(x, y); Point2D pprime = affineTransform.transform(p, null); String xySet = point2dToWkt(pprime); if (firstCoordinate == null) { firstCoordinate = xySet; } coordinateList.add(xySet); } coordinateList.add(firstCoordinate); String wktString = StringUtils.join(coordinateList, ", "); LOGGER.debug("{}", wktString); return wktString.toString(); }
From source file:ddf.catalog.transformer.input.pdf.GeoPdfParserImpl.java
/** * Parses a given NeatLine and Transformation matrix into a WKT String * * @param lgidict - The PDF's LGIDict object * @param neatLineArray - The NeatLine array of points for the PDF * @param toDoubleVisitor - A visitor that converts PDF Strings / Ints / Longs into doubles. * @return the generated WKT Lat/Lon set * @throws IOException//from ww w. j av a 2 s .co m */ private Optional<String> getWktFromNeatLine(COSDictionary lgidict, COSArray neatLineArray, ICOSVisitor toDoubleVisitor) throws IOException { List<Double> neatline = new LinkedList<>(); List<String> coordinateList = new LinkedList<>(); String firstCoordinate = null; double[] points = new double[CTM_SIZE]; for (int i = 0; i < CTM_SIZE; i++) { Object obj = lgidict.getObjectFromPath(CTM + "/[" + i + "]").accept(toDoubleVisitor); if (obj != null) { points[i] = (Double) obj; } else { return Optional.empty(); } } AffineTransform affineTransform = new AffineTransform(points); for (int i = 0; i < neatLineArray.size(); i++) { neatline.add((Double) neatLineArray.get(i).accept(toDoubleVisitor)); } for (int i = 0; i < neatline.size(); i += 2) { double x = neatline.get(i); double y = neatline.get(i + 1); Point2D p = new Point2D.Double(x, y); Point2D pprime = affineTransform.transform(p, null); String xySet = point2dToWkt(pprime); if (firstCoordinate == null) { firstCoordinate = xySet; } coordinateList.add(xySet); } coordinateList.add(firstCoordinate); String wktString = StringUtils.join(coordinateList, ", "); LOGGER.debug("{}", wktString); return Optional.of(wktString); }
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 {/*w w w . ja va 2 s .c o m*/ 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.tinymediamanager.ui.components.ImageLabel.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (scaledImage != null) { int originalWidth = scaledImage.getWidth(null); int originalHeight = scaledImage.getHeight(null); // calculate new height/width int newWidth = 0; int newHeight = 0; int offsetX = 0; int offsetY = 0; if (drawBorder && !drawFullWidth) { Point size = ImageCache.calculateSize(this.getWidth() - 8, this.getHeight() - 8, originalWidth, originalHeight, true); // calculate offsets if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) { offsetX = this.getWidth() - size.x - 8; }/*w w w . ja v a2s. c o m*/ if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) { offsetY = this.getHeight() - size.y - 8; } if (position == Position.CENTER) { offsetX = (this.getWidth() - size.x - 8) / 2; offsetY = (this.getHeight() - size.y - 8) / 2; } newWidth = size.x; newHeight = size.y; // when the image size differs too much - reload and rescale the original image recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight); g.setColor(Color.BLACK); g.drawRect(offsetX, offsetY, size.x + 7, size.y + 7); g.setColor(Color.WHITE); g.fillRect(offsetX + 1, offsetY + 1, size.x + 6, size.y + 6); // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX + 4, offsetY + 4, newWidth, newHeight, this); g.drawImage(scaledImage, offsetX + 4, offsetY + 4, newWidth, newHeight, this); } else { Point size = null; if (drawFullWidth) { size = new Point(this.getWidth(), this.getWidth() * originalHeight / originalWidth); } else { size = ImageCache.calculateSize(this.getWidth(), this.getHeight(), originalWidth, originalHeight, true); } // calculate offsets if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) { offsetX = this.getWidth() - size.x; } if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) { offsetY = this.getHeight() - size.y; } if (position == Position.CENTER) { offsetX = (this.getWidth() - size.x) / 2; offsetY = (this.getHeight() - size.y) / 2; } newWidth = size.x; newHeight = size.y; // when the image size differs too much - reload and rescale the original image recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight); // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX, offsetY, newWidth, newHeight, this); g.drawImage(scaledImage, offsetX, offsetY, newWidth, newHeight, this); } } else { // draw border and background if (drawBorder) { g.setColor(Color.BLACK); g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); if (getParent().isOpaque()) { g.setColor(getParent().getBackground()); g.fillRect(1, 1, this.getWidth() - 2, this.getHeight() - 2); } } // calculate diagonal int diagonalSize = (int) Math .sqrt(this.getWidth() * this.getWidth() + this.getHeight() * this.getHeight()); // draw text String text = ""; if (alternativeText != null) { text = alternativeText; } else { text = BUNDLE.getString("image.nonefound"); //$NON-NLS-1$ } if (!getParent().isOpaque()) { text = ""; } Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AffineTransform orig = g2.getTransform(); AffineTransform at = new AffineTransform(orig); at.translate(0, this.getHeight()); at.rotate(this.getWidth(), -this.getHeight()); g2.setTransform(at); g2.setColor(Color.BLACK); g2.setFont(FONT); FontMetrics fm = g2.getFontMetrics(); int x = (diagonalSize - fm.stringWidth(text)) / 2; int y = (fm.getAscent() - fm.getDescent()) / 2; g2.drawString(text, x, y); // g2.drawLine(0, 0, diagonalSize, 0); at.translate(0, -this.getHeight()); g2.setTransform(orig); } }