List of usage examples for java.awt.geom AffineTransform getShearX
public double getShearX()
From source file:Main.java
public void paint(Graphics g) { Shape shape = new Rectangle2D.Float(100, 50, 80, 80); Graphics2D g2 = (Graphics2D) g; AffineTransform at = new AffineTransform(); at.setToQuadrantRotation(2, 0.5, 0.5); System.out.println(at.getShearX()); g2.setTransform(at);//w ww . ja v a 2 s . c o m g2.draw(shape); }
From source file:Matrix.java
/** * Set the values of the matrix from the AffineTransform. * //from w w w . j av a 2 s .com * @param af The transform to get the values from. */ public void setFromAffineTransform(AffineTransform af) { single[0] = (float) af.getScaleX(); single[1] = (float) af.getShearY(); single[3] = (float) af.getShearX(); single[4] = (float) af.getScaleY(); single[6] = (float) af.getTranslateX(); single[7] = (float) af.getTranslateY(); }
From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.BeginInlineImage.java
/** * process : BI : begin inline image./*www. j a va 2 s. c o m*/ * @param operator The operator that is being executed. * @param arguments List * @throws java.io.IOException If there is an error displaying the inline image. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context; PDPage page = drawer.getPage(); //begin inline image object ImageParameters params = operator.getImageParameters(); PDInlinedImage image = new PDInlinedImage(); image.setImageParameters(params); image.setImageData(operator.getImageData()); BufferedImage awtImage = image.createImage(context.getColorSpaces()); if (awtImage == null) { log.warn("BeginInlineImage.process(): createImage returned NULL"); return; } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = drawer.getPageSize().getHeight(); Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.findRotation(); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(ctmAT); // calculate the inverse rotation angle // scaleX = m00 = cos // shearX = m01 = -sin // tan = sin/cos double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX()); Matrix translationMatrix = null; if (pageRotation == 0 || pageRotation == 180) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()), (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale())); } else if (pageRotation == 90 || pageRotation == 270) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()), (float) (pageHeight - 2 * ctm.getYPosition())); } rotationMatrix = rotationMatrix.multiply(translationMatrix); rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1)); rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0)); AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1), rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0), rotationMatrix.getValue(2, 1)); drawer.drawImage(awtImage, at); }
From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.BeginInlineImage.java
/** * process : BI : begin inline image.//from w ww . ja v a 2s . c om * * @param operator The operator that is being executed. * @param arguments List * @throws IOException If there is an error displaying the inline image. */ @Override public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context; PDPage page = extractor.getPage(); //begin inline image object ImageParameters params = operator.getImageParameters(); PDInlinedImage image = new PDInlinedImage(); image.setImageParameters(params); image.setImageData(operator.getImageData()); if (params.isStencil()) { //TODO implement inline image stencil masks LOG.warn("Stencil masks are not implemented, background may be incorrect"); } BufferedImage awtImage = image.createImage(context.getColorSpaces()); if (awtImage == null) { LOG.warn("BeginInlineImage.process(): createImage returned NULL"); return; } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = extractor.getPageSize().getHeight(); Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.findRotation(); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(ctmAT); // calculate the inverse rotation angle // scaleX = m00 = cos // shearX = m01 = -sin // tan = sin/cos double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX()); Matrix translationMatrix = null; if (pageRotation == 0 || pageRotation == 180) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()), (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale())); } else if (pageRotation == 90 || pageRotation == 270) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()), (float) (pageHeight - 2 * ctm.getYPosition())); } rotationMatrix = rotationMatrix.multiply(translationMatrix); rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1)); rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0)); AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1), rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0), rotationMatrix.getValue(2, 1)); extractor.drawImage(awtImage, at); }
From source file:org.apache.fop.render.pcl.PCLRenderingUtil.java
/** * Determines the print direction based on the given transformation matrix. This method * only detects right angles (0, 90, 180, 270). If any other angle is determined, 0 is * returned./*from ww w. j a v a 2 s. co m*/ * @param transform the transformation matrix * @return the angle in degrees of the print direction. */ public static int determinePrintDirection(AffineTransform transform) { int newDir; if (transform.getScaleX() == 0 && transform.getScaleY() == 0 && transform.getShearX() == 1 && transform.getShearY() == -1) { newDir = 90; } else if (transform.getScaleX() == -1 && transform.getScaleY() == -1 && transform.getShearX() == 0 && transform.getShearY() == 0) { newDir = 180; } else if (transform.getScaleX() == 0 && transform.getScaleY() == 0 && transform.getShearX() == -1 && transform.getShearY() == 1) { newDir = 270; } else { newDir = 0; } return newDir; }
From source file:org.apache.pdfbox.util.operator.pagedrawer.BeginInlineImage.java
/** * process : BI : begin inline image.//from w ww .ja v a 2 s . c o m * @param operator The operator that is being executed. * @param arguments List * @throws IOException If there is an error displaying the inline image. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { PageDrawer drawer = (PageDrawer) context; PDPage page = drawer.getPage(); //begin inline image object ImageParameters params = operator.getImageParameters(); PDInlinedImage image = new PDInlinedImage(); image.setImageParameters(params); image.setImageData(operator.getImageData()); BufferedImage awtImage = image.createImage(context.getColorSpaces()); if (awtImage == null) { log.warn("BeginInlineImage.process(): createImage returned NULL"); return; } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = drawer.getPageSize().getHeight(); Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.findRotation(); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(ctmAT); // calculate the inverse rotation angle // scaleX = m00 = cos // shearX = m01 = -sin // tan = sin/cos double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX()); Matrix translationMatrix = null; if (pageRotation == 0 || pageRotation == 180) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()), (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale())); } else if (pageRotation == 90 || pageRotation == 270) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()), (float) (pageHeight - 2 * ctm.getYPosition())); } rotationMatrix = rotationMatrix.multiply(translationMatrix); rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1)); rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0)); AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1), rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0), rotationMatrix.getValue(2, 1)); drawer.drawImage(awtImage, at); }
From source file:org.geoserver.data.test.MockData.java
void coverageInfo(QName name, File coverageFile, String styleName) throws Exception { String coverage = name.getLocalPart(); File coverageDir = new File(coverages, coverage); coverageDir.mkdir();// ww w . j av a 2 s .c o m File info = new File(coverageDir, "info.xml"); info.createNewFile(); // let's grab the necessary metadata AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(coverageFile); GridCoverage2DReader reader; try { reader = (GridCoverage2DReader) format.getReader(coverageFile); } catch (Exception e) { String message = "Exception while trying to read " + coverageFile.getCanonicalPath() + " with format" + format.getName(); throw new RuntimeException(message, e); } if (reader == null) { throw new RuntimeException( "No reader for " + coverageFile.getCanonicalPath() + " with format " + format.getName()); } // basic info FileWriter writer = new FileWriter(info); writer.write("<coverage format=\"" + coverage + "\">\n"); writer.write("<name>" + coverage + "</name>\n"); writer.write("<label>" + coverage + "</label>\n"); writer.write("<description>" + coverage + " description</description>\n"); writer.write( "<metadataLink about = \"http://www.remotesensing.org:16080/websites/geotiff/geotiff.html\" metadataType = \"other\" />"); writer.write("<keywords>WCS," + coverage + " </keywords>\n"); if (styleName == null) styleName = "raster"; writer.write("<styles default=\"" + styleName + "\"/>\n"); // envelope CoordinateReferenceSystem crs = reader.getCoordinateReferenceSystem(); GeneralEnvelope envelope = reader.getOriginalEnvelope(); GeneralEnvelope wgs84envelope = CoverageStoreUtils.getWGS84LonLatEnvelope(envelope); final String nativeCrsName = CRS.lookupIdentifier(crs, false); writer.write("<envelope crs=\"" + crs.toString().replaceAll("\"", "'") + "\" srsName=\"" + nativeCrsName + "\">\n"); writer.write("<pos>" + wgs84envelope.getMinimum(0) + " " + wgs84envelope.getMinimum(1) + "</pos>\n"); writer.write("<pos>" + wgs84envelope.getMaximum(0) + " " + wgs84envelope.getMaximum(1) + "</pos>\n"); writer.write("</envelope>\n"); /** * Now reading a fake small GridCoverage just to retrieve meta information: * - calculating a new envelope which is 1/20 of the original one * - reading the GridCoverage subset */ final ParameterValueGroup readParams = reader.getFormat().getReadParameters(); final Map parameters = CoverageUtils.getParametersKVP(readParams); double[] minCP = envelope.getLowerCorner().getCoordinate(); double[] maxCP = new double[] { minCP[0] + (envelope.getSpan(0) / 20.0), minCP[1] + (envelope.getSpan(1) / 20.0) }; final GeneralEnvelope subEnvelope = new GeneralEnvelope(minCP, maxCP); subEnvelope.setCoordinateReferenceSystem(reader.getCoordinateReferenceSystem()); parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(), new GridGeometry2D(reader.getOriginalGridRange(), subEnvelope)); GridCoverage2D gc = (GridCoverage2D) reader.read(CoverageUtils.getParameters(readParams, parameters, true)); // grid geometry final GridGeometry geometry = gc.getGridGeometry(); final int dimensions = geometry.getGridRange().getDimension(); String lower = ""; String upper = ""; for (int i = 0; i < dimensions; i++) { lower = lower + geometry.getGridRange().getLow(i) + " "; upper = upper + geometry.getGridRange().getHigh(i) + " "; } writer.write("<grid dimension = \"" + dimensions + "\">\n"); writer.write("<low>" + lower + "</low>\n"); writer.write("<high>" + upper + "</high>\n"); final CoordinateSystem cs = crs.getCoordinateSystem(); for (int i = 0; i < cs.getDimension(); i++) { writer.write("<axisName>" + cs.getAxis(i).getName().getCode() + "</axisName>\n"); } if (geometry.getGridToCRS() instanceof AffineTransform) { AffineTransform aTX = (AffineTransform) geometry.getGridToCRS(); writer.write("<geoTransform>"); writer.write("<scaleX>" + aTX.getScaleX() + "</scaleX>\n"); writer.write("<scaleY>" + aTX.getScaleY() + "</scaleY>\n"); writer.write("<shearX>" + aTX.getShearX() + "</shearX>\n"); writer.write("<shearY>" + aTX.getShearY() + "</shearY>\n"); writer.write("<translateX>" + aTX.getTranslateX() + "</translateX>\n"); writer.write("<translateY>" + aTX.getTranslateY() + "</translateY>\n"); writer.write("</geoTransform>\n"); } writer.write("</grid>\n"); // coverage dimensions final GridSampleDimension[] sd = gc.getSampleDimensions(); for (int i = 0; i < sd.length; i++) { writer.write("<CoverageDimension>\n"); writer.write("<name>" + sd[i].getDescription().toString() + "</name>\n"); writer.write("<interval>\n"); writer.write("<min>" + sd[i].getMinimumValue() + "</min>\n"); writer.write("<max>" + sd[i].getMaximumValue() + "</max>\n"); writer.write("</interval>\n"); final List<Category> categories = sd[i].getCategories(); if (categories != null && categories.size() >= 1) { writer.write("<nullValues>\n"); for (Iterator<Category> it = sd[i].getCategories().iterator(); it.hasNext();) { Category cat = (Category) it.next(); if ((cat != null) && cat.getName().toString().equalsIgnoreCase("no data")) { double min = cat.getRange().getMinimum(); double max = cat.getRange().getMaximum(); writer.write("<value>" + min + "</value>\n"); if (min != max) writer.write("<value>" + max + "</value>\n"); } } writer.write("</nullValues>\n"); } else writer.write("<nullValues/>\n"); writer.write("</CoverageDimension>\n"); } // supported crs writer.write("<supportedCRSs>\n"); writer.write("<requestCRSs>" + nativeCrsName + "</requestCRSs>\n"); writer.write("<responseCRSs>" + nativeCrsName + "</responseCRSs>\n"); writer.write("</supportedCRSs>\n"); // supported formats writer.write("<supportedFormats nativeFormat = \"" + format.getName() + "\">\n"); writer.write("<formats>ARCGRID,ARCGRID-GZIP,GEOTIFF,PNG,GIF,TIFF</formats>\n"); writer.write("</supportedFormats>\n"); // supported interpolations writer.write("<supportedInterpolations default = \"nearest neighbor\">\n"); writer.write("<interpolationMethods>nearest neighbor</interpolationMethods>\n"); writer.write("</supportedInterpolations>\n"); // the end writer.write("</coverage>\n"); writer.flush(); writer.close(); }
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 . ja va2 s. c om 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: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.ja v a 2 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: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).// w w w . j a v a 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)); }