/** * Modify the GeometricLayer so the layer coordinate system matches the image coordinate system ("pixel" projection). */ public static GeometryImage createImageProjected(GeometryImage layer, AffineTransform geoTransform) { for(Geometry geom:layer.geoms){ for(Coordinate pos:geom.getCoordinates()){ Point2D.Double temp=new Point2D.Double(); try { geoTransform.inverseTransform(new Point2D.Double(pos.x, pos.y),temp); } catch (NoninvertibleTransformException e) { e.printStackTrace(); } pos.x=temp.x; pos.y=temp.y; } } return layer; }
/** * !!! not used currently, but might be by getPixelbounds? */ public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) { if (renderFRC == null) { renderFRC = frc; } // it is a total pain that you have to copy the transform. AffineTransform at = renderFRC.getTransform(); at.transform(loc, loc); pxResult.x = (int)loc.getX(); // but must not behave oddly around zero pxResult.y = (int)loc.getY(); loc.setLocation(pxResult.x, pxResult.y); try { at.inverseTransform(loc, loc); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("must be able to invert frc transform"); } }
/** * Change the dtx for the strike refs we use. Keeps a reference to the at. At * must not contain translation. * Called by setRenderTransform, setDTX, initFontData. */ private final void resetDTX(AffineTransform at) { fsref = null; dtx = at; invdtx = null; if (!dtx.isIdentity()) { try { invdtx = dtx.createInverse(); } catch (NoninvertibleTransformException e) { // we needn't care for rendering } } if (gti != null) { gti.strikesRef = null; } }
private static AffineTransform extractRotation(Point2D.Double pt, AffineTransform tx, boolean andTranslation) { tx.deltaTransform(pt, pt); AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y); try { AffineTransform rtxi = rtx.createInverse(); double dx = tx.getTranslateX(); double dy = tx.getTranslateY(); tx.preConcatenate(rtxi); if (andTranslation) { if (dx != 0 || dy != 0) { tx.setTransform(tx.getScaleX(), tx.getShearY(), tx.getShearX(), tx.getScaleY(), 0, 0); rtx.setTransform(rtx.getScaleX(), rtx.getShearY(), rtx.getShearX(), rtx.getScaleY(), dx, dy); } } } catch (NoninvertibleTransformException e) { return null; } return rtx; }
private void computeAffineTransforms() { if (natoceni == 0) { tam = null; zpet = null; return; } final AffineTransform tra = new AffineTransform(); final double widthPul = (double) dim.width / 2; final double heightPul = (double) dim.height / 2; tra.translate(widthPul, heightPul); tra.rotate(natoceni); tra.translate(-widthPul, -heightPul); tam = tra; try { zpet = tam.createInverse(); } catch (final NoninvertibleTransformException e) { throw new RuntimeException(e); } }
@Override protected void updateLayout() { super.updateLayout(); // Set the bounding node to match exactly the size of the viewport. AffineTransform transform = getWorldTransformStrategy().getTransform(); AffineTransform inverseTransform; try { inverseTransform = transform.createInverse(); } catch ( NoninvertibleTransformException e ) { System.err.println( getClass().getName() + " - Error: Unable to invert transform." ); e.printStackTrace(); inverseTransform = new AffineTransform(); // Unity transform by default. } Shape tranformedBounds = inverseTransform.createTransformedShape( getBounds() ); _probeDragBounds.setPathTo( tranformedBounds ); }
private void setAmplitude( Point mousePoint ) { double localY = 0; try { AffineTransform transform = getNetTransform(); transform.inverseTransform( mousePoint, _somePoint /* output */ ); localY = _somePoint.getY(); } catch ( NoninvertibleTransformException e ) { e.printStackTrace(); } localY = -localY; // +Y is up double amplitude = MAX_AMPLITUDE * ( localY / ( _maxSize.height / 2.0 ) ); amplitude = MathUtil.clamp( -MAX_AMPLITUDE, amplitude, +MAX_AMPLITUDE ); _harmonic.setAmplitude( amplitude ); fireChangeEvent(); }
@Override void pick(Point2D point, boolean boundingBox, List<List<SVGElement>> retVec) throws SVGException { Point2D xPoint = new Point2D.Double(point.getX(), point.getY()); if (xform != null) { try { xform.inverseTransform(point, xPoint); } catch (NoninvertibleTransformException ex) { throw new SVGException(ex); } } for (SVGElement ele : children) { if (ele instanceof RenderableElement) { RenderableElement rendEle = (RenderableElement) ele; rendEle.pick(xPoint, boundingBox, retVec); } } }
/** * @param geometry * geometry to fill * @param viewport * viewport * @param graphics * graphics to draw into */ @SuppressWarnings("unchecked") public static void fill(final IGeometry geometry, final Viewport viewport, final double opacity) { if (geometry.isPolygon()) { try { Shape shape = viewport.toShape(geometry); if (shape != null) { glFillNearlySimpleShape(shape); } } catch (NoninvertibleTransformException e) { e.printStackTrace(); } } else { if (geometry.isMultiSurface()) { GM_Aggregate<IGeometry> aggregate = (GM_Aggregate<IGeometry>) geometry; for (IGeometry element : aggregate) { RenderGL11Util.fill(element, viewport, opacity); } } } }
public void transform(AffineTransform tx) { if (transform == null) transform = new AffineTransform(tx); else transform.concatenate(tx); if (clip != null) { try { AffineTransform clipTransform = tx.createInverse(); updateClip(clipTransform); } catch (NoninvertibleTransformException ex) { // TODO: How can we deal properly with this? ex.printStackTrace(); } } setTransformImpl(transform); }
protected void updateAffineTransform() { if (!hasServer()) return; transform.setToIdentity(); transform.translate(getWidth()*.5, getHeight()*.5); transform.scale(1.0/downsampleFactor, 1.0/downsampleFactor); transform.translate(-xCenter, -yCenter); if (rotation != 0) transform.rotate(rotation, xCenter, yCenter); transformInverse.setTransform(transform); try { transformInverse.invert(); } catch (NoninvertibleTransformException e) { e.printStackTrace(); } }
public void displayCercles() { // ProjectFrame projectFrame = // application.getMainFrame().newProjectFrame(); this.exampleGraphicFill_Fill_Polygon(); this.exampleGraphicFill_Stroke_Polygon(); this.exampleGraphicStroke_Stroke_Polygon(); this.exampleShadow(); this.exampleGraphicStroke_Line(); this.exampleGraphicFill_Line(); this.exampleTexture(); FileWriter fichier; try { fichier = new FileWriter("./src/main/resources/sld/GraphicMark.xml"); this.projectFrame.getSld().marshall(fichier); } catch (IOException e1) { e1.printStackTrace(); } try { this.projectFrame.getLayerViewPanel().getViewport().zoomToFullExtent(); } catch (NoninvertibleTransformException e) { e.printStackTrace(); } }
/** * Sets the transform of this node. * * @param newTransform the new transform of this node */ public void setTransform(AffineTransform newTransform) { fireGraphicsNodeChangeStarted(); this.transform = newTransform; if(transform.getDeterminant() != 0){ try{ inverseTransform = transform.createInverse(); }catch(NoninvertibleTransformException e){ // Should never happen. throw new Error( e.getMessage() ); } } else { // The transform is not invertible. Use the same // transform. inverseTransform = transform; } if (parent != null) parent.invalidateGeometryCache(); fireGraphicsNodeChangeCompleted(); }
@Override public final void addRoadNetworkTxtLayer(final String fileName) { int lastIndexOfSeparator = fileName.lastIndexOf(File.separatorChar); String populationName = fileName.substring(lastIndexOfSeparator + 1, fileName.lastIndexOf(".")); //$NON-NLS-1$ logger.info(populationName); Population<DefaultFeature> population = RoadNetworkTextfileReader.read(fileName, populationName, this.getDataSet(), true); logger.info(population.size()); if (population != null) { this.addFeatureCollection(population, population.getNom()); if (this.getLayers().size() == 1) { try { this.getLayerViewPanel().getViewport().zoom(population.envelope()); } catch (NoninvertibleTransformException e1) { e1.printStackTrace(); } } } }
@Override public void leftMouseButtonClicked(final MouseEvent e, final ProjectFrame frame) { try { DirectPosition p = frame.getLayerViewPanel().getViewport() .toModelDirectPosition(e.getPoint()); if (e.getClickCount() >= 2) { if (this.getPoints().size() >= 3) { this.getGeometryToolBar().createPolygon(this.getPoints()); this.getPoints().clear(); } } else { this.getPoints().add(p); } frame.getLayerViewPanel().superRepaint(); } catch (NoninvertibleTransformException e1) { e1.printStackTrace(); } }
/** * Set the current transform */ public void setTransform(AffineTransform tx) { // Transform clip into target space using the old transform. updateClip(transform); // Update the native transform. setTransformImpl(tx); // Transform the clip back into user space using the inverse new transform. try { updateClip(transform.createInverse()); } catch (NoninvertibleTransformException ex) { // TODO: How can we deal properly with this? ex.printStackTrace(); } if (clip != null) setClip(clip); }
/** * Zoom to the given coordinates with the given width and height. * * @param x * upper left corner X coordinate * @param y * upper left corner Y coordinate * @param widthOfNewView * widht of the new view * @param heightOfNewView * height of the new view * @throws NoninvertibleTransformException * throws an exception when the transformation fails */ public final void zoom(final int x, final int y, final double widthOfNewView, final double heightOfNewView) throws NoninvertibleTransformException { LayerViewPanel lvp = this.layerViewPanels.iterator().next(); double zoomFactor = Math.min(lvp.getWidth() / widthOfNewView, lvp.getHeight() / heightOfNewView); double realWidthOfNewView = lvp.getWidth() / zoomFactor; double realHeightOfNewView = lvp.getHeight() / zoomFactor; IEnvelope zoomEnvelope; try { zoomEnvelope = this.toModelEnvelope(x - Viewport.ZERO_POINT_FIVE * realWidthOfNewView, x + Viewport.ZERO_POINT_FIVE * realWidthOfNewView, y - Viewport.ZERO_POINT_FIVE * realHeightOfNewView, y + Viewport.ZERO_POINT_FIVE * realHeightOfNewView); } catch (NoninvertibleTransformException ex) { this.zoomToFullExtent(); return; } this.zoom(zoomEnvelope); }
/** * @param geometry * geometry to fill * @param viewport * viewport * @param graphics * graphics to draw into */ @SuppressWarnings("unchecked") public static void fill(final IGeometry geometry, final Viewport viewport, final Graphics2D graphics, double opacity) { if (geometry.isPolygon()) { try { Shape shape = viewport.toShape(geometry); if (shape != null) { graphics.fill(shape); } } catch (NoninvertibleTransformException e) { e.printStackTrace(); } } else { if (geometry.isMultiSurface()) { GM_Aggregate<IGeometry> aggregate = (GM_Aggregate<IGeometry>) geometry; for (IGeometry element : aggregate) { RenderUtil.fill(element, viewport, graphics, opacity); } } } }
public void setTransformTranslation(int x, int y) { try { // go back to initial values pix2geo.translate(-m_translationX, -m_translationY); // apply new translation to transform pix2geo.translate(-x, -y); // update reverse transform geo2pix = pix2geo.createInverse(); // keep new tranform values m_translationX = -x; m_translationY = -y; } catch (NoninvertibleTransformException ex) { logger.error(ex.getMessage(),ex); } }
public void draw(Graphics2D g){ Color originalColor = g.getColor(); g.setColor(Color.ORANGE); AffineTransform af = new AffineTransform(); af.translate(x, y); g.transform(af); g.fill(shape); try { g.transform(af.createInverse()); } catch (NoninvertibleTransformException e) { e.printStackTrace(); } g.setColor(originalColor); }
TexturePaintContext(ColorModel cm, AffineTransform xform, int bWidth, int bHeight, int maxw) { this.colorModel = getInternedColorModel(cm); this.bWidth = bWidth; this.bHeight = bHeight; this.maxWidth = maxw; try { xform = xform.createInverse(); } catch (NoninvertibleTransformException e) { xform.setToScale(0, 0); } this.incXAcross = mod(xform.getScaleX(), bWidth); this.incYAcross = mod(xform.getShearY(), bHeight); this.incXDown = mod(xform.getShearX(), bWidth); this.incYDown = mod(xform.getScaleY(), bHeight); this.xOrg = xform.getTranslateX(); this.yOrg = xform.getTranslateY(); this.colincx = (int) incXAcross; this.colincy = (int) incYAcross; this.colincxerr = fractAsInt(incXAcross); this.colincyerr = fractAsInt(incYAcross); this.rowincx = (int) incXDown; this.rowincy = (int) incYDown; this.rowincxerr = fractAsInt(incXDown); this.rowincyerr = fractAsInt(incYDown); }
public Shape untransformShape(Shape s) { if (s == null) { return null; } if (transformState > TRANSFORM_INT_TRANSLATE) { try { return transformShape(transform.createInverse(), s); } catch (NoninvertibleTransformException e) { return null; } } else { return transformShape(-transX, -transY, s); } }
public boolean pointToPath(Point2D pt, Point2D result) { result.setLocation(pt); if (tx != null) { try { tx.inverseTransform(pt, result); } catch (NoninvertibleTransformException ex) { } } return result.getX() > 0; }
private int getNativePointSize() { /* Make a copy of the glyphTX in which we will store the * font transform, inverting the devTx if necessary */ double[] mat = new double[4]; desc.glyphTx.getMatrix(mat); fontTx = new AffineTransform(mat); /* Now work backwards to get the font transform */ if (!desc.devTx.isIdentity() && desc.devTx.getType() != AffineTransform.TYPE_TRANSLATION) { try { invertDevTx = desc.devTx.createInverse(); fontTx.concatenate(invertDevTx); } catch (NoninvertibleTransformException e) { e.printStackTrace(); } } /* At this point the fontTx may be a simple +ve scale, or it * may be something more complex. */ Point2D.Float pt = new Point2D.Float(1f,1f); fontTx.deltaTransform(pt, pt); double ptSize = Math.abs(pt.y); int ttype = fontTx.getType(); if ((ttype & ~AffineTransform.TYPE_UNIFORM_SCALE) != 0 || fontTx.getScaleY() <= 0) { /* We need to create an inverse transform that doesn't * include the point size (strictly the uniform scale) */ fontTx.scale(1/ptSize, 1/ptSize); } else { fontTx = null; // no need } return (int)ptSize; }
public static void main(final String[] args) throws NoninvertibleTransformException { final BufferedImage bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB); final Graphics2D g = (Graphics2D) bi.getGraphics(); test(g); g.translate(2.0, 2.0); test(g); g.translate(-4.0, -4.0); test(g); g.scale(2.0, 2.0); test(g); g.scale(-4.0, -4.0); test(g); g.rotate(Math.toRadians(90)); test(g); g.rotate(Math.toRadians(90)); test(g); g.rotate(Math.toRadians(90)); test(g); g.rotate(Math.toRadians(90)); test(g); g.dispose(); if (!status) { throw new RuntimeException("Test failed"); } }