File: WandToolOptions.java

package info (click to toggle)
imagej 1.52j-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,604 kB
  • sloc: java: 120,017; sh: 279; xml: 161; makefile: 6
file content (79 lines) | stat: -rw-r--r-- 2,367 bytes parent folder | download | duplicates (4)
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
package ij.plugin;
import ij.*;
import ij.gui.*;
import ij.process.*;
import ij.io.*;
import ij.plugin.filter.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

/** This plugin implements the Edit/Options/Wand Tool command. */
public class WandToolOptions implements PlugIn, DialogListener {
	private static final String[] modes = {"Legacy", "4-connected", "8-connected"};
	private static String mode = modes[0];
	private static double tolerance;
	private ImagePlus imp;
	private boolean showCheckbox;
	private static int startx, starty;
	private static int ID;

 	public void run(String arg) {
 		imp = WindowManager.getCurrentImage();
 		Roi roi = imp!=null?imp.getRoi():null;
 		boolean selection = roi!=null && (roi.getType()==Roi.TRACED_ROI||roi.getType()==Roi.POLYGON);
 		if (imp==null || (ID!=0&&imp.getID()!=ID) || !selection)
 			startx = starty = 0;
 		ID = imp!=null?imp.getID():0;
 		double sliderMax = 255;
 		int depth = imp!=null?imp.getBitDepth():0;
 		if (depth==16 || depth==32) {
 			sliderMax = imp.getProcessor().getMax();
 			if (depth==32) sliderMax+=0.0000000001;
 		}
 		showCheckbox = imp!=null && depth!=24 && WindowManager.getFrame("Threshold")==null && !imp.isThreshold();
		GenericDialog gd = new GenericDialog("Wand Tool");
		gd.addSlider("Tolerance: ", 0, sliderMax, tolerance);
		gd.addChoice("Mode:", modes, mode);
		if (showCheckbox)
			gd.addCheckbox("Enable Thresholding", false);
		gd.addCheckbox("Smooth if thresholded", Prefs.smoothWand);
		if (showCheckbox) {
			gd.setInsets(2,0,0);
			gd.addMessage("Thresholded objects are traced and \"Tolerance\"\nis ignored when thresholding is enabled.");
		}
		gd.addDialogListener(this); 
		gd.showDialog();
	}
	
	public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
		if (gd.wasCanceled())
			return false;
		tolerance = gd.getNextNumber();
		mode = gd.getNextChoice();
		if (showCheckbox) {
			if (gd.getNextBoolean()) {
				imp.deleteRoi();
				IJ.run("Threshold...");
			}
		}
		Prefs.smoothWand = gd.getNextBoolean();
		if (startx>0||starty>0)
			IJ.doWand(startx, starty, tolerance, mode+(Prefs.smoothWand?" smooth":""));
		return true;
	}

	public static String getMode() {
		return mode;
	}

	public static double getTolerance() {
		return tolerance;
	}
	
	public static final void setStart(int x, int y) {
		startx = x;
		starty = y;
	}

}