(PolygonRoi roi, double length)
| 366 | } |
| 367 | |
| 368 | PolygonRoi trimPolygon(PolygonRoi roi, double length) { |
| 369 | int[] x = roi.getXCoordinates(); |
| 370 | int[] y = roi.getYCoordinates(); |
| 371 | int n = roi.getNCoordinates(); |
| 372 | x = smooth(x, n); |
| 373 | y = smooth(y, n); |
| 374 | float[] curvature = getCurvature(x, y, n); |
| 375 | Rectangle r = roi.getBounds(); |
| 376 | double threshold = rodbard(length); |
| 377 | double distance = Math.sqrt((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0])); |
| 378 | x[0] += r.x; y[0]+=r.y; |
| 379 | int i2 = 1; |
| 380 | int x1,y1,x2=0,y2=0; |
| 381 | for (int i=1; i<n-1; i++) { |
| 382 | x1=x[i]; y1=y[i]; x2=x[i+1]; y2=y[i+1]; |
| 383 | distance += Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) + 1; |
| 384 | distance += curvature[i]*2; |
| 385 | if (distance>=threshold) { |
| 386 | x[i2] = x2 + r.x; |
| 387 | y[i2] = y2 + r.y; |
| 388 | i2++; |
| 389 | distance = 0.0; |
| 390 | } |
| 391 | } |
| 392 | int type = roi.getType()==Roi.FREELINE?Roi.POLYLINE:Roi.POLYGON; |
| 393 | if (type==Roi.POLYLINE && distance>0.0) { |
| 394 | x[i2] = x2 + r.x; |
| 395 | y[i2] = y2 + r.y; |
| 396 | i2++; |
| 397 | } |
| 398 | PolygonRoi p = new PolygonRoi(x, y, i2, type); |
| 399 | if (roi.getStroke()!=null) |
| 400 | p.setStrokeWidth(roi.getStrokeWidth()); |
| 401 | p.setStrokeColor(roi.getStrokeColor()); |
| 402 | p.setName(roi.getName()); |
| 403 | imp.setRoi(p); |
| 404 | return p; |
| 405 | } |
| 406 | |
| 407 | double rodbard(double x) { |
| 408 | // y = c*((a-x/(x-d))^(1/b) |
no test coverage detected