/** Paint only if area is not the target_area. */ private final void paint(final Graphics2D g, final AffineTransform aff, final boolean fill) { if (area == target_area) return; if (null != area) { synchronized (arealock) { if (null == area) return; if (fill) g.fill(area.createTransformedArea(aff)); else g.draw(area.createTransformedArea(aff)); // won't be perfect except on mouse release } } }
area.transform(transform); } else { shape = area.createTransformedArea(transform);
Area area = new Area(myShape); //myShape is the shape I want to scale AffineTransform at = new AffineTransform(); at.scale(2,2); area = area.createTransformedArea(at); graphics2d.draw(area); //graphics2d is the Graphics2D instance to do the drawing
public void paint(final Graphics2D g, final AffineTransform aff, final boolean fill, final Color color) { g.setColor(color); if (!area.isEmpty()) { if (fill) g.fill(area.createTransformedArea(aff)); else g.draw(area.createTransformedArea(aff)); } if (null != this.painter) { try { this.painter.paint(g, aff, fill); } catch (Exception e) {} } }
/** In world coordinates, a copy of the area at {@code layer}. May be null. */ @Override public Area getAreaAt(final Layer layer) { final Area a = getArea(layer); if (null == a) return null; return a.createTransformedArea(this.at); }
@Override public Rectangle getBounds() { return boundArea.createTransformedArea(transform).getBounds(); }
/** Expects Area in world coords. * @return The first {@link Node} that intersects the {@code area} at the given {@code layer}, or null if none do. */ public Node<T> firstIntersectingNode(final Layer layer, final Area area) { final Set<Node<T>> nodes = node_layer_map.get(layer); if (null == nodes || nodes.isEmpty()) return null; try { return findFirstIntersectingNode(nodes, area.createTransformedArea(this.at.createInverse())); } catch (final NoninvertibleTransformException e) { IJError.print(e); } return null; }
/** Expects Rectangle in world coords. */ @Override public boolean intersects(final Layer layer, final Rectangle r) { final Set<Node<T>> nodes = node_layer_map.get(layer); if (null == nodes || nodes.isEmpty()) return false; try { return null != findFirstIntersectingNode(nodes, new Area(r).createTransformedArea(this.at.createInverse())); } catch (final NoninvertibleTransformException e) { IJError.print(e); } return false; } /** Expects Area in world coords. */
/** Returns a new Rectangle which encloses completly the given rectangle after transforming it with this Displayable's AffineTransform. The given rectangle's fields are untouched.*/ final public Rectangle transformRectangle(final Rectangle r) { if (this.at.isIdentity()) return (Rectangle)r.clone(); return new Area(r).createTransformedArea(this.at).getBounds(); }
private void calculateShape() { // terrible hack to avoid OOM when cx = 0 & cy = 0 if( cx == 0f ) cx = 0.0001f; if( cy == 0f ) cy = 0.0001f; Area l = createArm(); l.add(createArm().createTransformedArea(AffineTransform.getRotateInstance(Math.toRadians( 90 ), cx, cy))); l.add(createArm().createTransformedArea(AffineTransform.getRotateInstance(Math.toRadians( 180 ), cx, cy))); l.add(createArm().createTransformedArea(AffineTransform.getRotateInstance(Math.toRadians( 270 ), cx, cy))); lauburu = ShapeUtils.rotate( l, angle, cx, cy ); }
@Override public boolean intersects(final Layer layer, final Rectangle r) { Object ob = ht_areas.get(layer.getId()); if (null == ob) return false; if (AreaList.UNLOADED == ob) { ob = loadLayer(layer.getId()); if (null == ob) return false; } final Area a = ((Area)ob).createTransformedArea(this.at); return a.intersects(r.x, r.y, r.width, r.height); }
/** Add the given area, in world coords, to the alpha mask, using the given fill value. */ public void addAlphaMask(final Area aw, final int value) { try { addAlphaMaskLocal(aw.createTransformedArea(Patch.this.at.createInverse()), value); } catch (final NoninvertibleTransformException nite) { IJError.print(nite); } }
static public Area makeMouseBrush(int diameter, double mag) { Display front = Display.getFront(); Area brush = makeBrush(diameter, mag); if (null == front) return brush; Point p = front.getCanvas().getCursorLoc(); return brush.createTransformedArea(new AffineTransform(1, 0, 0, 1, p.x, p.y)); }
@Override public Collection<Displayable> findLinkTargets(final AffineTransform aff) { if (null == aw) return super.findLinkTargets(aff); Area a = aw.getArea(); if (!aff.isIdentity()) { a = a.createTransformedArea(aff); } return this.la.getDisplayables(Patch.class, a, true); }
/** Returns a copy whose roi and ct are local to the affine transform of @param d. */ public VectorDataTransform makeLocalTo(final Displayable d) throws Exception { final VectorDataTransform local = new VectorDataTransform(this.layer); final AffineTransform inverse = d.at.createInverse(); for (final ROITransform rt : transforms) { local.add(rt.roi.createTransformedArea(inverse), M.wrap(d.at, rt.ct, inverse)); } return local; } }
/** Subtract an area in world coordinates. */ public void subtract(final Area wa, final Layer layer) { try { this.area.subtract(wa.createTransformedArea(source.getAffineTransform().createInverse())); ((AreaContainer)source).calculateBoundingBox(layer); } catch (NoninvertibleTransformException nite) { IJError.print(nite); } }
/** Add an area in world coordinates. */ public void add(final Area wa, final Layer layer) { try { this.area.add(wa.createTransformedArea(source.getAffineTransform().createInverse())); ((AreaContainer)source).calculateBoundingBox(layer); } catch (NoninvertibleTransformException nite) { IJError.print(nite); } }
/** Add an area that needs to be transformed by tmp first to bring it to world coordinates; * will MODIFY the to_world AffineTransform object. */ public void add(final Area a, final AffineTransform to_world) { try { to_world.preConcatenate(source.getAffineTransform().createInverse()); this.area.add(a.createTransformedArea(to_world)); } catch (NoninvertibleTransformException nite) { IJError.print(nite); } }
@Override public boolean apply(final Layer la, final Area roi, final mpicbg.models.CoordinateTransform ct) throws Exception { final Area a = getArea(la); if (null == a) return true; final AffineTransform inverse = this.at.createInverse(); if (M.intersects(a, roi.createTransformedArea(inverse))) { M.apply(M.wrap(this.at, ct, inverse), roi, a); calculateBoundingBox(la); } return true; }
/** Subtracts the given ROI, which is expected in world/LayerSet coordinates, to the area present at Layer with id layer_id, or set it if none present yet. */ public void subtract(final long layer_id, final ShapeRoi roi) throws NoninvertibleTransformException { if (null == roi) return; final Area a = getArea(layer_id); if (null == a) return; a.subtract(M.getArea(roi).createTransformedArea(this.at.createInverse())); calculateBoundingBox(null != layer_set ? layer_set.getLayer(layer_id) : null); updateInDatabase("points=" + layer_id); }