Hi-
My plugin generates numerous plotWindows that eventually take over the screen. Is there an easy way to have each new plotWindow placed into a stack? I figure that would keep it nice and clean, but have been struggling on writing the java to make this happen. Thanks, Mike |
Mike,
> My plugin generates numerous plotWindows that eventually take over the > screen. Is there an easy way to have each new plotWindow placed into > a stack? PlotWindow is an extended ImageWindow, thus you can call getImagePlus().getProcessor() on it. So to make a stack: PlotWindow[] pw = .... ImageProcessor ip = pw[0].getImagePlus().getProcessor(); int w = ip.getWidth(); int h = ip.getHeight(); ImageStack stack = new ImageStack(w, h); stack.addSlice("plotwindow 1", ip); // the first one // start at the second one, index 1 for (int i=1; i<pw.length; i++) { stack.addSlice("plotwindow" + (i+1), pw[i].getImagePlus().getProcessor()); } new ImagePlus("All PlotWindows", stack).show(); -- Albert Cardona http://www.mcdb.ucla.edu/Research/Hartenstein/acardona |
Albert Cardona wrote:
> Mike, > > >> My plugin generates numerous plotWindows that eventually take over the >> screen. Is there an easy way to have each new plotWindow placed into >> a stack? > > > PlotWindow is an extended ImageWindow, thus you can call > getImagePlus().getProcessor() on it. So to make a stack: > > > PlotWindow[] pw = .... > > ImageProcessor ip = pw[0].getImagePlus().getProcessor(); > int w = ip.getWidth(); > int h = ip.getHeight(); > > ImageStack stack = new ImageStack(w, h); > stack.addSlice("plotwindow 1", ip); // the first one > > // start at the second one, index 1 > for (int i=1; i<pw.length; i++) { > stack.addSlice("plotwindow" + (i+1), > pw[i].getImagePlus().getProcessor()); > } > > > new ImagePlus("All PlotWindows", stack).show(); > > Thank you for the help. However, I dont think this way will work for me, because the plots are not generated all at once. The following class is in the plugin and is used to plot the results. As I use the plugin multiple times I wind up with numerous "PSD Sum" windows, but they are not all generated at one time. public void PSDPlot(float[] PSD){ float[] frequency = new float[PSD.length]; for (int i=0; i<frequency.length; i++) frequency[i] = frequency(i,frequency.length); PlotWindow psdSumPlot = new PlotWindow("PSD Sum","CBF","PSD", frequency, PSD); psdSumPlot.draw(); } I am pretty new with java and have been hacking my way through... I appreciate the help, Mike |
> Thank you for the help. However, I dont think this way will work for
> me, because the plots are not generated all at once. The following > class is in the plugin and is used to plot the results. As I use the > plugin multiple times I wind up with numerous "PSD Sum" windows, but > they are not all generated at one time. You have then several options. 1) reshape your code so that you can capture them or: 2) scan WindowManager for windows that are instances of PlotWindow. For example: int[] ids = WindowManager.getIDList(); for (int i=0; i<ids.length; i++) { ImagePlus imp = WindowManager.getImage(ids[i]); if (imp.getWindow() instanceof PlotWindow) { // Add this window to the list of PlotWindow to put into a stack // ... } } Ideally you'd run this when done generating all. Albert -- Albert Cardona http://www.mcdb.ucla.edu/Research/Hartenstein/acardona |
Albert Cardona wrote:
>> Thank you for the help. However, I dont think this way will work for >> me, because the plots are not generated all at once. The following >> class is in the plugin and is used to plot the results. As I use the >> plugin multiple times I wind up with numerous "PSD Sum" windows, but >> they are not all generated at one time. > > > > You have then several options. > > 1) reshape your code so that you can capture them > > or: > > 2) scan WindowManager for windows that are instances of PlotWindow. For > example: > > > int[] ids = WindowManager.getIDList(); > for (int i=0; i<ids.length; i++) { > ImagePlus imp = WindowManager.getImage(ids[i]); > if (imp.getWindow() instanceof PlotWindow) { > // Add this window to the list of PlotWindow to put into a stack > // ... > } > } > > > Ideally you'd run this when done generating all. > > Albert > Thanks for the suggestions- I think that I am getting closer. I added this to the routine and created a static psdStack. ImageProcessor ip = psdSumPlot.getImagePlus().getProcessor(); if (psdStack.getSize() == 0) { psdStack.addSlice("plotwindow 1", ip); // the first one new ImagePlus("All PlotWindows", psdStack).show(); } else psdStack.addSlice("plotwindow 1", ip); The first image gets placed in the stack and when it runs the next time nothing happens. I assume that the slice is added, but the ImagePlus is not refreshed. Is there a way to make the ImagePlus update itself? Thanks, Mike |
Free forum by Nabble | Edit this page |