1 package com.github.celldynamics.quimp;
2
3 import java.awt.Polygon;
4 import java.io.File;
5
6 import com.github.celldynamics.quimp.geom.ExtendedVector2d;
7
8 import ij.IJ;
9 import ij.ImagePlus;
10 import ij.WindowManager;
11 import ij.gui.Overlay;
12 import ij.gui.PolygonRoi;
13 import ij.gui.Roi;
14 import ij.measure.Measurements;
15 import ij.plugin.PlugIn;
16 import ij.process.ImageProcessor;
17 import ij.process.ImageStatistics;
18
19
20
21
22 @Deprecated
23 public class Test_QuimP implements PlugIn {
24
25 private static final int m =
26 Measurements.AREA + Measurements.INTEGRATED_DENSITY + Measurements.MEAN;
27
28
29
30
31
32
33 @Override
34 public void run(String arg) {
35
36
37 testLineIntersect();
38
39
40
41
42
43
44 }
45
46
47
48
49 void testArea() {
50 ImagePlus imp = WindowManager.getCurrentImage();
51 if (imp == null) {
52 IJ.noImage();
53 return;
54 }
55
56 imp.setSlice(1);
57 ImageProcessor impProc = imp.getProcessor();
58
59 Polygon outerPoly = new Polygon();
60 outerPoly.addPoint(11, 11);
61 outerPoly.addPoint(11, 110);
62 outerPoly.addPoint(110, 11);
63
64 Polygon innerPoly = new Polygon();
65 innerPoly.addPoint(110, 110);
66 innerPoly.addPoint(140, 120);
67 innerPoly.addPoint(60, 130);
68
69 PolygonRoi outerRoi = new PolygonRoi(outerPoly, Roi.POLYGON);
70 impProc.setRoi(outerRoi);
71
72 ImageStatistics is = ImageStatistics.getStatistics(impProc, m, null);
73
74 System.out.println("Area=" + is.area + ", mean=" + is.mean);
75
76
77
78
79
80
81
82
83
84
85 }
86
87
88
89
90 void testAngle() {
91
92 Vert a, b, c;
93
94 a = new Vert(10, 10, 1);
95 b = new Vert(15, 15, 2);
96 c = new Vert(10, 15, 3);
97
98 ExtendedVector2d edge1 = ExtendedVector2d.vecP2P(b.getPoint(), a.getPoint());
99
100 ExtendedVector2d edge2 = ExtendedVector2d.vecP2P(b.getPoint(), c.getPoint());
101
102 double curvature = ExtendedVector2d.angle(edge1, edge2) * (180 / Math.PI);
103
104 System.out.println("curv = " + curvature);
105 }
106
107
108
109
110
111
112 void testQparams() throws QuimpException {
113 QParams p =
114 new QParams(new File("/Users/rtyson/Documents/phd/tmp/smallStack/SmallStack_0.paQP"));
115 p.readParams();
116 System.out.println("" + p.nmax);
117 System.out.println("" + p.getPath());
118 System.out.println("" + p.getFileName());
119 System.out.println("" + p.getConvexFile());
120
121
122
123
124 }
125
126
127
128
129 void testOverlay() {
130
131 ImagePlus imp = IJ.getImage();
132
133 PolygonRoi roiP = (PolygonRoi) imp.getRoi();
134
135 Polygon p = roiP.getPolygon();
136 Polygon np = new Polygon();
137
138 float[] xf = new float[p.npoints];
139 float[] yf = new float[p.npoints];
140
141 for (int i = 0; i < p.npoints; i++) {
142 np.addPoint(p.xpoints[i] + 10, p.ypoints[i] + 10);
143 xf[i] = p.xpoints[i] + 10.4f;
144 yf[i] = p.ypoints[i] + 10.4f;
145 }
146
147 Overlay ov = new Overlay();
148 PolygonRoi intRoi = new PolygonRoi(np, Roi.POLYGON);
149
150 ov.add(intRoi);
151
152 imp.setOverlay(ov);
153
154
155
156 }
157
158 private void testLineIntersect() {
159 System.out.println("Test line intersection");
160
161
162
163
164
165
166 ExtendedVector2dm/ExtendedVector2d.html#ExtendedVector2d">ExtendedVector2d a = new ExtendedVector2d(238, 180);
167 ExtendedVector2dm/ExtendedVector2d.html#ExtendedVector2d">ExtendedVector2d b = new ExtendedVector2d(252, 179);
168
169 ExtendedVector2dm/ExtendedVector2d.html#ExtendedVector2d">ExtendedVector2d c = new ExtendedVector2d(248.217, 383);
170 ExtendedVector2dm/ExtendedVector2d.html#ExtendedVector2d">ExtendedVector2d d = new ExtendedVector2d(248.227, 395);
171
172 double[] intersect = new double[2];
173
174 int state = ExtendedVector2d.segmentIntersection(a.getX(), a.getY(), b.getX(), b.getY(),
175 c.getX(), c.getY(), d.getX(), d.getY(), intersect);
176 System.out.println("Sate: " + state);
177 if (state == -1) {
178 System.out.println("\nLines parallel");
179 System.out.println("close all;plot([" + a.getX() + "," + b.getX() + "],[" + a.getY() + ","
180 + b.getY() + "],'-ob');");
181 System.out.println("hold on; plot([" + c.getX() + "," + d.getX() + "],[" + c.getY() + ","
182 + d.getY() + "],'-or');");
183
184 } else if (state == -2) {
185 System.out.println("\nLines parallel and overlap");
186 System.out.println("close all;plot([" + a.getX() + "," + b.getX() + "],[" + a.getY() + ","
187 + b.getY() + "],'-ob');");
188 System.out.println("hold on; plot([" + c.getX() + "," + d.getX() + "],[" + c.getY() + ","
189 + d.getY() + "],'-or');");
190 System.out.println("plot(" + intersect[0] + "," + intersect[1] + ", 'og');");
191 } else if (state == 1) {
192 System.out.println("\nLines intersect at " + intersect[0] + ", " + intersect[1]);
193 System.out.println("close all;plot([" + a.getX() + "," + b.getX() + "],[" + a.getY() + ","
194 + b.getY() + "],'-ob');");
195 System.out.println("hold on; plot([" + c.getX() + "," + d.getX() + "],[" + c.getY() + ","
196 + d.getY() + "],'-or');");
197 System.out.println("plot(" + intersect[0] + "," + intersect[1] + ", 'og');");
198 }
199
200 }
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292 }