ij.process.FloatPolygon Java Examples
The following examples show how to use
ij.process.FloatPolygon.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Path.java From SNT with GNU General Public License v3.0 | 6 votes |
private void addPolyLineToOverlay(final FloatPolygon p, final int z_position, final int roi_id, final Overlay overlay) { if (p.npoints > 0) { if (p.npoints == 1) { // create 1-pixel length lines for single points p.xpoints[0] -= 0.5f; p.ypoints[0] -= 0.5f; p.addPoint(p.xpoints[0] + 0.5f, p.ypoints[0] + 0.5f); } final PolygonRoi polyline = new PolygonRoi(p, Roi.FREELINE); polyline.enableSubPixelResolution(); // polyline.fitSplineForStraightening(); if (name == null) setDefaultName(); polyline.setStrokeColor(getColor()); polyline.setName(String.format(name + "-%04d-Z%d", roi_id, z_position)); polyline.setPosition(z_position + 1); // index 1 overlay.add(polyline); } }
Example #2
Source File: M.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** Copied from ImageJ's ij.gui.PolygonRoi.getInterpolatedPolygon, by Wayne Rasband and collaborators. * The reason I copied this method is that creating a new PolygonRoi just to get an interpolated polygon * processes the float[] arrays of the coordinates, subtracting the minimum x,y. Not only it is an extra * operation but it is also in place, altering data arrays. Fortunately FloatPolygon does not touch the arrays. */ final static public FloatPolygon createInterpolatedPolygon( final FloatPolygon p, final double interval, final boolean isLine) { final double length = p.getLength(isLine); final int npoints2 = (int)((length*1.2)/interval); final float[] xpoints2 = new float[npoints2]; final float[] ypoints2 = new float[npoints2]; xpoints2[0] = p.xpoints[0]; ypoints2[0] = p.ypoints[0]; int n=1, n2; final double inc = 0.01; double distance=0.0, distance2=0.0, dx=0.0, dy=0.0, xinc, yinc; double x, y, lastx, lasty, x1, y1, x2=p.xpoints[0], y2=p.ypoints[0]; int npoints = p.npoints; if (!isLine) npoints++; for (int i=1; i<npoints; i++) { x1=x2; y1=y2; x=x1; y=y1; if (i<p.npoints) { x2=p.xpoints[i]; y2=p.ypoints[i]; } else { x2=p.xpoints[0]; y2=p.ypoints[0]; } dx = x2-x1; dy = y2-y1; distance = Math.sqrt(dx*dx+dy*dy); xinc = dx*inc/distance; yinc = dy*inc/distance; lastx=xpoints2[n-1]; lasty=ypoints2[n-1]; //n2 = (int)(dx/xinc); n2 = (int)(distance/inc); if (npoints==2) n2++; do { dx = x-lastx; dy = y-lasty; distance2 = Math.sqrt(dx*dx+dy*dy); //IJ.log(i+" "+IJ.d2s(xinc,5)+" "+IJ.d2s(yinc,5)+" "+IJ.d2s(distance,2)+" "+IJ.d2s(distance2,2)+" "+IJ.d2s(x,2)+" "+IJ.d2s(y,2)+" "+IJ.d2s(lastx,2)+" "+IJ.d2s(lasty,2)+" "+n+" "+n2); if (distance2>=interval-inc/2.0 && n<xpoints2.length-1) { xpoints2[n] = (float)x; ypoints2[n] = (float)y; //IJ.log("--- "+IJ.d2s(x,2)+" "+IJ.d2s(y,2)+" "+n); n++; lastx=x; lasty=y; } x += xinc; y += yinc; } while (--n2>0); } return new FloatPolygon(xpoints2, ypoints2, n); }