public int numVertices() { return poly.getNCoordinates(); }
void doIrregularSetup(Roi roi) { n = ((PolygonRoi)roi).getNCoordinates(); int[] ix = ((PolygonRoi)roi).getXCoordinates(); int[] iy = ((PolygonRoi)roi).getYCoordinates();
void doIrregularSetup(Roi roi) { n = ((PolygonRoi)roi).getNCoordinates(); int[] ix = ((PolygonRoi)roi).getXCoordinates(); int[] iy = ((PolygonRoi)roi).getYCoordinates();
/** * {@inheritDoc} * <p> * Since {@link PolygonRoi#contains(int, int)} uses the "pnpoly" algorithm for * real space polygons, so does this implementation. Thus resulting in a * {@code Polygon2D} with {@link net.imglib2.roi.BoundaryType#UNSPECIFIED * unspecified} boundary behavior. * </p> */ @Override public boolean test(final RealLocalizable t) { final float[] xf = getRoi().getFloatPolygon().xpoints; final float[] yf = getRoi().getFloatPolygon().ypoints; final TDoubleArrayList x = new TDoubleArrayList(getRoi().getNCoordinates()); final TDoubleArrayList y = new TDoubleArrayList(getRoi().getNCoordinates()); for (int i = 0; i < getRoi().getNCoordinates(); i++) { x.add(xf[i]); y.add(yf[i]); } return GeomMaths.pnpoly(x, y, t); }
/** * {@inheritDoc} * <p> * Since {@link PolygonRoi#contains(int, int)} uses the "pnpoly" algorithm for * real space polygons, so does this implementation. Thus resulting in a * {@code Polygon2D} with {@link net.imglib2.roi.BoundaryType#UNSPECIFIED * unspecified} boundary behavior. * </p> */ @Override public boolean test(final RealLocalizable t) { final float[] xf = getRoi().getFloatPolygon().xpoints; final float[] yf = getRoi().getFloatPolygon().ypoints; final TDoubleArrayList x = new TDoubleArrayList(getRoi().getNCoordinates()); final TDoubleArrayList y = new TDoubleArrayList(getRoi().getNCoordinates()); for (int i = 0; i < getRoi().getNCoordinates(); i++) { x.add(xf[i]); y.add(yf[i]); } return GeomMaths.pnpoly(x, y, t); }
n = ((PolygonRoi) roi).getNCoordinates(); final int[] ix = ((PolygonRoi) roi).getXCoordinates(); final int[] iy = ((PolygonRoi) roi).getYCoordinates();
/** * {@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; }
int n = ((PolygonRoi)roi).getNCoordinates(); int[] cx = ((PolygonRoi)roi).getXCoordinates(); int[] cy = ((PolygonRoi)roi).getYCoordinates();
private void fillPolygon(ImageProcessor ip, Polygon p, boolean internContour) { PolygonRoi proi = new PolygonRoi(p, PolygonRoi.POLYGON); Rectangle r = proi.getBounds(); PolygonFiller pf = new PolygonFiller(); pf.setPolygon(proi.getXCoordinates(), proi.getYCoordinates(), proi.getNCoordinates()); ip.setRoi(r); ImageProcessor objectMask = pf.getMask(r.width, r.height); ip.fill(objectMask); if(!internContour){ ip.drawPolygon(p); } }
void fitSpline() { Roi roi = imp.getRoi(); if (roi==null) {noRoi("Spline"); return;} int type = roi.getType(); boolean segmentedSelection = type==Roi.POLYGON||type==Roi.POLYLINE; if (!(segmentedSelection||type==Roi.FREEROI||type==Roi.TRACED_ROI||type==Roi.FREELINE)) {IJ.error("Spline Fit", "Polygon or polyline selection required"); return;} if (roi instanceof EllipseRoi) return; PolygonRoi p = (PolygonRoi)roi; Undo.setup(Undo.ROI, imp); if (!segmentedSelection && p.getNCoordinates()>3) { if (p.subPixelResolution()) p = trimFloatPolygon(p, p.getUncalibratedLength()); else p = trimPolygon(p, p.getUncalibratedLength()); } String options = Macro.getOptions(); if (options!=null && options.indexOf("straighten")!=-1) p.fitSplineForStraightening(); else if (options!=null && options.indexOf("remove")!=-1) p.removeSplineFit(); else p.fitSpline(); imp.draw(); LineWidthAdjuster.update(); }
void fitSpline() { Roi roi = imp.getRoi(); if (roi==null) {noRoi("Spline"); return;} int type = roi.getType(); boolean segmentedSelection = type==Roi.POLYGON||type==Roi.POLYLINE; if (!(segmentedSelection||type==Roi.FREEROI||type==Roi.TRACED_ROI||type==Roi.FREELINE)) {IJ.error("Spline Fit", "Polygon or polyline selection required"); return;} if (roi instanceof EllipseRoi) return; PolygonRoi p = (PolygonRoi)roi; Undo.setup(Undo.ROI, imp); if (!segmentedSelection && p.getNCoordinates()>3) { if (p.subPixelResolution()) p = trimFloatPolygon(p, p.getUncalibratedLength()); else p = trimPolygon(p, p.getUncalibratedLength()); } String options = Macro.getOptions(); if (options!=null && options.indexOf("straighten")!=-1) p.fitSplineForStraightening(); else if (options!=null && options.indexOf("remove")!=-1) p.removeSplineFit(); else p.fitSpline(); imp.draw(); LineWidthAdjuster.update(); }
@Override final protected void setHandles() { final Roi currentRoi = imp.getRoi(); int[] x; int[] y; if (currentRoi instanceof PolygonRoi && ((PolygonRoi)currentRoi).getNCoordinates() == 4 ) { x = currentRoi.getPolygon().xpoints; y = currentRoi.getPolygon().ypoints; } else { x = new int[]{ imp.getWidth() / 4, 3 * imp.getWidth() / 4, 3 * imp.getWidth() / 4, imp.getWidth() / 4 }; y = new int[]{ imp.getHeight() / 4, imp.getHeight() / 4, 3 * imp.getHeight() / 4, 3 * imp.getHeight() / 4 }; } p = new Point[]{ new Point( new double[]{ x[ 0 ], y[ 0 ] } ), new Point( new double[]{ x[ 1 ], y[ 1 ] } ), new Point( new double[]{ x[ 2 ], y[ 2 ] } ), new Point( new double[]{ x[ 3 ], y[ 3 ] } ) }; q = new Point[]{ p[ 0 ].clone(), p[ 1 ].clone(), p[ 2 ].clone(), p[ 3 ].clone() }; m.add( new PointMatch( p[ 0 ], q[ 0 ] ) ); m.add( new PointMatch( p[ 1 ], q[ 1 ] ) ); m.add( new PointMatch( p[ 2 ], q[ 2 ] ) ); m.add( new PointMatch( p[ 3 ], q[ 3 ] ) ); handles = new PointRoi( x, y, 4 ); imp.setRoi( handles ); }
@Override final protected void setHandles() { final Roi currentRoi = imp.getRoi(); int[] x; int[] y; if (currentRoi instanceof PolygonRoi && ((PolygonRoi)currentRoi).getNCoordinates() == 4 ) { x = currentRoi.getPolygon().xpoints; y = currentRoi.getPolygon().ypoints; } else { x = new int[]{ imp.getWidth() / 4, 3 * imp.getWidth() / 4, 3 * imp.getWidth() / 4, imp.getWidth() / 4 }; y = new int[]{ imp.getHeight() / 4, imp.getHeight() / 4, 3 * imp.getHeight() / 4, 3 * imp.getHeight() / 4 }; } p = new Point[]{ new Point( new double[]{ x[ 0 ], y[ 0 ] } ), new Point( new double[]{ x[ 1 ], y[ 1 ] } ), new Point( new double[]{ x[ 2 ], y[ 2 ] } ), new Point( new double[]{ x[ 3 ], y[ 3 ] } ) }; q = new Point[]{ p[ 0 ].clone(), p[ 1 ].clone(), p[ 2 ].clone(), p[ 3 ].clone() }; m.add( new PointMatch( p[ 0 ], q[ 0 ] ) ); m.add( new PointMatch( p[ 1 ], q[ 1 ] ) ); m.add( new PointMatch( p[ 2 ], q[ 2 ] ) ); m.add( new PointMatch( p[ 3 ], q[ 3 ] ) ); handles = new PointRoi( x, y, 4 ); imp.setRoi( handles ); }
PolygonRoi trimPolygon(PolygonRoi roi, double length) { int[] x = roi.getXCoordinates(); int[] y = roi.getYCoordinates(); int n = roi.getNCoordinates(); x = smooth(x, n); y = smooth(y, n);
PolygonRoi trimPolygon(PolygonRoi roi, double length) { int[] x = roi.getXCoordinates(); int[] y = roi.getYCoordinates(); int n = roi.getNCoordinates(); x = smooth(x, n); y = smooth(y, n);
public void mark(int slice, int distance) { image.setPosition(slice); if (distance < 0) { unmark(); return; } PolygonRoi roi = rois[slice - 1]; if (roi == null) { image.killRoi(); return; } image.setRoi(roi); roi = (PolygonRoi)roi.clone(); roi.fitSplineForStraightening(); if (distance >= roi.getNCoordinates()) { unmark(); return; } Rectangle bounds = roi.getBounds(); int x = roi.getXCoordinates()[distance] + bounds.x; int y = roi.getYCoordinates()[distance] + bounds.y; Overlay overlay = new Overlay(new OvalRoi(x - 10, y - 10, 21, 21)); image.setOverlay(overlay); }
roi.setFillColor(defaultRoi.getFillColor()); boolean points = roi instanceof PointRoi && ((PolygonRoi)roi).getNCoordinates()>1; if (points) roi.setStrokeColor(Color.red); roi.setPosition(defaultRoi.getPosition());
roi.setFillColor(defaultRoi.getFillColor()); boolean points = roi instanceof PointRoi && ((PolygonRoi)roi).getNCoordinates()>1; if (points) roi.setStrokeColor(Color.red); roi.setPosition(defaultRoi.getPosition());
} else { Rectangle r = roi.getBounds(); int nPoints = ((PolygonRoi)roi).getNCoordinates(); int[] xp = ((PolygonRoi)roi).getXCoordinates(); int[] yp = ((PolygonRoi)roi).getYCoordinates();
boolean points = roi instanceof PointRoi && ((PolygonRoi)roi).getNCoordinates()>1; if (IJ.altKeyDown() || (IJ.macroRunning() && Macro.getOptions()!=null)) { RoiProperties rp = new RoiProperties("Add to Overlay", roi);