1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
package ij.plugin;
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import java.awt.event.*;
/** Implements the Analyze/Plot Profile and Edit/Options/Profile Plot Options commands. */
public class Profiler implements PlugIn, PlotMaker {
ImagePlus imp;
boolean firstTime = true;
boolean plotVertically;
public void run(String arg) {
if (arg.equals("set"))
{doOptions(); return;}
imp = IJ.getImage();
if (firstTime)
plotVertically = Prefs.verticalProfile || IJ.altKeyDown();
Plot plot = getPlot();
firstTime = false;
if (plot==null)
return;
plot.setPlotMaker(this);
plot.show();
}
public Plot getPlot() {
Roi roi = imp.getRoi();
if (roi==null || !(roi.isLine()||roi.getType()==Roi.RECTANGLE)) {
if (firstTime)
IJ.error("Plot Profile", "Line or rectangular selection required");
return null;
}
ProfilePlot pp = new ProfilePlot(imp, plotVertically);
return pp.getPlot();
}
public ImagePlus getSourceImage() {
return imp;
}
public void doOptions() {
double ymin = ProfilePlot.getFixedMin();
double ymax = ProfilePlot.getFixedMax();
boolean fixedScale = ymin!=0.0 || ymax!=0.0;
boolean wasFixedScale = fixedScale;
GenericDialog gd = new GenericDialog("Plot Options");
gd.addNumericField("Width:", PlotWindow.plotWidth, 0);
gd.addNumericField("Height:", PlotWindow.plotHeight, 0);
gd.addNumericField("Font Size:", PlotWindow.fontSize, 0);
gd.setInsets(5,20,0); //distance to previous
gd.addCheckbox("Draw grid lines", !PlotWindow.noGridLines);
gd.addCheckbox("Draw_ticks", !PlotWindow.noTicks);
gd.addCheckbox("Auto-close", PlotWindow.autoClose);
gd.addCheckbox("List values", PlotWindow.listValues);
gd.setInsets(15,0,0);
gd.addMessage("--------Profile Plot Options--------");
gd.setInsets(5,20,0);
gd.addCheckbox("Fixed y-axis scale", fixedScale);
gd.addNumericField("Minimum Y:", ymin, 2);
gd.addNumericField("Maximum Y:", ymax, 2);
gd.setInsets(10,20,0);
gd.addCheckbox("Vertical profile", Prefs.verticalProfile);
gd.addCheckbox("Interpolate line profiles", PlotWindow.interpolate);
gd.addCheckbox("Sub-pixel resolution", Prefs.subPixelResolution);
gd.addHelp(IJ.URL+"/docs/menus/edit.html#plot-options");
gd.showDialog();
if (gd.wasCanceled())
return;
int w = (int)gd.getNextNumber();
int h = (int)gd.getNextNumber();
if (w<Plot.MIN_FRAMEWIDTH) w = Plot.MIN_FRAMEWIDTH;
if (h<Plot.MIN_FRAMEHEIGHT) h = Plot.MIN_FRAMEHEIGHT;
if (!gd.invalidNumber()) {
PlotWindow.plotWidth = w;
PlotWindow.plotHeight = h;
}
int fontSize = (int)gd.getNextNumber();
if (fontSize < 9) fontSize = 9;
if (fontSize > 28) fontSize = 28;
if (!gd.invalidNumber())
PlotWindow.fontSize = fontSize;
PlotWindow.noGridLines = !gd.getNextBoolean();
PlotWindow.noTicks = !gd.getNextBoolean();
//data options
PlotWindow.autoClose = gd.getNextBoolean();
PlotWindow.listValues = gd.getNextBoolean();
//profile plot options
fixedScale = gd.getNextBoolean();
ymin = gd.getNextNumber();
ymax = gd.getNextNumber();
//profile options
Prefs.verticalProfile = gd.getNextBoolean();
PlotWindow.interpolate = gd.getNextBoolean();
Prefs.subPixelResolution = gd.getNextBoolean();
if (!fixedScale && !wasFixedScale && (ymin!=0.0 || ymax!=0.0))
fixedScale = true;
if (!fixedScale) {
ymin = 0.0;
ymax = 0.0;
} else if (ymin>ymax) {
double tmp = ymin;
ymin = ymax;
ymax = tmp;
}
ProfilePlot.setMinAndMax(ymin, ymax);
IJ.register(Profiler.class);
}
}
|