@Override public void mouseMoved(MouseEvent e) { try { affineTransform.inverseTransform(e.getPoint(), currentMousePointLogic); } catch (Exception ex) { } }
/** * Creates the map's bounding box in real world coordinates. * * @param worldToScreen a transform which converts World coordinates to screen pixel coordinates. * No assumptions are done on axis order as this is assumed to be pre-calculated. The affine * transform may specify an rotation, in case the envelope will encompass the complete * (rotated) world polygon. * @param paintArea the size of the rendering output area * @return the envelope in world coordinates corresponding to the screen rectangle. */ public static Envelope createMapEnvelope(Rectangle paintArea, AffineTransform worldToScreen) throws NoninvertibleTransformException { // // (X1,Y1) (X2,Y1) // // (X1,Y2) (X2,Y2) double[] pts = new double[8]; pts[0] = paintArea.getMinX(); pts[1] = paintArea.getMinY(); pts[2] = paintArea.getMaxX(); pts[3] = paintArea.getMinY(); pts[4] = paintArea.getMaxX(); pts[5] = paintArea.getMaxY(); pts[6] = paintArea.getMinX(); pts[7] = paintArea.getMaxY(); worldToScreen.inverseTransform(pts, 0, pts, 0, 4); double xMin = Double.MAX_VALUE; double yMin = Double.MAX_VALUE; double xMax = -Double.MAX_VALUE; double yMax = -Double.MAX_VALUE; for (int i = 0; i < 4; i++) { xMin = Math.min(xMin, pts[2 * i]); yMin = Math.min(yMin, pts[2 * i + 1]); xMax = Math.max(xMax, pts[2 * i]); yMax = Math.max(yMax, pts[2 * i + 1]); } return new Envelope(xMin, xMax, yMin, yMax); }
public void setFontSize(float size) { // FONT_SIZE.basicSet(this, new Double(size)); Point2D.Double p = new Point2D.Double(0, size); AffineTransform tx = TRANSFORM.get(this); if (tx != null) { try { tx.inverseTransform(p, p); Point2D.Double p0 = new Point2D.Double(0, 0); tx.inverseTransform(p0, p0); p.y -= p0.y; } catch (NoninvertibleTransformException ex) { ex.printStackTrace(); } } FONT_SIZE.set(this, Math.abs(p.y)); }
/** * Converts screen point to cartesian space. Takes into account inner tiles grid offset. * * @param aScreenPoint Point, expressed in centered screen coordinate space. E.g. center of the * control will have coordinates (0, 0). * @return Point in cartesian space. * @throws NoninvertibleTransformException */ public Point2D.Double screen2Cartesian(Point aScreenPoint) throws NoninvertibleTransformException { assert cartesian2Screen != null; Point2D.Double centeredScreenPt = new Point2D.Double(aScreenPoint.x + offset.x, aScreenPoint.y + offset.y); Point2D.Double cartesianPt = new Point2D.Double(); return (Point2D.Double) cartesian2Screen.inverseTransform(centeredScreenPt, cartesianPt); }
/** * Función de pintado del canvas. Pintamos un marco a la imagen para saber donde la movemos. * * <p>Para dibujar el marco alrededor del raster hacemos lo mismo que para pintar el raster * rotado. En realidad dibujamos un cuadrado y luego le aplicamos las transformaciones necesarias * para que se vea con la misma forma del raster al que representa. */ public void paintComponent(Graphics g) { if (isMoveable && lyr != null && ptoFin != null && ptoIni != null) { try { ViewPort vp = grBehavior.getMapControl().getMapContext().getViewPort(); AffineTransform at = (AffineTransform) lyr.getAffineTransform().clone(); at.preConcatenate(vp.getAffineTransform()); Extent ext = lyr.getFullRasterExtent(); Point2D pt = new Point2D.Double(ext.getULX(), ext.getULY()); vp.getAffineTransform().transform(pt, pt); at.inverseTransform(pt, pt); Point2D size = new Point2D.Double(ext.getLRX(), ext.getLRY()); vp.getAffineTransform().transform(size, size); at.inverseTransform(size, size); double distX = ptoFin.getX() - ptoIni.getX(); double distY = ptoFin.getY() - ptoIni.getY(); Point2D d = new Point2D.Double(ext.getULX() + distX, ext.getULY() + distY); vp.getAffineTransform().transform(d, d); at.inverseTransform(d, d); // Giramos el graphics se dibuja y se vuelve a dejar como estaba ((Graphics2D) g).transform(at); g.setColor(rectangleColor); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f); ((Graphics2D) g).setComposite(alpha); g.fillRect( (int) pt.getX() + (int) d.getX(), (int) pt.getY() + (int) d.getY(), (int) size.getX(), (int) size.getY()); ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g.drawRect( (int) pt.getX() + (int) d.getX(), (int) pt.getY() + (int) d.getY(), (int) size.getX(), (int) size.getY()); ((Graphics2D) g).transform(at.createInverse()); } catch (NoninvertibleTransformException e1) { RasterToolsUtil.messageBoxError("error_transformacion1", this, e1); } } }
private Point2D getTranslatedPoint(double x, double y, AffineTransform matrix) { Point2D point2d = new Point2D.Double(x, y); try { return matrix.inverseTransform(point2d, null); } catch (NoninvertibleTransformException ex) { ex.printStackTrace(); return point2d; } }
/** * Converts screen point to cartesian space. Takes into account inner tiles grid offset. * * @param aScreenPoint Point, expressed in AWT events coordinate space. E.g. center of the control * will have coordinates (size.width/2, size.height/2). * @return Point in cartesian space. * @throws NoninvertibleTransformException */ public Point2D.Double awtScreen2Cartesian(Point aScreenPoint) throws NoninvertibleTransformException { assert cartesian2Screen != null; Dimension size = getSize(); Point2D.Double centeredScreenPt = new Point2D.Double( aScreenPoint.x - size.width / 2 + offset.x, aScreenPoint.y - size.height / 2 + offset.y); Point2D.Double cartesianPt = new Point2D.Double(); return (Point2D.Double) cartesian2Screen.inverseTransform(centeredScreenPt, cartesianPt); }
public Point2D componentToImage(Point2D p) { Point2D tp = null; try { tp = t.inverseTransform(p, null); } catch (NoninvertibleTransformException ex) { // can't happen. } return tp; }
@Override public void mouseClicked(MouseEvent e) { if (Globals.editMode == Constants.EditMode.NONE) { return; } Point2D.Double clickPoint = new Point2D.Double(); try { affineTransform.inverseTransform(e.getPoint(), clickPoint); } catch (Exception ex) { } }
public ViewPort getTileViewPort(ViewPort viewPort, int tileNr) throws NoninvertibleTransformException { /* * if(viewPortList == null) this.calcViewPort(viewPort); return * viewPortList[tileNr]; */ if (tile.length == 1) return viewPort; double[] dstPts = new double[8]; double[] srcPts = getTilePts(tileNr); Rectangle tile = getTile(tileNr); // Rectangle newRect = new Rectangle((int)srcPts[0], (int)srcPts[1], // tileSz[0], tileSz[1]); mat.inverseTransform(srcPts, 0, dstPts, 0, 4); double x = dstPts[0], w = dstPts[2] - dstPts[0]; double y = dstPts[1], h = dstPts[5] - dstPts[3]; if (w < 0) { x = dstPts[2]; w = dstPts[0] - dstPts[2]; } if (h < 0) { y = dstPts[5]; h = dstPts[3] - dstPts[5]; } Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(x, y, w, h); // Extent extent = new Extent(rectCuadricula); ViewPort vp = viewPort.cloneViewPort(); vp.setImageSize(tile.getSize()); // vp.setOffset(tile.getLocation()); vp.setExtent(rectCuadricula); vp.setAffineTransform(mat); if (debug) System.out.println( "Tiling.print(): tile " + tileNr + " de " + getNumTiles() + "\n, Extent = " + vp.getAdjustedExtent() + " tile: " + tile); return vp; }
@Test public void testTransform() throws Exception { MathTransform t = CRS.findMathTransform(CRS.decode("EPSG:3005"), DefaultGeographicCRS.WGS84); // $NON-NLS-1$ AffineTransform translateInstance = AffineTransform.getTranslateInstance(180, 90); EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, translateInstance, t); int x = -12 + 180; int y = 52 + 90; map.addPoint(x, y, map.getGeoms().get(0).getShell()); double[] tmp = new double[] {x + .5, y + .5}; double[] expected = new double[2]; translateInstance.inverseTransform(tmp, 0, tmp, 0, 1); t.inverse().transform(tmp, 0, expected, 0, 1); assertEquals(new Coordinate(expected[0], expected[1]), map.getCoords(x, y).get(0)); }
/** * Converts a coordinate expressed on the device space back to real world coordinates. Stolen from * LiteRenderer but without the need of a Graphics object * * @param x horizontal coordinate on device space * @param y vertical coordinate on device space * @param map The map extent * @param width image width * @param height image height * @return The correspondent real world coordinate * @throws RuntimeException */ public static Coordinate pixelToWorld( double x, double y, ReferencedEnvelope map, double width, double height) { // set up the affine transform and calculate scale values AffineTransform at = worldToScreenTransform(map, width, height); Point2D result = null; try { result = at.inverseTransform( new java.awt.geom.Point2D.Double(x, y), new java.awt.geom.Point2D.Double()); } catch (NoninvertibleTransformException e) { throw new RuntimeException(e); } Coordinate c = new Coordinate(result.getX(), result.getY()); return c; }
@Override public void mouseDragged(MouseEvent e) { if (javax.swing.SwingUtilities.isRightMouseButton(e)) { transX += (double) (e.getX() - preMousePoint.getX()) / scale; transY += (double) (e.getY() - preMousePoint.getY()) / scale; preMousePoint = e.getPoint(); updateAffineTransform(); repaint(); } else if (javax.swing.SwingUtilities.isLeftMouseButton(e)) { rotateAngle += ((double) e.getX() - preMousePoint.getX()) / 100.0; preMousePoint = e.getPoint(); updateAffineTransform(); repaint(); } // Gets the value of the current logical coordinates of the mouse try { affineTransform.inverseTransform(e.getPoint(), currentMousePointLogic); } catch (Exception ex) { } }