Dear Listpeople:
I am working on a plugin for quality assurance on dental cone beam CT. For this I need to scroll trough a stack. But I also need some more control items like buttons so I have to make my own layout. I managed to get the stack loadet and the beginning image shown, add a working scrollbar. But the image on the ImageCanvas is never updated. I did some search and looked at some source, but cannot solve the problem. I have tried to call all kinds of update to the ImagePlus, ImageCanvas and so on, without success. The slicenumber is set correct to the ImagePlus object, but the canvas is not updated. Happy for any sugestions. Code (extract): import ij.*; import ij.plugin.frame.*; import ij.plugin.FolderOpener; import ij.gui.GenericDialog; import ij.gui.ImageCanvas; import ij.gui.ImageWindow; import ij.io.DirectoryChooser; import java.awt.*; import java.awt.event.*; public class Test extends PlugInFrame implements AdjustmentListener{ private Scrollbar sliceSelector; private Panel stackPanel; private ImagePlus imp; public Test() { super("Test"); FolderOpener fo = new FolderOpener(); imp = fo.open("some directory containing stack images"); int stackSize = imp.getStackSize(); Panel mainWindow = new Panel(); mainWindow.setLayout(new BorderLayout()); // The stack: stackPanel = new Panel(); stackPanel.setLayout(new BorderLayout()); ImageCanvas imageCanvas = new ImageCanvas(imp); imageCanvas.setVisible(true); stackPanel.add(imageCanvas, BorderLayout.CENTER); // The scrollbar sliceSelector = new Scrollbar(); sliceSelector.addAdjustmentListener(this); sliceSelector.setFocusable(false); sliceSelector.setMinimum(1); sliceSelector.setMaximum(stackSize + 1); sliceSelector.setOrientation(Scrollbar.HORIZONTAL); sliceSelector.setVisible(true); stackPanel.add(sliceSelector, BorderLayout.SOUTH); add(stackPanel); setSize(512, 512); setVisible(true); } public synchronized void adjustmentValueChanged(AdjustmentEvent e) { int z = sliceSelector.getValue(); int slice = imp.getCurrentSlice(); IJ.log("Slicenr: " + slice); imp.setSlice(z); } } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Gerald,
The ImagePlus updates its canvas via the ImageWindow. Since your ImagePlus is still associated with its original ImageWindow, only that canvas gets updated. The easiest way to implement stack scrolling control with added buttons is to create a GenericDialog with a slider and utilize the dialog listener to catch its updates and reflect them in the original stack. You could also listen to the original stack's slider updates with the image listener interface from essentially any frame. If you really want to completely reimplement the display, the easiest way is to extend the ImageWindow class like the PlotWindow does. I created a scrollable PlotWindow stack that is similar to what you are trying to do for my plotting utility: http://research.stowers.org/imagejplugins/Jay_Plugins_HTML_source/jguis/PlotStack4.java.html. Jay -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Gerald Torgersen Sent: Friday, April 12, 2013 6:52 AM To: [hidden email] Subject: Scrolling trough a stack without StackWindow Dear Listpeople: I am working on a plugin for quality assurance on dental cone beam CT. For this I need to scroll trough a stack. But I also need some more control items like buttons so I have to make my own layout. I managed to get the stack loadet and the beginning image shown, add a working scrollbar. But the image on the ImageCanvas is never updated. I did some search and looked at some source, but cannot solve the problem. I have tried to call all kinds of update to the ImagePlus, ImageCanvas and so on, without success. The slicenumber is set correct to the ImagePlus object, but the canvas is not updated. Happy for any sugestions. Code (extract): import ij.*; import ij.plugin.frame.*; import ij.plugin.FolderOpener; import ij.gui.GenericDialog; import ij.gui.ImageCanvas; import ij.gui.ImageWindow; import ij.io.DirectoryChooser; import java.awt.*; import java.awt.event.*; public class Test extends PlugInFrame implements AdjustmentListener{ private Scrollbar sliceSelector; private Panel stackPanel; private ImagePlus imp; public Test() { super("Test"); FolderOpener fo = new FolderOpener(); imp = fo.open("some directory containing stack images"); int stackSize = imp.getStackSize(); Panel mainWindow = new Panel(); mainWindow.setLayout(new BorderLayout()); // The stack: stackPanel = new Panel(); stackPanel.setLayout(new BorderLayout()); ImageCanvas imageCanvas = new ImageCanvas(imp); imageCanvas.setVisible(true); stackPanel.add(imageCanvas, BorderLayout.CENTER); // The scrollbar sliceSelector = new Scrollbar(); sliceSelector.addAdjustmentListener(this); sliceSelector.setFocusable(false); sliceSelector.setMinimum(1); sliceSelector.setMaximum(stackSize + 1); sliceSelector.setOrientation(Scrollbar.HORIZONTAL); sliceSelector.setVisible(true); stackPanel.add(sliceSelector, BorderLayout.SOUTH); add(stackPanel); setSize(512, 512); setVisible(true); } public synchronized void adjustmentValueChanged(AdjustmentEvent e) { int z = sliceSelector.getValue(); int slice = imp.getCurrentSlice(); IJ.log("Slicenr: " + slice); imp.setSlice(z); } } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Gerald Torgersen
Hi Jay,
thank you for your suggestion. I have already tried to subclass StackWindow. But anyway, I tried with subclassing ImageWindow, but i was not working well. But then I took a closer look at how ImageWindow is updating the canvas and found a solution just by adding a few commands, now the method looks like, and everything works well public synchronized void adjustmentValueChanged(AdjustmentEvent e) { int z = sliceSelector.getValue(); int slice = imp.getCurrentSlice(); IJ.log("Slicenr: " + slice); imp.setSlice(z); imageCanvas.setImageUpdated(); imageCanvas.repaint(); } So that works. The problem now is that the ROI's set by the ROI-manager in the imp are noe shown. I think that is because the ROI-manager is working on the "current window". Anybody has any idea how I can show 4 ROI's on my imp (which is not living in an ImageWindow, but only on an ImageCanvas? Regards Gerald -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi group,
now I managed it. Here is the very simple solution to change the layout of the ImageWindow, I don't know what I did wrong before, but now it works: class IW extends ImageWindow implements AdjustmentListener{ private Scrollbar sliceSelector; public IW(ImagePlus imp) { super(imp); remove(ic); // remove the canvas in order to add it again with the new LayoutManager setLayout(new BorderLayout()); add(ic, BorderLayout.CENTER); // The scrollbar int stackSize = imp.getStackSize(); sliceSelector = new Scrollbar(); sliceSelector.addAdjustmentListener(this); sliceSelector.setFocusable(false); sliceSelector.setMinimum(1); sliceSelector.setMaximum(stackSize + 1); sliceSelector.setOrientation(Scrollbar.HORIZONTAL); sliceSelector.setVisible(true); add(sliceSelector, BorderLayout.SOUTH); setVisible(true); } public synchronized void adjustmentValueChanged(AdjustmentEvent e) { int z = sliceSelector.getValue(); imp.setSlice(z); } } Kind regards Gerald -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |