/** * Get the x coordinate of the ROI centroid; * <p> * Warning: If the centroid computation was too difficult (i.e. the area is particularly elaborate), * then the center of the bounding box will be used instead! (However this should not be relied upon as it is liable to change in later versions) */ @Override public double getCentroidX() { if (stats == null) calculateShapeMeasurements(); double centroidX = stats.getCentroidX(); if (Double.isNaN(centroidX)) return getBoundsX() + .5 * getBoundsWidth(); else return centroidX; }
/** * Get the y coordinate of the ROI centroid; * <p> * Warning: If the centroid computation was too difficult (i.e. the area is particularly elaborate), * then the center of the bounding box will be used instead! (However this should not be relied upon as it is liable to change in later versions) */ @Override public double getCentroidY() { if (stats == null) calculateShapeMeasurements(); double centroidY = stats.getCentroidY(); if (Double.isNaN(centroidY)) return getBoundsY() + .5 * getBoundsHeight(); else return centroidY; }
public AWTAreaROI(AreaROI roi) { super(roi.vertices, roi.getC(), roi.getZ(), roi.getT()); shape = new Path2D.Float(); for (Vertices vertices : vertices) { if (vertices.isEmpty()) continue; shape.moveTo(vertices.getX(0), vertices.getY(0)); for (int i = 1; i < vertices.size(); i++) { shape.lineTo(vertices.getX(i), vertices.getY(i)); } shape.closePath(); } }
private Object readResolve() { AreaROI roi = new AreaROI(x, y, c, z, t); roi.stats = this.stats; return roi; }
@Override public double getBoundsWidth() { if (stats == null) calculateShapeMeasurements(); return stats.getBoundsWidth(); }
@Override public double getScaledArea(double pixelWidth, double pixelHeight) { if (GeneralTools.almostTheSame(pixelWidth, pixelHeight, 0.0001)) return getArea() * pixelWidth * pixelHeight; // TODO: Need to confirm this is not a performance bottleneck in practice (speed vs. memory issue) return new ClosedShapeStatistics(vertices, pixelWidth, pixelHeight).getArea(); }
private Object writeReplace() { AreaROI roi = new AreaROI(getVertices(shape), c, z, t); return roi; }
@Override public double getBoundsHeight() { if (stats == null) calculateShapeMeasurements(); return stats.getBoundsHeight(); }
@Override public TranslatableROI translate(double dx, double dy) { // Shift the bounds if (dx == 0 && dy == 0) return this; // Create shifted vertices float[][] xx = new float[vertices.size()][]; float[][] yy = new float[vertices.size()][]; int idx = 0; for (MutableVertices v : vertices) { // Shift the region float[] x = v.getX(null); float[] y = v.getY(null); for (int i = 0; i < x.length; i++) { x[i] = (float)(x[i] + dx); y[i] = (float)(y[i] + dy); } xx[idx] = x; yy[idx] = y; idx++; } return new AreaROI(xx, yy, getC(), getZ(), getT()); }
@Override public double getBoundsX() { if (stats == null) calculateShapeMeasurements(); return stats.getBoundsX(); }
@Override public double getArea() { if (stats == null) calculateShapeMeasurements(); return stats.getArea(); }
@Override public double getPerimeter() { if (stats == null) calculateShapeMeasurements(); return stats.getPerimeter(); }
@Override public double getBoundsY() { if (stats == null) calculateShapeMeasurements(); return stats.getBoundsY(); }
/** * Get the number of vertices used to represent this area. There is some 'fuzziness' to the meaning of this, since * curved regions will be flattened and the same complex areas may be represented in different ways - nevertheless * it provides some measure of the 'complexity' of the area. * @return */ public int nVertices() { if (stats == null) calculateShapeMeasurements(); return stats.getNVertices(); }