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

Method interpolate

ij/src/main/java/ij/plugin/Selection.java:296–357  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

294 }
295
296 void interpolate() {
297 Roi roi = imp.getRoi();
298 if (roi==null)
299 {noRoi("Interpolate"); return;}
300 if (roi.getType()==Roi.POINT)
301 return;
302 if (IJ.isMacro()&&Macro.getOptions()==null)
303 Macro.setOptions("interval=1");
304 GenericDialog gd = new GenericDialog("Interpolate");
305 gd.addNumericField("Interval:", 1.0, 1, 4, "pixel");
306 gd.addCheckbox("Smooth", IJ.isMacro()?false:smooth);
307 gd.addCheckbox("Adjust interval to match", IJ.isMacro()?false:adjust);
308 gd.showDialog();
309 if (gd.wasCanceled())
310 return;
311 double interval = gd.getNextNumber();
312 smooth = gd.getNextBoolean();
313 Undo.setup(Undo.ROI, imp);
314 adjust = gd.getNextBoolean();
315 int sign = adjust ? -1 : 1;
316 Roi newRoi = null;
317 if (roi instanceof ShapeRoi && ((ShapeRoi)roi).getRois().length>1) {
318 // handle composite roi, thanks to Michael Ellis
319 Roi[] rois = ((ShapeRoi) roi).getRois();
320 ShapeRoi newShapeRoi = null;
321 for (Roi roi2 : rois) {
322 FloatPolygon fPoly = roi2.getInterpolatedPolygon(interval,smooth);
323 PolygonRoi polygon = new PolygonRoi(fPoly,PolygonRoi.POLYGON);
324 if (newShapeRoi==null) // First Roi is the outer boundary
325 newShapeRoi = new ShapeRoi(polygon);
326 else {
327 // Assume subsequent Rois are holes to be subtracted
328 ShapeRoi tempRoi = new ShapeRoi(polygon);
329 tempRoi.not(newShapeRoi);
330 newShapeRoi = tempRoi;
331 }
332 }
333 newRoi = newShapeRoi;
334 } else {
335 FloatPolygon poly = roi.getInterpolatedPolygon(sign*interval, smooth);
336 int t = roi.getType();
337 int type = roi.isLine()?Roi.FREELINE:Roi.FREEROI;
338 if (t==Roi.POLYGON && interval>1.0)
339 type = Roi.POLYGON;
340 if ((t==Roi.RECTANGLE||t==Roi.OVAL||t==Roi.FREEROI) && interval>=8.0)
341 type = Roi.POLYGON;
342 if ((t==Roi.LINE||t==Roi.FREELINE) && interval>=8.0)
343 type = Roi.POLYLINE;
344 if (t==Roi.POLYLINE && interval>=8.0)
345 type = Roi.POLYLINE;
346 ImageCanvas ic = imp.getCanvas();
347 if (poly.npoints<=150 && ic!=null && ic.getMagnification()>=12.0)
348 type = roi.isLine()?Roi.POLYLINE:Roi.POLYGON;
349 newRoi = new PolygonRoi(poly,type);
350 }
351 if (roi.getStroke()!=null)
352 newRoi.setStrokeWidth(roi.getStrokeWidth());
353 newRoi.setStrokeColor(roi.getStrokeColor());

Callers 1

runMethod · 0.95

Calls 15

noRoiMethod · 0.95
getTypeMethod · 0.95
isMacroMethod · 0.95
getOptionsMethod · 0.95
setOptionsMethod · 0.95
addNumericFieldMethod · 0.95
addCheckboxMethod · 0.95
showDialogMethod · 0.95
wasCanceledMethod · 0.95
getNextNumberMethod · 0.95
getNextBooleanMethod · 0.95
setupMethod · 0.95

Tested by

no test coverage detected