(String arg)
| 14 | public class XY_Reader implements PlugIn { |
| 15 | |
| 16 | public void run(String arg) { |
| 17 | TextReader tr = new TextReader(); |
| 18 | ImageProcessor ip = tr.open(); |
| 19 | if (ip==null) |
| 20 | return; |
| 21 | int width = ip.getWidth(); |
| 22 | int height = ip.getHeight(); |
| 23 | if (width!=2 || height<3) { |
| 24 | IJ.showMessage("XY Reader", "Two column text file required"); |
| 25 | return; |
| 26 | } |
| 27 | float[] x = new float[height]; |
| 28 | float[] y = new float[height]; |
| 29 | boolean allIntegers = true; |
| 30 | double length = 0.0; |
| 31 | for (int i=0; i<height; i++) { |
| 32 | x[i] = ip.getf(0, i); |
| 33 | y[i] = ip.getf(1, i); |
| 34 | if ((int)x[i]!=x[i] || (int)y[i]!=y[i]) |
| 35 | allIntegers = false; |
| 36 | if (i>0) { |
| 37 | double dx = x[i] - x[i-1]; |
| 38 | double dy = y[i] - y[i-1]; |
| 39 | length += Math.sqrt(dx*dx+dy*dy); |
| 40 | } |
| 41 | } |
| 42 | Roi roi = null; |
| 43 | int type = length/x.length>10?Roi.POLYGON:Roi.FREEROI; |
| 44 | if (allIntegers) |
| 45 | roi = new PolygonRoi(Roi.toIntR(x), Roi.toIntR(y), height, type); |
| 46 | else |
| 47 | roi = new PolygonRoi(x, y, height, type); |
| 48 | Rectangle r = roi.getBoundingRect(); |
| 49 | ImagePlus imp = WindowManager.getCurrentImage(); |
| 50 | if (imp==null || imp.getWidth()<r.x+r.width || imp.getHeight()<r.y+r.height) { |
| 51 | new ImagePlus(tr.getName(), new ByteProcessor(Math.abs(r.x)+r.width+10, Math.abs(r.y)+r.height+10)).show(); |
| 52 | imp = WindowManager.getCurrentImage(); |
| 53 | } |
| 54 | if (imp!=null) |
| 55 | imp.setRoi(roi); |
| 56 | } |
| 57 | |
| 58 | } |
nothing calls this directly
no test coverage detected