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

Method run

ij/src/main/java/ij/plugin/filter/ScaleDialog.java:37–133  ·  view source on GitHub ↗
(ImageProcessor ip)

Source from the content-addressed store, hash-verified

35 }
36
37 public void run(ImageProcessor ip) {
38 double measured = 0.0;
39 double known = 0.0;
40 double aspectRatio = 1.0;
41 String unit = "pixel";
42 boolean global1 = imp.getGlobalCalibration()!=null;
43 boolean global2;
44 Calibration cal = imp.getCalibration();
45 Calibration calOrig = cal.copy();
46 boolean isCalibrated = cal.scaled();
47 String length = "0.00";
48
49 String scale = "<no scale>";
50 int digits = 2;
51 Roi roi = imp.getRoi();
52 if (roi!=null) {
53 if (roi instanceof Line) {
54 measured = ((Line)roi).getRawLength();
55 length = IJ.d2s(measured, 2);
56 } else if (roi.getType()==Roi.RECTANGLE) {
57 Rectangle2D r = roi.getFloatBounds();
58 measured = Math.max(r.getWidth(),r.getHeight());
59 length = IJ.d2s(measured, 2);
60 }
61 }
62
63 if (isCalibrated) {
64 if (measured!=0.0)
65 known = measured*cal.pixelWidth;
66 else {
67 measured = 1.0/cal.pixelWidth;
68 known = 1.0;
69 }
70 double dscale = measured/known;
71 digits = Tools.getDecimalPlaces(dscale);
72 unit = cal.getUnit();
73 scale = IJ.d2s(dscale, digits)+" pixels/"+unit;
74 aspectRatio = cal.pixelHeight/cal.pixelWidth;
75 }
76
77 digits = Tools.getDecimalPlaces(measured);
78 int asDigits = aspectRatio==1.0?1:3;
79 SetScaleDialog gd = new SetScaleDialog("Set Scale", scale, length);
80 gd.addNumericField("Distance in pixels:", measured, digits, 8, null);
81 gd.addNumericField("Known distance:", known, 2, 8, null);
82 gd.addNumericField("Pixel aspect ratio:", aspectRatio, asDigits, 8, null);
83 gd.addStringField("Unit of length:", unit);
84 gd.addPanel(makeButtonPanel(gd), GridBagConstraints.EAST, new Insets(5, 0, 0, 0));
85 gd.setInsets(0, 30, 0);
86 gd.addCheckbox("Global", global1);
87 gd.setInsets(10, 0, 0);
88 gd.addMessage("Scale: "+"12345.789 pixels per centimeter");
89 gd.addHelp(IJ.URL2+"/docs/menus/analyze.html#scale");
90 gd.showDialog();
91 if (gd.wasCanceled())
92 return;
93 measured = gd.getNextNumber();
94 known = gd.getNextNumber();

Callers

nothing calls this directly

Calls 15

copyMethod · 0.95
scaledMethod · 0.95
d2sMethod · 0.95
getTypeMethod · 0.95
getFloatBoundsMethod · 0.95
getDecimalPlacesMethod · 0.95
getUnitMethod · 0.95
makeButtonPanelMethod · 0.95
setUnitMethod · 0.95
macroRunningMethod · 0.95
equalsMethod · 0.95
repaintImageWindowsMethod · 0.95

Tested by

no test coverage detected