filterMenu.addSeparator();
JMenuItem removeMarkedVoxels = new JMenuItem("Remove marked");
removeMarkedVoxels.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Stack activeVolume = getCurrentView().getVolume();
disableMenus();
Thread r = new Thread() {
public void run() {
byte ff = (byte) 0xff;
int count = 0;
for (int z = 0; z < activeVolume.getDepth(); z++) {
if (isStopped)
return;
setProgress(z);
short[] slice = activeVolume.getSlice(z);
for (int i = 0; i < slice.length; i++) {
if (slice[i] != 0 && slice[i] != ff) {
count++;
slice[i] = 0;
}
}
}
activeVolume.flush();
StringBuffer output = new StringBuffer();
output.append("Removed " + count + " voxels \n");
showResults(output, "Voxelcount");
enableMenus();
updateImage();
}
};
r.start();
}
});
JMenuItem removeSmallRegions = new JMenuItem("Remove small labeled regions");
removeSmallRegions.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread r = new Thread() {
public void run() {
String input = JOptionPane.showInputDialog(null, "Enter minmum regsize.", 100);
if (input == null) return;
int tval = Integer.parseInt(input);
setLabel("Creating histogram...");
long[] histo = new long[MAX_FIBERS + 256];
for (int z = 0; z < volume.getDepth(); z++) {
setProgress(z);
short[] slice = volume.getSlice(z);
for (short aSlice : slice) {
histo[aSlice]++;
}
}
setLabel("Removing regions");
for (int z = 0; z < volume.getDepth(); z++) {
setProgress(z);
short[] slice = volume.getSlice(z);
for (int i = 0; i < slice.length; i++) {
if (histo[slice[i]] < tval) slice[i] = 0;
}
}
enableMenus();
updateImage();
}
};
disableMenus();
r.start();
}
});
JMenuItem removeUnmarkedVoxels = new JMenuItem("Remove unlabeled");
removeUnmarkedVoxels.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Stack activeVolume = getCurrentView().getVolume();
disableMenus();
Thread r = new Thread() {
public void run() {
int count = 0;
for (int z = 0; z < activeVolume.getDepth(); z++) {
if (isStopped)
return;
setProgress(z);
short[] slice = activeVolume.getSlice(z);
for (int i = 0; i < slice.length; i++) {
if (slice[i] == 255) {
count++;
slice[i] = 0;
}
}
}
activeVolume.flush();
StringBuffer output = new StringBuffer();
output.append("Removed " + count + " voxels \n");
showResults(output, "Voxelcount");
enableMenus();
updateImage();
}
};
r.start();
}
});
JMenuItem resetMarkedVoxels = new JMenuItem("Remove colors");
resetMarkedVoxels.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Stack activeVolume = getCurrentView().getVolume();
disableMenus();
Thread r = new Thread() {
public void run() {
byte ff = (byte) 0xff;
int count = 0;
for (int z = 0; z < activeVolume.getDepth(); z++) {
setProgress(z);
short[] slice = activeVolume.getSlice(z);
for (int i = 0; i < slice.length; i++) {
if (slice[i] != 0 && slice[i] != ff) {
count++;
slice[i] = 0;
}
}
}
activeVolume.flush();
StringBuffer output = new StringBuffer();
output.append("Reset " + count + " voxels \n");
showResults(output, "Voxelcount");
enableMenus();
updateImage();
}
};
r.start();
}
});
JMenuItem resetLabels = new JMenuItem("Reset labels");
resetMarkedVoxels.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Stack activeVolume = getCurrentView().getVolume();
disableMenus();
Thread r = new Thread() {
public void run() {
int count = 0;
for (int z = 0; z < activeVolume.getDepth(); z++) {
setProgress(z);
short[] slice = activeVolume.getSlice(z);
for (int i = 0; i < slice.length; i++) {
if (slice[i] != 0) {
count++;
slice[i] = 255;
}
}
}
activeVolume.flush();
StringBuffer output = new StringBuffer();
output.append("Reset " + count + " voxels \n");
showResults(output, "Voxelcount");
enableMenus();
updateImage();
}
};
r.start();
}
});
filterMenu.add(removeMarkedVoxels);
filterMenu.add(removeUnmarkedVoxels);
filterMenu.add(resetMarkedVoxels);
filterMenu.add(resetLabels);
filterMenu.addSeparator();
filterMenu.add(removeSmallRegions);
filterMenu.addSeparator();
flipItem.addActionListener(this);
filterMenu.add(flipItem);
helpMenu.setMnemonic('h');
JMenuItem pluginItem = new JMenuItem("Installed Plugins");
pluginItem.addActionListener(this);
helpMenu.add(pluginItem);
JMenuItem aboutItem = new JMenuItem("About");
aboutItem.addActionListener(this);
helpMenu.add(aboutItem);
JMenu editMenu = new JMenu("Edit");
editMenu.setMnemonic('e');
JMenuItem undoItem = new JMenuItem("Undo");
JMenuItem preferencesItem = new JMenuItem("Preferences...");
preferencesItem.setMnemonic('p');
undoItem.setEnabled(false);
editMenu.add(undoItem);
editMenu.add(preferencesItem);
JMenuItem reloadItem = new JMenuItem("Reload stack");
reloadItem.setMnemonic('r');
reloadItem.setAccelerator(KeyStroke.getKeyStroke('r'));
reloadItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Thread r = new Thread() {
public void run() {
loadStack();
}
};
r.start();
}
});
editMenu.add(reloadItem);
preferencesItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
preferences = new ThebaPrefs(mainWindow);
preferences.setVisible(true);
}
});
analyzeMenu = new JMenu("Analyze");
analyzeMenu.setMnemonic('a');
JMenuItem fiberMenu = new JMenu("Region measurements");
JMenuItem measureAllItem = new JMenuItem("Perform all");
if (descriptors != null) {
for (final RegionDescriptor d : descriptors) {
if (d.does3D()) {
JMenuItem item = new JMenuItem("Measure :" + d.getName());
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Stack volume = getCurrentView().getVolume();
disableMenus();
Thread r = new Thread() {
public void run() {
setLabel("Counting regions...");
StringBuffer buf = new StringBuffer("Bounding regions...");