@Override public TranslatableROI translate(double dx, double dy) { if (dx == 0 && dy == 0) return this; // Shift the bounds return new EllipseROI(getBoundsX()+dx, getBoundsY()+dy, getBoundsWidth(), getBoundsHeight(), getC(), getZ(), getT()); }
@Override public boolean contains(double xx, double yy) { // See http://math.stackexchange.com/questions/76457/check-if-a-point-is-within-an-ellipse double dx = xx - getCentroidX(); double dy = yy - getCentroidY(); double rx = getBoundsWidth() * 0.5; double ry = getBoundsHeight() * 0.5; return (dx*dx/(rx*rx) + dy*dy/(ry*ry)) <= 1; }
@Override public double getScaledArea(double pixelWidth, double pixelHeight) { double a = getBoundsWidth() * pixelWidth * .5; double b = getBoundsHeight() * pixelHeight * .5; return Math.PI * a * b; }
@Override public ROI duplicate() { EllipseROI duplicate = new EllipseROI(); duplicate.x = x; duplicate.x2 = x2; duplicate.y= y; duplicate.y2 = y2; duplicate.c = c; duplicate.z = z; duplicate.t = t; return duplicate; }
@Override public double getScaledPerimeter(double pixelWidth, double pixelHeight) { if (isCircle(pixelWidth, pixelHeight)) return Math.PI * getBoundsWidth() * pixelWidth; // See circumference approximations at http://en.wikipedia.org/wiki/Ellipse#Circumference double a = getBoundsWidth() * pixelWidth * .5; double b = getBoundsHeight() * pixelHeight * .5; double h = (a - b)*(a - b) / ((a + b) * (a + b)); return Math.PI * (a + b) * (1 + 3 * h / (10 + Math.sqrt(4 - 3 * h))); }
@Override EllipseROI createROI(double x, double y, double width, double height, int c, int z, int t) { return new EllipseROI(x, y, width, height, c, z, t); }
public boolean isCircle(double pixelWidth, double pixelHeight) { return GeneralTools.almostTheSame(getBoundsWidth() * pixelWidth, getBoundsHeight() * pixelHeight, 0.00001); }
private Object readResolve() { EllipseROI roi = new EllipseROI(x, y, x2-x, y2-y, c, z, t); return roi; }
public TMACoreObject(double x, double y, double width, double height, boolean isMissing) { super(new EllipseROI(x, y, width, height, -1, 0, 0), null); this.isMissing = isMissing; }
/** * Get a PathShape from an Area. * This will try to return a PathRectangleROI or PathPolygonROI if possible, * or PathAreaROI if neither of the other classes can adequately represent the area. * * In the input shape is an Ellipse2D then an EllipseROI will be returned. * * @param area * @param c * @param z * @param t * @param flatness - can be used to prefer polygons, see Shape.getPathIterator(AffineTransform at, double flatness) * @return */ public static PathShape getShapeROI(Shape shape, int c, int z, int t, double flatness) { if (shape instanceof Rectangle2D) { Rectangle2D bounds = shape.getBounds2D(); return new RectangleROI(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), c, z, t); } if (shape instanceof Ellipse2D) { Rectangle2D bounds = shape.getBounds2D(); return new EllipseROI(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), c, z, t); } return getShapeROI(new Area(shape), c, z, t, flatness); }