@Override public double realMax(final int d) { if (d != 0 && d != 1) throw new IllegalArgumentException( "Invalid dimension " + d); // NB: bounding box doesn't update after vertex removed final float[] c = d == 0 ? poly.getFloatPolygon().xpoints : poly .getFloatPolygon().ypoints; double max = Double.NEGATIVE_INFINITY; for (int i = 0; i < numVertices(); i++) if (c[i] > max) max = c[i]; return max; }
@Override public double realMin(final int d) { if (d != 0 && d != 1) throw new IllegalArgumentException( "Invalid dimension " + d); // NB: bounding box doesn't update after vertex removed final float[] c = d == 0 ? poly.getFloatPolygon().xpoints : poly .getFloatPolygon().ypoints; double min = Double.POSITIVE_INFINITY; for (int i = 0; i < numVertices(); i++) if (c[i] < min) min = c[i]; return min; }
@Override public RealLocalizable vertex(final int pos) { final FloatPolygon fp = getRoi().getFloatPolygon(); return new AbstractRealLocalizable(new double[] { fp.xpoints[pos], fp.ypoints[pos] }) {}; }
@Override public RealLocalizable vertex(final int pos) { final FloatPolygon fp = getRoi().getFloatPolygon(); return new AbstractRealLocalizable(new double[] { fp.xpoints[pos], fp.ypoints[pos] }) {}; }
public FloatPolygon getInterpolatedPolygon(double interval, boolean smooth) { FloatPolygon p = getFloatPolygon(); if (smooth && (type==TRACED_ROI || type==FREEROI || type==FREELINE)) { for (int i=1; i<p.npoints-2; i++) { p.xpoints[i] = (p.xpoints[i-1]+p.xpoints[i]+p.xpoints[i+1])/3f; p.ypoints[i] = (p.ypoints[i-1]+p.ypoints[i]+p.ypoints[i+1])/3f; } if (type!=FREELINE) { p.xpoints[0] = (p.xpoints[p.npoints-1]+p.xpoints[0]+p.xpoints[1])/3f; p.ypoints[0] = (p.ypoints[p.npoints-1]+p.ypoints[0]+p.ypoints[1])/3f; p.xpoints[p.npoints-1] = (p.xpoints[p.npoints-2]+p.xpoints[p.npoints-1]+p.xpoints[0])/3f; p.ypoints[p.npoints-1] = (p.ypoints[p.npoints-2]+p.ypoints[p.npoints-1]+p.ypoints[0])/3f; } } return super.getInterpolatedPolygon(p, interval, smooth); }
public FloatPolygon getInterpolatedPolygon(double interval, boolean smooth) { FloatPolygon p = getFloatPolygon(); if (smooth && (type==TRACED_ROI || type==FREEROI || type==FREELINE)) { for (int i=1; i<p.npoints-2; i++) { p.xpoints[i] = (p.xpoints[i-1]+p.xpoints[i]+p.xpoints[i+1])/3f; p.ypoints[i] = (p.ypoints[i-1]+p.ypoints[i]+p.ypoints[i+1])/3f; } if (type!=FREELINE) { p.xpoints[0] = (p.xpoints[p.npoints-1]+p.xpoints[0]+p.xpoints[1])/3f; p.ypoints[0] = (p.ypoints[p.npoints-1]+p.ypoints[0]+p.ypoints[1])/3f; p.xpoints[p.npoints-1] = (p.xpoints[p.npoints-2]+p.xpoints[p.npoints-1]+p.xpoints[0])/3f; p.ypoints[p.npoints-1] = (p.ypoints[p.npoints-2]+p.ypoints[p.npoints-1]+p.ypoints[0])/3f; } } return super.getInterpolatedPolygon(p, interval, smooth); }
@Override public RealLocalizableRealPositionable vertex(final int pos) { final FloatPolygon fp = getRoi().getFloatPolygon(); return Rois.ijRoiPoint(fp.xpoints[pos], fp.ypoints[pos]); }
@Override public RealLocalizableRealPositionable vertex(final int pos) { final FloatPolygon fp = getRoi().getFloatPolygon(); return Rois.ijRoiPoint(fp.xpoints[pos], fp.ypoints[pos]); }
@Override public boolean test(final RealLocalizable t) { if (Intervals.contains(this, t)) { final float[] x = getRoi().getFloatPolygon().xpoints; final float[] y = getRoi().getFloatPolygon().ypoints; for (int i = 1; i < numVertices(); i++) { final double[] start = new double[] { x[i - 1], y[i - 1] }; final double[] end = new double[] { x[i], y[i] }; final boolean testLineContains = GeomMaths.lineContains(start, end, t, 2); if (testLineContains) return true; } } return false; }
@Override public boolean test(final RealLocalizable t) { if (Intervals.contains(this, t)) { final float[] x = getRoi().getFloatPolygon().xpoints; final float[] y = getRoi().getFloatPolygon().ypoints; for (int i = 1; i < numVertices(); i++) { final double[] start = new double[] { x[i - 1], y[i - 1] }; final double[] end = new double[] { x[i], y[i] }; final boolean testLineContains = GeomMaths.lineContains(start, end, t, 2); if (testLineContains) return true; } } return false; }
/** * If the wrapped {@link PolygonRoi} is not associated with an * {@link ImagePlus}, then this method will always throw an * {@code UnsupportedOperationException}. Otherwise, the vertex will be * removed provided the index is valid. */ @Override public void removeVertex(final int index) { if (getRoi().getImage() != null) { final double x = getRoi().getFloatPolygon().xpoints[index]; final double y = getRoi().getFloatPolygon().ypoints[index]; getRoi().deleteHandle(x, y); } else throw new UnsupportedOperationException("removeVertex"); }
private Overlay createAngleOverlay(final Roi roi) { assert roi instanceof PolygonRoi; final PolygonRoi pRoi = (PolygonRoi) roi; final FloatPolygon poly = pRoi.getFloatPolygon(); final double[] end1 = new double[] { poly.xpoints[0], poly.ypoints[0] }; final double[] ctr = new double[] { poly.xpoints[1], poly.ypoints[1] }; final double[] end2 = new double[] { poly.xpoints[2], poly.ypoints[2] }; final AngleOverlay angleOverlay = new AngleOverlay(getContext(), ctr, end1, end2); assignPropertiesToOverlay(angleOverlay, roi); return angleOverlay; }
/** * {@inheritDoc} * <p> * This includes some additional points near the vertices of the polyline. * </p> */ @Override public boolean test(final RealLocalizable t) { final float[] x = roi.getFloatPolygon().xpoints; final float[] y = roi.getFloatPolygon().ypoints; final double xt = t.getDoublePosition(0); final double yt = t.getDoublePosition(1); for (int i = 1; i < getRoi().getNCoordinates(); i++) { if (lineContains(x[i - 1], y[i - 1], x[i], y[i], xt, yt, roi .getStrokeWidth())) return true; } return false; }
/** * If the wrapped {@link PolygonRoi} is not associated with an * {@link ImagePlus}, then this method will always throw an * {@code UnsupportedOperationException}. Otherwise, the vertex will be * removed provided the index is valid. */ @Override public void removeVertex(final int index) { if (getRoi().getImage() != null) { final double x = getRoi().getFloatPolygon().xpoints[index]; final double y = getRoi().getFloatPolygon().ypoints[index]; getRoi().deleteHandle(x, y); } else Rois.unsupported("removeVertex"); }
public FloatPolygon getNonSplineFloatPolygon() { if (xpf!=null) { FloatPolygon p = (new FloatPolygon(xpf, ypf, nPoints)).duplicate(); float xbase = (float)getXBase(); float ybase = (float)getYBase(); for (int i=0; i<p.npoints; i++) { p.xpoints[i] += xbase; p.ypoints[i] += ybase; } return p; } else return getFloatPolygon(); }
public FloatPolygon getNonSplineFloatPolygon() { if (xpf!=null) { FloatPolygon p = (new FloatPolygon(xpf, ypf, nPoints)).duplicate(); float xbase = (float)getXBase(); float ybase = (float)getYBase(); for (int i=0; i<p.npoints; i++) { p.xpoints[i] += xbase; p.ypoints[i] += ybase; } return p; } else return getFloatPolygon(); }
public void deleteHandle(double ox, double oy) { if (imp==null) return; if (nPoints<=1) { imp.deleteRoi(); return; } boolean splineFit = xSpline!=null; if (splineFit) removeSplineFit(); FloatPolygon points = getFloatPolygon(); int pointToDelete = getClosestPoint(ox, oy, points); if (pointToDelete>=0) { deletePoint(pointToDelete); if (splineFit) fitSpline(splinePoints); imp.draw(); } }
public void mouseMoved(MouseEvent e) { int x = canvas.offScreenX(e.getX()); int y = canvas.offScreenY(e.getY()); original.setSlice(y + 1); PolygonRoi roi = rois[y]; if (roi == null) { original.setOverlay(null); original.killRoi(); return; } FloatPolygon polygon = roi.getFloatPolygon(); if (polygon.npoints <= x) return; int x2 = (int)polygon.xpoints[x]; int y2 = (int)polygon.ypoints[x]; original.setOverlay(new Overlay(new PointRoi(x2, y2))); original.setRoi(roi); }
private PolygonOverlay createPolygonOverlay(final Roi roi) { assert roi instanceof PolygonRoi; final PolygonRoi polygonRoi = (PolygonRoi) roi; final PolygonOverlay overlay = new PolygonOverlay(getContext()); final PolygonRegionOfInterest region = overlay.getRegionOfInterest(); final FloatPolygon poly = polygonRoi.getFloatPolygon(); final float[] xCoords = poly.xpoints; final float[] yCoords = poly.ypoints; for (int i = 0; i < xCoords.length; i++) { final double x = xCoords[i]; final double y = yCoords[i]; region.addVertex(i, new RealPoint(x, y)); } assignPropertiesToOverlay(overlay, roi); return overlay; }
public void deleteHandle(double ox, double oy) { if (imp==null) return; if (nPoints<=1) { imp.deleteRoi(); return; } boolean splineFit = xSpline!=null; if (splineFit) removeSplineFit(); FloatPolygon points = getFloatPolygon(); int pointToDelete = getClosestPoint(ox, oy, points); if (pointToDelete>=0) { deletePoint(pointToDelete); if (splineFit) fitSpline(splinePoints); imp.draw(); } }