MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / run

Method run

ij/src/main/java/ij/plugin/XY_Reader.java:16–56  ·  view source on GitHub ↗
(String arg)

Source from the content-addressed store, hash-verified

14public 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}

Callers

nothing calls this directly

Calls 15

openMethod · 0.95
getWidthMethod · 0.95
getHeightMethod · 0.95
showMessageMethod · 0.95
getfMethod · 0.95
toIntRMethod · 0.95
getBoundingRectMethod · 0.95
getCurrentImageMethod · 0.95
getWidthMethod · 0.95
getHeightMethod · 0.95
getNameMethod · 0.95
setRoiMethod · 0.95

Tested by

no test coverage detected